Guard and name Raw manual entry and browsing workflows
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><base href="/" /><title>Local raw workflow fixture</title>
|
||||
<link rel="stylesheet" href="_content/ZB.MOM.WW.OtOpcUa.AdminUI/lib/bootstrap/css/bootstrap.min.css" /><ThemeHead /><link rel="stylesheet" href="_content/ZB.MOM.WW.OtOpcUa.AdminUI/css/site.css" />
|
||||
</head><body><Router AppAssembly="typeof(App).Assembly"><Found Context="route"><RouteView RouteData="route" /></Found></Router><script src="_content/ZB.MOM.WW.OtOpcUa.AdminUI/js/dialog-focus.js"></script><script src="_framework/blazor.web.js"></script></body></html>
|
||||
@@ -0,0 +1,29 @@
|
||||
@page "/"
|
||||
@rendermode InteractiveServer
|
||||
@inject WorkflowState State
|
||||
@implements IDisposable
|
||||
<ThemeShell Product="Raw workflow fixture">
|
||||
<main class="p-3">
|
||||
<h1>Raw workflow fixture</h1><p>Local synthetic callbacks; no real tag, broker, driver or database operations.</p>
|
||||
<output id="open-requests">@State.OpenRequests</output><output id="closed-sessions">@State.ClosedSessions</output>
|
||||
<output id="rebirth-requests">@State.RebirthRequests</output>
|
||||
<output id="ready">@_ready</output><output id="requests">@State.Requests</output><output id="saved">@_saved</output>
|
||||
<button id="open" class="btn btn-primary" @onclick="() => _visible=true">Add synthetic tags</button>
|
||||
@if(Kind=="browse" || Kind=="rebirth")
|
||||
{
|
||||
<RawBrowseModal @bind-Visible="_visible" DeviceId="synthetic-device" DriverType="@State.DriverType" OnSaved="() => _saved++" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<RawManualTagEntryModal @bind-Visible="_visible" DeviceId="synthetic-device" DriverType='@(Kind=="typed" ? "S7" : "Unmapped")' OnSaved="() => _saved++" />
|
||||
}
|
||||
</main>
|
||||
</ThemeShell>
|
||||
@code {
|
||||
[SupplyParameterFromQuery(Name="kind")]public string? Kind{get;set;}
|
||||
protected override void OnInitialized(){State.DriverType=Kind=="rebirth"?"Mqtt":"AbCip";State.Changed+=OnFixtureChanged;}
|
||||
private void OnFixtureChanged()=>_=InvokeAsync(StateHasChanged);
|
||||
public void Dispose()=>State.Changed-=OnFixtureChanged;
|
||||
private bool _visible,_ready;private int _saved;
|
||||
protected override void OnAfterRender(bool firstRender){if(firstRender){_ready=true;StateHasChanged();}}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@using Microsoft.AspNetCore.Components
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using ZB.MOM.WW.Theme
|
||||
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Raw
|
||||
@using RawWorkflowCanary
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Browsing;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Browsing;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using RawWorkflowCanary;
|
||||
using RawWorkflowCanary.Components;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
var builder=WebApplication.CreateBuilder(args);
|
||||
builder.WebHost.UseStaticWebAssets();
|
||||
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
||||
builder.Services.AddScoped<WorkflowState>();
|
||||
builder.Services.AddAuthorizationCore(o=>o.AddPolicy(ZB.MOM.WW.OtOpcUa.Security.Auth.AdminUiPolicies.DriverOperator,p=>p.RequireRole("Operator","Administrator")));
|
||||
builder.Services.AddScoped<AuthenticationStateProvider,FixturePrincipal>();
|
||||
builder.Services.AddScoped<IBrowserSessionService>(sp=>FixtureBrowser.Create(sp.GetRequiredService<WorkflowState>()));
|
||||
builder.Services.AddDbContextFactory<OtOpcUaConfigDbContext>(o=>o.UseInMemoryDatabase("raw-workflow-local"));
|
||||
builder.Services.AddScoped<RawTagCsvExportReader>();
|
||||
builder.Services.AddScoped<IRawTreeService>(sp=>WorkflowProxy.Create(sp.GetRequiredService<WorkflowState>()));
|
||||
var app=builder.Build();app.UseStaticFiles();app.UseAntiforgery();app.MapRazorComponents<App>().AddInteractiveServerRenderMode();app.Run();
|
||||
namespace RawWorkflowCanary
|
||||
{
|
||||
public sealed class WorkflowState {public int Requests {get;set;}public int RebirthRequests {get;set;} public int OpenRequests {get;set;} public int ClosedSessions {get;set;} public event Action? Changed; public void Notify()=>Changed?.Invoke(); public string DriverType {get;set;}="AbCip";}
|
||||
public class WorkflowProxy:DispatchProxy
|
||||
{
|
||||
private WorkflowState _state=null!;
|
||||
public static IRawTreeService Create(WorkflowState state){var proxy=Create<IRawTreeService,WorkflowProxy>();((WorkflowProxy)proxy)._state=state;return proxy;}
|
||||
protected override object? Invoke(MethodInfo? method,object?[]? args)=>method!.Name switch
|
||||
{
|
||||
"LoadMergedProbeConfigAsync"=>Task.FromResult<(string DriverType,string MergedConfigJson)?>((_state.DriverType,"{}")),
|
||||
"LoadDeviceDriverInstanceIdAsync"=>Task.FromResult<string?>("synthetic-owner"),
|
||||
"ImportTagsAsync"=>Import((IReadOnlyList<RawTagImportRow>)args![1]!),
|
||||
"CreateTagAsync"=>CreateTag(),
|
||||
_=>throw new InvalidOperationException("Operational service refused by local fixture: "+method.Name)
|
||||
};
|
||||
private async Task<RawTagImportResult> Import(IReadOnlyList<RawTagImportRow> rows){_state.Requests++;_state.Notify();await Task.Delay(900);return new(rows.Count,[]);}
|
||||
private async Task<UnsMutationResult> CreateTag(){_state.Requests++;_state.Notify();await Task.Delay(900);return new(true,null);}
|
||||
}
|
||||
public sealed class FixturePrincipal:AuthenticationStateProvider
|
||||
{public override Task<AuthenticationState> GetAuthenticationStateAsync()=>Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity([new(ClaimTypes.Name,"local-fixture"),new(ClaimTypes.Role,"Operator")],"fixture"))));}
|
||||
public class FixtureBrowser:DispatchProxy
|
||||
{
|
||||
private WorkflowState _state=null!;
|
||||
public static IBrowserSessionService Create(WorkflowState state){var p=Create<IBrowserSessionService,FixtureBrowser>();((FixtureBrowser)p)._state=state;return p;}
|
||||
protected override object? Invoke(MethodInfo? m,object?[]? args)=>m!.Name switch
|
||||
{
|
||||
"CanBrowse"=>true,
|
||||
"OpenAsync"=>Open(),
|
||||
"CloseAsync"=>Close(),
|
||||
"CanRequestRebirth"=>_state.DriverType=="Mqtt",
|
||||
"RootAsync"=>Task.FromResult<IReadOnlyList<BrowseNode>>(_state.DriverType=="Mqtt"?[]:[new("SyntheticTag1","Synthetic tag one",BrowseNodeKind.Leaf,false),new("SyntheticTag2","Synthetic tag two",BrowseNodeKind.Leaf,false)]),
|
||||
"AttributesAsync"=>Task.FromResult<IReadOnlyList<AttributeInfo>>([]),
|
||||
"RequestRebirthAsync"=>Rebirth(),
|
||||
_=>throw new InvalidOperationException("Unexpected fixture operation: "+m.Name)
|
||||
};
|
||||
private async Task<BrowseOpenResult> Open(){_state.OpenRequests++;_state.Notify();await Task.Delay(700);return new(true,null,Guid.NewGuid());}
|
||||
private Task Close(){_state.ClosedSessions++;_state.Notify();return Task.CompletedTask;}
|
||||
private async Task<int> Rebirth(){_state.RebirthRequests++;_state.Notify();await Task.Delay(900);return 1;}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>net10.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings><RootNamespace>RawWorkflowCanary</RootNamespace></PropertyGroup><ItemGroup><ProjectReference Include="../../../../src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/ZB.MOM.WW.OtOpcUa.AdminUI.csproj"/><PackageReference Include="Microsoft.EntityFrameworkCore.InMemory"/></ItemGroup></Project>
|
||||
Reference in New Issue
Block a user