private Dictionary <string, System.Management.Automation.PSObject> GetParameters(System.Collections.ObjectModel.Collection <FieldDescription> descriptions) { Dictionary <string, System.Management.Automation.PSObject> rtn = new Dictionary <string, System.Management.Automation.PSObject>(); psparamtype parm = new psparamtype(); foreach (FieldDescription descr in descriptions) { psparameter prm = new psparameter(); prm.Name = descr.Name; if (descr.IsMandatory) { prm.Category = "Required"; } else { prm.Category = "Optional"; } prm.DefaultValue = descr.DefaultValue; prm.Description = descr.HelpMessage; prm.Type = Type.GetType(descr.ParameterAssemblyFullName); if (prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } if (prm.Name.ToLower() == "credential") { prm.IsCredential = true; } parm.Properties.Add(prm); } if (frm.ShowParams(parm) == System.Windows.Forms.DialogResult.OK) { foreach (psparameter prm in parm.Properties) { rtn.Add(prm.Name, new System.Management.Automation.PSObject(prm.Value)); } } return(rtn); }
public psparamdescriptor(psparameter psparam) : base(psparam.Name, null) { this.psparam = psparam; }
public psparamdescriptor(psparameter psparam) : base(psparam.Name, null) { this.psparam = psparam; }
public List<psparameter> CheckForParams(String scriptcommand) { cancel = false; List<psparameter> parms = null; psparamtype parm = new psparamtype(); Pipeline pline = rspace.CreatePipeline(); String scrpt = ""; if (iscommand) { scrpt = StringValue.GetHelpFull.Replace("{0}", scriptcommand); } else { scrpt = StringValue.GetHelpFull.Replace("{0}", "\"" + scriptcommand + "\""); } pline.Commands.AddScript(scrpt); pline.Commands.Add(StringValue.OutString); Collection<PSObject> rslt = pline.Invoke(); HandleWarningsErrors(pline.Error); if (rslt != null) { if (rslt[0].ToString().Contains("PARAMETERS")) { String[] lines = rslt[0].ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines != null) { int idx = 0; bool found = false; List<String> fileparams = GetEditorParams(rslt[0].ToString(), "psfilename"); List<String> hostparams = GetEditorParams(rslt[0].ToString(), "pshosts"); do { String line = lines[idx]; if (line == "PARAMETERS") { found = true; } idx++; } while (found == false && idx < lines.Length); if (found) { String line = ""; do { line = lines[idx]; if (line.Trim() != "" && line.Trim().Substring(0, 1) == "-") { psparameter prm = new psparameter(); String param = line.Trim().Substring(1, line.Trim().Length - 1); String[] paramparts = param.Split(' '); prm.Name = paramparts[0].Trim(); if (paramparts.Length == 2) { prm.Type = GetTypeFromString(paramparts[1]); } else { prm.Type = typeof(int); } idx++; line = lines[idx]; prm.Description = line.Trim(); idx += 2; line = lines[idx]; if (line.Contains("true")) { prm.Category = "Required"; } else { prm.Category = "Optional"; } idx += 2; line = lines[idx]; if (line.Contains("Default value")) { String defval = line.Replace("Default value", "").Trim(); if (defval != "") { if (defval.ToLower() == "true" || defval.ToLower() == "false") { prm.DefaultValue = bool.Parse(defval); } else { prm.DefaultValue = defval; } } } if (fileparams.Contains(prm.Name) || prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } if (hostparams.Contains(prm.Name)) { prm.IsHostList = true; } if (prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } if (prm.Name.ToLower() == "credential") { prm.IsCredential = true; } parm.Properties.Add(prm); } idx++; } while (line.Substring(0, 1) == " " && idx < lines.Length); } } } } pline.Stop(); pline.Dispose(); pline = null; GC.Collect(); if (parm.Properties.Count > 0) { if (frm.ShowParams(parm) == System.Windows.Forms.DialogResult.OK) { parms = parm.Properties; } else { cancel = true; } } return parms; }
private Dictionary<string, System.Management.Automation.PSObject> GetParameters(System.Collections.ObjectModel.Collection<FieldDescription> descriptions) { Dictionary<string, System.Management.Automation.PSObject> rtn = new Dictionary<string, System.Management.Automation.PSObject>(); psparamtype parm = new psparamtype(); foreach (FieldDescription descr in descriptions) { psparameter prm = new psparameter(); prm.Name = descr.Name; if (descr.IsMandatory) { prm.Category = "Required"; } else { prm.Category = "Optional"; } prm.DefaultValue = descr.DefaultValue; prm.Description = descr.HelpMessage; prm.Type = Type.GetType(descr.ParameterAssemblyFullName); if(prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } parm.Properties.Add(prm); } if (frm.ShowParams(parm) == System.Windows.Forms.DialogResult.OK) { foreach (psparameter prm in parm.Properties) { rtn.Add(prm.Name, new System.Management.Automation.PSObject(prm.Value)); } } return rtn; }
public List <psparameter> CheckForParams(String scriptcommand) { cancel = false; List <psparameter> parms = null; psparamtype parm = new psparamtype(); Pipeline pline = rspace.CreatePipeline(); String scrpt = ""; if (iscommand) { scrpt = StringValue.GetHelpFull.Replace("{0}", scriptcommand); } else { scrpt = StringValue.GetHelpFull.Replace("{0}", "\"" + scriptcommand + "\""); } pline.Commands.AddScript(scrpt); pline.Commands.Add(StringValue.OutString); Collection <PSObject> rslt = pline.Invoke(); HandleWarningsErrors(pline.Error); if (rslt != null) { if (rslt[0].ToString().Contains("PARAMETERS")) { String[] lines = rslt[0].ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (lines != null) { int idx = 0; bool found = false; List <String> fileparams = GetEditorParams(rslt[0].ToString(), "psfilename"); List <String> hostparams = GetEditorParams(rslt[0].ToString(), "pshosts"); do { String line = lines[idx]; if (line == "PARAMETERS") { found = true; } idx++; } while (found == false && idx < lines.Length); if (found) { String line = ""; do { line = lines[idx]; if (line.Trim() != "" && line.Trim().Substring(0, 1) == "-") { psparameter prm = new psparameter(); String param = line.Trim().Substring(1, line.Trim().Length - 1); String[] paramparts = param.Split(' '); prm.Name = paramparts[0].Trim(); if (paramparts.Length == 2) { prm.Type = GetTypeFromString(paramparts[1]); } else { prm.Type = typeof(int); } idx++; line = lines[idx]; prm.Description = line.Trim(); idx += 2; line = lines[idx]; if (line.Contains("true")) { prm.Category = "Required"; } else { prm.Category = "Optional"; } idx += 2; line = lines[idx]; if (line.Contains("Default value")) { String defval = line.Replace("Default value", "").Trim(); if (defval != "") { if (defval.ToLower() == "true" || defval.ToLower() == "false") { prm.DefaultValue = bool.Parse(defval); } else { prm.DefaultValue = defval; } } } if (fileparams.Contains(prm.Name) || prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } if (hostparams.Contains(prm.Name)) { prm.IsHostList = true; } if (prm.Name.ToLower() == "file" || prm.Name.ToLower() == "filename") { prm.IsFileName = true; } if (prm.Name.ToLower() == "credential") { prm.IsCredential = true; } parm.Properties.Add(prm); } idx++; } while (line.Substring(0, 1) == " " && idx < lines.Length); } } } } pline.Stop(); pline.Dispose(); pline = null; GC.Collect(); if (parm.Properties.Count > 0) { if (frm.ShowParams(parm) == System.Windows.Forms.DialogResult.OK) { parms = parm.Properties; } else { cancel = true; } } return(parms); }