using System.Reflection; using CollectionCanary.Components; using Microsoft.AspNetCore.DataProtection; using ZB.MOM.WW.OtOpcUa.AdminUI.Uns; var builder=WebApplication.CreateBuilder(args);builder.WebHost.UseStaticWebAssets();builder.Services.AddRazorComponents().AddInteractiveServerComponents();builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();builder.Services.AddScoped();builder.Services.AddScoped(sp=>{var proxy=DispatchProxy.Create();((FixtureRaw)(object)proxy).State=sp.GetRequiredService();return proxy;}); var app=builder.Build();app.UseAntiforgery();app.MapStaticAssets();app.MapRazorComponents().AddInteractiveServerRenderMode();app.Run(); public sealed class FixtureState {public int Requests;public string Json="{\"endpointUrls\":[\"opc.tcp://fixture-a:4840\",\"opc.tcp://fixture-b:4840\"]}";} public class FixtureRaw:DispatchProxy { public FixtureState State=null!; protected override object? Invoke(MethodInfo? method,object?[]? args)=>method?.Name switch { "LoadDriverForEditAsync"=>Task.FromResult(new("fixture-driver","fixture-driver","OpcUaClient",State.Json,null,[1,2])), "UpdateDriverAsync"=>Update(args!), _=>throw new InvalidOperationException("Synthetic fixture refuses "+method?.Name) }; private Task Update(object?[] args){if(args[0] is not string target || target!="fixture-driver")throw new InvalidOperationException("Unknown fixture target");State.Requests++;State.Json=(string)args[2]!;return Task.FromResult(new UnsMutationResult(true,null));} }