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 });
        }
Example #2
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);
            }
        }
Example #3
0
        internal override void RaiseDataReceivedEvent(RemoteDataEventArgs dataArg)
        {
            using (ServerRemoteSessionDSHandlerlImpl._trace.TraceMethod())
            {
                RemoteDataObject <PSObject> remoteDataObject = dataArg != null ? dataArg.ReceivedData : throw ServerRemoteSessionDSHandlerlImpl._trace.NewArgumentNullException(nameof(dataArg));
                int targetInterface       = (int)remoteDataObject.TargetInterface;
                RemotingDataType dataType = remoteDataObject.DataType;
                switch (dataType)
                {
                case RemotingDataType.SessionCapability:
                    RemoteSessionCapability sessionCapability;
                    try
                    {
                        sessionCapability = RemotingDecoder.GetSessionCapability((object)remoteDataObject.Data);
                    }
                    catch (PSRemotingDataStructureException ex)
                    {
                        throw new PSRemotingDataStructureException(PSRemotingErrorId.ServerNotFoundCapabilityProperties, new object[3]
                        {
                            (object)ex.Message,
                            (object)PSVersionInfo.BuildVersion,
                            (object)RemotingConstants.ProtocolVersion
                        });
                    }
                    this._stateMachine.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.NegotiationReceived)
                    {
                        RemoteSessionCapability = sessionCapability
                    });
                    if (this.NegotiationReceived == null)
                    {
                        break;
                    }
                    this.NegotiationReceived((object)this, new RemoteSessionNegotiationEventArgs(sessionCapability)
                    {
                        RemoteData = remoteDataObject
                    });
                    break;

                case RemotingDataType.CloseSession:
                    this._stateMachine.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, (Exception) new PSRemotingDataStructureException(PSRemotingErrorId.ClientRequestedToCloseSession, new object[0])));
                    break;

                case RemotingDataType.CreateRunspacePool:
                    if (this.CreateRunspacePoolReceived == null)
                    {
                        break;
                    }
                    this.CreateRunspacePoolReceived((object)this, dataArg);
                    break;

                case RemotingDataType.PublicKey:
                    this.PublicKeyReceived((object)this, new RemoteDataEventArgs <string>((object)RemotingDecoder.GetPublicKey(remoteDataObject.Data)));
                    break;

                default:
                    throw new PSRemotingDataStructureException(PSRemotingErrorId.ReceivedUnsupportedAction, new object[1]
                    {
                        (object)dataType
                    });
                }
            }
        }