internal static RemoteDataObject <T> CreateFrom( Stream serializedDataStream, Fragmentor defragmentor) { if (serializedDataStream.Length - serializedDataStream.Position < 40L) { throw new PSRemotingTransportException(PSRemotingErrorId.NotEnoughHeaderForRemoteDataObject, new object[1] { (object)61 }); } RemotingDestination destination = (RemotingDestination)RemoteDataObject <T> .DeserializeUInt(serializedDataStream); RemotingDataType dataType = (RemotingDataType)RemoteDataObject <T> .DeserializeUInt(serializedDataStream); Guid runspacePoolId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream); Guid powerShellId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream); object valueToConvert = (object)null; if (serializedDataStream.Length - 40L > 0L) { valueToConvert = (object)defragmentor.DeserializeToPSObject(serializedDataStream); } T data = (T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), (IFormatProvider)CultureInfo.CurrentCulture); return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, data)); }
/// <summary> /// Creates a RemoteDataObject by deserializing <paramref name="data"/>. /// </summary> /// <param name="serializedDataStream"></param> /// <param name="defragmentor"> /// Defragmentor used to deserialize an object. /// </param> /// <returns></returns> internal static RemoteDataObject <T> CreateFrom(Stream serializedDataStream, Fragmentor defragmentor) { Dbg.Assert(serializedDataStream != null, "cannot construct a RemoteDataObject from null data"); Dbg.Assert(defragmentor != null, "defragmentor cannot be null."); if ((serializedDataStream.Length - serializedDataStream.Position) < headerLength) { PSRemotingTransportException e = new PSRemotingTransportException(PSRemotingErrorId.NotEnoughHeaderForRemoteDataObject, RemotingErrorIdStrings.NotEnoughHeaderForRemoteDataObject, headerLength + FragmentedRemoteObject.HeaderLength); throw e; } RemotingDestination destination = (RemotingDestination)DeserializeUInt(serializedDataStream); RemotingDataType dataType = (RemotingDataType)DeserializeUInt(serializedDataStream); Guid runspacePoolId = DeserializeGuid(serializedDataStream); Guid powerShellId = DeserializeGuid(serializedDataStream); object actualData = null; if ((serializedDataStream.Length - headerLength) > 0) { actualData = defragmentor.DeserializeToPSObject(serializedDataStream); } T deserializedObject = (T)LanguagePrimitives.ConvertTo(actualData, typeof(T), System.Globalization.CultureInfo.CurrentCulture); return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, deserializedObject)); }
public override object ServiceMessage(IMessage message) { RemotingMessage message2 = message as RemotingMessage; RemotingDestination destination = base.GetDestination(message) as RemotingDestination; return(destination.ServiceAdapter.Invoke(message)); }
internal void DispatchInputQueueData(object sender, RemoteDataEventArgs dataArg) { using (ClientRemoteSessionDSHandlerImpl._trace.TraceMethod()) { RemoteDataObject <PSObject> remoteDataObject = dataArg != null ? dataArg.ReceivedData : throw ClientRemoteSessionDSHandlerImpl._trace.NewArgumentNullException(nameof(dataArg)); RemotingDestination remotingDestination = remoteDataObject != null ? remoteDataObject.Destination : throw ClientRemoteSessionDSHandlerImpl._trace.NewArgumentException(nameof(dataArg)); if ((remotingDestination & RemotingDestination.Client) != RemotingDestination.Client) { throw new PSRemotingDataStructureException(PSRemotingErrorId.RemotingDestinationNotForMe, new object[2] { (object)RemotingDestination.Client, (object)remotingDestination }); } switch (remoteDataObject.TargetInterface) { case RemotingTargetInterface.Session: this.ProcessSessionMessages(dataArg); break; case RemotingTargetInterface.RunspacePool: case RemotingTargetInterface.PowerShell: RemoteSessionStateMachineEventArgs machineEventArgs = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.MessageReceived, (Exception)null); if (this.StateMachine.CanByPassRaiseEvent(machineEventArgs)) { this.ProcessNonSessionMessages(dataArg.ReceivedData); break; } this.StateMachine.RaiseEvent(machineEventArgs); break; } } }
/// <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; } }
protected RemoteDataObject(RemotingDestination destination, RemotingDataType dataType, Guid runspacePoolId, Guid powerShellId, T data) { this.destination = destination; this.dataType = dataType; this.runspacePoolId = runspacePoolId; this.powerShellId = powerShellId; this.data = data; }
/// <summary> /// </summary> /// <param name="destination"></param> /// <param name="dataType"></param> /// <param name="runspacePoolId"></param> /// <param name="powerShellId"></param> /// <param name="data"></param> /// <returns></returns> internal static RemoteDataObject <T> CreateFrom(RemotingDestination destination, RemotingDataType dataType, Guid runspacePoolId, Guid powerShellId, T data) { return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, data)); }
private RemoteDataObject( RemotingDestination destination, RemotingDataType dataType, Guid runspacePoolId, Guid powerShellId, object data) : base(destination, dataType, runspacePoolId, powerShellId, data) { }
public override object ServiceMessage(IMessage message) { RemotingMessage remotingMessage = message as RemotingMessage; RemotingDestination destination = GetDestination(message) as RemotingDestination; ServiceAdapter adapter = destination.ServiceAdapter; object result = adapter.Invoke(message); return(result); }
internal RemoteSessionCapability(RemotingDestination remotingDestination, Version protocolVersion, Version psVersion, Version serVersion) { _protocolVersion = protocolVersion; _psversion = psVersion; _serversion = serVersion; _remotingDestination = remotingDestination; }
internal static RemoteDataObject GenerateMyPublicKey( Guid runspacePoolId, string publicKey, RemotingDestination destination) { PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject(); emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("PublicKey", (object)publicKey)); return(RemoteDataObject.CreateFrom(destination, RemotingDataType.PublicKey, runspacePoolId, Guid.Empty, (object)emptyPsObject)); }
public override async Task <object> ServiceMessage(IMessage message) { RemotingMessage remotingMessage = message as RemotingMessage; RemotingDestination destination = GetDestination(message) as RemotingDestination; ServiceAdapter adapter = destination.ServiceAdapter; Task <object> result = adapter.Invoke(message); await result; return(result.Result); }
/// <summary> /// Constructor for RemoteSessionCapability. /// </summary> /// <remarks>should not be called from outside, use create methods instead /// </remarks> internal RemoteSessionCapability(RemotingDestination remotingDestination) { ProtocolVersion = RemotingConstants.ProtocolVersion; // PS Version 3 is fully backward compatible with Version 2 // In the remoting protocol sense, nothing is changing between PS3 and PS2 // For negotiation to succeed with old client/servers we have to use 2. PSVersion = new Version(2, 0); //PSVersionInfo.PSVersion; SerializationVersion = PSVersionInfo.SerializationVersion; RemotingDestination = remotingDestination; }
internal RemoteSessionCapability(RemotingDestination remotingDestination, Version protocolVersion, Version psVersion, Version serVersion) { ProtocolVersion = protocolVersion; PSVersion = psVersion; SerializationVersion = serVersion; RemotingDestination = remotingDestination; }
/// <summary> /// Constructs a RemoteDataObject from its /// individual components. /// </summary> /// <param name="destination"> /// Destination this object is going to. /// </param> /// <param name="dataType"> /// Payload type this object represents. /// </param> /// <param name="runspacePoolId"> /// Runspace id this object belongs to. /// </param> /// <param name="powerShellId"> /// PowerShell (pipeline) id this object belongs to. /// This may be null if the payload belongs to runspace. /// </param> /// <param name="data"> /// Actual payload. /// </param> protected RemoteDataObject(RemotingDestination destination, RemotingDataType dataType, Guid runspacePoolId, Guid powerShellId, T data) { Destination = destination; DataType = dataType; RunspacePoolId = runspacePoolId; PowerShellId = powerShellId; Data = data; }
internal ClientRemoteSessionImpl(RemoteRunspacePoolInternal rsPool, ClientRemoteSession.URIDirectionReported uriRedirectionHandler) { base.RemoteRunspacePoolInternal = rsPool; base.Context.RemoteAddress = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <Uri>(rsPool.ConnectionInfo, "ConnectionUri", null); this._cryptoHelper = new PSRemotingCryptoHelperClient(); this._cryptoHelper.Session = this; base.Context.ClientCapability = RemoteSessionCapability.CreateClientCapability(); base.Context.UserCredential = rsPool.ConnectionInfo.Credential; base.Context.ShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo <string>(rsPool.ConnectionInfo, "ShellUri", string.Empty); this._mySelf = RemotingDestination.InvalidDestination | RemotingDestination.Client; base.SessionDataStructureHandler = new ClientRemoteSessionDSHandlerImpl(this, this._cryptoHelper, rsPool.ConnectionInfo, uriRedirectionHandler); base.BaseSessionDataStructureHandler = base.SessionDataStructureHandler; this._waitHandleForConfigurationReceived = new ManualResetEvent(false); base.SessionDataStructureHandler.NegotiationReceived += new EventHandler <RemoteSessionNegotiationEventArgs>(this.HandleNegotiationReceived); base.SessionDataStructureHandler.ConnectionStateChanged += new EventHandler <RemoteSessionStateEventArgs>(this.HandleConnectionStateChanged); base.SessionDataStructureHandler.EncryptedSessionKeyReceived += new EventHandler <RemoteDataEventArgs <string> >(this.HandleEncryptedSessionKeyReceived); base.SessionDataStructureHandler.PublicKeyRequestReceived += new EventHandler <RemoteDataEventArgs <string> >(this.HandlePublicKeyRequestReceived); }
internal ClientRemoteSessionImpl(RemoteRunspacePoolInternal rsPool, ClientRemoteSession.URIDirectionReported uriRedirectionHandler) { base.RemoteRunspacePoolInternal = rsPool; base.Context.RemoteAddress = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo<Uri>(rsPool.ConnectionInfo, "ConnectionUri", null); this._cryptoHelper = new PSRemotingCryptoHelperClient(); this._cryptoHelper.Session = this; base.Context.ClientCapability = RemoteSessionCapability.CreateClientCapability(); base.Context.UserCredential = rsPool.ConnectionInfo.Credential; base.Context.ShellName = WSManConnectionInfo.ExtractPropertyAsWsManConnectionInfo<string>(rsPool.ConnectionInfo, "ShellUri", string.Empty); this._mySelf = RemotingDestination.InvalidDestination | RemotingDestination.Client; base.SessionDataStructureHandler = new ClientRemoteSessionDSHandlerImpl(this, this._cryptoHelper, rsPool.ConnectionInfo, uriRedirectionHandler); base.BaseSessionDataStructureHandler = base.SessionDataStructureHandler; this._waitHandleForConfigurationReceived = new ManualResetEvent(false); base.SessionDataStructureHandler.NegotiationReceived += new EventHandler<RemoteSessionNegotiationEventArgs>(this.HandleNegotiationReceived); base.SessionDataStructureHandler.ConnectionStateChanged += new EventHandler<RemoteSessionStateEventArgs>(this.HandleConnectionStateChanged); base.SessionDataStructureHandler.EncryptedSessionKeyReceived += new EventHandler<RemoteDataEventArgs<string>>(this.HandleEncryptedSessionKeyReceived); base.SessionDataStructureHandler.PublicKeyRequestReceived += new EventHandler<RemoteDataEventArgs<string>>(this.HandlePublicKeyRequestReceived); }
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; } } }
internal static RemoteDataObject <T> CreateFrom(Stream serializedDataStream, Fragmentor defragmentor) { if ((serializedDataStream.Length - serializedDataStream.Position) < 40L) { PSRemotingTransportException exception = new PSRemotingTransportException(PSRemotingErrorId.NotEnoughHeaderForRemoteDataObject, RemotingErrorIdStrings.NotEnoughHeaderForRemoteDataObject, new object[] { 0x3d }); throw exception; } RemotingDestination destination = (RemotingDestination)RemoteDataObject <T> .DeserializeUInt(serializedDataStream); RemotingDataType dataType = (RemotingDataType)RemoteDataObject <T> .DeserializeUInt(serializedDataStream); Guid runspacePoolId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream); Guid powerShellId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream); object valueToConvert = null; if ((serializedDataStream.Length - 40L) > 0L) { valueToConvert = defragmentor.DeserializeToPSObject(serializedDataStream); } return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, (T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), CultureInfo.CurrentCulture))); }
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; } }
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; } } }
internal static RemoteDataObject GenerateMyPublicKey(Guid runspacePoolId, string publicKey, RemotingDestination destination) { PSObject data = CreateEmptyPSObject(); data.Properties.Add(new PSNoteProperty("PublicKey", publicKey)); return(RemoteDataObject.CreateFrom(destination, RemotingDataType.PublicKey, runspacePoolId, Guid.Empty, data)); }
protected override Destination NewDestination(DestinationDefinition destinationDefinition) { RemotingDestination remotingDestination = new RemotingDestination(this, destinationDefinition); return remotingDestination; }
protected override Destination NewDestination(DestinationSettings destinationSettings) { RemotingDestination remotingDestination = new RemotingDestination(this, destinationSettings); return(remotingDestination); }
protected override Destination NewDestination(DestinationDefinition destinationDefinition) { RemotingDestination remotingDestination = new RemotingDestination(this, destinationDefinition); return(remotingDestination); }