public static async Task <PowerShellScriptInfo> TryLoadAsync(LooselyQualifiedName scriptName) { using (var raft = RaftRepository.OpenRaft(scriptName.Namespace ?? RaftRepository.DefaultName)) { if (raft == null) { return(null); } using (var item = await raft.OpenRaftItemAsync(RaftItemType.Script, scriptName.Name + ".ps1", FileMode.Open, FileAccess.Read).ConfigureAwait(false)) { if (item == null) { return(null); } using (var reader = new StreamReader(item, InedoLib.UTF8Encoding)) { if (!TryParse(reader, out var info)) { return(null); } return(info); } } } }
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) }) }); }
protected override ExtendedRichDescription GetDescription(IOperationConfiguration config) { if (string.IsNullOrWhiteSpace(config.DefaultArgument)) { return(new ExtendedRichDescription(new RichDescription("PSVerify {error parsing statement}"))); } var defaultArg = config.DefaultArgument; var longDesc = new RichDescription(); bool longDescInclused = false; var scriptName = LooselyQualifiedName.TryParse(defaultArg); if (scriptName != null) { var info = PowerShellScriptInfo.TryLoad(scriptName); if (!string.IsNullOrEmpty(info?.Description)) { longDesc.AppendContent(info.Description); longDescInclused = true; } var listParams = new List <string>(); foreach (var prop in config.NamedArguments) { listParams.Add($"{prop.Key}: {prop.Value}"); } foreach (var prop in config.OutArguments) { listParams.Add($"{prop.Key} => {prop.Value}"); } if (listParams.Count > 0) { if (longDescInclused) { longDesc.AppendContent(" - "); } longDesc.AppendContent(new ListHilite(listParams)); longDescInclused = true; } } if (!longDescInclused) { longDesc.AppendContent("with no parameters"); } return(new ExtendedRichDescription( new RichDescription("PSVerify ", new Hilite(defaultArg)), longDesc )); }
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 }) )); }
public static PowerShellScriptInfo TryLoad(LooselyQualifiedName scriptName, object context = null) { // this is a preposterous hack, and should be removed as soon as we get context added to SDK (see SDK-74) if (SDK.ProductName == "BuildMaster") { // this is only ever called from the planeditor page, but there are multiple ways to get the data... if (HttpContextThatWorksOnLinux.Current == null) { return(null); } // the really easy way to get the applicationId (building the operation editor) var applicationId = AH.ParseInt(HttpContextThatWorksOnLinux.Current.Request.QueryString["applicationId"]); if (!applicationId.HasValue) { // the "other" ways (rebuilding TSSatements) var fullItemId = AH.CoalesceString( HttpContextThatWorksOnLinux.Current.Request.QueryString["planId"], HttpContextThatWorksOnLinux.Current.Request.Form["additionalContext"] ); if (string.IsNullOrEmpty(fullItemId)) { return(null); } // this is logic based on RaftItemId.TryParse var parts = fullItemId.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 4) { return(null); } if (string.Equals(parts[1], "global", StringComparison.OrdinalIgnoreCase)) { return(null); } // find the appId by name var appIdtyp = Type.GetType("Inedo.BuildMaster.ApplicationId,BuildMaster"); var appId = Activator.CreateInstance(appIdtyp, parts[1]); applicationId = (int)appIdtyp.GetProperty("Id").GetValue(appId); } // stuff into a SimpleContext var ctxTyp = Type.GetType("Inedo.BuildMaster.Extensibility.SimpleBuildMasterContext,BuildMaster"); context = Activator.CreateInstance(ctxTyp, /*applicationGroupId*/ null, applicationId, /*deployableId*/ null, /*executionId*/ null, /*environmentId*/ null, /*serverId*/ null, /*promotionId*/ null, /*serverRoleId*/ null, /*releaseId*/ null, /*buildId*/ null); } // END HACK var name = scriptName.FullName; if (!name.EndsWith(".ps1", StringComparison.OrdinalIgnoreCase)) { name += ".ps1"; } var item = SDK.GetRaftItem(RaftItemType.Script, name, context); if (item == null) { return(null); } using var reader = new StringReader(item.Content); _ = TryParse(reader, out var info); return(info); }