Beispiel #1
0
 internal ConnectRunspaceOperation(PSSession session, ObjectStream stream, PSHost host, QueryRunspaces queryRunspaces, Collection <PSSession> retryList)
 {
     this._session        = session;
     this._writeStream    = stream;
     this._host           = host;
     this._queryRunspaces = queryRunspaces;
     this._retryList      = retryList;
     this._session.Runspace.StateChanged += new EventHandler <RunspaceStateEventArgs>(this.StateCallBackHandler);
 }
Beispiel #2
0
 public ConnectPSSessionCommand()
 {
     this.allSessions          = new Collection <PSSession>();
     this.throttleManager      = new ThrottleManager();
     this.operationsComplete   = new ManualResetEvent(true);
     this.queryRunspaces       = new QueryRunspaces();
     this.stream               = new ObjectStream();
     this.retryThrottleManager = new ThrottleManager();
     this.failedSessions       = new Collection <PSSession>();
 }
Beispiel #3
0
 internal ConnectRunspaceOperation(
     PSSession session,
     ObjectStream stream,
     PSHost host,
     QueryRunspaces queryRunspaces,
     Collection <PSSession> retryList)
 {
     _session        = session;
     _writeStream    = stream;
     _host           = host;
     _queryRunspaces = queryRunspaces;
     _retryList      = retryList;
     _session.Runspace.StateChanged += StateCallBackHandler;
 }
        private void QueryForAndConnectCommands(string name, Guid instanceId)
        {
            Runspace[]          runspaceArray;
            WSManConnectionInfo connectionObject = this.GetConnectionObject();

            try
            {
                runspaceArray = Runspace.GetRunspaces(connectionObject, base.Host, QueryRunspaces.BuiltInTypesTable);
            }
            catch (RuntimeException exception)
            {
                int         num;
                string      message = StringUtil.Format(RemotingErrorIdStrings.QueryForRunspacesFailed, connectionObject.ComputerName, QueryRunspaces.ExtractMessage(exception.InnerException, out num));
                string      fQEIDFromTransportError = WSManTransportManagerUtils.GetFQEIDFromTransportError(num, "ReceivePSSessionQueryForSessionFailed");
                Exception   exception2  = new RuntimeException(message, exception.InnerException);
                ErrorRecord errorRecord = new ErrorRecord(exception2, fQEIDFromTransportError, ErrorCategory.InvalidOperation, connectionObject);
                base.WriteError(errorRecord);
                return;
            }
            string str3 = null;

            if (!string.IsNullOrEmpty(this.ConfigurationName))
            {
                str3 = (this.ConfigurationName.IndexOf("http://schemas.microsoft.com/powershell/", StringComparison.OrdinalIgnoreCase) != -1) ? this.ConfigurationName : ("http://schemas.microsoft.com/powershell/" + this.ConfigurationName);
            }
            foreach (Runspace runspace in runspaceArray)
            {
                if (this._stopProcessing)
                {
                    return;
                }
                if (str3 != null)
                {
                    WSManConnectionInfo connectionInfo = runspace.ConnectionInfo as WSManConnectionInfo;
                    if ((connectionInfo != null) && !str3.Equals(connectionInfo.ShellUri, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }
                bool flag = false;
                if (!string.IsNullOrEmpty(name) && (string.Compare(name, ((RemoteRunspace)runspace).RunspacePool.RemoteRunspacePoolInternal.Name, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    flag = true;
                }
                else if (instanceId.Equals(runspace.InstanceId))
                {
                    flag = true;
                }
                if (flag && base.ShouldProcess(((RemoteRunspace)runspace).Name, "Receive"))
                {
                    Exception exception3;
                    PSSession item     = base.RunspaceRepository.GetItem(runspace.InstanceId);
                    PSSession session2 = this.ConnectSession(item, out exception3);
                    if (session2 != null)
                    {
                        base.RunspaceRepository.AddOrReplace(session2);
                        PSRemotingJob job = this.FindJobForSession(session2);
                        if (this.OutTarget == Microsoft.PowerShell.Commands.OutTarget.Host)
                        {
                            this.ConnectSessionToHost(session2, job);
                            return;
                        }
                        this.ConnectSessionToJob(session2, job);
                        return;
                    }
                    PSSession session = new PSSession(runspace as RemoteRunspace);
                    session2 = this.ConnectSession(session, out exception3);
                    if (session2 != null)
                    {
                        if (item != null)
                        {
                            session2 = item.InsertRunspace(session2.Runspace as RemoteRunspace) ? item : session2;
                        }
                        base.RunspaceRepository.AddOrReplace(session2);
                        if (this.OutTarget == Microsoft.PowerShell.Commands.OutTarget.Job)
                        {
                            this.ConnectSessionToJob(session2, null);
                            return;
                        }
                        this.ConnectSessionToHost(session2, null);
                        return;
                    }
                    string str4 = StringUtil.Format(RemotingErrorIdStrings.RunspaceCannotBeConnected, session.Name);
                    base.WriteError(new ErrorRecord(new ArgumentException(str4, exception3), "ReceivePSSessionCannotConnectSession", ErrorCategory.InvalidOperation, session));
                    return;
                }
            }
        }
Beispiel #5
0
 internal ConnectRunspaceOperation(
     PSSession session,
     ObjectStream stream,
     PSHost host,
     QueryRunspaces queryRunspaces,
     Collection<PSSession> retryList)
 {
     _session = session;
     _writeStream = stream;
     _host = host;
     _queryRunspaces = queryRunspaces;
     _retryList = retryList;
     _session.Runspace.StateChanged += StateCallBackHandler;
 }
 internal ConnectRunspaceOperation(PSSession session, ObjectStream stream, PSHost host, QueryRunspaces queryRunspaces, Collection<PSSession> retryList)
 {
     this._session = session;
     this._writeStream = stream;
     this._host = host;
     this._queryRunspaces = queryRunspaces;
     this._retryList = retryList;
     this._session.Runspace.StateChanged += new EventHandler<RunspaceStateEventArgs>(this.StateCallBackHandler);
 }
 public ConnectPSSessionCommand()
 {
     this.allSessions = new Collection<PSSession>();
     this.throttleManager = new ThrottleManager();
     this.operationsComplete = new ManualResetEvent(true);
     this.queryRunspaces = new QueryRunspaces();
     this.stream = new ObjectStream();
     this.retryThrottleManager = new ThrottleManager();
     this.failedSessions = new Collection<PSSession>();
 }