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 }); }
// 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); } } }
private void ProcessSessionMessages(RemoteDataEventArgs arg) { using (ClientRemoteSessionDSHandlerImpl._trace.TraceMethod()) { RemoteDataObject <PSObject> remoteDataObject = arg != null && arg.ReceivedData != null ? arg.ReceivedData : throw ClientRemoteSessionDSHandlerImpl._trace.NewArgumentNullException(nameof(arg)); 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.ClientNotFoundCapabilityProperties, 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)); break; case RemotingDataType.CloseSession: this._stateMachine.RaiseEvent(new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Close, (Exception) new PSRemotingDataStructureException(PSRemotingErrorId.ServerRequestedToCloseSession, new object[0]))); break; case RemotingDataType.EncryptedSessionKey: this.EncryptedSessionKeyReceived((object)this, new RemoteDataEventArgs <string>((object)RemotingDecoder.GetEncryptedSessionKey(remoteDataObject.Data))); break; case RemotingDataType.PublicKeyRequest: this.PublicKeyRequestReceived((object)this, new RemoteDataEventArgs <string>((object)string.Empty)); break; default: throw new PSRemotingDataStructureException(PSRemotingErrorId.ReceivedUnsupportedAction, new object[1] { (object)dataType }); } } }