Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public void RegisterVariable(string name, object value)
 {
     PsInstance
     .AddCommand("Set-Variable")
     .AddParameter("Name", name)
     .AddParameter("Value", value);
     Invoke();
 }
Esempio n. 3
0
 public PsRunner AddParameterIf(bool expression, string parameterName)
 {
     if (expression)
     {
         PsInstance.AddParameter(parameterName);
     }
     return(this);
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
 public void Dispose()
 {
     PsInstance?.Dispose();
 }
Esempio n. 7
0
 public void Abort()
 {
     PsInstance.Stop();
 }
Esempio n. 8
0
 public void AddScript(string script)
 {
     PsInstance.AddScript(script);
 }
Esempio n. 9
0
 public PsRunner AddParameter(string parameterName)
 {
     PsInstance.AddParameter(parameterName);
     return(this);
 }
Esempio n. 10
0
 public PsRunner AddCommand(string cmdletName)
 {
     PsInstance.AddCommand(cmdletName);
     return(this);
 }