Exemplo n.º 1
0
 internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, Executor.ExecutionOptions options)
 {
     exceptionThrown = null;
     lock (this.instanceStateLock)
     {
         this.pipeline = tempPipeline;
     }
     try
     {
         try
         {
             if ((options & Executor.ExecutionOptions.AddOutputter) > Executor.ExecutionOptions.None && this.parent.OutputFormat == Serialization.DataFormat.Text)
             {
                 if (tempPipeline.Commands.Count == 1)
                 {
                     tempPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                 }
                 Command command = new Command("Out-Default", false, true);
                 tempPipeline.Commands.Add(command);
             }
             tempPipeline.Output.DataReady += new EventHandler(this.OutputObjectStreamHandler);
             tempPipeline.Error.DataReady  += new EventHandler(this.ErrorObjectStreamHandler);
             tempPipeline.StateChanged     += HandleStateChanged;
             tempPipeline.InvokeAsync();
             if ((options & Executor.ExecutionOptions.ReadInputObjects) > Executor.ExecutionOptions.None && this.parent.IsStandardInputRedirected)
             {
                 WrappedDeserializer wrappedDeserializer = new WrappedDeserializer(this.parent.InputFormat, "Input", this.parent.StandardInReader);
                 while (!wrappedDeserializer.AtEnd)
                 {
                     object obj = wrappedDeserializer.Deserialize();
                     if (obj == null)
                     {
                         break;
                     }
                     try
                     {
                         tempPipeline.Input.Write(obj);
                     }
                     catch (PipelineClosedException pipelineClosedException)
                     {
                         break;
                     }
                 }
                 wrappedDeserializer.End();
             }
             tempPipeline.Input.Close();
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             PowwaHost.CheckForSevereException(exception);
             exceptionThrown = exception;
         }
     }
     finally
     {
         this.parent.ResetProgress();
         this.Reset();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Executes a pipeline in the console when we are running asnyc.
        /// </summary>
        /// <param name="tempPipeline">
        /// The pipeline to execute.
        /// </param>
        /// <param name="exceptionThrown">
        /// Any exception thrown trying to run the pipeline.
        /// </param>
        /// <param name="options">
        /// The options to use to execute the pipeline.
        /// </param>
        internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, ExecutionOptions options)
        {
            Dbg.Assert(!_isPromptFunctionExecutor, "should not async invoke the prompt");

            exceptionThrown = null;
            Executor oldCurrent = CurrentExecutor;

            CurrentExecutor = this;

            lock (_instanceStateLock)
            {
                Dbg.Assert(_pipeline == null, "no other pipeline should exist");
                _pipeline = tempPipeline;
            }

            try
            {
                if ((options & ExecutionOptions.AddOutputter) > 0 && _parent.OutputFormat == Serialization.DataFormat.Text)
                {
                    // Tell the script command to merge it's output and error streams

                    if (tempPipeline.Commands.Count == 1)
                    {
                        tempPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                    }

                    // then add out-default to the pipeline to render everything...
                    Command outDefault = new Command("Out-Default", /* isScript */ false, /* useLocalScope */ true);
                    tempPipeline.Commands.Add(outDefault);
                }

                tempPipeline.Output.DataReady += OutputObjectStreamHandler;
                tempPipeline.Error.DataReady  += ErrorObjectStreamHandler;
                PipelineFinishedWaitHandle pipelineWaiter = new PipelineFinishedWaitHandle(tempPipeline);

                // close the input pipeline so the command will do something
                // if we are not reading input
                if ((options & Executor.ExecutionOptions.ReadInputObjects) == 0)
                {
                    tempPipeline.Input.Close();
                }

                tempPipeline.InvokeAsync();
                if ((options & ExecutionOptions.ReadInputObjects) > 0 && Console.IsInputRedirected)
                {
                    // read input objects from stdin
                    WrappedDeserializer des = new WrappedDeserializer(_parent.InputFormat, "Input", _parent.ConsoleIn.Value);
                    while (!des.AtEnd)
                    {
                        object o = des.Deserialize();
                        if (o == null)
                        {
                            break;
                        }

                        try
                        {
                            tempPipeline.Input.Write(o);
                        }
                        catch (PipelineClosedException)
                        {
                            // This exception can occurs when input is closed. This can happen
                            // for various reasons. For ex:Command in the pipeline is invalid and
                            // command discovery throws exception which closes the pipeline and
                            // hence the Input pipe.
                            break;
                        }
                    }
                    des.End();
                }

                tempPipeline.Input.Close();

                pipelineWaiter.Wait();

                // report error if pipeline failed
                if (tempPipeline.PipelineStateInfo.State == PipelineState.Failed && tempPipeline.PipelineStateInfo.Reason != null)
                {
                    if (_parent.OutputFormat == Serialization.DataFormat.Text)
                    {
                        // Report the exception using normal error reporting
                        exceptionThrown = tempPipeline.PipelineStateInfo.Reason;
                    }
                    else
                    {
                        // serialize the error record
                        AsyncPipelineFailureHandler(tempPipeline.PipelineStateInfo.Reason);
                    }
                }
            }
            catch (Exception e)
            {
                exceptionThrown = e;
            }
            finally
            {
                // Once we have the results, or an exception is thrown, we throw away the pipeline.

                _parent.ui.ResetProgress();
                CurrentExecutor = oldCurrent;
                Reset();
            }
        }
Exemplo n.º 3
0
		internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, Executor.ExecutionOptions options)
		{
			exceptionThrown = null;
			lock (this.instanceStateLock)
			{
				this.pipeline = tempPipeline;
			}
			try
			{
				try
				{
					if ((options & Executor.ExecutionOptions.AddOutputter) > Executor.ExecutionOptions.None && this.parent.OutputFormat == Serialization.DataFormat.Text)
					{
						if (tempPipeline.Commands.Count == 1)
						{
							tempPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
						}
						Command command = new Command("Out-Default", false, true);
						tempPipeline.Commands.Add(command);
					}
					tempPipeline.Output.DataReady += new EventHandler(this.OutputObjectStreamHandler);
					tempPipeline.Error.DataReady += new EventHandler(this.ErrorObjectStreamHandler);
					tempPipeline.StateChanged += HandleStateChanged;
					tempPipeline.InvokeAsync();
					if ((options & Executor.ExecutionOptions.ReadInputObjects) > Executor.ExecutionOptions.None && this.parent.IsStandardInputRedirected)
					{
						WrappedDeserializer wrappedDeserializer = new WrappedDeserializer(this.parent.InputFormat, "Input", this.parent.StandardInReader);
						while (!wrappedDeserializer.AtEnd)
						{
							object obj = wrappedDeserializer.Deserialize();
							if (obj == null)
							{
								break;
							}
							try
							{
								tempPipeline.Input.Write(obj);
							}
							catch (PipelineClosedException pipelineClosedException)
							{
								break;
							}
						}
						wrappedDeserializer.End();
					}
					tempPipeline.Input.Close();
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					PowwaHost.CheckForSevereException(exception);
					exceptionThrown = exception;
				}
			}
			finally
			{
				this.parent.ResetProgress();
				this.Reset();
			}
		}
Exemplo n.º 4
0
        internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, ExecutionOptions options)
        {
            Dbg.Assert(!_isPromptFunctionExecutor, "should not async invoke the prompt");

            exceptionThrown = null;
            Executor oldCurrent = CurrentExecutor;
            CurrentExecutor = this;

            lock (_instanceStateLock)
            {
                Dbg.Assert(_pipeline == null, "no other pipeline should exist");
                _pipeline = tempPipeline;
            }

            try
            {
                if ((options & ExecutionOptions.AddOutputter) > 0 && _parent.OutputFormat == Serialization.DataFormat.Text)
                {
                    // Tell the script command to merge it's output and error streams

                    if (tempPipeline.Commands.Count == 1)
                    {
                        tempPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
                    }

                    // then add out-default to the pipeline to render everything...
                    Command outDefault = new Command("Out-Default", /* isScript */false, /* useLocalScope */ true);
                    tempPipeline.Commands.Add(outDefault);
                }

                tempPipeline.Output.DataReady += new EventHandler(OutputObjectStreamHandler);
                tempPipeline.Error.DataReady += new EventHandler(ErrorObjectStreamHandler);
                PipelineFinishedWaitHandle waiterThereIsAFlyInMySoup = new PipelineFinishedWaitHandle(tempPipeline);

                tempPipeline.InvokeAsync();
                if ((options & ExecutionOptions.ReadInputObjects) > 0 && Console.IsInputRedirected)
                {
                    // read input objects from stdin

                    WrappedDeserializer des = new WrappedDeserializer(_parent.InputFormat, "Input", Console.In);
                    while (!des.AtEnd)
                    {
                        object o = des.Deserialize();
                        if (o == null)
                        {
                            break;
                        }

                        try
                        {
                            tempPipeline.Input.Write(o);
                        }
                        catch (PipelineClosedException)
                        {
                            //This exception can occurs when input is closed. This can happen 
                            //for various reasons. For ex:Command in the pipeline is invalid and 
                            //command discovery throws exception which closes the pipeline and 
                            //hence the Input pipe.
                            break;
                        }
                    };
                    des.End();
                }
                tempPipeline.Input.Close();

                waiterThereIsAFlyInMySoup.Wait();

                //report error if pipeline failed
                if (tempPipeline.PipelineStateInfo.State == PipelineState.Failed && tempPipeline.PipelineStateInfo.Reason != null)
                {
                    if (_parent.OutputFormat == Serialization.DataFormat.Text)
                    {
                        //Report the exception using normal error reporting
                        exceptionThrown = tempPipeline.PipelineStateInfo.Reason;
                    }
                    else
                    {
                        //serialize the error record
                        AsyncPipelineFailureHandler(tempPipeline.PipelineStateInfo.Reason);
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleHost.CheckForSevereException(e);
                exceptionThrown = e;
            }
            finally
            {
                // Once we have the results, or an exception is thrown, we throw away the pipeline.

                _parent.ui.ResetProgress();
                CurrentExecutor = oldCurrent;
                Reset();
            }
        }