private void OpenToolStripButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); DialogResult dialogResult = openFileDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { string path = openFileDialog.FileName; FileInfo fi = new FileInfo(path); string fileName = fi.Name.Replace(fi.Extension, ""); string synopsis = ""; ScreenNotification.Wait(this); EnabledControls(false); StatusToolStripStatusLabel.Text = "Opening file..."; KryptonPage kryptonPage = new KryptonPage(fileName); ScriptUserControl scriptUserControl = new ScriptUserControl(); List <ParameterControl> parameterControls = new List <ParameterControl>(); scriptUserControl.Dock = DockStyle.Fill; scriptUserControl.Path = path; scriptUserControl.Title = fileName; using (PowerShell powerShellInstance = PowerShell.Create()) { ExecuteMainScript(powerShellInstance, path); Collection <string> results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Synopsis"); synopsis = results[0]; results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter.Count"); int count = Convert.ToInt32(results[0]); for (int i = 0; i < count; i++) { string name = ""; string description = ""; Type dataType = null; ParameterControlType parameterControlType = ParameterControlType.Text; bool isRequired = false; string defaultValue = ""; string helpText = ""; results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter[{i}].Name"); name = results[0]; results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter[{i}].Description.Text"); description = results.Count > 0 ? results[0] : ""; results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter[{i}].Type.Name"); dataType = Type.GetType($"System.{results[0]}"); parameterControlType = description.Contains("[TEXT]") ? ParameterControlType.Text : description.Contains("[NUMERIC]") ? ParameterControlType.Numeric : description.Contains("[DATETIME]") ? ParameterControlType.DateTime : description.Contains("[FILEDIALOG]") ? ParameterControlType.FileDialog : description.Contains("[FOLDERDIALOG]") ? ParameterControlType.FolderDialog : dataType == typeof(Int32) || dataType == typeof(Int64) || dataType == typeof(Byte) || dataType == typeof(Decimal) || dataType == typeof(Single) || dataType == typeof(Double) ? ParameterControlType.Numeric : ParameterControlType.Text; description = description.Replace("[TEXT]", "").Replace("[NUMERIC]", "").Replace("[DATETIME]", "").Replace("[FILEDIALOG]", "").Replace("[FOLDERDIALOG]", ""); results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter[{i}].Required"); isRequired = results[0].ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase) ? true : false; results = ExecuteScript(powerShellInstance, $"(Get-Help {fileName} -Full).Parameters.Parameter[{i}].DefaultValue"); defaultValue = results.Count > 0 ? results[0].ToString() : ""; results = ExecuteScript(powerShellInstance, $"(Get-Command -Name '{fileName}').Parameters['{name}'].Attributes.HelpMessage"); helpText = results.Count > 0 ? results[0] : ""; parameterControls.Add(new ParameterControl() { Name = name, DisplayName = description, DataType = dataType, ControlType = parameterControlType, IsRequired = isRequired, DefaultValue = defaultValue, HelpText = helpText }); } } scriptUserControl.Description = synopsis; scriptUserControl.ParameterControls = parameterControls; kryptonPage.Tag = scriptUserControl; kryptonPage.Controls.Add(scriptUserControl); MainKryptonNavigator.Pages.Add(kryptonPage); MainKryptonNavigator.SelectedPage = kryptonPage; StatusToolStripStatusLabel.Text = "Ready"; EnabledControls(true); ScreenNotification.Default(this); } }
/// <summary> /// Control to be used in BPS Logic Builder for the parameter. /// </summary> /// <param name="controlType"></param> public ParameterEditorControlAttribute(ParameterControlType controlType) { this.ControlType = controlType; }