Exemplo n.º 1
0
        private void CloseOrDisconnectAllRemoteRunspaces(Func <List <RemoteRunspace> > getRunspaces)
        {
            List <RemoteRunspace> list = getRunspaces();

            if (list.Count != 0)
            {
                EventHandler <EventArgs> handler = null;
                using (ManualResetEvent remoteRunspaceCloseCompleted = new ManualResetEvent(false))
                {
                    ThrottleManager manager = new ThrottleManager();
                    if (handler == null)
                    {
                        handler = (sender, e) => remoteRunspaceCloseCompleted.Set();
                    }
                    manager.ThrottleComplete += handler;
                    foreach (RemoteRunspace runspace in list)
                    {
                        IThrottleOperation operation = new CloseOrDisconnectRunspaceOperationHelper(runspace);
                        manager.AddOperation(operation);
                    }
                    manager.EndSubmitOperations();
                    remoteRunspaceCloseCompleted.WaitOne();
                }
            }
        }
Exemplo n.º 2
0
        internal PSWmiChildJob(Cmdlet cmds, string computerName, ThrottleManager throttleManager, int count) : base(null, null)
        {
            this.syncObject            = new object();
            this.statusMessage         = "test";
            base.UsesResultsCollection = true;
            this.computerName          = computerName;
            this.throttleManager       = throttleManager;
            this.wmiSinkArray          = new ArrayList();
            ManagementOperationObserver managementOperationObserver = new ManagementOperationObserver();

            this.wmiSinkArray.Add(managementOperationObserver);
            PSWmiChildJob pSWmiChildJob = this;

            pSWmiChildJob.sinkCompleted              = pSWmiChildJob.sinkCompleted + count;
            managementOperationObserver.ObjectReady += new ObjectReadyEventHandler(this.NewObject);
            managementOperationObserver.Completed   += new CompletedEventHandler(this.JobDone);
            this.helper = new WmiAsyncCmdletHelper(this, cmds, computerName, managementOperationObserver, count);
            this.helper.WmiOperationState += new EventHandler <WmiJobStateEventArgs>(this.HandleWMIState);
            this.helper.ShutdownComplete  += new EventHandler <EventArgs>(this.JobDoneForWin32Shutdown);
            base.SetJobState(JobState.NotStarted);
            IThrottleOperation throttleOperation = this.helper;

            throttleOperation.OperationComplete += new EventHandler <OperationStateEventArgs>(this.HandleOperationComplete);
            throttleManager.ThrottleComplete    += new EventHandler <EventArgs>(this.HandleThrottleComplete);
            throttleManager.AddOperation(throttleOperation);
        }
Exemplo n.º 3
0
        private void StopOrDisconnectAllJobs()
        {
            List <RemoteRunspace> disconnectRunspaces;

            if (this.JobRepository.Jobs.Count != 0)
            {
                disconnectRunspaces = new List <RemoteRunspace>();
                EventHandler <EventArgs> handler = null;
                using (ManualResetEvent jobsStopCompleted = new ManualResetEvent(false))
                {
                    ThrottleManager manager = new ThrottleManager();
                    if (handler == null)
                    {
                        handler = (sender, e) => jobsStopCompleted.Set();
                    }
                    manager.ThrottleComplete += handler;
                    foreach (Job job in this.JobRepository.Jobs)
                    {
                        if (job is PSRemotingJob)
                        {
                            if (!job.CanDisconnect)
                            {
                                manager.AddOperation(new StopJobOperationHelper(job));
                            }
                            else if (job.JobStateInfo.State == JobState.Running)
                            {
                                IEnumerable <RemoteRunspace> runspaces = job.GetRunspaces();
                                if (runspaces != null)
                                {
                                    disconnectRunspaces.AddRange(runspaces);
                                }
                            }
                        }
                    }
                    manager.EndSubmitOperations();
                    jobsStopCompleted.WaitOne();
                }
                this.CloseOrDisconnectAllRemoteRunspaces(() => disconnectRunspaces);
            }
        }