@using RobotNet.Shares @using RobotNet.Clients @using RobotNet.WebApp.Scripts.Models @inject ISnackbar Snackbar @inject IHttpClientFactory httpFactory @Title
@foreach (var param in Model.Parameters) {
@param.Name :
@switch (param.Type) { case "System.Boolean": break; case "System.Byte": break; case "System.SByte": break; case "System.Int16": break; case "System.UInt16": break; case "System.Int32": break; case "System.UInt32": break; case "System.Int64": break; case "System.UInt64": break; case "System.Single": break; case "System.Double": break; case "System.Decimal": break; case "System.String": break; case "System.Char": break; case "System.Threading.CancellationToken": <CancellationToken> break; default: Unsupport parameter with type @param.Type break; }
}
Cancel Instantiate
@code { [CascadingParameter] private IMudDialogInstance Dialog { get; set; } = null!; [Parameter, EditorRequired] public ScriptMissionModel Model { get; set; } = default!; public string Title => $"Instantiate Mission {Model.Name}"; private HttpClient http = default!; private bool IsInstantiating = false; protected override void OnInitialized() { base.OnInitialized(); http = httpFactory.CreateClient("ScriptManagerAPI"); } private void OnCancel() => Dialog.Cancel(); private async Task Instantiate() { if (IsInstantiating) return; IsInstantiating = true; StateHasChanged(); // Force UI update to reflect instantiation state var parameters = Model.Parameters .Where(p => p.Type != "RobotNet.Script.IRobot") .ToDictionary(p => p.Name, p => p.ToString()); var result = await http.PostFromJsonAsync>("api/ScriptMissions/Runner", new InstanceMissionCreateModel(Model.Name, parameters)); if (result is null) { Snackbar.Add("Failed to instantiate mission: server response null", Severity.Error); } else if (result.IsSuccess) { Snackbar.Add($"Mission {Model.Name} instantiated successfully with ID: {result.Data}", Severity.Success); Dialog.Close(DialogResult.Ok(Model.Name)); } else { Snackbar.Add($"Failed to instantiate mission: {result.Message}", Severity.Error); } } }