示例#1
0
 internal static void Dispatch(BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream<ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall)
 {
     ClientMethodExecutor executor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall);
     if (clientPowerShellId == Guid.Empty)
     {
         executor.Execute(errorStream);
     }
     else
     {
         bool flag = false;
         if (clientHost != null)
         {
             PSObject privateData = clientHost.PrivateData;
             if (privateData != null)
             {
                 PSNoteProperty property = privateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty;
                 flag = ((property != null) && (property.Value is bool)) ? ((bool) property.Value) : false;
             }
         }
         if ((remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) && !flag)
         {
             runspacePool.Close();
         }
         else if (isMethodExecutorStreamEnabled)
         {
             methodExecutorStream.Write(executor);
         }
         else
         {
             executor.Execute(errorStream);
         }
     }
 }
示例#2
0
 private ClientMethodExecutor(BaseClientTransportManager transportManager, PSHost clientHost, Guid clientRunspacePoolId, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall)
 {
     this._transportManager = transportManager;
     this._remoteHostCall = remoteHostCall;
     this._clientHost = clientHost;
     this._clientRunspacePoolId = clientRunspacePoolId;
     this._clientPowerShellId = clientPowerShellId;
 }
示例#3
0
 /// <summary>
 /// Constructor for ClientMethodExecutor.
 /// </summary>
 private ClientMethodExecutor(BaseClientTransportManager transportManager, PSHost clientHost, Guid clientRunspacePoolId, Guid clientPowerShellId, RemoteHostCall remoteHostCall)
 {
     Dbg.Assert(transportManager != null, "Expected transportManager != null");
     Dbg.Assert(remoteHostCall != null, "Expected remoteHostCall != null");
     _transportManager = transportManager;
     _remoteHostCall = remoteHostCall;
     _clientHost = clientHost;
     _clientRunspacePoolId = clientRunspacePoolId;
     _clientPowerShellId = clientPowerShellId;
 }
示例#4
0
        /// <summary>
        /// Create a new ClientMethodExecutor object and then dispatch it.
        /// </summary>
        internal static void Dispatch(
            BaseClientTransportManager transportManager,
            PSHost clientHost,
            PSDataCollectionStream<ErrorRecord> errorStream,
            ObjectStream methodExecutorStream,
            bool isMethodExecutorStreamEnabled,
            RemoteRunspacePoolInternal runspacePool,
            Guid clientPowerShellId,
            RemoteHostCall remoteHostCall)
        {
            ClientMethodExecutor methodExecutor =
                new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId,
                    clientPowerShellId, remoteHostCall);

            // If the powershell id is not specified, this message is for the runspace pool, execute
            // it immediately and return
            if (clientPowerShellId == Guid.Empty)
            {
                methodExecutor.Execute(errorStream);
                return;
            }

            // Check client host to see if SetShouldExit should be allowed
            bool hostAllowSetShouldExit = false;
            if (clientHost != null)
            {
                PSObject hostPrivateData = clientHost.PrivateData as PSObject;
                if (hostPrivateData != null)
                {
                    PSNoteProperty allowSetShouldExit = hostPrivateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty;
                    hostAllowSetShouldExit = (allowSetShouldExit != null && allowSetShouldExit.Value is bool) ?
                        (bool)allowSetShouldExit.Value : false;
                }
            }

            // Should we kill remote runspace? Check if "SetShouldExit" and if we are in the
            // cmdlet case. In the API case (when we are invoked from an API not a cmdlet) we
            // should not interpret "SetShouldExit" but should pass it on to the host. The
            // variable IsMethodExecutorStreamEnabled is only true in the cmdlet case. In the
            // API case it is false.

            if (remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled && !hostAllowSetShouldExit)
            {
                runspacePool.Close();
                return;
            }

            // Cmdlet case: queue up the executor in the pipeline stream.
            if (isMethodExecutorStreamEnabled)
            {
                Dbg.Assert(!isMethodExecutorStreamEnabled ||
                           (isMethodExecutorStreamEnabled && methodExecutorStream != null),
                           "method executor stream can't be null when enabled");
                methodExecutorStream.Write(methodExecutor);
            }

            // API case: execute it immediately.
            else
            {
                methodExecutor.Execute(errorStream);
            }
        }