private void pipelineExecutor_OnDataReady(PipelineExecutor sender, ICollection <PSObject> data)
 {
     foreach (PSObject obj in data)
     {
         OutputTextBox.AppendText(obj.ToString() + "\n");
     }
 }
 void pipelineExecutor_OnOutputReady(PipelineExecutor sender, ICollection <object> data)
 {
     foreach (object e in data)
     {
         OutputTextBox.AppendText(e.ToString() + "\n");
     }
 }
        /// <summary>
        /// private ErrorReady handling method that will pass the call on to any event handlers that are
        /// attached to the OnErrorReady event of this <see cref="PipelineExecutor"/> instance.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void SynchErrorReady(PipelineExecutor sender, ICollection <object> data)
        {
            ErrorReadyDelegate delegateErrorReadyCopy = OnOutputReady;

            if (delegateErrorReadyCopy != null)
            {
                delegateErrorReadyCopy(sender, data);
            }
        }
        /// <summary>
        /// private DataEnd handling method that will pass the call on to any handlers that are
        /// attached to the OnDataEnd event of this <see cref="PipelineExecutor"/> instance.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void SynchDataEnd(PipelineExecutor sender)
        {
            DataEndDelegate delegateDataEndCopy = OnDataEnd;

            if (delegateDataEndCopy != null)
            {
                delegateDataEndCopy(sender);
            }
        }
        /// <summary>
        /// private DataReady handling method that will pass the call on to any event handlers that are
        /// attached to the OnDataReady event of this <see cref="PipelineExecutor"/> instance.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        private void SynchDataReady(PipelineExecutor sender, ICollection <PSObject> data)
        {
            DataReadyDelegate delegateDataReadyCopy = OnDataReady;

            if (delegateDataReadyCopy != null)
            {
                delegateDataReadyCopy(sender, data);
            }
        }
        private void RunProcess(string script)
        {
            Command command = new Command(script);

            foreach (var param in this.Parameters)
            {
                command.Parameters.Add(param.Key, param.Value);
            }
            pipelineExecutor                = new PipelineExecutor(runSpace, Invoker, command);
            pipelineExecutor.OnDataReady   += new PipelineExecutor.DataReadyDelegate(pipelineExecutor_OnDataReady);
            pipelineExecutor.OnDataEnd     += new PipelineExecutor.DataEndDelegate(pipelineExecutor_OnDataEnd);
            pipelineExecutor.OnOutputReady += new PipelineExecutor.ErrorReadyDelegate(pipelineExecutor_OnOutputReady);
            pipelineExecutor.Start();
        }
 private void pipelineExecutor_OnDataEnd(PipelineExecutor sender)
 {
     if (sender.Pipeline.PipelineStateInfo.State == PipelineState.Failed)
     {
         shouldReturn = true;
         result       = -1;
         OutputTextBox.AppendText(string.Format("Error in script: {0}", sender.Pipeline.PipelineStateInfo.Reason));
     }
     else
     {
         var allOutputs = OutputTextBox.Text.Split('\n');
         result       = Convert.ToInt32(allOutputs[allOutputs.Length - 2]);
         shouldReturn = true;
     }
 }