示例#1
0
        private void HandleStateChanged(object sender, RemoteSessionStateEventArgs arg)
        {
            if (arg == null)
            {
                throw PSTraceSource.NewArgumentNullException("arg");
            }

            // Enqueue session related negotiation packets first
            if ((arg.SessionStateInfo.State == RemoteSessionState.NegotiationSending) || (arg.SessionStateInfo.State == RemoteSessionState.NegotiationSendingOnConnect))
            {
                HandleNegotiationSendingStateChange();
            }

            // this will enable top-layers to enqueue any packets during NegotiationSending and
            // during other states.
            ConnectionStateChanged.SafeInvoke(this, arg);

            if ((arg.SessionStateInfo.State == RemoteSessionState.NegotiationSending) || (arg.SessionStateInfo.State == RemoteSessionState.NegotiationSendingOnConnect))
            {
                SendNegotiationAsync(arg.SessionStateInfo.State);
            }

            //once session is established.. start receiving data (if not already done and only apples to wsmanclientsessionTM)
            if (arg.SessionStateInfo.State == RemoteSessionState.Established)
            {
                WSManClientSessionTransportManager tm = _transportManager as WSManClientSessionTransportManager;
                if (tm != null)
                {
                    tm.AdjustForProtocolVariations(_session.ServerProtocolVersion);
                    tm.StartReceivingData();
                }
            }

            // Close the transport manager only after powershell's close their transports
            // Powershell's close their transport using the ConnectionStateChanged event notification.
            if (arg.SessionStateInfo.State == RemoteSessionState.ClosingConnection)
            {
                CloseConnectionAsync();
            }

            //process disconnect
            if (arg.SessionStateInfo.State == RemoteSessionState.Disconnecting)
            {
                DisconnectAsync();
            }

            //process reconnect
            if (arg.SessionStateInfo.State == RemoteSessionState.Reconnecting)
            {
                ReconnectAsync();
            }
        }
示例#2
0
 private void HandleStateChanged(object sender, RemoteSessionStateEventArgs arg)
 {
     if (arg == null)
     {
         throw PSTraceSource.NewArgumentNullException("arg");
     }
     if ((arg.SessionStateInfo.State == RemoteSessionState.NegotiationSending) || (arg.SessionStateInfo.State == RemoteSessionState.NegotiationSendingOnConnect))
     {
         this.HandleNegotiationSendingStateChange();
     }
     this.ConnectionStateChanged.SafeInvoke <RemoteSessionStateEventArgs>(this, arg);
     if ((arg.SessionStateInfo.State == RemoteSessionState.NegotiationSending) || (arg.SessionStateInfo.State == RemoteSessionState.NegotiationSendingOnConnect))
     {
         this.SendNegotiationAsync(arg.SessionStateInfo.State);
     }
     if (arg.SessionStateInfo.State == RemoteSessionState.Established)
     {
         WSManClientSessionTransportManager manager = this._transportManager as WSManClientSessionTransportManager;
         if (manager != null)
         {
             manager.AdjustForProtocolVariations(this._session.ServerProtocolVersion);
             manager.StartReceivingData();
         }
     }
     if (arg.SessionStateInfo.State == RemoteSessionState.ClosingConnection)
     {
         this.CloseConnectionAsync();
     }
     if (arg.SessionStateInfo.State == RemoteSessionState.Disconnecting)
     {
         this.DisconnectAsync();
     }
     if (arg.SessionStateInfo.State == RemoteSessionState.Reconnecting)
     {
         this.ReconnectAsync();
     }
 }