internal ClientRemoteSessionDSHandlerImpl(ClientRemoteSession session, PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo connectionInfo, ClientRemoteSession.URIDirectionReported uriRedirectionHandler)
 {
     if (session == null)
     {
         throw PSTraceSource.NewArgumentNullException("session");
     }
     this._session = session;
     this._stateMachine = new ClientRemoteSessionDSHandlerStateMachine();
     this._stateMachine.StateChanged += new EventHandler<RemoteSessionStateEventArgs>(this.HandleStateChanged);
     this._connectionInfo = connectionInfo;
     this._cryptoHelper = cryptoHelper;
     if (this._connectionInfo is NewProcessConnectionInfo)
     {
         this._transportManager = new OutOfProcessClientSessionTransportManager(this._session.RemoteRunspacePoolInternal.InstanceId, (NewProcessConnectionInfo) this._connectionInfo, cryptoHelper);
     }
     else
     {
         this._transportManager = new WSManClientSessionTransportManager(this._session.RemoteRunspacePoolInternal.InstanceId, (WSManConnectionInfo) this._connectionInfo, cryptoHelper, this._session.RemoteRunspacePoolInternal.Name);
     }
     this._transportManager.DataReceived += new EventHandler<RemoteDataEventArgs>(this.DispatchInputQueueData);
     this._transportManager.WSManTransportErrorOccured += new EventHandler<TransportErrorOccuredEventArgs>(this.HandleTransportError);
     this._transportManager.CloseCompleted += new EventHandler<EventArgs>(this.HandleCloseComplete);
     this._transportManager.DisconnectCompleted += new EventHandler<EventArgs>(this.HandleDisconnectComplete);
     this._transportManager.ReconnectCompleted += new EventHandler<EventArgs>(this.HandleReconnectComplete);
     this._transportManager.RobustConnectionNotification += new EventHandler<ConnectionStatusEventArgs>(this.HandleRobustConnectionNotification);
     WSManConnectionInfo info = connectionInfo as WSManConnectionInfo;
     if (info != null)
     {
         this.uriRedirectionHandler = uriRedirectionHandler;
         this.maxUriRedirectionCount = info.MaximumConnectionRedirectionCount;
     }
 }
 protected BaseClientCommandTransportManager(ClientRemotePowerShell shell, PSRemotingCryptoHelper cryptoHelper, BaseClientSessionTransportManager sessnTM) : base(sessnTM.RunspacePoolInstanceId, cryptoHelper)
 {
     RemoteDataObject obj2;
     base.Fragmentor.FragmentSize = sessnTM.Fragmentor.FragmentSize;
     base.Fragmentor.TypeTable = sessnTM.Fragmentor.TypeTable;
     base.dataToBeSent.Fragmentor = base.Fragmentor;
     this.powershellInstanceId = shell.PowerShell.InstanceId;
     this.cmdText = new StringBuilder();
     foreach (Command command in shell.PowerShell.Commands.Commands)
     {
         this.cmdText.Append(command.CommandText);
         this.cmdText.Append(" | ");
     }
     this.cmdText.Remove(this.cmdText.Length - 3, 3);
     if (shell.PowerShell.IsGetCommandMetadataSpecialPipeline)
     {
         obj2 = RemotingEncoder.GenerateGetCommandMetadata(shell);
     }
     else
     {
         obj2 = RemotingEncoder.GenerateCreatePowerShell(shell);
     }
     this.serializedPipeline = new SerializedDataStream(base.Fragmentor.FragmentSize);
     base.Fragmentor.Fragment<object>(obj2, this.serializedPipeline);
 }
        /// <summary>
        /// Creates an instance of ClientRemoteSessionDSHandlerImpl
        /// </summary>
        internal ClientRemoteSessionDSHandlerImpl(ClientRemoteSession session,
            PSRemotingCryptoHelper cryptoHelper,
            RunspaceConnectionInfo connectionInfo,
            ClientRemoteSession.URIDirectionReported uriRedirectionHandler)
        {
            Dbg.Assert(_maxUriRedirectionCount >= 0, "maxUriRedirectionCount cannot be less than 0.");

            if (session == null)
            {
                throw PSTraceSource.NewArgumentNullException("session");
            }

            _session = session;

            //Create state machine
            _stateMachine = new ClientRemoteSessionDSHandlerStateMachine();
            _stateMachine.StateChanged += HandleStateChanged;

            _connectionInfo = connectionInfo;

            // Create transport manager
            _cryptoHelper = cryptoHelper;
            _transportManager = _connectionInfo.CreateClientSessionTransportManager(
                _session.RemoteRunspacePoolInternal.InstanceId,
                _session.RemoteRunspacePoolInternal.Name,
                cryptoHelper);

            _transportManager.DataReceived += DispatchInputQueueData;
            _transportManager.WSManTransportErrorOccured += HandleTransportError;
            _transportManager.CloseCompleted += HandleCloseComplete;
            _transportManager.DisconnectCompleted += HandleDisconnectComplete;
            _transportManager.ReconnectCompleted += HandleReconnectComplete;

            _transportManager.RobustConnectionNotification += new EventHandler<ConnectionStatusEventArgs>(HandleRobustConnectionNotification);

            WSManConnectionInfo wsmanConnectionInfo = _connectionInfo as WSManConnectionInfo;
            if (null != wsmanConnectionInfo)
            {
                // only WSMan transport supports redirection

                // store the uri redirection handler and authmechanism 
                // for uri redirection.
                _uriRedirectionHandler = uriRedirectionHandler;
                _maxUriRedirectionCount = wsmanConnectionInfo.MaximumConnectionRedirectionCount;
            }
        }
Exemplo n.º 4
0
        protected BaseClientCommandTransportManager(
            ClientRemotePowerShell shell,
            PSRemotingCryptoHelper cryptoHelper,
            BaseClientSessionTransportManager sessnTM)
            : base(sessnTM.RunspacePoolInstanceId, cryptoHelper)
        {
            this.Fragmentor.FragmentSize = sessnTM.Fragmentor.FragmentSize;
            this.Fragmentor.TypeTable    = sessnTM.Fragmentor.TypeTable;
            this.dataToBeSent.Fragmentor = this.Fragmentor;
            this.powershellInstanceId    = shell.PowerShell.InstanceId;
            this.cmdText = new StringBuilder();
            foreach (Command command in (Collection <Command>)shell.PowerShell.Commands.Commands)
            {
                this.cmdText.Append(command.CommandText);
                this.cmdText.Append(" | ");
            }
            this.cmdText.Remove(this.cmdText.Length - 3, 3);
            RemoteDataObject remoteDataObject = !shell.PowerShell.IsGetCommandMetadataSpecialPipeline ? RemotingEncoder.GenerateCreatePowerShell(shell) : RemotingEncoder.GenerateGetCommandMetadata(shell);

            this.serializedPipeline = new SerializedDataStream(this.Fragmentor.FragmentSize);
            this.Fragmentor.Fragment <object>((RemoteDataObject <object>)remoteDataObject, this.serializedPipeline);
        }