internal override void CloseConnectionAsync(Exception reasonForClose)
 {
     this.SessionClosing.SafeInvoke<EventArgs>(this, EventArgs.Empty);
     this._transportManager.Close(reasonForClose);
     RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.CloseCompleted);
     this._stateMachine.RaiseEvent(fsmEventArg);
 }
Ejemplo n.º 2
0
 internal void Close(RemoteSessionStateMachineEventArgs reasonForClose)
 {
     this.Closed.SafeInvoke<RemoteSessionStateMachineEventArgs>(this, reasonForClose);
     if (this._runspacePoolDriver != null)
     {
         this._runspacePoolDriver.Closed = (EventHandler<EventArgs>) Delegate.Remove(this._runspacePoolDriver.Closed, new EventHandler<EventArgs>(this.HandleResourceClosing));
     }
 }
        internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg)
        {
            if (dataArg == null)
            {
                throw PSTraceSource.NewArgumentNullException("dataArg");
            }
            RemoteDataObject<PSObject> receivedData = dataArg.ReceivedData;
            RemotingTargetInterface targetInterface = receivedData.TargetInterface;
            RemotingDataType dataType = receivedData.DataType;
            switch (dataType)
            {
                case RemotingDataType.SessionCapability:
                {
                    RemoteSessionCapability remoteSessionCapability = null;
                    try
                    {
                        remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data);
                    }
                    catch (PSRemotingDataStructureException exception2)
                    {
                        throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion });
                    }
                    RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) {
                        RemoteSessionCapability = remoteSessionCapability
                    };
                    this._stateMachine.RaiseEvent(fsmEventArg);
                    if (this.NegotiationReceived != null)
                    {
                        RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability) {
                            RemoteData = receivedData
                        };
                        this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs);
                    }
                    return;
                }
                case RemotingDataType.CloseSession:
                {
                    PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession);
                    RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason);
                    this._stateMachine.RaiseEvent(args);
                    return;
                }
                case RemotingDataType.CreateRunspacePool:
                    this.CreateRunspacePoolReceived.SafeInvoke<RemoteDataEventArgs>(this, dataArg);
                    return;

                case RemotingDataType.PublicKey:
                {
                    string publicKey = RemotingDecoder.GetPublicKey(receivedData.Data);
                    this.PublicKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(publicKey));
                    return;
                }
            }
            throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType });
        }
Ejemplo n.º 4
0
 internal static ServerRemoteSession CreateServerRemoteSession(PSSenderInfo senderInfo, string configurationProviderId, string initializationParameters, AbstractServerSessionTransportManager transportManager)
 {
     _trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Finding InitialSessionState provider for id : {0}", new object[] { configurationProviderId }), new object[0]);
     if (string.IsNullOrEmpty(configurationProviderId))
     {
         throw PSTraceSource.NewInvalidOperationException("remotingerroridstrings", "NonExistentInitialSessionStateProvider", new object[] { configurationProviderId });
     }
     ServerRemoteSession session = new ServerRemoteSession(senderInfo, configurationProviderId, initializationParameters, transportManager);
     RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.CreateSession);
     session._sessionDSHandler.StateMachine.RaiseEvent(fsmEventArg);
     return session;
 }
 internal override void SendNegotiationAsync(RemoteSessionState sessionState)
 {
     RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationSendCompleted);
     this._stateMachine.RaiseEvent(arg, false);
     if (sessionState == RemoteSessionState.NegotiationSending)
     {
         this._transportManager.CreateAsync();
     }
     else if (sessionState == RemoteSessionState.NegotiationSendingOnConnect)
     {
         this._transportManager.ConnectCompleted += new EventHandler<EventArgs>(this.HandleConnectComplete);
         this._transportManager.ConnectAsync();
     }
 }
        internal void HandleTransportError(object sender, TransportErrorOccuredEventArgs e)
        {
            PSRemotingTransportRedirectException exception = e.Exception as PSRemotingTransportRedirectException;
            if ((exception != null) && (this.maxUriRedirectionCount > 0))
            {
                Exception exception2 = null;
                try
                {
                    this.maxUriRedirectionCount--;
                    this.PerformURIRedirection(exception.RedirectLocation);
                    return;
                }
                catch (ArgumentNullException exception3)
                {
                    exception2 = exception3;
                }
                catch (UriFormatException exception4)
                {
                    exception2 = exception4;
                }
                if (exception2 != null)
                {
                    PSRemotingTransportException exception5 = new PSRemotingTransportException(PSRemotingErrorId.RedirectedURINotWellFormatted, RemotingErrorIdStrings.RedirectedURINotWellFormatted, new object[] { this._session.Context.RemoteAddress.OriginalString, exception.RedirectLocation }) {
                        TransportMessage = e.Exception.TransportMessage
                    };
                    e.Exception = exception5;
                }
            }
            RemoteSessionEvent connectFailed = RemoteSessionEvent.ConnectFailed;
            switch (e.ReportingTransportMethod)
            {
                case TransportMethodEnum.CreateShellEx:
                    connectFailed = RemoteSessionEvent.ConnectFailed;
                    break;

                case TransportMethodEnum.SendShellInputEx:
                case TransportMethodEnum.CommandInputEx:
                    connectFailed = RemoteSessionEvent.SendFailed;
                    break;

                case TransportMethodEnum.ReceiveShellOutputEx:
                case TransportMethodEnum.ReceiveCommandOutputEx:
                    connectFailed = RemoteSessionEvent.ReceiveFailed;
                    break;

                case TransportMethodEnum.CloseShellOperationEx:
                    connectFailed = RemoteSessionEvent.CloseFailed;
                    break;

                case TransportMethodEnum.DisconnectShellEx:
                    connectFailed = RemoteSessionEvent.DisconnectFailed;
                    break;

                case TransportMethodEnum.ReconnectShellEx:
                    connectFailed = RemoteSessionEvent.ReconnectFailed;
                    break;
            }
            RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(connectFailed, e.Exception);
            this._stateMachine.RaiseEvent(arg, false);
        }
 private void HandleReconnectComplete(object sender, EventArgs args)
 {
     RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.ReconnectCompleted);
     this.StateMachine.RaiseEvent(arg, false);
 }
Ejemplo n.º 8
0
 public override void CreateAsync()
 {
     RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.CreateSession);
     base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
 }
Ejemplo n.º 9
0
        private void HandlePublicKeyRequestReceived(object sender, RemoteDataEventArgs<string> eventArgs)
        {
			var state = base.SessionDataStructureHandler.StateMachine.State;
            if (state == RemoteSessionState.Established)
            {
                RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyRequested);
                base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
                this.StartKeyExchange();
            }
        }
Ejemplo n.º 10
0
 private void HandleEncryptedSessionKeyReceived(object sender, RemoteDataEventArgs<string> eventArgs)
 {
     if (base.SessionDataStructureHandler.StateMachine.State == RemoteSessionState.EstablishedAndKeySent)
     {
         string data = eventArgs.Data;
         bool flag = this._cryptoHelper.ImportEncryptedSessionKey(data);
         RemoteSessionStateMachineEventArgs arg = null;
         if (!flag)
         {
             arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceiveFailed);
             base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
         }
         this.CompleteKeyExchange();
         arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeyReceived);
         base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
     }
 }
 private void DoDisconnectDuringKeyExchange(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     this.pendingDisconnect = true;
 }
 private void DoCreateSession(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     using (_trace.TraceEventHandlers())
     {
         if (this.State == RemoteSessionState.Idle)
         {
             RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationSending);
             this.RaiseEvent(args, false);
         }
     }
 }
 private void DoClose(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     using (_trace.TraceEventHandlers())
     {
         switch (this._state)
         {
             case RemoteSessionState.Connecting:
             case RemoteSessionState.Connected:
             case RemoteSessionState.NegotiationSending:
             case RemoteSessionState.NegotiationSent:
             case RemoteSessionState.NegotiationReceived:
             case RemoteSessionState.Established:
             case RemoteSessionState.EstablishedAndKeySent:
             case RemoteSessionState.EstablishedAndKeyReceived:
             case RemoteSessionState.Disconnecting:
             case RemoteSessionState.Disconnected:
             case RemoteSessionState.Reconnecting:
             case RemoteSessionState.RCDisconnecting:
                 this.SetState(RemoteSessionState.ClosingConnection, arg.Reason);
                 break;
             case RemoteSessionState.ClosingConnection:
             case RemoteSessionState.Closed:
                 break;
             default:
             {
                 PSRemotingTransportException reason = new PSRemotingTransportException(arg.Reason, RemotingErrorIdStrings.ForceClosed, new object[0]);
                 this.SetState(RemoteSessionState.Closed, reason);
                 break;
             }
         }
         this.CleanAll();
     }
 }
 internal bool CanByPassRaiseEvent(RemoteSessionStateMachineEventArgs arg)
 {
     if ((arg.StateEvent != RemoteSessionEvent.MessageReceived) || (((this._state != RemoteSessionState.Established) && (this._state != RemoteSessionState.EstablishedAndKeyReceived)) && (((this._state != RemoteSessionState.EstablishedAndKeySent) && (this._state != RemoteSessionState.Disconnecting)) && (this._state != RemoteSessionState.Disconnected))))
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 15
0
		public void CloseSession(Guid sessionId, string reason)
		{
			ServerRemoteSession session;
			if (_sessions.TryGetValue (sessionId, out session)) {
				EnsureSessionSecurity (session);
				var args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, string.IsNullOrEmpty (reason) ? null : new RemoteException(reason));
				session.Close (args);
			}
			_sessions.Remove (sessionId);
		}
        private void SetStateHandler(object sender, RemoteSessionStateMachineEventArgs eventArgs)
        {
            switch (eventArgs.StateEvent)
            {
                case RemoteSessionEvent.NegotiationSendCompleted:
                    this.SetState(RemoteSessionState.NegotiationSent, null);
                    return;

                case RemoteSessionEvent.NegotiationReceived:
                    if (eventArgs.RemoteSessionCapability == null)
                    {
                        throw PSTraceSource.NewArgumentException("eventArgs");
                    }
                    this.SetState(RemoteSessionState.NegotiationReceived, null);
                    return;

                case RemoteSessionEvent.NegotiationCompleted:
                    this.SetState(RemoteSessionState.Established, null);
                    return;

                case RemoteSessionEvent.NegotiationPending:
                case RemoteSessionEvent.Close:
                case RemoteSessionEvent.KeySendFailed:
                case RemoteSessionEvent.KeyReceiveFailed:
                case RemoteSessionEvent.KeyRequestFailed:
                case RemoteSessionEvent.DisconnectStart:
                case RemoteSessionEvent.ReconnectStart:
                    break;

                case RemoteSessionEvent.CloseCompleted:
                    this.SetState(RemoteSessionState.Closed, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.CloseFailed:
                    this.SetState(RemoteSessionState.Closed, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.ConnectFailed:
                    this.SetState(RemoteSessionState.ClosingConnection, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.KeySent:
                    if ((this._state != RemoteSessionState.Established) && (this._state != RemoteSessionState.EstablishedAndKeyRequested))
                    {
                        break;
                    }
                    this.SetState(RemoteSessionState.EstablishedAndKeySent, eventArgs.Reason);
                    this._keyExchangeTimer = new System.Timers.Timer();
                    this._keyExchangeTimer.AutoReset = false;
                    this._keyExchangeTimer.Elapsed += new ElapsedEventHandler(this.HandleKeyExchangeTimeout);
                    this._keyExchangeTimer.Interval = 180000.0;
                    return;

                case RemoteSessionEvent.KeyReceived:
                    if (this._state != RemoteSessionState.EstablishedAndKeySent)
                    {
                        break;
                    }
                    if (this._keyExchangeTimer != null)
                    {
                        this._keyExchangeTimer.Enabled = false;
                        this._keyExchangeTimer.Dispose();
                        this._keyExchangeTimer = null;
                    }
                    this.keyExchanged = true;
                    this.SetState(RemoteSessionState.Established, eventArgs.Reason);
                    if (!this.pendingDisconnect)
                    {
                        break;
                    }
                    this.pendingDisconnect = false;
                    this.DoDisconnect(sender, eventArgs);
                    return;

                case RemoteSessionEvent.KeyRequested:
                    if (this._state != RemoteSessionState.Established)
                    {
                        break;
                    }
                    this.SetState(RemoteSessionState.EstablishedAndKeyRequested, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.DisconnectCompleted:
                    if ((this._state != RemoteSessionState.Disconnecting) && (this._state != RemoteSessionState.RCDisconnecting))
                    {
                        break;
                    }
                    this.SetState(RemoteSessionState.Disconnected, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.DisconnectFailed:
                    if (this._state != RemoteSessionState.Disconnecting)
                    {
                        break;
                    }
                    this.SetState(RemoteSessionState.Disconnected, eventArgs.Reason);
                    return;

                case RemoteSessionEvent.ReconnectCompleted:
                    if (this._state == RemoteSessionState.Reconnecting)
                    {
                        this.SetState(RemoteSessionState.Established, eventArgs.Reason);
                    }
                    break;

                default:
                    return;
            }
        }
 private void SetStateToClosedHandler(object sender, RemoteSessionStateMachineEventArgs eventArgs)
 {
     if ((eventArgs.StateEvent != RemoteSessionEvent.NegotiationTimeout) || (this.State != RemoteSessionState.Established))
     {
         this.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, eventArgs.Reason), false);
     }
 }
 private void DoFatal(object sender, RemoteSessionStateMachineEventArgs eventArgs)
 {
     PSRemotingDataStructureException reason = new PSRemotingDataStructureException(eventArgs.Reason, RemotingErrorIdStrings.FatalErrorCausingClose, new object[0]);
     RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason);
     this.RaiseEvent(arg, false);
 }
Ejemplo n.º 19
0
 private void HandleNegotiationReceived(object sender, RemoteSessionNegotiationEventArgs arg)
 {
     using (_trace.TraceEventHandlers())
     {
         if (arg == null)
         {
             throw PSTraceSource.NewArgumentNullException("arg");
         }
         if (arg.RemoteSessionCapability == null)
         {
             throw PSTraceSource.NewArgumentException("arg");
         }
         base.Context.ServerCapability = arg.RemoteSessionCapability;
         try
         {
             this.RunClientNegotiationAlgorithm(base.Context.ServerCapability);
             RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationCompleted);
             base.SessionDataStructureHandler.StateMachine.RaiseEvent(args, false);
         }
         catch (PSRemotingDataStructureException exception)
         {
             RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationFailed, exception);
             base.SessionDataStructureHandler.StateMachine.RaiseEvent(args2, false);
         }
     }
 }
 private void DoNegotiationSending(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     if (arg.StateEvent == RemoteSessionEvent.NegotiationSending)
     {
         this.SetState(RemoteSessionState.NegotiationSending, null);
     }
     else if (arg.StateEvent == RemoteSessionEvent.NegotiationSendingOnConnect)
     {
         this.SetState(RemoteSessionState.NegotiationSendingOnConnect, null);
     }
 }
Ejemplo n.º 21
0
 internal override void StartKeyExchange()
 {
     if ((base.SessionDataStructureHandler.StateMachine.State == RemoteSessionState.Established) || (base.SessionDataStructureHandler.StateMachine.State == RemoteSessionState.EstablishedAndKeyRequested))
     {
         string publicKeyAsString = null;
         bool flag = false;
         RemoteSessionStateMachineEventArgs arg = null;
         Exception reason = null;
         try
         {
             flag = this._cryptoHelper.ExportLocalPublicKey(out publicKeyAsString);
         }
         catch (PSCryptoException exception2)
         {
             flag = false;
             reason = exception2;
         }
         if (!flag)
         {
             this.CompleteKeyExchange();
             arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeySendFailed, reason);
             base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
         }
         arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.KeySent);
         base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
         base.SessionDataStructureHandler.SendPublicKeyAsync(publicKeyAsString);
     }
 }
 private void DoRCDisconnectStarted(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     if ((this.State != RemoteSessionState.Disconnecting) && (this.State != RemoteSessionState.Disconnected))
     {
         this.SetState(RemoteSessionState.RCDisconnecting, null);
     }
 }
Ejemplo n.º 23
0
 public override void DisconnectAsync()
 {
     RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.DisconnectStart);
     base.SessionDataStructureHandler.StateMachine.RaiseEvent(arg, false);
 }
 private void DoReconnect(object sender, RemoteSessionStateMachineEventArgs arg)
 {
     this.SetState(RemoteSessionState.Reconnecting, null);
 }
        private void HandleRobustConnectionNotification(object sender, ConnectionStatusEventArgs e)
        {
            RemoteSessionStateMachineEventArgs arg = null;
            switch (e.Notification)
            {
                case ConnectionStatus.AutoDisconnectStarting:
                    arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.RCDisconnectStarted);
                    break;

                case ConnectionStatus.AutoDisconnectSucceeded:
                    arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.DisconnectCompleted, new RuntimeException(StringUtil.Format(RemotingErrorIdStrings.RCAutoDisconnectingError, this._session.RemoteRunspacePoolInternal.ConnectionInfo.ComputerName)));
                    break;

                case ConnectionStatus.InternalErrorAbort:
                    arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError);
                    break;
            }
            if (arg != null)
            {
                this.StateMachine.RaiseEvent(arg, false);
            }
        }
 private void ProcessEvents()
 {
     RemoteSessionStateMachineEventArgs arg = null;
     do
     {
         lock (this.syncObject)
         {
             if (this.processPendingEventsQueue.Count == 0)
             {
                 this.eventsInProcess = false;
                 break;
             }
             arg = this.processPendingEventsQueue.Dequeue();
         }
         try
         {
             this.RaiseEventPrivate(arg);
         }
         catch (Exception exception)
         {
             PSRemotingDataStructureException reason = new PSRemotingDataStructureException(exception, RemotingErrorIdStrings.FatalErrorCausingClose, new object[0]);
             RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason);
             this.RaiseEvent(args2, true);
         }
         this.RaiseStateMachineEvents();
     }
     while (this.eventsInProcess);
 }
 private void ProcessSessionMessages(RemoteDataEventArgs arg)
 {
     if ((arg == null) || (arg.ReceivedData == null))
     {
         throw PSTraceSource.NewArgumentNullException("arg");
     }
     RemoteDataObject<PSObject> receivedData = arg.ReceivedData;
     RemotingTargetInterface targetInterface = receivedData.TargetInterface;
     RemotingDataType dataType = receivedData.DataType;
     switch (dataType)
     {
         case RemotingDataType.SessionCapability:
         {
             RemoteSessionCapability remoteSessionCapability = null;
             try
             {
                 remoteSessionCapability = RemotingDecoder.GetSessionCapability(receivedData.Data);
             }
             catch (PSRemotingDataStructureException exception2)
             {
                 throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties, new object[] { exception2.Message, PSVersionInfo.BuildVersion, RemotingConstants.ProtocolVersion });
             }
             RemoteSessionStateMachineEventArgs args2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived) {
                 RemoteSessionCapability = remoteSessionCapability
             };
             this._stateMachine.RaiseEvent(args2, false);
             RemoteSessionNegotiationEventArgs eventArgs = new RemoteSessionNegotiationEventArgs(remoteSessionCapability);
             this.NegotiationReceived.SafeInvoke<RemoteSessionNegotiationEventArgs>(this, eventArgs);
             return;
         }
         case RemotingDataType.CloseSession:
         {
             PSRemotingDataStructureException reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession);
             RemoteSessionStateMachineEventArgs args = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reason);
             this._stateMachine.RaiseEvent(args, false);
             return;
         }
         case RemotingDataType.EncryptedSessionKey:
         {
             string encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(receivedData.Data);
             this.EncryptedSessionKeyReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(encryptedSessionKey));
             return;
         }
         case RemotingDataType.PublicKeyRequest:
             this.PublicKeyRequestReceived.SafeInvoke<RemoteDataEventArgs<string>>(this, new RemoteDataEventArgs<string>(string.Empty));
             return;
     }
     throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, new object[] { dataType });
 }
 internal void RaiseEvent(RemoteSessionStateMachineEventArgs arg, bool clearQueuedEvents = false)
 {
     lock (this.syncObject)
     {
         _trace.WriteLine("Event recieved : {0} for {1}", new object[] { arg.StateEvent, this.id });
         if (clearQueuedEvents)
         {
             this.processPendingEventsQueue.Clear();
         }
         this.processPendingEventsQueue.Enqueue(arg);
         if (!this.eventsInProcess)
         {
             this.eventsInProcess = true;
         }
         else
         {
             return;
         }
     }
     this.ProcessEvents();
 }
        internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataArg)
        {
            if (dataArg == null)
            {
                throw PSTraceSource.NewArgumentNullException("dataArg");
            }
            RemoteDataObject<PSObject> receivedData = dataArg.ReceivedData;
            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentException("dataArg");
            }
            RemotingDestination destination = receivedData.Destination;
			var d = receivedData.Data;
            if ((destination & (RemotingDestination.InvalidDestination | RemotingDestination.Client)) != (RemotingDestination.InvalidDestination | RemotingDestination.Client))
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RemotingDestinationNotForMe, new object[] { RemotingDestination.InvalidDestination | RemotingDestination.Client, destination });
            }
            switch (receivedData.TargetInterface)
            {
                case RemotingTargetInterface.Session:
                    this.ProcessSessionMessages(dataArg);
                    return;

                case RemotingTargetInterface.RunspacePool:
                case RemotingTargetInterface.PowerShell:
                {
                    RemoteSessionStateMachineEventArgs arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived, null);
                    if (!this.StateMachine.CanByPassRaiseEvent(arg))
                    {
                        this.StateMachine.RaiseEvent(arg, false);
                        return;
                    }
                    this.ProcessNonSessionMessages(dataArg.ReceivedData);
                    return;
                }
            }
        }
        private void RaiseEventPrivate (RemoteSessionStateMachineEventArgs arg)
		{
			if (arg == null) {
				throw PSTraceSource.NewArgumentNullException ("arg");
			}
			EventHandler<RemoteSessionStateMachineEventArgs> handler = this._stateMachineHandle [(int)this.State, (int)arg.StateEvent];
			if (arg.StateEvent == RemoteSessionEvent.MessageReceived) return;
			if (handler != null) {
				_trace.WriteLine ("Before calling state machine event handler: state = {0}, event = {1}, id = {2}", new object[] {
					this.State,
					arg.StateEvent,
					this.id
				});
				handler (this, arg);
				_trace.WriteLine ("After calling state machine event handler: state = {0}, event = {1}, id = {2}", new object[] {
					this.State,
					arg.StateEvent,
					this.id
				});
			} else {
				_trace.WriteLine ("Could not call state machine event handler: state = {0}, event = {1}, id = {2}", new object[] {
					this.State,
					arg.StateEvent,
					this.id
				});
			}
        }