예제 #1
0
        protected void OnSignalPacketReceived(Guid psGuid)
        {
            if (psGuid == Guid.Empty)
            {
                throw new PSRemotingTransportException(PSRemotingErrorId.IPCNoSignalForSession, RemotingErrorIdStrings.IPCNoSignalForSession,
                                                       OutOfProcessUtils.PS_OUT_OF_PROC_SIGNAL_TAG);
            }
            else
            {
                // this is for a command
                AbstractServerTransportManager cmdTM = null;

                try
                {
                    lock (_syncObject)
                    {
                        cmdTM = sessionTM.GetCommandTransportManager(psGuid);
                    }

                    // dont throw if there is no cmdTM as it might have legitimately closed
                    if (cmdTM != null)
                    {
                        cmdTM.Close(null);
                    }
                }
                finally
                {
                    // Always send ack signal to avoid not responding in client.
                    originalStdOut.WriteLine(OutOfProcessUtils.CreateSignalAckPacket(psGuid));
                }
            }
        }
예제 #2
0
        private void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid)
        {
            string str = "stdin";

            if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                str = "pr";
            }
            if (Guid.Empty == psGuid)
            {
                lock (this._syncObject)
                {
                    this.sessionTM.ProcessRawData(rawData, str);
                    return;
                }
            }
            AbstractServerTransportManager commandTransportManager = null;

            lock (this._syncObject)
            {
                commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid);
            }
            if (commandTransportManager != null)
            {
                commandTransportManager.ProcessRawData(rawData, str);
            }
            else
            {
                this.originalStdOut.WriteLine(OutOfProcessUtils.CreateDataAckPacket(psGuid));
            }
        }
예제 #3
0
        private void OnClosePacketReceived(Guid psGuid)
        {
            PowerShellTraceSource traceSource = PowerShellTraceSourceFactory.GetTraceSource();

            if (psGuid == Guid.Empty)
            {
                traceSource.WriteMessage("BEGIN calling close on session transport manager");
                bool flag = false;
                lock (this._syncObject)
                {
                    if (this._inProgressCommandsCount > 0)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    this.allcmdsClosedEvent.WaitOne();
                }
                lock (this._syncObject)
                {
                    traceSource.WriteMessage(string.Concat(new object[] { "OnClosePacketReceived, in progress commands count should be zero : ", this._inProgressCommandsCount, ", psGuid : ", psGuid.ToString() }));
                    if (this.sessionTM != null)
                    {
                        this.sessionTM.Close(null);
                    }
                    traceSource.WriteMessage("END calling close on session transport manager");
                    this.sessionTM = null;
                    goto Label_01D5;
                }
            }
            traceSource.WriteMessage("Closing command with GUID " + psGuid.ToString());
            AbstractServerTransportManager commandTransportManager = null;

            lock (this._syncObject)
            {
                commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid);
            }
            if (commandTransportManager != null)
            {
                commandTransportManager.Close(null);
            }
            lock (this._syncObject)
            {
                traceSource.WriteMessage(string.Concat(new object[] { "OnClosePacketReceived, in progress commands count should be greater than zero : ", this._inProgressCommandsCount, ", psGuid : ", psGuid.ToString() }));
                this._inProgressCommandsCount--;
                if (this._inProgressCommandsCount == 0)
                {
                    this.allcmdsClosedEvent.Set();
                }
            }
Label_01D5:
            this.originalStdOut.WriteLine(OutOfProcessUtils.CreateCloseAckPacket(psGuid));
        }
예제 #4
0
        private void OnSignalPacketReceived(Guid psGuid)
        {
            if (psGuid == Guid.Empty)
            {
                throw new PSRemotingTransportException(PSRemotingErrorId.IPCNoSignalForSession, RemotingErrorIdStrings.IPCNoSignalForSession, new object[] { "Signal" });
            }
            AbstractServerTransportManager commandTransportManager = null;

            lock (this._syncObject)
            {
                commandTransportManager = this.sessionTM.GetCommandTransportManager(psGuid);
            }
            if (commandTransportManager != null)
            {
                commandTransportManager.Close(null);
            }
            this.originalStdOut.WriteLine(OutOfProcessUtils.CreateSignalAckPacket(psGuid));
        }
예제 #5
0
        protected void OnDataPacketReceived(byte[] rawData, string stream, Guid psGuid)
        {
            string streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_STDIN;

            if (stream.Equals(DataPriorityType.PromptResponse.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                streamTemp = System.Management.Automation.Remoting.Client.WSManNativeApi.WSMAN_STREAM_ID_PROMPTRESPONSE;
            }

            if (Guid.Empty == psGuid)
            {
                lock (_syncObject)
                {
                    sessionTM.ProcessRawData(rawData, streamTemp);
                }
            }
            else
            {
                // this is for a command
                AbstractServerTransportManager cmdTM = null;

                lock (_syncObject)
                {
                    cmdTM = sessionTM.GetCommandTransportManager(psGuid);
                }

                if (cmdTM != null)
                {
                    // not throwing when there is no associated command as the command might have
                    // legitimately closed while the client is sending data. however the client
                    // should die after timeout as we are not sending an ACK back.
                    cmdTM.ProcessRawData(rawData, streamTemp);
                }
                else
                {
                    // There is no command transport manager to process the input data.
                    // However, we still need to acknowledge to the client that this input data
                    // was received.  This can happen with some cmdlets such as Select-Object -First
                    // where the cmdlet completes before all input data is received.
                    originalStdOut.WriteLine(OutOfProcessUtils.CreateDataAckPacket(psGuid));
                }
            }
        }
예제 #6
0
        protected void OnClosePacketReceived(Guid psGuid)
        {
            PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource();

            if (psGuid == Guid.Empty)
            {
                tracer.WriteMessage("BEGIN calling close on session transport manager");

                bool waitForAllcmdsClosedEvent = false;

                lock (_syncObject)
                {
                    if (_inProgressCommandsCount > 0)
                    {
                        waitForAllcmdsClosedEvent = true;
                    }
                }

                // Wait outside sync lock if required for all cmds to be closed
                //
                if (waitForAllcmdsClosedEvent)
                {
                    allcmdsClosedEvent.WaitOne();
                }

                lock (_syncObject)
                {
                    tracer.WriteMessage("OnClosePacketReceived, in progress commands count should be zero : " + _inProgressCommandsCount + ", psGuid : " + psGuid.ToString());

                    if (sessionTM != null)
                    {
                        // it appears that when closing PowerShell ISE, therefore closing OutOfProcServerMediator, there are 2 Close command requests
                        // changing PSRP/IPC at this point is too risky, therefore protecting about this duplication
                        sessionTM.Close(null);
                    }

                    tracer.WriteMessage("END calling close on session transport manager");
                    sessionTM = null;
                }
            }
            else
            {
                tracer.WriteMessage("Closing command with GUID " + psGuid.ToString());

                // this is for a command
                AbstractServerTransportManager cmdTM = null;

                lock (_syncObject)
                {
                    cmdTM = sessionTM.GetCommandTransportManager(psGuid);
                }

                // dont throw if there is no cmdTM as it might have legitimately closed
                if (cmdTM != null)
                {
                    cmdTM.Close(null);
                }

                lock (_syncObject)
                {
                    tracer.WriteMessage("OnClosePacketReceived, in progress commands count should be greater than zero : " + _inProgressCommandsCount + ", psGuid : " + psGuid.ToString());

                    _inProgressCommandsCount--;

                    if (_inProgressCommandsCount == 0)
                    {
                        allcmdsClosedEvent.Set();
                    }
                }
            }

            // send close ack
            originalStdOut.WriteLine(OutOfProcessUtils.CreateCloseAckPacket(psGuid));
        }