예제 #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);
     }
 }
예제 #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;
        }
예제 #3
0
 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);
 }
예제 #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;
     }
 }
예제 #5
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();
 }
예제 #6
0
 protected PipelineBase(Runspace runspace, string command, bool addToHistory, bool isNested)
     : base(runspace)
 {
     using (PipelineBase._trace.TraceConstructor((object)this))
     {
         this.Initialize(runspace, command, addToHistory, isNested);
         this._inputStream  = (ObjectStreamBase) new ObjectStream();
         this._outputStream = (ObjectStreamBase) new ObjectStream();
         this._errorStream  = (ObjectStreamBase) new ObjectStream();
     }
 }
예제 #7
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;
            }
예제 #9
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;
 }
예제 #10
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 += 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;
        }
예제 #11
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();
 }