Files
lmxopcua/docs/ui-consistency/evidence/ot13-collection-inline/canary/Program.cs
T

19 lines
1.6 KiB
C#

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<FixtureState>();builder.Services.AddScoped<IRawTreeService>(sp=>{var proxy=DispatchProxy.Create<IRawTreeService,FixtureRaw>();((FixtureRaw)(object)proxy).State=sp.GetRequiredService<FixtureState>();return proxy;});
var app=builder.Build();app.UseAntiforgery();app.MapStaticAssets();app.MapRazorComponents<App>().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<RawDriverEditDto?>(new("fixture-driver","fixture-driver","OpcUaClient",State.Json,null,[1,2])),
"UpdateDriverAsync"=>Update(args!),
_=>throw new InvalidOperationException("Synthetic fixture refuses "+method?.Name)
};
private Task<UnsMutationResult> 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));}
}