From fcf86ae4e36d40689ef96dd9aa67d8478cce81e0 Mon Sep 17 00:00:00 2001 From: iwate Date: Sat, 22 Feb 2020 01:20:33 +0900 Subject: [PATCH] support validateset --- .../Powershell/PowershellExtensions.cs | 2 +- .../Services/Powershell/PowershellWorker.cs | 18 +++++++++++++----- .../Views/Shared/Pages/List.cshtml | 5 ++++- .../Shared/Pages/Parts/ParametersForm.cshtml | 11 ++++++++++- .../Views/Shared/Pages/Singleton.cshtml | 5 +++++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Aiplugs.PoshApp/Services/Powershell/PowershellExtensions.cs b/src/Aiplugs.PoshApp/Services/Powershell/PowershellExtensions.cs index 8c3e0c2..4fff344 100644 --- a/src/Aiplugs.PoshApp/Services/Powershell/PowershellExtensions.cs +++ b/src/Aiplugs.PoshApp/Services/Powershell/PowershellExtensions.cs @@ -72,7 +72,7 @@ public static IEnumerable GetParameters(this PowerShell ps, str var validateSetAttr = (AttributeAst)paramAst.Attributes.FirstOrDefault(attr => attr.TypeName.Name == "ValidateSet"); if (validateSetAttr != null) { - info.ValidateSet = validateSetAttr.PositionalArguments.Select(arg => arg.Extent.Text).ToArray(); + info.ValidateSet = validateSetAttr.PositionalArguments.Select(arg => (string)arg.SafeGetValue()).ToArray(); } var validateCountAttr = (AttributeAst)paramAst.Attributes.FirstOrDefault(attr => attr.TypeName.Name == "ValidateCount"); diff --git a/src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs b/src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs index c29d5b1..30fe14d 100644 --- a/src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs +++ b/src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs @@ -68,7 +68,8 @@ private async Task TryInvokeCommand(Runspace runspace) return; using var ps = PowerShell.Create(runspace); - ps.Streams.Error.DataAdding += (sender, args) => { + ps.Streams.Error.DataAdding += (sender, args) => + { var record = (ErrorRecord)args.ItemAdded; Client.SendAsync("WriteErrorLine", record.ToString()).Wait(); }; @@ -84,11 +85,13 @@ private async Task TryInvokeCommand(Runspace runspace) var result = ps.InvokeWithPipeline(content, detailCmd.InputObject); await Client.SendAsync("DetailResult", JsonConvert.SerializeObject(result)); } - else if (invokeCommand is ActionInvokeCommand actionCmd) { + else if (invokeCommand is ActionInvokeCommand actionCmd) + { var result = ps.InvokeWithPipeline(content, actionCmd.InputObject); await Client.SendAsync("ActionResult", actionCmd.ScriptId, JsonConvert.SerializeObject(result)); } - else if (invokeCommand is GetParametersCommand) { + else if (invokeCommand is GetParametersCommand) + { var parameters = ps.GetParameters(content); await Client.SendAsync("GetParameters", parameters.Select(p => new { p.Name, @@ -100,15 +103,20 @@ private async Task TryInvokeCommand(Runspace runspace) p.ValueFromPipeline, p.ValueFromPipelineByPropertyName, p.ValueFromRemainingArguments, + p.ValidateSet, Type = p.Type.FullName })); } } - catch(ParseException parseException) { + catch(ParseException parseException) + { await Client.SendAsync("ParseError", parseException.Message); + await Client.SendAsync("UnitResult"); } - catch(Exception exception) { + catch(Exception exception) + { await Client.SendAsync("WriteErrorLine", exception.Message); + await Client.SendAsync("UnitResult"); } } } diff --git a/src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml b/src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml index 9d4b8fe..6106ada 100644 --- a/src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml +++ b/src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml @@ -116,7 +116,6 @@ }) this.$signalr.on("ActionResult", (id, json) => { this.loading = null; - this.loadings[id] = false; const data = JSON.parse(json); this.toast({ text: `${id} is succeeded` , @@ -125,6 +124,9 @@ right: true }); }) + this.$signalr.on('UnitResult', () => { + this.loading = null; + }) }, run(value) { this.loading = '$run'; @@ -150,6 +152,7 @@ beforeRouteLeave (to, from , next) { this.$signalr.off('DefaultResult'); this.$signalr.off('ActionResult'); + this.$signalr.off('UnitResult'); next(); } }) diff --git a/src/Aiplugs.PoshApp/Views/Shared/Pages/Parts/ParametersForm.cshtml b/src/Aiplugs.PoshApp/Views/Shared/Pages/Parts/ParametersForm.cshtml index a58507d..827afc8 100644 --- a/src/Aiplugs.PoshApp/Views/Shared/Pages/Parts/ParametersForm.cshtml +++ b/src/Aiplugs.PoshApp/Views/Shared/Pages/Parts/ParametersForm.cshtml @@ -10,6 +10,12 @@ filled rounded dense v-if="p.type == 'System.DateTimeOffset' || p.type == 'System.DateTime'"> + + ({ text: v, value: v })); + }, getClixmls() { return this.parameters.reduce((o, p) => { if (p.value !== undefined) { @@ -127,7 +136,7 @@ }) this.$signalr.onconnected(() => { this.getParameters(); - }) + }) }, beforeDestroy() { this.$signalr.off('DetailResult') diff --git a/src/Aiplugs.PoshApp/Views/Shared/Pages/Singleton.cshtml b/src/Aiplugs.PoshApp/Views/Shared/Pages/Singleton.cshtml index 8d93a62..181f7b6 100644 --- a/src/Aiplugs.PoshApp/Views/Shared/Pages/Singleton.cshtml +++ b/src/Aiplugs.PoshApp/Views/Shared/Pages/Singleton.cshtml @@ -56,6 +56,9 @@ right: true }); }) + this.$signalr.on('UnitResult', () => { + this.loading = null; + }) }, run(value) { this.loading = '$run'; @@ -75,6 +78,8 @@ }, beforeRouteLeave (to, from , next) { this.$signalr.off('DefaultResult'); + this.$signalr.off('ActionResult'); + this.$signalr.off('UnitResult'); next(); } })