protected override object CreateModel(ActionStatement action) { if (action.PositionalArguments?.Count != 1) { return(null); } var scriptName = LooselyQualifiedName.Parse(action.PositionalArguments[0]); var info = PowerShellScriptInfo.TryLoadAsync(scriptName).GetAwaiter().GetResult(); if (info == null) { return(null); } return(new PSCallOperationModel { ScriptName = scriptName.ToString(), Arguments = info.Parameters.Select(p => new Argument { DefaultValue = p.DefaultValue, Description = p.Description, IsBooleanOrSwitch = p.IsBooleanOrSwitch, IsOutput = p.IsOutput, Name = p.Name, Value = p.IsOutput ? action.OutArguments.GetValueOrDefault(p.Name)?.ToString() : action.Arguments.GetValueOrDefault(p.Name) }) }); }
public override ISimpleControl CreateView(ActionStatement action) { if (action.PositionalArguments?.Count != 1) { return(new LiteralHtml("Cannot edit this statement; the target script name is not present.")); } var scriptName = LooselyQualifiedName.Parse(action.PositionalArguments[0]); var info = PowerShellScriptInfo.TryLoadAsync(scriptName).GetAwaiter().GetResult(); if (info == null) { return(new LiteralHtml("Cannot edit this statement; script metatdata could not be parsed.")); } var argumentName = new KoElement(KoBind.text(nameof(Argument.Name))); var argumentDesc = new KoElement( KoBind.text(nameof(Argument.Description)) ); var field = new SlimFormField(new LiteralHtml(argumentName.ToString())); field.HelpText = new LiteralHtml(argumentDesc.ToString()); field.Controls.Add( new Element("input", new KoBindAttribute("planargvalue", nameof(Argument.Value))) { Attributes = { ["type"] = "text" } }); return(new SimpleVirtualCompositeControl( new SlimFormField("Script name:", info.Name ?? scriptName.ToString()), new Div( new KoElement( KoBind.@foreach(nameof(PSCallOperationModel.Arguments)), field ) ) { Class = "argument-container" }, new SlimFormField( "Parameters:", KoBind.visible($"{nameof(PSCallOperationModel.Arguments)}().length == 0"), "This script does not have any input or output parameters." ) )); }
public CallScriptInfo TryLoad(string name, object loadContext) { var scriptName = LooselyQualifiedName.Parse(name); var info = PowerShellScriptInfo.TryLoad(scriptName, loadContext); if (info == null) { return(null); } return(new CallScriptInfo( scriptName.ToString(), info.Parameters.Select(p => new CallScriptArgument { DefaultValue = p.DefaultValue, Description = p.Description, IsBooleanOrSwitch = p.IsBooleanOrSwitch, IsOutput = p.IsOutput, Name = p.Name }) )); }