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 ServerPowerShellDataStructureHandler CreatePowerShellDataStructureHandler( ServerPowerShellDriver driver) { using (ServerRunspacePoolDataStructureHandler.tracer.TraceMethod()) { AbstractServerTransportManager transportManager = (AbstractServerTransportManager)this.transportManager; if (driver.InstanceId != Guid.Empty) { transportManager = this.transportManager.GetCommandTransportManager(driver.InstanceId); } ServerPowerShellDataStructureHandler structureHandler = new ServerPowerShellDataStructureHandler(driver, transportManager); lock (this.associationSyncObject) this.associatedShells.Add(structureHandler.PowerShellId, structureHandler); structureHandler.RemoveAssociation += new EventHandler(this.HandleRemoveAssociation); return(structureHandler); } }
internal ServerPowerShellDataStructureHandler CreatePowerShellDataStructureHandler(Guid instanceId, Guid runspacePoolId, RemoteStreamOptions remoteStreamOptions, PowerShell localPowerShell) { AbstractServerTransportManager transportManager = this.transportManager; if (instanceId != Guid.Empty) { transportManager = this.transportManager.GetCommandTransportManager(instanceId); } ServerPowerShellDataStructureHandler handler = new ServerPowerShellDataStructureHandler(instanceId, runspacePoolId, remoteStreamOptions, transportManager, localPowerShell); lock (this.associationSyncObject) { this.associatedShells.Add(handler.PowerShellId, handler); } handler.RemoveAssociation += new EventHandler(this.HandleRemoveAssociation); return(handler); }
internal static ServerRemoteSession CreateServerRemoteSession( PSSenderInfo senderInfo, string configurationProviderId, string initializationParameters, AbstractServerSessionTransportManager transportManager) { ServerRemoteSession._trace.WriteLine(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Finding InitialSessionState provider for id : {0}", (object)configurationProviderId), new object[0]); if (string.IsNullOrEmpty(configurationProviderId)) { throw ServerRemoteSession._trace.NewInvalidOperationException("remotingerroridstrings", "NonExistentInitialSessionStateProvider", (object)configurationProviderId); } ServerRemoteSession serverRemoteSession = new ServerRemoteSession(senderInfo, configurationProviderId, initializationParameters, transportManager); RemoteSessionStateMachineEventArgs fsmEventArg = new RemoteSessionStateMachineEventArgs(RemoteSessionEvent.Start); serverRemoteSession._sessionDSHandler.StateMachine.RaiseEvent(fsmEventArg); return(serverRemoteSession); }
internal ServerRemoteSession( PSSenderInfo senderInfo, string configurationProviderId, string initializationParameters, AbstractServerSessionTransportManager transportManager) { NativeCommandProcessor.IsServerSide = true; this._senderInfo = senderInfo; this._configProviderId = configurationProviderId; this._initParameters = initializationParameters; this._cryptoHelper = (PSRemotingCryptoHelperServer)transportManager.CryptoHelper; this._cryptoHelper.Session = (RemoteSession)this; this._context = new ServerRemoteSessionContext(); this._sessionDSHandler = (ServerRemoteSessionDataStructureHandler) new ServerRemoteSessionDSHandlerlImpl(this, transportManager); this.BaseSessionDataStructureHandler = (BaseSessionDataStructureHandler)this._sessionDSHandler; this._sessionDSHandler.CreateRunspacePoolReceived += new EventHandler <RemoteDataEventArgs>(this.HandleCreateRunspacePool); this._sessionDSHandler.NegotiationReceived += new EventHandler <RemoteSessionNegotiationEventArgs>(this.HandleNegotiationReceived); this._sessionDSHandler.SessionClosing += new EventHandler <EventArgs>(this.HandleSessionDSHandlerClosing); this._sessionDSHandler.PublicKeyReceived += new EventHandler <RemoteDataEventArgs <string> >(this.HandlePublicKeyReceived); transportManager.Closing += new EventHandler(this.HandleResourceClosing); transportManager.ReceivedDataCollection.MaximumReceivedObjectSize = new int?(10485760); transportManager.ReceivedDataCollection.MaximumReceivedDataSize = new int?(); }
/// <summary> /// Constructor which takes a server runspace pool driver and /// creates an associated ServerRunspacePoolDataStructureHandler. /// </summary> /// <param name="driver"></param> /// <param name="transportManager"></param> internal ServerRunspacePoolDataStructureHandler(ServerRunspacePoolDriver driver, AbstractServerSessionTransportManager transportManager) { _clientRunspacePoolId = driver.InstanceId; _transportManager = transportManager; }
internal static ServerRemoteSession CreateServerRemoteSession(PSSenderInfo senderInfo, string initializationScriptForOutOfProcessRunspace, AbstractServerSessionTransportManager transportManager) { ServerRemoteSession session = CreateServerRemoteSession(senderInfo, "Microsoft.PowerShell", "", transportManager); session._initScriptForOutOfProcRS = initializationScriptForOutOfProcessRunspace; return(session); }