Skip to content

Commit

Permalink
support validateset
Browse files Browse the repository at this point in the history
  • Loading branch information
iwate committed Feb 21, 2020
1 parent 48aca59 commit fcf86ae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static IEnumerable<PSParameterInfo> 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");
Expand Down
18 changes: 13 additions & 5 deletions src/Aiplugs.PoshApp/Services/Powershell/PowershellWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand All @@ -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,
Expand All @@ -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");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Aiplugs.PoshApp/Views/Shared/Pages/List.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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` ,
Expand All @@ -125,6 +124,9 @@
right: true
});
})
this.$signalr.on('UnitResult', () => {
this.loading = null;
})
},
run(value) {
this.loading = '$run';
Expand All @@ -150,6 +152,7 @@
beforeRouteLeave (to, from , next) {
this.$signalr.off('DefaultResult');
this.$signalr.off('ActionResult');
this.$signalr.off('UnitResult');
next();
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
filled rounded dense
v-if="p.type == 'System.DateTimeOffset' || p.type == 'System.DateTime'">
</datetime-field>
<v-select
v-model="p.value"
:label="p.name"
:items="validateSet(p)"
v-else-if="p.validateSet">
</v-select>
<v-text-field
v-model="p.value"
:label="p.name"
Expand Down Expand Up @@ -99,6 +105,9 @@
colSize(parameter) {
return this.isNumberType(parameter.type) ? 2 : null;
},
validateSet(parameter) {
return parameter.validateSet.map(v => ({ text: v, value: v }));
},
getClixmls() {
return this.parameters.reduce((o, p) => {
if (p.value !== undefined) {
Expand Down Expand Up @@ -127,7 +136,7 @@
})
this.$signalr.onconnected(() => {
this.getParameters();
})
})
},
beforeDestroy() {
this.$signalr.off('DetailResult')
Expand Down
5 changes: 5 additions & 0 deletions src/Aiplugs.PoshApp/Views/Shared/Pages/Singleton.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
right: true
});
})
this.$signalr.on('UnitResult', () => {
this.loading = null;
})
},
run(value) {
this.loading = '$run';
Expand All @@ -75,6 +78,8 @@
},
beforeRouteLeave (to, from , next) {
this.$signalr.off('DefaultResult');
this.$signalr.off('ActionResult');
this.$signalr.off('UnitResult');
next();
}
})
Expand Down

0 comments on commit fcf86ae

Please sign in to comment.