Example #1
0
 internal ClientRemotePowerShell(
     PowerShell shell,
     ObjectStreamBase inputstream,
     ObjectStreamBase outputstream,
     ObjectStreamBase errorstream,
     PSInformationalBuffers informationalBuffers,
     PSInvocationSettings settings,
     RemoteRunspacePoolInternal runspacePool)
 {
     using (ClientRemotePowerShell.tracer.TraceConstructor((object)this))
     {
         this.shell = shell;
         this.informationalBuffers = informationalBuffers;
         this.InputStream          = inputstream;
         this.errorstream          = errorstream;
         this.outputstream         = outputstream;
         this.settings             = settings;
         this.clientRunspacePoolId = runspacePool.InstanceId;
         this.hostToUse            = settings == null || settings.Host == null ? runspacePool.Host : settings.Host;
         this.computerName         = runspacePool.ConnectionInfo.ComputerName;
         this.dataStructureHandler = runspacePool.DataStructureHandler.CreatePowerShellDataStructureHandler(this);
         this.dataStructureHandler.InvocationStateInfoReceived += new EventHandler <RemoteDataEventArgs <PSInvocationStateInfo> >(this.HandleInvocationStateInfoReceived);
         this.dataStructureHandler.OutputReceived += new EventHandler <RemoteDataEventArgs <object> >(this.HandleOutputReceived);
         this.dataStructureHandler.ErrorReceived  += new EventHandler <RemoteDataEventArgs <ErrorRecord> >(this.HandleErrorReceived);
         this.dataStructureHandler.InformationalMessageReceived       += new EventHandler <RemoteDataEventArgs <InformationalMessage> >(this.HandleInformationalMessageReceived);
         this.dataStructureHandler.HostCallReceived                   += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived);
         this.dataStructureHandler.ClosedNotificationFromRunspacePool += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleCloseNotificationFromRunspacePool);
         this.dataStructureHandler.BrokenNotificationFromRunspacePool += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleBrokenNotificationFromRunspacePool);
     }
 }
Example #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(inputStream != null, "Caller Should validate inputstream parameter");
            Dbg.Assert(outputStream != null, "Caller Should validate outputStream parameter");
            Dbg.Assert(errorStream != null, "Caller Should validate errorStream parameter");
            Dbg.Assert(infoBuffers != null, "Caller Should validate informationalBuffers parameter");
            Dbg.Assert(command != null, "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 (addToHistory)
            {
                // get command text for history..
                string cmdText = command.GetCommandStringForHistory();
                HistoryString = cmdText;
                AddToHistory  = addToHistory;
            }

            // Initialize streams
            InputStream          = inputStream;
            OutputStream         = outputStream;
            ErrorStream          = errorStream;
            InformationalBuffers = infoBuffers;
        }
 internal void Initialize(ObjectStreamBase inputstream, ObjectStreamBase outputstream, ObjectStreamBase errorstream, PSInformationalBuffers informationalBuffers, PSInvocationSettings settings)
 {
     this.initialized          = true;
     this.informationalBuffers = informationalBuffers;
     this.InputStream          = inputstream;
     this.errorstream          = errorstream;
     this.outputstream         = outputstream;
     this.settings             = settings;
     if ((settings == null) || (settings.Host == null))
     {
         this.hostToUse = this.runspacePool.Host;
     }
     else
     {
         this.hostToUse = settings.Host;
     }
     this.dataStructureHandler = this.runspacePool.DataStructureHandler.CreatePowerShellDataStructureHandler(this);
     this.dataStructureHandler.InvocationStateInfoReceived += new EventHandler <RemoteDataEventArgs <PSInvocationStateInfo> >(this.HandleInvocationStateInfoReceived);
     this.dataStructureHandler.OutputReceived += new EventHandler <RemoteDataEventArgs <object> >(this.HandleOutputReceived);
     this.dataStructureHandler.ErrorReceived  += new EventHandler <RemoteDataEventArgs <ErrorRecord> >(this.HandleErrorReceived);
     this.dataStructureHandler.InformationalMessageReceived       += new EventHandler <RemoteDataEventArgs <InformationalMessage> >(this.HandleInformationalMessageReceived);
     this.dataStructureHandler.HostCallReceived                   += new EventHandler <RemoteDataEventArgs <RemoteHostCall> >(this.HandleHostCallReceived);
     this.dataStructureHandler.ClosedNotificationFromRunspacePool += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleCloseNotificationFromRunspacePool);
     this.dataStructureHandler.BrokenNotificationFromRunspacePool += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleBrokenNotificationFromRunspacePool);
     this.dataStructureHandler.ConnectCompleted                   += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleConnectCompleted);
     this.dataStructureHandler.ReconnectCompleted                 += new EventHandler <RemoteDataEventArgs <Exception> >(this.HandleConnectCompleted);
     this.dataStructureHandler.RobustConnectionNotification       += new EventHandler <ConnectionStatusEventArgs>(this.HandleRobustConnectionNotification);
     this.dataStructureHandler.CloseCompleted += new EventHandler <EventArgs>(this.HandleCloseCompleted);
 }
Example #4
0
 protected PipelineBase(
     Runspace runspace,
     CommandCollection command,
     bool addToHistory,
     bool isNested,
     ObjectStreamBase inputStream,
     ObjectStreamBase outputStream,
     ObjectStreamBase errorStream,
     PSInformationalBuffers infoBuffers)
     : base(runspace, command)
 {
     using (PipelineBase._trace.TraceConstructor((object)this))
     {
         this.Initialize(runspace, (string)null, false, isNested);
         if (addToHistory)
         {
             this._historyString = command.GetCommandStringForHistory();
             this._addToHistory  = addToHistory;
         }
         this._inputStream          = inputStream;
         this._outputStream         = outputStream;
         this._errorStream          = errorStream;
         this._informationalBuffers = infoBuffers;
     }
 }
Example #5
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();
 }
Example #6
0
 internal LocalPipeline(
     LocalRunspace runspace,
     CommandCollection command,
     bool addToHistory,
     bool isNested,
     ObjectStreamBase inputStream,
     ObjectStreamBase outputStream,
     ObjectStreamBase errorStream,
     PSInformationalBuffers infoBuffers)
     : base((Runspace)runspace, command, addToHistory, isNested, inputStream, outputStream, errorStream, infoBuffers)
 {
     this._stopper = new PipelineStopper(this);
     this.InitStreams();
 }
        /// <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 is null || settings.Host is null)
            {
                hostToUse = runspacePool.Host;
            }
Example #8
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;
 }
        /// <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 += HandleInvocationStateInfoReceived;
            dataStructureHandler.OutputReceived += HandleOutputReceived;
            dataStructureHandler.ErrorReceived  += HandleErrorReceived;
            dataStructureHandler.InformationalMessageReceived       += HandleInformationalMessageReceived;
            dataStructureHandler.HostCallReceived                   += HandleHostCallReceived;
            dataStructureHandler.ClosedNotificationFromRunspacePool += HandleCloseNotificationFromRunspacePool;
            dataStructureHandler.BrokenNotificationFromRunspacePool += HandleBrokenNotificationFromRunspacePool;
            dataStructureHandler.ConnectCompleted                   += HandleConnectCompleted;
            dataStructureHandler.ReconnectCompleted                 += HandleConnectCompleted;
            dataStructureHandler.RobustConnectionNotification       += HandleRobustConnectionNotification;
            dataStructureHandler.CloseCompleted += HandleCloseCompleted;
        }
 /// <summary>
 /// If informationBuffers is not null, the respective messages will also
 /// be written to the buffers along with external host.
 /// </summary>
 /// <param name="informationalBuffers">
 /// Buffers to which Debug, Verbose, Warning, Progress, Information messages
 /// will be written to.
 /// </param>
 /// <remarks>
 /// This method is not thread safe. Caller should make sure of the
 /// associated risks.
 /// </remarks>
 internal void SetInformationalMessageBuffers(PSInformationalBuffers informationalBuffers)
 {
     _informationalBuffers = informationalBuffers;
 }
Example #11
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);
        }
Example #12
0
 internal void SetInformationalMessageBuffers(PSInformationalBuffers informationalBuffers) => this.informationalBuffers = informationalBuffers;
 /// <summary>
 /// If informationBuffers is not null, the respective messages will also
 /// be written to the buffers along with external host.
 /// </summary>
 /// <param name="informationalBuffers">
 /// Buffers to which Debug, Verbose, Warning, Progress, Information messages
 /// will be written to.
 /// </param>
 /// <remarks>
 /// This method is not thread safe. Caller should make sure of the
 /// associated risks. 
 /// </remarks>
 internal void SetInformationalMessageBuffers(PSInformationalBuffers informationalBuffers)
 {
     _informationalBuffers = informationalBuffers;
 }
Example #14
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();
 }
Example #15
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;
        }