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 });
        }
예제 #2
0
        /// <summary>
        /// Dispatches data when it arrives from the input queue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="dataArg">
        /// arg which contains the data received from input queue
        /// </param>
        internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataArg)
        {
            if (dataArg == null)
            {
                throw PSTraceSource.NewArgumentNullException("dataArg");
            }

            RemoteDataObject <PSObject> rcvdData = dataArg.ReceivedData;

            if (rcvdData == null)
            {
                throw PSTraceSource.NewArgumentException("dataArg");
            }

            RemotingDestination destination = rcvdData.Destination;

            if ((destination & RemotingDestination.Client) != RemotingDestination.Client)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RemotingDestinationNotForMe, RemotingDestination.Client, destination);
            }

            RemotingTargetInterface targetInterface = rcvdData.TargetInterface;

            switch (targetInterface)
            {
            case RemotingTargetInterface.Session:
            {
                //Messages for session can cause statemachine state to change.
                //These messages are first processed by Sessiondata structure handler and depending
                //on the type of message, appropriate event is raised in state machine
                ProcessSessionMessages(dataArg);
                break;
            }

            case RemotingTargetInterface.RunspacePool:
            case RemotingTargetInterface.PowerShell:
                //Non Session messages do not change the state of the statemachine.
                //However instead of forwarding them to Runspace/pipeline here, an
                //event is raised in state machine which verified that state is
                //suitable for accepting these messages. if state is suitable statemachine
                //will call DoMessageForwading which will forward the messages appropriately
                RemoteSessionStateMachineEventArgs msgRcvArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived, null);
                if (StateMachine.CanByPassRaiseEvent(msgRcvArg))
                {
                    ProcessNonSessionMessages(dataArg.ReceivedData);
                }
                else
                {
                    StateMachine.RaiseEvent(msgRcvArg);
                }
                break;

            default:
            {
                Dbg.Assert(false, "we should not be encountering this");
            }
            break;
            }
        }
예제 #3
0
        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 });
        }
예제 #4
0
        /// <summary>
        /// This processes the object received from transport which are
        /// not targeted for session
        /// </summary>
        /// <param name="rcvdData">
        /// received data.
        /// </param>
        internal void ProcessNonSessionMessages(RemoteDataObject <PSObject> rcvdData)
        {
            // TODO: Consider changing to Dbg.Assert()
            if (rcvdData == null)
            {
                throw PSTraceSource.NewArgumentNullException("rcvdData");
            }

            RemotingTargetInterface targetInterface = rcvdData.TargetInterface;

            Guid clientRunspacePoolId;
            RemoteRunspacePoolInternal runspacePool;

            switch (targetInterface)
            {
            case RemotingTargetInterface.Session:

                Dbg.Assert(false,
                           "The session remote data is handled my session data structure handler, not here");
                break;

            case RemotingTargetInterface.RunspacePool:
                clientRunspacePoolId = rcvdData.RunspacePoolId;
                runspacePool         = _session.GetRunspacePool(clientRunspacePoolId);

                if (runspacePool != null)
                {
                    // GETBACK
                    runspacePool.DataStructureHandler.ProcessReceivedData(rcvdData);
                }
                else
                {
                    // The runspace pool may have been removed on the client side,
                    // so, we should just ignore the message.
                    s_trace.WriteLine(@"Client received data for Runspace (id: {0}),
                            but the Runspace cannot be found", clientRunspacePoolId);
                }

                break;

            case RemotingTargetInterface.PowerShell:
                clientRunspacePoolId = rcvdData.RunspacePoolId;
                runspacePool         = _session.GetRunspacePool(clientRunspacePoolId);

                // GETBACK
                runspacePool.DataStructureHandler.DispatchMessageToPowerShell(rcvdData);
                break;

            default:

                break;
            }
        }
        internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg)
        {
            using (ServerRemoteSessionDSHandlerStateMachine._trace.TraceEventHandlers())
            {
                if (fsmEventArg == null)
                {
                    throw ServerRemoteSessionDSHandlerStateMachine._trace.NewArgumentNullException(nameof(fsmEventArg));
                }
                if (fsmEventArg.RemoteData == null)
                {
                    throw ServerRemoteSessionDSHandlerStateMachine._trace.NewArgumentException(nameof(fsmEventArg));
                }
                RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface;
                RemotingDataType        dataType        = fsmEventArg.RemoteData.DataType;
                switch (targetInterface)
                {
                case RemotingTargetInterface.Session:
                    if (dataType != RemotingDataType.CreateRunspacePool)
                    {
                        break;
                    }
                    this._session.SessionDataStructureHandler.RaiseDataReceivedEvent(new RemoteDataEventArgs(fsmEventArg.RemoteData));
                    break;

                case RemotingTargetInterface.RunspacePool:
                    Guid runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId;
                    ServerRunspacePoolDriver runspacePoolDriver = this._session.GetRunspacePoolDriver(runspacePoolId);
                    if (runspacePoolDriver != null)
                    {
                        runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData);
                        break;
                    }
                    ServerRemoteSessionDSHandlerStateMachine._trace.WriteLine("Server received data for Runspace (id: {0}), \r\n                                but the Runspace cannot be found", (object)runspacePoolId);
                    this.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, (Exception) new PSRemotingDataStructureException(PSRemotingErrorId.RunspaceCannotBeFound, new object[1]
                    {
                        (object)runspacePoolId
                    })));
                    break;

                case RemotingTargetInterface.PowerShell:
                    this._session.GetRunspacePoolDriver(fsmEventArg.RemoteData.RunspacePoolId).DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData);
                    break;

                default:
                    ServerRemoteSessionDSHandlerStateMachine._trace.WriteLine("Server received data unknown targetInterface: {0}", (object)targetInterface);
                    this.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, (Exception) new PSRemotingDataStructureException(PSRemotingErrorId.ReceivedUnsupportedRemotingTargetInterfaceType, new object[1]
                    {
                        (object)targetInterface
                    })));
                    break;
                }
            }
        }
 internal virtual void SendDataToClient <T>(RemoteDataObject <T> data, bool flush, bool reportPending = false)
 {
     lock (this.syncObject)
     {
         RemoteDataObject obj2 = RemoteDataObject.CreateFrom(data.Destination, data.DataType, data.RunspacePoolId, data.PowerShellId, data.Data);
         if (this.isSerializing)
         {
             if (this.dataToBeSentQueue == null)
             {
                 this.dataToBeSentQueue = new Queue <Tuple <RemoteDataObject, bool, bool> >();
             }
             this.dataToBeSentQueue.Enqueue(new Tuple <RemoteDataObject, bool, bool>(obj2, flush, reportPending));
         }
         else
         {
             this.isSerializing = true;
             try
             {
                 do
                 {
                     using (SerializedDataStream stream = new SerializedDataStream(base.Fragmentor.FragmentSize, this.onDataAvailable))
                     {
                         this.shouldFlushData       = flush;
                         this.reportAsPending       = reportPending;
                         this.runpacePoolInstanceId = obj2.RunspacePoolId;
                         this.powerShellInstanceId  = obj2.PowerShellId;
                         this.dataType        = obj2.DataType;
                         this.targetInterface = obj2.TargetInterface;
                         base.Fragmentor.Fragment <object>(obj2, stream);
                     }
                     if ((this.dataToBeSentQueue != null) && (this.dataToBeSentQueue.Count > 0))
                     {
                         Tuple <RemoteDataObject, bool, bool> tuple = this.dataToBeSentQueue.Dequeue();
                         obj2          = tuple.Item1;
                         flush         = tuple.Item2;
                         reportPending = tuple.Item3;
                     }
                     else
                     {
                         obj2 = null;
                     }
                 }while (obj2 != null);
             }
             finally
             {
                 this.isSerializing = false;
             }
         }
     }
 }
예제 #7
0
 internal void SendDataToClient <T>(RemoteDataObject <T> data, bool flush)
 {
     using (SerializedDataStream dataToBeSent = new SerializedDataStream(this.Fragmentor.FragmentSize, this.onDataAvailable))
     {
         lock (this.syncObject)
         {
             this.shouldFlushData       = flush;
             this.runpacePoolInstanceId = data.RunspacePoolId;
             this.powerShellInstanceId  = data.PowerShellId;
             this.dataType        = data.DataType;
             this.targetInterface = data.TargetInterface;
             this.Fragmentor.Fragment <T>(data, dataToBeSent);
         }
     }
 }
예제 #8
0
        /// <summary>
        /// This is the handler for MessageReceived event. It dispatches the data to various components
        /// that uses the data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="fsmEventArg">
        /// This parameter contains the FSM event.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If the parameter <paramref name="fsmEventArg"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If the parameter <paramref name="fsmEventArg"/> does not contain remote data.
        /// </exception>
        internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg)
        {
            using (s_trace.TraceEventHandlers())
            {
                if (fsmEventArg == null)
                {
                    throw PSTraceSource.NewArgumentNullException("fsmEventArg");
                }

                if (fsmEventArg.RemoteData == null)
                {
                    throw PSTraceSource.NewArgumentException("fsmEventArg");
                }

                Dbg.Assert(_state == RemoteSessionState.Established ||
                           _state == RemoteSessionState.EstablishedAndKeyExchanged ||
                           _state == RemoteSessionState.EstablishedAndKeyReceived ||
                           _state == RemoteSessionState.EstablishedAndKeySent,  //server session will never be in this state.. TODO- remove this
                           "State must be Established or EstablishedAndKeySent or EstablishedAndKeyReceived or EstablishedAndKeyExchanged");

                RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface;
                RemotingDataType        dataType        = fsmEventArg.RemoteData.DataType;

                Guid clientRunspacePoolId;
                ServerRunspacePoolDriver runspacePoolDriver;
                //string errorMessage = null;

                RemoteDataEventArgs remoteDataForSessionArg = null;

                switch (targetInterface)
                {
                case RemotingTargetInterface.Session:
                {
                    switch (dataType)
                    {
                    // GETBACK
                    case RemotingDataType.CreateRunspacePool:
                        remoteDataForSessionArg = new RemoteDataEventArgs(fsmEventArg.RemoteData);
                        _session.SessionDataStructureHandler.RaiseDataReceivedEvent(remoteDataForSessionArg);
                        break;

                    default:
                        Dbg.Assert(false, "Should never reach here");
                        break;
                    }
                }
                break;

                case RemotingTargetInterface.RunspacePool:
                    // GETBACK
                    clientRunspacePoolId = fsmEventArg.RemoteData.RunspacePoolId;
                    runspacePoolDriver   = _session.GetRunspacePoolDriver(clientRunspacePoolId);

                    if (runspacePoolDriver != null)
                    {
                        runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData);
                    }
                    else
                    {
                        s_trace.WriteLine(@"Server received data for Runspace (id: {0}),
                                but the Runspace cannot be found", clientRunspacePoolId);

                        PSRemotingDataStructureException reasonOfFailure = new
                                                                           PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceCannotBeFound,
                                                                                                            clientRunspacePoolId);
                        RemoteSessionStateMachineEventArgs runspaceNotFoundArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reasonOfFailure);
                        RaiseEvent(runspaceNotFoundArg);
                    }

                    break;

                case RemotingTargetInterface.PowerShell:
                    clientRunspacePoolId = fsmEventArg.RemoteData.RunspacePoolId;
                    runspacePoolDriver   = _session.GetRunspacePoolDriver(clientRunspacePoolId);

                    runspacePoolDriver.DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData);
                    break;

                default:
                    s_trace.WriteLine("Server received data unknown targetInterface: {0}", targetInterface);

                    PSRemotingDataStructureException   reasonOfFailure2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedRemotingTargetInterfaceType, targetInterface);
                    RemoteSessionStateMachineEventArgs unknownTargetArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reasonOfFailure2);
                    RaiseEvent(unknownTargetArg);
                    break;
                }
            }
        }
예제 #9
0
        // TODO: If this is not used remove this
        // internal override event EventHandler<RemoteDataEventArgs> DataReceived;

        /// <summary>
        /// This processes the object received from transport which are
        /// targeted for session
        /// </summary>
        /// <param name="arg">
        /// argument contains the data object
        /// </param>
        private void ProcessSessionMessages(RemoteDataEventArgs arg)
        {
            if (arg == null || arg.ReceivedData == null)
            {
                throw PSTraceSource.NewArgumentNullException("arg");
            }

            RemoteDataObject <PSObject> rcvdData = arg.ReceivedData;

            RemotingTargetInterface targetInterface = rcvdData.TargetInterface;

            Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session");

            RemotingDataType dataType = rcvdData.DataType;

            switch (dataType)
            {
            case RemotingDataType.CloseSession:
                PSRemotingDataStructureException   reasonOfClose   = new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerRequestedToCloseSession);
                RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose);
                _stateMachine.RaiseEvent(closeSessionArg);
                break;

            case RemotingDataType.SessionCapability:
                RemoteSessionCapability capability = null;
                try
                {
                    capability = RemotingDecoder.GetSessionCapability(rcvdData.Data);
                }
                catch (PSRemotingDataStructureException dse)
                {
                    // this will happen if expected properties are not
                    // received for session capability
                    throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientNotFoundCapabilityProperties,
                                                               dse.Message, PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion);
                }

                RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived);
                capabilityArg.RemoteSessionCapability = capability;
                _stateMachine.RaiseEvent(capabilityArg);

                RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability);
                NegotiationReceived.SafeInvoke(this, negotiationArg);
                break;

            case RemotingDataType.EncryptedSessionKey:
            {
                String encryptedSessionKey = RemotingDecoder.GetEncryptedSessionKey(rcvdData.Data);
                EncryptedSessionKeyReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(encryptedSessionKey));
            }
            break;

            case RemotingDataType.PublicKeyRequest:
            {
                PublicKeyRequestReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(String.Empty));
            }
            break;

            default:
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType);
            }
            }
        }
예제 #10
0
        /// <summary>
        /// This method is used by the input queue dispatching mechanism.
        /// It examines the data and takes appropriate actions.
        /// </summary>
        /// <param name="dataArg">
        /// The received client data.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the parameter is null.
        /// </exception>
        internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg)
        {
            if (dataArg == null)
            {
                throw PSTraceSource.NewArgumentNullException("dataArg");
            }

            RemoteDataObject <PSObject> rcvdData = dataArg.ReceivedData;

            RemotingTargetInterface targetInterface = rcvdData.TargetInterface;
            RemotingDataType        dataType        = rcvdData.DataType;

            Dbg.Assert(targetInterface == RemotingTargetInterface.Session, "targetInterface must be Session");

            switch (dataType)
            {
            case RemotingDataType.CreateRunspacePool:
            {
                // At this point, the negotiation is complete, so
                // need to import the clients public key
                CreateRunspacePoolReceived.SafeInvoke(this, dataArg);
            }

            break;

            case RemotingDataType.CloseSession:
                PSRemotingDataStructureException   reasonOfClose   = new PSRemotingDataStructureException(RemotingErrorIdStrings.ClientRequestedToCloseSession);
                RemoteSessionStateMachineEventArgs closeSessionArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, reasonOfClose);
                _stateMachine.RaiseEvent(closeSessionArg);
                break;

            case RemotingDataType.SessionCapability:
                RemoteSessionCapability capability = null;
                try
                {
                    capability = RemotingDecoder.GetSessionCapability(rcvdData.Data);
                }
                catch (PSRemotingDataStructureException dse)
                {
                    // this will happen if expected properties are not
                    // received for session capability
                    throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ServerNotFoundCapabilityProperties,
                                                               dse.Message, PSVersionInfo.GitCommitId, RemotingConstants.ProtocolVersion);
                }

                RemoteSessionStateMachineEventArgs capabilityArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived);
                capabilityArg.RemoteSessionCapability = capability;
                _stateMachine.RaiseEvent(capabilityArg);

                if (NegotiationReceived != null)
                {
                    RemoteSessionNegotiationEventArgs negotiationArg = new RemoteSessionNegotiationEventArgs(capability);
                    negotiationArg.RemoteData = rcvdData;
                    NegotiationReceived.SafeInvoke(this, negotiationArg);
                }

                break;

            case RemotingDataType.PublicKey:
            {
                string remotePublicKey = RemotingDecoder.GetPublicKey(rcvdData.Data);
                PublicKeyReceived.SafeInvoke(this, new RemoteDataEventArgs <string>(remotePublicKey));
            }

            break;

            default:
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedAction, dataType);
            }
        }
        internal void DoMessageReceived(object sender, RemoteSessionStateMachineEventArgs fsmEventArg)
        {
            using (_trace.TraceEventHandlers())
            {
                Guid runspacePoolId;
                if (fsmEventArg == null)
                {
                    throw PSTraceSource.NewArgumentNullException("fsmEventArg");
                }
                if (fsmEventArg.RemoteData == null)
                {
                    throw PSTraceSource.NewArgumentException("fsmEventArg");
                }
                RemotingTargetInterface targetInterface = fsmEventArg.RemoteData.TargetInterface;
                RemotingDataType        dataType        = fsmEventArg.RemoteData.DataType;
                RemoteDataEventArgs     arg             = null;
                switch (targetInterface)
                {
                case RemotingTargetInterface.Session:
                    switch (dataType)
                    {
                    case RemotingDataType.CreateRunspacePool:
                    {
                        arg = new RemoteDataEventArgs(fsmEventArg.RemoteData);
                        this._session.SessionDataStructureHandler.RaiseDataReceivedEvent(arg);
                    }
                    break;
                    }
                    return;

                case RemotingTargetInterface.RunspacePool:
                {
                    runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId;
                    ServerRunspacePoolDriver runspacePoolDriver = this._session.GetRunspacePoolDriver(runspacePoolId);
                    if (runspacePoolDriver == null)
                    {
                        break;
                    }
                    runspacePoolDriver.DataStructureHandler.ProcessReceivedData(fsmEventArg.RemoteData);
                    return;
                }

                case RemotingTargetInterface.PowerShell:
                    runspacePoolId = fsmEventArg.RemoteData.RunspacePoolId;
                    this._session.GetRunspacePoolDriver(runspacePoolId).DataStructureHandler.DispatchMessageToPowerShell(fsmEventArg.RemoteData);
                    return;

                default:
                    goto Label_0151;
                }
                _trace.WriteLine("Server received data for Runspace (id: {0}), \r\n                                but the Runspace cannot be found", new object[] { runspacePoolId });
                PSRemotingDataStructureException   reason = new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceCannotBeFound, new object[] { runspacePoolId });
                RemoteSessionStateMachineEventArgs args2  = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, reason);
                this.RaiseEvent(args2);
                return;

                Label_0151 :;
                _trace.WriteLine("Server received data unknown targetInterface: {0}", new object[] { targetInterface });
                PSRemotingDataStructureException   exception2 = new PSRemotingDataStructureException(RemotingErrorIdStrings.ReceivedUnsupportedRemotingTargetInterfaceType, new object[] { targetInterface });
                RemoteSessionStateMachineEventArgs args3      = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.FatalError, exception2);
                this.RaiseEvent(args3);
            }
        }
예제 #12
0
        internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataEventArg)
        {
            using (ServerRemoteSession._trace.TraceMethod())
            {
                RemoteDataObject <PSObject> remoteDataObject    = dataEventArg != null ? dataEventArg.ReceivedData : throw ServerRemoteSession._trace.NewArgumentNullException(nameof(dataEventArg));
                RemotingDestination         remotingDestination = remoteDataObject != null ? remoteDataObject.Destination : throw ServerRemoteSession._trace.NewArgumentException(nameof(dataEventArg));
                if ((remotingDestination & this.MySelf) != this.MySelf)
                {
                    throw new PSRemotingDataStructureException(PSRemotingErrorId.RemotingDestinationNotForMe, new object[2]
                    {
                        (object)this.MySelf,
                        (object)remotingDestination
                    });
                }
                RemotingTargetInterface targetInterface = remoteDataObject.TargetInterface;
                RemotingDataType        dataType        = remoteDataObject.DataType;
                switch (targetInterface)
                {
                case RemotingTargetInterface.Session:
                    switch (dataType)
                    {
                    case RemotingDataType.SessionCapability:
                        this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                        return;

                    case RemotingDataType.CloseSession:
                        this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                        return;

                    case RemotingDataType.CreateRunspacePool:
                        RemoteSessionStateMachineEventArgs fsmEventArg1 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived);
                        if (this.SessionDataStructureHandler.StateMachine.CanByPassRaiseEvent(fsmEventArg1))
                        {
                            fsmEventArg1.RemoteData = remoteDataObject;
                            this.SessionDataStructureHandler.StateMachine.DoMessageReceived((object)this, fsmEventArg1);
                            return;
                        }
                        this.SessionDataStructureHandler.StateMachine.RaiseEvent(fsmEventArg1);
                        return;

                    case RemotingDataType.PublicKey:
                        this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                        return;

                    default:
                        return;
                    }

                case RemotingTargetInterface.RunspacePool:
                case RemotingTargetInterface.PowerShell:
                    RemoteSessionStateMachineEventArgs fsmEventArg2 = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived);
                    if (this.SessionDataStructureHandler.StateMachine.CanByPassRaiseEvent(fsmEventArg2))
                    {
                        fsmEventArg2.RemoteData = remoteDataObject;
                        this.SessionDataStructureHandler.StateMachine.DoMessageReceived((object)this, fsmEventArg2);
                        break;
                    }
                    this.SessionDataStructureHandler.StateMachine.RaiseEvent(fsmEventArg2);
                    break;
                }
            }
        }
예제 #13
0
        internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataEventArg)
        {
            if (dataEventArg == null)
            {
                throw PSTraceSource.NewArgumentNullException("dataEventArg");
            }
            RemoteDataObject <PSObject> receivedData = dataEventArg.ReceivedData;

            if (receivedData == null)
            {
                throw PSTraceSource.NewArgumentException("dataEventArg");
            }
            RemotingDestination destination = receivedData.Destination;

            if ((destination & this.MySelf) != this.MySelf)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RemotingDestinationNotForMe, new object[] { this.MySelf, destination });
            }
            RemotingTargetInterface            targetInterface = receivedData.TargetInterface;
            RemotingDataType                   dataType        = receivedData.DataType;
            RemoteSessionStateMachineEventArgs arg             = null;

            switch (targetInterface)
            {
            case RemotingTargetInterface.Session:
                switch (dataType)
                {
                case RemotingDataType.SessionCapability:
                    this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                    return;

                case RemotingDataType.CloseSession:
                    this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                    return;

                case RemotingDataType.CreateRunspacePool:
                    arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived);
                    if (this.SessionDataStructureHandler.StateMachine.CanByPassRaiseEvent(arg))
                    {
                        arg.RemoteData = receivedData;
                        this.SessionDataStructureHandler.StateMachine.DoMessageReceived(this, arg);
                        return;
                    }
                    this.SessionDataStructureHandler.StateMachine.RaiseEvent(arg);
                    return;

                case RemotingDataType.PublicKey:
                    this._sessionDSHandler.RaiseDataReceivedEvent(dataEventArg);
                    return;
                }
                return;

            case RemotingTargetInterface.RunspacePool:
            case RemotingTargetInterface.PowerShell:
                arg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived);
                if (!this.SessionDataStructureHandler.StateMachine.CanByPassRaiseEvent(arg))
                {
                    this.SessionDataStructureHandler.StateMachine.RaiseEvent(arg);
                    return;
                }
                arg.RemoteData = receivedData;
                this.SessionDataStructureHandler.StateMachine.DoMessageReceived(this, arg);
                return;
            }
        }