Пример #1
0
 internal LocalPipeline(System.Management.Automation.Runspaces.LocalRunspace runspace, CommandCollection command, bool addToHistory, bool isNested, ObjectStreamBase inputStream, ObjectStreamBase outputStream, ObjectStreamBase errorStream, PSInformationalBuffers infoBuffers) : base(runspace, command, addToHistory, isNested, inputStream, outputStream, errorStream, infoBuffers)
 {
     this._historyIdForThisPipeline = -1L;
     this._invokeHistoryIds = new List<long>();
     this._stopper = new PipelineStopper(this);
     this.InitStreams();
 }
Пример #2
0
        /// <summary>
        /// Create a Pipeline with an existing command string.
        /// Caller should validate all the parameters.
        /// </summary>
        /// <param name="runspace">
        /// The LocalRunspace to associate with this pipeline.
        /// </param>
        /// <param name="command">
        /// The command to invoke.
        /// </param>
        /// <param name="addToHistory"> 
        /// If true, add the command to history.
        /// </param>
        /// <param name="isNested">
        /// If true, mark this pipeline as a nested pipeline.
        /// </param>
        /// <param name="inputStream">
        /// Stream to use for reading input objects.
        /// </param>
        /// <param name="errorStream">
        /// Stream to use for writing error objects.
        /// </param>
        /// <param name="outputStream">
        /// Stream to use for writing output objects.
        /// </param>
        /// <param name="infoBuffers">
        /// Buffers used to write progress, verbose, debug, warning, information
        /// information of an invocation.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Command is null and add to history is true
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// 1. InformationalBuffers is null
        /// </exception>
        protected PipelineBase(Runspace runspace,
            CommandCollection command,
            bool addToHistory,
            bool isNested,
            ObjectStreamBase inputStream,
            ObjectStreamBase outputStream,
            ObjectStreamBase errorStream,
            PSInformationalBuffers infoBuffers)
            : base(runspace, command)
        {
            Dbg.Assert(null != inputStream, "Caller Should validate inputstream parameter");
            Dbg.Assert(null != outputStream, "Caller Should validate outputStream parameter");
            Dbg.Assert(null != errorStream, "Caller Should validate errorStream parameter");
            Dbg.Assert(null != infoBuffers, "Caller Should validate informationalBuffers parameter");
            Dbg.Assert(null != command, "Command cannot be null");

            // Since we are constructing this pipeline using a commandcollection we dont need
            // to add cmd to CommandCollection again (Initialize does this).. because of this
            // I am handling history here..
            Initialize(runspace, null, false, isNested);
            if (true == addToHistory)
            {
                // get command text for history..
                string cmdText = command.GetCommandStringForHistory();
                HistoryString = cmdText;
                AddToHistory = addToHistory;
            }

            //Initialize streams
            InputStream = inputStream;
            OutputStream = outputStream;
            ErrorStream = errorStream;
            InformationalBuffers = infoBuffers;
        }
Пример #3
0
 public ObjectWriter([In, Out] ObjectStreamBase stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     this._stream = stream;
 }
 private void HandleInputDataReady(object sender, EventArgs e)
 {
     lock (this.inputSyncObject)
     {
         ObjectStreamBase inputstream = sender as ObjectStreamBase;
         this.WriteInput(inputstream);
     }
 }
Пример #5
0
 public ObjectWriter([In, Out] ObjectStreamBase stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     this._stream = stream;
 }
Пример #6
0
        /// <summary>
        /// Construct with an existing ObjectStream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <exception cref="ArgumentNullException">Thrown if the specified stream is null.</exception>
        protected ObjectReaderBase([In, Out] ObjectStreamBase stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), "stream may not be null");
            }

            _stream = stream;
        }
Пример #7
0
        /// <summary>
        /// Construct with an existing ObjectStream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <exception cref="ArgumentNullException">Thrown if the specified stream is null.</exception>
        public ObjectReaderBase([In, Out] ObjectStreamBase stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream", "stream may not be null");
            }

            _stream = stream;
        }
Пример #8
0
 public ObjectReaderBase([In, Out] ObjectStreamBase stream)
 {
     this._monitorObject = new object();
     if (stream == null)
     {
         throw new ArgumentNullException("stream", "stream may not be null");
     }
     this._stream = stream;
 }
Пример #9
0
 protected PipelineBase(System.Management.Automation.Runspaces.Runspace runspace, string command, bool addToHistory, bool isNested) : base(runspace)
 {
     this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(System.Management.Automation.Runspaces.PipelineState.NotStarted);
     this._performNestedCheck = true;
     this._executionEventQueue = new Queue<ExecutionEventQueueItem>();
     this._syncRoot = new object();
     this.Initialize(runspace, command, addToHistory, isNested);
     this._inputStream = new ObjectStream();
     this._outputStream = new ObjectStream();
     this._errorStream = new ObjectStream();
 }
Пример #10
0
        /// <summary>
        /// Construct with an existing ObjectStream.
        /// </summary>
        /// <param name="stream">The stream to write.</param>
        /// <exception cref="ArgumentNullException">Thrown if the specified stream is null.</exception>
        public ObjectWriter([In, Out] ObjectStreamBase stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            _stream = stream;
#if (false)
            stream.WriteReady += new EventHandler(this.OnWriteReady);
#endif
        }
Пример #11
0
 /// <summary>
 /// Create a Pipeline with an existing command string.
 /// Caller should validate all the parameters.
 /// </summary>
 /// <param name="runspace">
 /// The LocalRunspace to associate with this pipeline.
 /// </param>
 /// <param name="command">
 /// The command to execute.
 /// </param>
 /// <param name="addToHistory">
 /// If true, add the command(s) to the history list of the runspace.
 /// </param>
 /// <param name="isNested">
 /// If true, mark this pipeline as a nested pipeline.
 /// </param>
 /// <param name="inputStream">
 /// Stream to use for reading input objects.
 /// </param>
 /// <param name="errorStream">
 /// Stream to use for writing error objects.
 /// </param>
 /// <param name="outputStream">
 /// Stream to use for writing output objects.
 /// </param>
 /// <param name="infoBuffers">
 /// Buffers used to write progress, verbose, debug, warning, information
 /// information of an invocation.
 /// </param>
 internal LocalPipeline(LocalRunspace runspace,
     CommandCollection command,
     bool addToHistory,
     bool isNested,
     ObjectStreamBase inputStream,
     ObjectStreamBase outputStream,
     ObjectStreamBase errorStream,
     PSInformationalBuffers infoBuffers)
     : base(runspace, command, addToHistory, isNested, inputStream, outputStream, errorStream, infoBuffers)
 {
     _stopper = new PipelineStopper(this);
     InitStreams();
 }
 private void WriteInput(ObjectStreamBase inputstream)
 {
     foreach (object obj2 in inputstream.ObjectReader.NonBlockingRead(0x7fffffff))
     {
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(obj2, this.clientRunspacePoolId, this.clientPowerShellId));
     }
     if (!inputstream.IsOpen)
     {
         foreach (object obj3 in inputstream.ObjectReader.NonBlockingRead(0x7fffffff))
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(obj3, this.clientRunspacePoolId, this.clientPowerShellId));
         }
         inputstream.DataReady -= new EventHandler(this.HandleInputDataReady);
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
     }
 }
 internal void SendInput(ObjectStreamBase inputstream)
 {
     if (!inputstream.IsOpen && (inputstream.Count == 0))
     {
         lock (this.inputSyncObject)
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
             return;
         }
     }
     lock (this.inputSyncObject)
     {
         inputstream.DataReady += new EventHandler(this.HandleInputDataReady);
         this.WriteInput(inputstream);
     }
 }
Пример #14
0
 protected PipelineBase(System.Management.Automation.Runspaces.Runspace runspace, CommandCollection command, bool addToHistory, bool isNested, ObjectStreamBase inputStream, ObjectStreamBase outputStream, ObjectStreamBase errorStream, PSInformationalBuffers infoBuffers) : base(runspace, command)
 {
     this._pipelineStateInfo = new System.Management.Automation.Runspaces.PipelineStateInfo(System.Management.Automation.Runspaces.PipelineState.NotStarted);
     this._performNestedCheck = true;
     this._executionEventQueue = new Queue<ExecutionEventQueueItem>();
     this._syncRoot = new object();
     this.Initialize(runspace, null, false, isNested);
     if (addToHistory)
     {
         string commandStringForHistory = command.GetCommandStringForHistory();
         this._historyString = commandStringForHistory;
         this._addToHistory = addToHistory;
     }
     this._inputStream = inputStream;
     this._outputStream = outputStream;
     this._errorStream = errorStream;
     this._informationalBuffers = infoBuffers;
 }
 internal void SendInput(ObjectStreamBase inputstream)
 {
     using (ClientPowerShellDataStructureHandler.tracer.TraceMethod())
     {
         if (!inputstream.IsOpen && inputstream.Count == 0)
         {
             lock (this.inputSyncObject)
                 this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
         }
         else
         {
             lock (this.inputSyncObject)
             {
                 inputstream.DataReady += new EventHandler(this.HandleInputDataReady);
                 this.WriteInput(inputstream);
             }
         }
     }
 }
 private void WriteInput(ObjectStreamBase inputstream)
 {
     using (ClientPowerShellDataStructureHandler.tracer.TraceMethod())
     {
         foreach (object data in inputstream.ObjectReader.NonBlockingRead(int.MaxValue))
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(data, this.clientRunspacePoolId, this.clientPowerShellId));
         }
         if (inputstream.IsOpen)
         {
             return;
         }
         foreach (object data in inputstream.ObjectReader.NonBlockingRead(int.MaxValue))
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(data, this.clientRunspacePoolId, this.clientPowerShellId));
         }
         inputstream.DataReady -= new EventHandler(this.HandleInputDataReady);
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
     }
 }
Пример #17
0
        /// <summary>
        /// Initialize the client remote powershell instance
        /// </summary>
        /// <param name="inputstream">input for execution</param>
        /// <param name="errorstream">error stream to which
        /// data needs to be written to</param>
        /// <param name="informationalBuffers">informational buffers
        /// which will hold debug, verbose and warning messages</param>
        /// <param name="settings">settings based on which this powershell 
        /// needs to be executed</param>
        /// <param name="outputstream">output stream to which data
        /// needs to be written to</param>
        internal void Initialize(
            ObjectStreamBase inputstream, ObjectStreamBase outputstream,
                 ObjectStreamBase errorstream, PSInformationalBuffers informationalBuffers,
                        PSInvocationSettings settings)
        {
            initialized = true;
            this.informationalBuffers = informationalBuffers;
            InputStream = inputstream;
            this.errorstream = errorstream;
            this.outputstream = outputstream;
            this.settings = settings;

            if (settings == null || settings.Host == null)
            {
                hostToUse = runspacePool.Host;
            }
            else
            {
                hostToUse = settings.Host;
            }

            dataStructureHandler = runspacePool.DataStructureHandler.CreatePowerShellDataStructureHandler(this);

            // register for events from the data structure handler
            dataStructureHandler.InvocationStateInfoReceived +=
                new EventHandler<RemoteDataEventArgs<PSInvocationStateInfo>>(HandleInvocationStateInfoReceived);
            dataStructureHandler.OutputReceived += new EventHandler<RemoteDataEventArgs<object>>(HandleOutputReceived);
            dataStructureHandler.ErrorReceived += new EventHandler<RemoteDataEventArgs<ErrorRecord>>(HandleErrorReceived);
            dataStructureHandler.InformationalMessageReceived +=
                new EventHandler<RemoteDataEventArgs<InformationalMessage>>(HandleInformationalMessageReceived);
            dataStructureHandler.HostCallReceived +=
                new EventHandler<RemoteDataEventArgs<RemoteHostCall>>(HandleHostCallReceived);
            dataStructureHandler.ClosedNotificationFromRunspacePool +=
                new EventHandler<RemoteDataEventArgs<Exception>>(HandleCloseNotificationFromRunspacePool);
            dataStructureHandler.BrokenNotificationFromRunspacePool +=
                new EventHandler<RemoteDataEventArgs<Exception>>(HandleBrokenNotificationFromRunspacePool);
            dataStructureHandler.ConnectCompleted += new EventHandler<RemoteDataEventArgs<Exception>>(HandleConnectCompleted);
            dataStructureHandler.ReconnectCompleted += new EventHandler<RemoteDataEventArgs<Exception>>(HandleConnectCompleted);
            dataStructureHandler.RobustConnectionNotification +=
                new EventHandler<ConnectionStatusEventArgs>(HandleRobustConnectionNotification);
            dataStructureHandler.CloseCompleted +=
                new EventHandler<EventArgs>(HandleCloseCompleted);
        }
Пример #18
0
 public ObjectWriter([In, Out] ObjectStreamBase stream)
 {
     using (ObjectWriter._trace.TraceConstructor((object)this))
         this._stream = stream != null ? stream : throw new ArgumentNullException(nameof(stream));
 }
Пример #19
0
 public ObjectReaderBase([In, Out] ObjectStreamBase stream)
 {
     using (ObjectReaderBase <T> ._trace.TraceConstructor((object)this))
         this._stream = stream != null ? stream : throw new ArgumentNullException(nameof(stream), "stream may not be null");
 }
 private void WriteInput(ObjectStreamBase inputstream)
 {
     foreach (object obj2 in inputstream.ObjectReader.NonBlockingRead(0x7fffffff))
     {
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(obj2, this.clientRunspacePoolId, this.clientPowerShellId));
     }
     if (!inputstream.IsOpen)
     {
         foreach (object obj3 in inputstream.ObjectReader.NonBlockingRead(0x7fffffff))
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInput(obj3, this.clientRunspacePoolId, this.clientPowerShellId));
         }
         inputstream.DataReady -= new EventHandler(this.HandleInputDataReady);
         this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
     }
 }
 internal void SendInput(ObjectStreamBase inputstream)
 {
     if (!inputstream.IsOpen && (inputstream.Count == 0))
     {
         lock (this.inputSyncObject)
         {
             this.SendDataAsync(RemotingEncoder.GeneratePowerShellInputEnd(this.clientRunspacePoolId, this.clientPowerShellId));
             return;
         }
     }
     lock (this.inputSyncObject)
     {
         inputstream.DataReady += new EventHandler(this.HandleInputDataReady);
         this.WriteInput(inputstream);
     }
 }