public Collection <PSObject> Invoke(bool discardOutput = false) { discardOutput = discardOutput || DiscardOutput; if (discardOutput) { PsInstance.AddCommand("Out-Null"); } Collection <PSObject> result; try { result = PsInstance.Invoke(); } catch (Exception e) { Logger.WriteError(e.GetExceptionMessage(), null); ErrorOccurred?.Invoke(this, new ErrorEventArgs(e)); throw; } finally { PsInstance.Commands.Clear(); } if (AutoDumpBufferLogger && Logger is BufferInterface bl) { bl.Dump(); } return(result); }
public void RegisterVariable(string name, object value) { PsInstance .AddCommand("Set-Variable") .AddParameter("Name", name) .AddParameter("Value", value); Invoke(); }
public PsRunner AddParameterIf(bool expression, string parameterName) { if (expression) { PsInstance.AddParameter(parameterName); } return(this); }
public void RunPwCreateProjectScript(string projectName, string destPath, string templateName, string templateSource, string templateSourceBranch, Hashtable properties) { bool hadErrors; string errorString = ""; // here is where we want to call pecan-waffle try { var instance = PsInstance; PsInstance.AddScript(_psNewProjectScript); PsInstance.AddParameter("templateName", templateName); PsInstance.AddParameter("projectName", projectName); PsInstance.AddParameter("destPath", destPath); if (!string.IsNullOrWhiteSpace(templateSource)) { PsInstance.AddParameter("TemplateSource", templateSource); } if (!string.IsNullOrWhiteSpace(templateSourceBranch)) { PsInstance.AddParameter("TemplateSourceBranch", templateSourceBranch); } if (properties != null) { PsInstance.AddParameter("Properties", properties); } try { var result = PsInstance.Invoke(); } catch (Exception ex) { string msg = WriteOutput ? $"An error occurred, see output window for more details {ex.ToString()}" : $"An error occurred. {ex.ToString()}"; MessageBox.Show(msg); } errorString = GetErrorStringFrom(PsInstance, out hadErrors); if (hadErrors && WriteOutput) { WriteToOutputWindow(errorString); } } catch (Exception ex) { // TODO: Improve throw ex; } if (hadErrors) { // TODO: Improve throw new ApplicationException(errorString); } }
public void EnsureInstallPwScriptInvoked(string extensionInstallDir) { PsInstance = PowerShell.Create(); PsInstance.AddScript(_psInstallPecanWaffleScript); PsInstance.AddParameter("extensionInstallDir", extensionInstallDir); var result = PsInstance.Invoke(); if (WriteOutput) { WriteToOutputWindow(GetStringFrom(result)); } bool hadErrors; string errorString = GetErrorStringFrom(PsInstance, out hadErrors); if (WriteOutput) { WriteToOutputWindow(errorString); } }
public void Dispose() { PsInstance?.Dispose(); }
public void Abort() { PsInstance.Stop(); }
public void AddScript(string script) { PsInstance.AddScript(script); }
public PsRunner AddParameter(string parameterName) { PsInstance.AddParameter(parameterName); return(this); }
public PsRunner AddCommand(string cmdletName) { PsInstance.AddCommand(cmdletName); return(this); }