using ScadaLink.Commons.Types; namespace ScadaLink.CentralUI.ScriptAnalysis; /// /// Runtime globals for an inbound API method Test Run. Mirrors /// 's public surface so the same user code that /// compiles for diagnostics also compiles against this type — but every /// Route accessor throws instead of /// reaching a deployed site. Cross-site routing needs the cluster transport and /// a live instance, neither of which exists in a central Test Run; pure logic /// and Parameters still work, matching how /// throws on Attributes for shared scripts. /// public class SandboxInboundScriptHost { /// Gets or initializes the script input parameters. public ScriptParameters Parameters { get; init; } = new(); /// Gets or initializes the cancellation token for the test run. public CancellationToken CancellationToken { get; init; } /// Gets the route accessor; every call throws in a test run. public RouteAccessor Route { get; } = new(); /// Mirror of ScadaLink.InboundAPI.RouteHelper. public class RouteAccessor { /// /// Creates a sandbox route target that throws on every operation. /// /// The instance code (used only in the exception message). public RouteTarget To(string instanceCode) => new(instanceCode); } /// Mirror of ScadaLink.InboundAPI.RouteTarget — every call throws. public class RouteTarget { private readonly string _instanceCode; /// /// Initializes the sandbox route target for the given instance code. /// /// The instance code referenced by the routing expression (used in the exception message). internal RouteTarget(string instanceCode) => _instanceCode = instanceCode; /// /// Always throws ; cross-site routing is unavailable in a Test Run. /// /// Script name (included in the exception message). /// Unused parameters. /// Unused token. public Task Call( string scriptName, object? parameters = null, CancellationToken cancellationToken = default) => throw Unavailable($"Call(\"{scriptName}\")"); /// /// Always throws ; cross-site routing is unavailable in a Test Run. /// /// Attribute name (included in the exception message). /// Unused token. public Task GetAttribute( string attributeName, CancellationToken cancellationToken = default) => throw Unavailable($"GetAttribute(\"{attributeName}\")"); /// /// Always throws ; cross-site routing is unavailable in a Test Run. /// /// Attribute names (unused). /// Unused token. public Task> GetAttributes( IEnumerable attributeNames, CancellationToken cancellationToken = default) => throw Unavailable("GetAttributes(...)"); /// /// Always throws ; cross-site routing is unavailable in a Test Run. /// /// Attribute name (included in the exception message). /// Unused value. /// Unused token. public Task SetAttribute( string attributeName, string value, CancellationToken cancellationToken = default) => throw Unavailable($"SetAttribute(\"{attributeName}\")"); /// /// Always throws ; cross-site routing is unavailable in a Test Run. /// /// Unused attribute values. /// Unused token. public Task SetAttributes( IReadOnlyDictionary attributeValues, CancellationToken cancellationToken = default) => throw Unavailable("SetAttributes(...)"); private ScriptSandboxException Unavailable(string operation) => new($"Route.To(\"{_instanceCode}\").{operation} is not available in Test Run — " + "cross-site routing needs a deployed site reachable over the cluster transport."); } }