예제 #1
0
        private PSRemotingJob FindJobForSession(PSSession session)
        {
            PSRemotingJob  job      = null;
            RemoteRunspace runspace = session.Runspace as RemoteRunspace;

            if ((runspace == null) || (runspace.RemoteCommand != null))
            {
                return(null);
            }
            foreach (Job job2 in base.JobRepository.Jobs)
            {
                if (!(job2 is PSRemotingJob))
                {
                    continue;
                }
                foreach (PSRemotingChildJob job3 in job2.ChildJobs)
                {
                    if (job3.Runspace.InstanceId.Equals(session.InstanceId) && (job3.JobStateInfo.State == JobState.Disconnected))
                    {
                        job = (PSRemotingJob)job2;
                        break;
                    }
                }
                if (job != null)
                {
                    return(job);
                }
            }
            return(job);
        }
예제 #2
0
        private void ConnectSessionToJob(PSSession session, PSRemotingJob job = null)
        {
            bool flag = false;

            if (job == null)
            {
                List <IThrottleOperation> helpers = new List <IThrottleOperation>();
                Pipeline pipeline = session.Runspace.CreateDisconnectedPipeline();
                helpers.Add(new DisconnectedJobOperation(pipeline));
                job = new PSRemotingJob(helpers, 0, this.JobName, false);
                job.PSJobTypeName    = InvokeCommandCommand.RemoteJobType;
                job.HideComputerName = false;
                flag = true;
            }
            if (job.JobStateInfo.State == JobState.Disconnected)
            {
                job.ConnectJob(session.Runspace.InstanceId);
                if (flag)
                {
                    base.JobRepository.Add(job);
                }
            }
            base.WriteObject(job);
        }
예제 #3
0
        /// <summary>
        /// The expression will be executed in the remote computer if a
        /// remote runspace parameter or computer name is specified. If
        /// none other than command parameter is specified, then it
        /// just executes the command locally without creating a new
        /// remote runspace object.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (ParameterSetName == DefinitionNameParameterSet)
            {
                // Get the Job2 object from the Job Manager for this definition name and start the job.
                string resolvedPath = null;
                if (!string.IsNullOrEmpty(_definitionPath))
                {
                    ProviderInfo provider = null;
                    System.Collections.ObjectModel.Collection <string> paths =
                        this.Context.SessionState.Path.GetResolvedProviderPathFromPSPath(_definitionPath, out provider);

                    // Only file system paths are allowed.
                    if (!provider.NameEquals(this.Context.ProviderNames.FileSystem))
                    {
                        string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotFSProvider,
                                                           _definitionName,
                                                           _definitionPath,
                                                           provider.FullName);
                        WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotFileSystemProvider",
                                                   ErrorCategory.InvalidArgument, null));

                        return;
                    }

                    // Only a single file path is allowed.
                    if (paths.Count != 1)
                    {
                        string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotSingle,
                                                           _definitionName,
                                                           _definitionPath);
                        WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotSingle",
                                                   ErrorCategory.InvalidArgument, null));

                        return;
                    }

                    resolvedPath = paths[0];
                }
                List <Job2> jobs = JobManager.GetJobToStart(_definitionName, resolvedPath, _definitionType, this, false);

                if (jobs.Count == 0)
                {
                    string message = (_definitionType != null) ?
                                     StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound2, _definitionType, _definitionName) :
                                     StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound1, _definitionName);

                    WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNameNotFound",
                                               ErrorCategory.ObjectNotFound, null));

                    return;
                }

                if (jobs.Count > 1)
                {
                    string message = StringUtil.Format(RemotingErrorIdStrings.StartJobManyDefNameMatches, _definitionName);
                    WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNameMoreThanOneMatch",
                                               ErrorCategory.InvalidResult, null));

                    return;
                }

                // Start job.
                Job2 job = jobs[0];
                job.StartJob();

                // Write job object to host.
                WriteObject(job);

                return;
            }

            if (_firstProcessRecord)
            {
                _firstProcessRecord = false;

                PSRemotingJob job = new PSRemotingJob(ResolvedComputerNames, Operations,
                                                      ScriptBlock.ToString(), ThrottleLimit, _name);

                job.PSJobTypeName = s_startJobType;

                this.JobRepository.Add(job);
                WriteObject(job);
            }

            // inject input
            if (InputObject != AutomationNull.Value)
            {
                foreach (IThrottleOperation operation in Operations)
                {
                    ExecutionCmdletHelper helper = (ExecutionCmdletHelper)operation;
                    helper.Pipeline.Input.Write(InputObject);
                }
            }
        } // ProcessRecord
예제 #4
0
 protected override void ProcessRecord()
 {
     if (base.ParameterSetName == "DefinitionName")
     {
         string definitionPath = null;
         if (!string.IsNullOrEmpty(this._definitionPath))
         {
             ProviderInfo        provider = null;
             Collection <string> resolvedProviderPathFromPSPath = base.Context.SessionState.Path.GetResolvedProviderPathFromPSPath(this._definitionPath, out provider);
             if (!provider.NameEquals(base.Context.ProviderNames.FileSystem))
             {
                 string message = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotFSProvider, new object[] { this._definitionName, this._definitionPath, provider.FullName });
                 base.WriteError(new ErrorRecord(new RuntimeException(message), "StartJobFromDefinitionNamePathInvalidNotFileSystemProvider", ErrorCategory.InvalidArgument, null));
                 return;
             }
             if (resolvedProviderPathFromPSPath.Count != 1)
             {
                 string str3 = StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionPathInvalidNotSingle, this._definitionName, this._definitionPath);
                 base.WriteError(new ErrorRecord(new RuntimeException(str3), "StartJobFromDefinitionNamePathInvalidNotSingle", ErrorCategory.InvalidArgument, null));
                 return;
             }
             definitionPath = resolvedProviderPathFromPSPath[0];
         }
         List <Job2> list = base.JobManager.GetJobToStart(this._definitionName, definitionPath, this._definitionType, this, false);
         if (list.Count == 0)
         {
             string str4 = (this._definitionType != null) ? StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound2, this._definitionType, this._definitionName) : StringUtil.Format(RemotingErrorIdStrings.StartJobDefinitionNotFound1, this._definitionName);
             base.WriteError(new ErrorRecord(new RuntimeException(str4), "StartJobFromDefinitionNameNotFound", ErrorCategory.ObjectNotFound, null));
         }
         else if (list.Count > 1)
         {
             string str5 = StringUtil.Format(RemotingErrorIdStrings.StartJobManyDefNameMatches, this._definitionName);
             base.WriteError(new ErrorRecord(new RuntimeException(str5), "StartJobFromDefinitionNameMoreThanOneMatch", ErrorCategory.InvalidResult, null));
         }
         else
         {
             Job2 sendToPipeline = list[0];
             sendToPipeline.StartJob();
             base.WriteObject(sendToPipeline);
         }
     }
     else
     {
         if (this.firstProcessRecord)
         {
             this.firstProcessRecord = false;
             PSRemotingJob item = new PSRemotingJob(base.ResolvedComputerNames, base.Operations, this.ScriptBlock.ToString(), this.ThrottleLimit, this.name)
             {
                 PSJobTypeName = StartJobType
             };
             base.JobRepository.Add(item);
             base.WriteObject(item);
         }
         if (this.InputObject != AutomationNull.Value)
         {
             foreach (IThrottleOperation operation in base.Operations)
             {
                 ExecutionCmdletHelper helper = (ExecutionCmdletHelper)operation;
                 helper.Pipeline.Input.Write(this.InputObject);
             }
         }
     }
 }
예제 #5
0
        private void ConnectSessionToHost(PSSession session, PSRemotingJob job = null)
        {
            RemoteRunspace runspace = session.Runspace as RemoteRunspace;

            if (job != null)
            {
                lock (this._syncObject)
                {
                    this._job = job;
                }
                using (job)
                {
                    Job job2 = job.ChildJobs[0];
                    job.ConnectJobs();
                    do
                    {
                        job2.Results.WaitHandle.WaitOne();
                        foreach (PSStreamObject obj2 in job2.ReadAll())
                        {
                            if (obj2 != null)
                            {
                                obj2.WriteStreamObject(this, false);
                            }
                        }
                    }while (!job.IsFinishedState(job.JobStateInfo.State));
                }
                lock (this._syncObject)
                {
                    this._job = null;
                }
            }
            else if (runspace.RemoteCommand != null)
            {
                lock (this._syncObject)
                {
                    this._remotePipeline = (RemotePipeline)session.Runspace.CreateDisconnectedPipeline();
                }
                using (this._remotePipeline)
                {
                    this._remotePipeline.ConnectAsync();
                    runspace.RunspacePool.RemoteRunspacePoolInternal.ConnectCommands = null;
                    while (!this._remotePipeline.Output.EndOfPipeline)
                    {
                        if (this._stopProcessing)
                        {
                            break;
                        }
                        this._remotePipeline.Output.WaitHandle.WaitOne();
                        while (this._remotePipeline.Output.Count > 0)
                        {
                            if (this._stopProcessing)
                            {
                                continue;
                            }
                            PSObject psObject = this._remotePipeline.Output.Read();
                            this.WriteRemoteObject(psObject, session);
                        }
                    }
                    if (this._remotePipeline.Error.Count > 0)
                    {
                        while (!this._remotePipeline.Error.EndOfPipeline)
                        {
                            object obj4 = this._remotePipeline.Error.Read();
                            if (obj4 is Collection <ErrorRecord> )
                            {
                                Collection <ErrorRecord> collection = (Collection <ErrorRecord>)obj4;
                                foreach (ErrorRecord record in collection)
                                {
                                    base.WriteError(record);
                                }
                            }
                            else if (obj4 is ErrorRecord)
                            {
                                base.WriteError((ErrorRecord)obj4);
                            }
                        }
                    }
                    this._remotePipeline.PipelineFinishedEvent.WaitOne();
                    if (this._remotePipeline.PipelineStateInfo.State == PipelineState.Failed)
                    {
                        string    pipelineFailedWithoutReason;
                        Exception reason = this._remotePipeline.PipelineStateInfo.Reason;
                        if ((reason != null) && !string.IsNullOrEmpty(reason.Message))
                        {
                            pipelineFailedWithoutReason = StringUtil.Format(RemotingErrorIdStrings.PipelineFailedWithReason, reason.Message);
                        }
                        else
                        {
                            pipelineFailedWithoutReason = RemotingErrorIdStrings.PipelineFailedWithoutReason;
                        }
                        ErrorRecord errorRecord = new ErrorRecord(new RuntimeException(pipelineFailedWithoutReason, reason), "ReceivePSSessionPipelineFailed", ErrorCategory.OperationStopped, this._remotePipeline);
                        base.WriteError(errorRecord);
                    }
                }
                lock (this._syncObject)
                {
                    this._remotePipeline = null;
                }
            }
        }
예제 #6
0
        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;
                }
            }
        }
예제 #7
0
        private void GetAndConnectSessionCommand()
        {
            PSSession sessionById = null;

            if (base.ParameterSetName == "Session")
            {
                sessionById = this.Session;
            }
            else if (base.ParameterSetName == "Id")
            {
                sessionById = this.GetSessionById(this.Id);
                if (sessionById == null)
                {
                    this.WriteInvalidArgumentError(PSRemotingErrorId.RemoteRunspaceNotAvailableForSpecifiedSessionId, RemotingErrorIdStrings.RemoteRunspaceNotAvailableForSpecifiedSessionId, this.Id);
                    return;
                }
            }
            else if (base.ParameterSetName == "SessionName")
            {
                sessionById = this.GetSessionByName(this.Name);
                if (sessionById == null)
                {
                    this.WriteInvalidArgumentError(PSRemotingErrorId.RemoteRunspaceNotAvailableForSpecifiedName, RemotingErrorIdStrings.RemoteRunspaceNotAvailableForSpecifiedName, this.Name);
                    return;
                }
            }
            else if (base.ParameterSetName == "InstanceId")
            {
                sessionById = this.GetSessionByInstanceId(this.InstanceId);
                if (sessionById == null)
                {
                    this.WriteInvalidArgumentError(PSRemotingErrorId.RemoteRunspaceNotAvailableForSpecifiedRunspaceId, RemotingErrorIdStrings.RemoteRunspaceNotAvailableForSpecifiedRunspaceId, this.InstanceId);
                    return;
                }
            }
            if (base.ShouldProcess(sessionById.Name, "Receive"))
            {
                Exception exception;
                if (this.ConnectSession(sessionById, out exception) == null)
                {
                    PSSession session = sessionById;
                    sessionById = this.TryGetSessionFromServer(session);
                    if (sessionById == null)
                    {
                        string message = StringUtil.Format(RemotingErrorIdStrings.RunspaceCannotBeConnected, session.Name);
                        base.WriteError(new ErrorRecord(new ArgumentException(message, exception), "ReceivePSSessionCannotConnectSession", ErrorCategory.InvalidOperation, session));
                        return;
                    }
                }
                PSRemotingJob job = this.FindJobForSession(sessionById);
                if (job != null)
                {
                    if (this.OutTarget == Microsoft.PowerShell.Commands.OutTarget.Host)
                    {
                        this.ConnectSessionToHost(sessionById, job);
                    }
                    else
                    {
                        this.ConnectSessionToJob(sessionById, job);
                    }
                }
                else if (this.OutTarget == Microsoft.PowerShell.Commands.OutTarget.Job)
                {
                    this.ConnectSessionToJob(sessionById, null);
                }
                else
                {
                    this.ConnectSessionToHost(sessionById, null);
                }
                if (sessionById.Runspace.RunspaceStateInfo.State != RunspaceState.Disconnected)
                {
                    base.RunspaceRepository.AddOrReplace(sessionById);
                }
            }
        }
예제 #8
0
        protected override void ProcessRecord()
        {
            bool checkForRecurse = false;
            List <System.Management.Automation.Job> jobsToWrite = new List <System.Management.Automation.Job>();
            string parameterSetName = base.ParameterSetName;

            if (parameterSetName != null)
            {
                if (!(parameterSetName == "Session"))
                {
                    if (parameterSetName == "ComputerName")
                    {
                        foreach (System.Management.Automation.Job job3 in this.jobs)
                        {
                            PSRemotingJob job4 = job3 as PSRemotingJob;
                            if (job4 == null)
                            {
                                string message = base.GetMessage(RemotingErrorIdStrings.ComputerNameParamNotSupported);
                                base.WriteError(new ErrorRecord(new ArgumentException(message), "ComputerNameParameterNotSupported", ErrorCategory.InvalidArgument, job3));
                            }
                            else
                            {
                                string[] resolvedComputerNames = null;
                                base.ResolveComputerNames(this.computerNames, out resolvedComputerNames);
                                foreach (string str3 in resolvedComputerNames)
                                {
                                    List <System.Management.Automation.Job> jobsForComputer = job4.GetJobsForComputer(str3);
                                    jobsToWrite.AddRange(jobsForComputer);
                                }
                            }
                        }
                    }
                    else if (parameterSetName == "Location")
                    {
                        if (this.locations == null)
                        {
                            jobsToWrite.AddRange(this.jobs);
                            checkForRecurse = true;
                        }
                        else
                        {
                            foreach (System.Management.Automation.Job job5 in this.jobs)
                            {
                                foreach (string str4 in this.locations)
                                {
                                    List <System.Management.Automation.Job> jobsForLocation = job5.GetJobsForLocation(str4);
                                    jobsToWrite.AddRange(jobsForLocation);
                                }
                            }
                        }
                    }
                    else if (parameterSetName == "InstanceIdParameterSet")
                    {
                        List <System.Management.Automation.Job> collection = base.FindJobsMatchingByInstanceId(true, false, true, false);
                        jobsToWrite.AddRange(collection);
                        checkForRecurse = true;
                    }
                    else if (parameterSetName == "SessionIdParameterSet")
                    {
                        List <System.Management.Automation.Job> list6 = base.FindJobsMatchingBySessionId(true, false, true, false);
                        jobsToWrite.AddRange(list6);
                        checkForRecurse = true;
                    }
                    else if (parameterSetName == "NameParameterSet")
                    {
                        List <System.Management.Automation.Job> list7 = base.FindJobsMatchingByName(true, false, true, false);
                        jobsToWrite.AddRange(list7);
                        checkForRecurse = true;
                    }
                }
                else
                {
                    foreach (System.Management.Automation.Job job in this.jobs)
                    {
                        PSRemotingJob job2 = job as PSRemotingJob;
                        if (job2 == null)
                        {
                            string str = base.GetMessage(RemotingErrorIdStrings.RunspaceParamNotSupported);
                            base.WriteError(new ErrorRecord(new ArgumentException(str), "RunspaceParameterNotSupported", ErrorCategory.InvalidArgument, job));
                        }
                        else
                        {
                            foreach (PSSession session in this.remoteRunspaceInfos)
                            {
                                List <System.Management.Automation.Job> jobsForRunspace = job2.GetJobsForRunspace(session);
                                jobsToWrite.AddRange(jobsForRunspace);
                            }
                        }
                    }
                }
            }
            if (this._wait)
            {
                this._writeExistingData.Reset();
                this.WriteJobsIfRequired(jobsToWrite);
                foreach (System.Management.Automation.Job job6 in jobsToWrite)
                {
                    this._jobsSpecifiedInParameters.Add(job6.InstanceId);
                }
                lock (this._syncObject)
                {
                    if (this._isDisposed || this._isStopping)
                    {
                        return;
                    }
                    if (!this._holdingResultsRef)
                    {
                        this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, (Job)null, "Adding Ref to results collection", null);
                        this._results.AddRef();
                        this._holdingResultsRef = true;
                    }
                }
                this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, null, "BEGIN Register for jobs", new string[0]);
                this.WriteResultsForJobsInCollection(jobsToWrite, checkForRecurse, true);
                this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, null, "END Register for jobs", new string[0]);
                lock (this._syncObject)
                {
                    if ((this._jobsBeingAggregated.Count == 0) && this._holdingResultsRef)
                    {
                        this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, (Job)null, "Removing Ref to results collection", null);
                        this._results.DecrementRef();
                        this._holdingResultsRef = false;
                    }
                }
                this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, null, "BEGIN Write existing job data", new string[0]);
                this.WriteResultsForJobsInCollection(jobsToWrite, checkForRecurse, false);
                this._tracer.WriteMessage("ReceiveJobCommand", "ProcessRecord", Guid.Empty, null, "END Write existing job data", new string[0]);
                this._writeExistingData.Set();
            }
            else
            {
                this.WriteResultsForJobsInCollection(jobsToWrite, checkForRecurse, false);
            }
        }
예제 #9
0
 private void WriteJobResults(bool nonblocking)
 {
     if (this.job != null)
     {
         PipelineStoppedException exception = null;
         this.job.PropagateThrows = this.propagateErrors;
         do
         {
             if (!nonblocking)
             {
                 if (this.disconnectComplete != null)
                 {
                     WaitHandle.WaitAny(new WaitHandle[] { this.disconnectComplete, this.job.Results.WaitHandle });
                 }
                 else
                 {
                     this.job.Results.WaitHandle.WaitOne();
                 }
             }
             try
             {
                 this.WriteStreamObjectsFromCollection(this.job.ReadAll());
             }
             catch (PipelineStoppedException exception2)
             {
                 exception = exception2;
             }
         }while (!nonblocking && !this.job.IsTerminalState());
         try
         {
             this.WriteStreamObjectsFromCollection(this.job.ReadAll());
         }
         catch (PipelineStoppedException exception3)
         {
             exception = exception3;
         }
         if (exception != null)
         {
             this.HandlePipelinesStopped();
             throw exception;
         }
         if (this.job.JobStateInfo.State == JobState.Disconnected)
         {
             if ((base.ParameterSetName == "Session") || (base.ParameterSetName == "FilePathRunspace"))
             {
                 PSRemotingJob item = this.job.CreateDisconnectedRemotingJob();
                 if (item != null)
                 {
                     item.PSJobTypeName = RemoteJobType;
                     base.JobRepository.Add(item);
                     this.asjob = true;
                     foreach (Job job2 in item.ChildJobs)
                     {
                         PSRemotingChildJob job3 = job2 as PSRemotingChildJob;
                         if (job3 != null)
                         {
                             PSSession pSSession = this.GetPSSession(job3.Runspace.InstanceId);
                             if (pSSession != null)
                             {
                                 this.WriteNetworkFailedError(pSSession);
                                 base.WriteWarning(StringUtil.Format(RemotingErrorIdStrings.RCDisconnectSession, new object[] { pSSession.Name, pSSession.InstanceId, pSSession.ComputerName }));
                             }
                         }
                     }
                     base.WriteWarning(StringUtil.Format(RemotingErrorIdStrings.RCDisconnectedJob, item.Name));
                 }
             }
             else if ((base.ParameterSetName == "ComputerName") || (base.ParameterSetName == "FilePathComputerName"))
             {
                 foreach (PSSession session2 in this.GetDisconnectedSessions(this.job))
                 {
                     base.RunspaceRepository.AddOrReplace(session2);
                     this.WriteNetworkFailedError(session2);
                     base.WriteWarning(StringUtil.Format(RemotingErrorIdStrings.RCDisconnectSession, new object[] { session2.Name, session2.InstanceId, session2.ComputerName }));
                     base.WriteWarning(StringUtil.Format(RemotingErrorIdStrings.RCDisconnectSessionCreated, session2.Name, session2.InstanceId));
                 }
             }
             this.HandleThrottleComplete(null, null);
         }
     }
 }
예제 #10
0
 protected override void ProcessRecord()
 {
     if (!this.pipelineinvoked && !this.needToCollect)
     {
         this.pipelineinvoked = true;
         if (this.InputObject == AutomationNull.Value)
         {
             base.CloseAllInputStreams();
             this.inputStreamClosed = true;
         }
         if (!base.ParameterSetName.Equals("InProcess"))
         {
             if (!this.asjob)
             {
                 this.CreateAndRunSyncJob();
             }
             else
             {
                 string parameterSetName = base.ParameterSetName;
                 if (parameterSetName != null)
                 {
                     if (!(parameterSetName == "ComputerName") && !(parameterSetName == "FilePathComputerName"))
                     {
                         if ((parameterSetName == "Session") || (parameterSetName == "FilePathRunspace"))
                         {
                             PSRemotingJob item = new PSRemotingJob(this.Session, base.Operations, this.ScriptBlock.ToString(), this.ThrottleLimit, this.name)
                             {
                                 PSJobTypeName    = RemoteJobType,
                                 HideComputerName = this.hideComputerName
                             };
                             base.JobRepository.Add(item);
                             base.WriteObject(item);
                         }
                         else if (((parameterSetName == "Uri") || (parameterSetName == "FilePathUri")) && (base.Operations.Count > 0))
                         {
                             string[] computerNames = new string[this.ConnectionUri.Length];
                             for (int i = 0; i < computerNames.Length; i++)
                             {
                                 computerNames[i] = this.ConnectionUri[i].ToString();
                             }
                             PSRemotingJob job3 = new PSRemotingJob(computerNames, base.Operations, this.ScriptBlock.ToString(), this.ThrottleLimit, this.name)
                             {
                                 PSJobTypeName    = RemoteJobType,
                                 HideComputerName = this.hideComputerName
                             };
                             base.JobRepository.Add(job3);
                             base.WriteObject(job3);
                         }
                     }
                     else if ((base.ResolvedComputerNames.Length != 0) && (base.Operations.Count > 0))
                     {
                         PSRemotingJob job = new PSRemotingJob(base.ResolvedComputerNames, base.Operations, this.ScriptBlock.ToString(), this.ThrottleLimit, this.name)
                         {
                             PSJobTypeName    = RemoteJobType,
                             HideComputerName = this.hideComputerName
                         };
                         base.JobRepository.Add(job);
                         base.WriteObject(job);
                     }
                 }
             }
         }
     }
     if ((this.InputObject != AutomationNull.Value) && !this.inputStreamClosed)
     {
         if ((base.ParameterSetName.Equals("InProcess") && (this.steppablePipeline == null)) || this.needToCollect)
         {
             this.input.Add(this.InputObject);
         }
         else if (base.ParameterSetName.Equals("InProcess") && (this.steppablePipeline != null))
         {
             this.steppablePipeline.Process(this.InputObject);
         }
         else
         {
             this.WriteInput(this.InputObject);
             if (!this.asjob)
             {
                 this.WriteJobResults(true);
             }
         }
     }
 }