@using RobotNet.Shares @using RobotNet.Clients @using RobotNet.WebApp.Scripts.Models @inject ISnackbar Snackbar @inject IHttpClientFactory httpFactory @Title
@Model.Name :
@switch (Model.TypeName) { 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 @ValueModel.Type break; }
Cancel Update
@code { [CascadingParameter] private IMudDialogInstance Dialog { get; set; } = null!; [Parameter, EditorRequired] public ScriptVariableModel Model { get; set; } = default!; public string Title => $"Set Variable \"{Model.Name}\""; private HttpClient http = default!; private ScriptValueModel ValueModel = null!; private bool IsRequesing = false; protected override void OnInitialized() { base.OnInitialized(); ValueModel = new ScriptValueModel(Model.Name, Model.TypeName, ""); switch (Model.TypeName) { case "System.Boolean": ValueModel.BoolValue = default; break; case "System.Byte": ValueModel.ByteValue = default; break; case "System.SByte": ValueModel.SByteValue = default; break; case "System.Int16": ValueModel.ShortValue = default; break; case "System.UInt16": ValueModel.UShortValue = default; break; case "System.Int32": ValueModel.IntValue = default; break; case "System.UInt32": ValueModel.UIntValue = default; break; case "System.Int64": ValueModel.LongValue = default; break; case "System.UInt64": ValueModel.ULongValue = default; break; case "System.Single": ValueModel.FloatValue = default; break; case "System.Double": ValueModel.DoubleValue = default; break; case "System.Decimal": ValueModel.DecimalValue = default; break; } http = httpFactory.CreateClient("ScriptManagerAPI"); } private async Task RequestSetValue() { if (IsRequesing) return; IsRequesing = true; StateHasChanged(); // Force UI update to reflect instantiation state var result = await http.PutFromJsonAsync($"/api/ScriptVariables/{ValueModel.Name}", new UpdateVariableModel(ValueModel.Name, ValueModel.ToString())); if (result == null) { Snackbar.Add("Failed to instantiate mission: server response null", Severity.Error); } else if (result.IsSuccess) { Snackbar.Add(result.Message, Severity.Success); Dialog.Close(); } else { Snackbar.Add($"Failed to reset variable value: {result.Message}", Severity.Error); Dialog.Close(); } } private void OnCancel() => Dialog.Cancel(); }