Exemplo n.º 1
0
        /// <summary>
        /// Push runspace to use for remote command execution.
        /// </summary>
        /// <param name="runspace">RemoteRunspace.</param>
        public override void PushRunspace(Runspace runspace)
        {
            if (_debugger == null)
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostNoDebuggerToPush);
            }

            if (_pushedRunspace != null)
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostAlreadyPushed);
            }

            if (!(runspace is RemoteRunspace remoteRunspace))
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostNotRemoteRunspace);
            }

            // PSEdit support.  Existence of RemoteSessionOpenFileEvent event indicates host supports PSEdit
            _hostSupportsPSEdit = false;
            PSEventManager localEventManager = Runspace?.Events;

            _hostSupportsPSEdit = (localEventManager != null) ? localEventManager.GetEventSubscribers(HostUtilities.RemoteSessionOpenFileEvent).GetEnumerator().MoveNext() : false;
            if (_hostSupportsPSEdit)
            {
                AddPSEditForRunspace(remoteRunspace);
            }

            _debugger.PushDebugger(runspace.Debugger);
            _pushedRunspace = remoteRunspace;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Push runspace to use for remote command execution
        /// </summary>
        /// <param name="runspace">RemoteRunspace</param>
        public override void PushRunspace(Runspace runspace)
        {
            // Double session hop is currently allowed only for WSMan (non-OutOfProc) sessions, where
            // the second session is either through a named pipe or hyperV socket connection.
            if (!AllowPushRunspace &&
                ((_transportManager is OutOfProcessServerSessionTransportManager) ||
                 !(runspace.ConnectionInfo is NamedPipeConnectionInfo ||
                   runspace.ConnectionInfo is VMConnectionInfo ||
                   runspace.ConnectionInfo is ContainerConnectionInfo))
                )
            {
                throw new PSNotSupportedException();
            }

            if (_debugger == null)
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostNoDebuggerToPush);
            }

            if (_pushedRunspace != null)
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostAlreadyPushed);
            }

            RemoteRunspace remoteRunspace = runspace as RemoteRunspace;

            if (remoteRunspace == null)
            {
                throw new PSInvalidOperationException(RemotingErrorIdStrings.ServerDriverRemoteHostNotRemoteRunspace);
            }

            // PSEdit support.  Existence of RemoteSessionOpenFileEvent event indicates host supports PSEdit
            _hostSupportsPSEdit = false;
            PSEventManager localEventManager = (Runspace != null) ? Runspace.Events : null;

            _hostSupportsPSEdit = (localEventManager != null) ? localEventManager.GetEventSubscribers(HostUtilities.RemoteSessionOpenFileEvent).GetEnumerator().MoveNext() : false;
            if (_hostSupportsPSEdit)
            {
                AddPSEditForRunspace(remoteRunspace);
            }

            _debugger.PushDebugger(runspace.Debugger);
            _pushedRunspace = remoteRunspace;
        }