internal static RemoteDataObject GenerateClientSessionCapability(RemoteSessionCapability capability, Guid runspacePoolId) { PSObject data = GenerateSessionCapability(capability); data.Properties.Add(new PSNoteProperty("TimeZone", RemoteSessionCapability.GetCurrentTimeZoneInByteFormat())); return(RemoteDataObject.CreateFrom(capability.RemotingDestination, RemotingDataType.SessionCapability, runspacePoolId, Guid.Empty, data)); }
internal static RemoteDataObject GenerateServerSessionCapability( RemoteSessionCapability capability, Guid runspacePoolId) { PSObject sessionCapability = RemotingEncoder.GenerateSessionCapability(capability); return(RemoteDataObject.CreateFrom(capability.RemotingDestination, RemotingDataType.SessionCapability, runspacePoolId, Guid.Empty, (object)sessionCapability)); }
private static PSObject GenerateSessionCapability(RemoteSessionCapability capability) { PSObject emptyPsObject = RemotingEncoder.CreateEmptyPSObject(); emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("protocolversion", (object)capability.ProtocolVersion)); emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("PSVersion", (object)capability.PSVersion)); emptyPsObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("SerializationVersion", (object)capability.SerializationVersion)); return(emptyPsObject); }
internal static RemoteDataObject GenerateClientSessionCapability( RemoteSessionCapability capability, Guid runspacePoolId) { PSObject sessionCapability = RemotingEncoder.GenerateSessionCapability(capability); sessionCapability.Properties.Add((PSPropertyInfo) new PSNoteProperty("TimeZone", (object)RemoteSessionCapability.GetCurrentTimeZoneInByteFormat())); return(RemoteDataObject.CreateFrom(capability.RemotingDestination, RemotingDataType.SessionCapability, runspacePoolId, Guid.Empty, (object)sessionCapability)); }
private static PSObject GenerateSessionCapability(RemoteSessionCapability capability) { PSObject obj2 = CreateEmptyPSObject(); obj2.Properties.Add(new PSNoteProperty("protocolversion", capability.ProtocolVersion)); obj2.Properties.Add(new PSNoteProperty("PSVersion", capability.PSVersion)); obj2.Properties.Add(new PSNoteProperty("SerializationVersion", capability.SerializationVersion)); return(obj2); }
internal RemoteSessionNegotiationEventArgs(RemoteSessionCapability remoteSessionCapability) { Dbg.Assert(remoteSessionCapability != null, "caller should validate the parameter"); if (remoteSessionCapability == null) { throw PSTraceSource.NewArgumentNullException("remoteSessionCapability"); } RemoteSessionCapability = remoteSessionCapability; }
internal ServerRunspacePoolDriver( Guid clientRunspacePoolId, int minRunspaces, int maxRunspaces, PSThreadOptions threadOptions, ApartmentState apartmentState, HostInfo hostInfo, InitialSessionState initialSessionState, PSPrimitiveDictionary applicationPrivateData, ConfigurationDataFromXML configData, AbstractServerSessionTransportManager transportManager, bool isAdministrator, RemoteSessionCapability serverCapability) { using (ServerRunspacePoolDriver.tracer.TraceConstructor((object)this)) { this.serverCapability = serverCapability; ServerRemoteHost serverRemoteHost = new ServerRemoteHost(clientRunspacePoolId, Guid.Empty, hostInfo, (AbstractServerTransportManager)transportManager); this.remoteHost = serverRemoteHost; this.configData = configData; this.applicationPrivateData = applicationPrivateData; this.localRunspacePool = RunspaceFactory.CreateRunspacePool(minRunspaces, maxRunspaces, initialSessionState, (PSHost)serverRemoteHost); PSThreadOptions psThreadOptions = configData.ShellThreadOptions.HasValue ? configData.ShellThreadOptions.Value : PSThreadOptions.UseCurrentThread; if (threadOptions == PSThreadOptions.Default || threadOptions == psThreadOptions) { this.localRunspacePool.ThreadOptions = psThreadOptions; } else { if (!isAdministrator) { throw new InvalidOperationException(PSRemotingErrorInvariants.FormatResourceString(PSRemotingErrorId.MustBeAdminToOverrideThreadOptions)); } this.localRunspacePool.ThreadOptions = threadOptions; } ApartmentState apartmentState1 = configData.ShellThreadApartmentState.HasValue ? configData.ShellThreadApartmentState.Value : ApartmentState.Unknown; this.localRunspacePool.ApartmentState = apartmentState == ApartmentState.Unknown || apartmentState == apartmentState1 ? apartmentState1 : apartmentState; this.clientRunspacePoolId = clientRunspacePoolId; this.dsHandler = new ServerRunspacePoolDataStructureHandler(this, transportManager); this.localRunspacePool.StateChanged += new EventHandler <RunspacePoolStateChangedEventArgs>(this.HandleRunspacePoolStateChanged); this.localRunspacePool.ForwardEvent += new EventHandler <PSEventArgs>(this.HandleRunspacePoolForwardEvent); this.localRunspacePool.RunspaceCreated += new EventHandler <RunspaceCreatedEventArgs>(this.HandleRunspaceCreated); this.localRunspacePool.RunspaceCreated += new EventHandler <RunspaceCreatedEventArgs>(this.HandleRunspaceCreatedForTypeTable); this.dsHandler.CreateAndInvokePowerShell += new EventHandler <RemoteDataEventArgs <RemoteDataObject <PSObject> > >(this.HandleCreateAndInvokePowerShell); this.dsHandler.GetCommandMetadata += new EventHandler <RemoteDataEventArgs <RemoteDataObject <PSObject> > >(this.HandleGetCommandMetadata); this.dsHandler.HostResponseReceived += new EventHandler <RemoteDataEventArgs <RemoteHostResponse> >(this.HandleHostResponseReceived); this.dsHandler.SetMaxRunspacesReceived += new EventHandler <RemoteDataEventArgs <PSObject> >(this.HandleSetMaxRunspacesReceived); this.dsHandler.SetMinRunspacesReceived += new EventHandler <RemoteDataEventArgs <PSObject> >(this.HandleSetMinRunspacesReceived); this.dsHandler.GetAvailableRunspacesReceived += new EventHandler <RemoteDataEventArgs <PSObject> >(this.HandleGetAvailalbeRunspacesReceived); } }
internal void SendApplicationPrivateDataToClient( PSPrimitiveDictionary applicationPrivateData, RemoteSessionCapability serverCapability) { using (ServerRunspacePoolDataStructureHandler.tracer.TraceMethod()) { PSPrimitiveDictionary applicationPrivateData1 = PSPrimitiveDictionary.CloneAndAddPSVersionTable(applicationPrivateData); PSPrimitiveDictionary primitiveDictionary = (PSPrimitiveDictionary)applicationPrivateData1["PSVersionTable"]; primitiveDictionary["PSRemotingProtocolVersion"] = (object)serverCapability.ProtocolVersion; primitiveDictionary["SerializationVersion"] = (object)serverCapability.SerializationVersion; primitiveDictionary["PSVersion"] = (object)serverCapability.PSVersion; this.SendDataAsync(RemotingEncoder.GenerateApplicationPrivateData(this.clientRunspacePoolId, applicationPrivateData1)); } }
internal static RemoteSessionCapability GetSessionCapability(object data) { RemoteSessionCapability sessionCapability = data is PSObject psObject ? new RemoteSessionCapability(RemotingDestination.InvalidDestination, RemotingDecoder.GetPropertyValue <Version>(psObject, "protocolversion"), RemotingDecoder.GetPropertyValue <Version>(psObject, "PSVersion"), RemotingDecoder.GetPropertyValue <Version>(psObject, "SerializationVersion")) : throw new PSRemotingDataStructureException(PSRemotingErrorId.CantCastRemotingDataToPSObject, new object[1] { (object)data.GetType().FullName }); if (psObject.Properties["TimeZone"] != null) { byte[] propertyValue = RemotingDecoder.GetPropertyValue <byte[]>(psObject, "TimeZone"); sessionCapability.TimeZone = RemoteSessionCapability.ConvertFromByteToTimeZone(propertyValue); } return(sessionCapability); }
internal static RemoteSessionCapability GetSessionCapability(object data) { PSObject psObject = data as PSObject; if (psObject == null) { throw new PSRemotingDataStructureException(RemotingErrorIdStrings.CantCastRemotingDataToPSObject, new object[] { data.GetType().FullName }); } Version propertyValue = GetPropertyValue <Version>(psObject, "protocolversion"); Version psVersion = GetPropertyValue <Version>(psObject, "PSVersion"); Version serVersion = GetPropertyValue <Version>(psObject, "SerializationVersion"); RemoteSessionCapability capability = new RemoteSessionCapability(RemotingDestination.InvalidDestination, propertyValue, psVersion, serVersion); if (psObject.Properties["TimeZone"] != null) { byte[] buffer = GetPropertyValue <byte[]>(psObject, "TimeZone"); capability.TimeZone = RemoteSessionCapability.ConvertFromByteToTimeZone(buffer); } return(capability); }
/// <summary> /// Send a message with application private data to the client. /// </summary> /// <param name="applicationPrivateData">ApplicationPrivateData to send.</param> /// <param name="serverCapability">Server capability negotiated during initial exchange of remoting messages / session capabilities of client and server.</param> internal void SendApplicationPrivateDataToClient(PSPrimitiveDictionary applicationPrivateData, RemoteSessionCapability serverCapability) { // make server's PSVersionTable available to the client using ApplicationPrivateData PSPrimitiveDictionary applicationPrivateDataWithVersionTable = PSPrimitiveDictionary.CloneAndAddPSVersionTable(applicationPrivateData); // override the hardcoded version numbers with the stuff that was reported to the client during negotiation PSPrimitiveDictionary versionTable = (PSPrimitiveDictionary)applicationPrivateDataWithVersionTable[PSVersionInfo.PSVersionTableName]; versionTable[PSVersionInfo.PSRemotingProtocolVersionName] = serverCapability.ProtocolVersion; versionTable[PSVersionInfo.SerializationVersionName] = serverCapability.SerializationVersion; // Pass back the true PowerShell version to the client via application private data. versionTable[PSVersionInfo.PSVersionName] = PSVersionInfo.PSVersion; RemoteDataObject data = RemotingEncoder.GenerateApplicationPrivateData( _clientRunspacePoolId, applicationPrivateDataWithVersionTable); SendDataAsync(data); }
internal RemoteSessionNegotiationEventArgs(RemoteSessionCapability remoteSessionCapability) { using (RemoteSessionNegotiationEventArgs._trace.TraceConstructor((object)this)) this._remoteSessionCapability = remoteSessionCapability != null ? remoteSessionCapability : throw RemoteSessionNegotiationEventArgs._trace.NewArgumentNullException(nameof(remoteSessionCapability)); }
internal void SendApplicationPrivateDataToClient(PSPrimitiveDictionary applicationPrivateData, RemoteSessionCapability serverCapability) { PSPrimitiveDictionary dictionary = PSPrimitiveDictionary.CloneAndAddPSVersionTable(applicationPrivateData); PSPrimitiveDictionary dictionary2 = (PSPrimitiveDictionary)dictionary["PSVersionTable"]; dictionary2["PSRemotingProtocolVersion"] = serverCapability.ProtocolVersion; dictionary2["SerializationVersion"] = serverCapability.SerializationVersion; dictionary2["PSVersion"] = serverCapability.PSVersion; RemoteDataObject data = RemotingEncoder.GenerateApplicationPrivateData(this.clientRunspacePoolId, dictionary); this.SendDataAsync(data); }
internal ServerRemoteSessionContext() { using (ServerRemoteSessionContext._trace.TraceConstructor((object)this)) this._serverCapability = RemoteSessionCapability.CreateServerCapability(); }