Пример #1
0
 protected PSRemotingJob()
 {
     this.moreData = true;
     this.hideComputerName = true;
     this.throttleManager = new ThrottleManager();
     this._syncObject = new object();
 }
Пример #2
0
 internal static void SubmitOperations(List<object> operations, ThrottleManager throttleManager)
 {
     List<IThrottleOperation> list = new List<IThrottleOperation>();
     foreach (object obj2 in operations)
     {
         list.Add((IThrottleOperation) obj2);
     }
     throttleManager.SubmitOperations(list);
 }
Пример #3
0
        internal static void SubmitOperations(List <object> operations, ThrottleManager throttleManager)
        {
            List <IThrottleOperation> list = new List <IThrottleOperation>();

            foreach (object obj2 in operations)
            {
                list.Add((IThrottleOperation)obj2);
            }
            throttleManager.SubmitOperations(list);
        }
        internal static void SubmitOperations(List <object> operations, ThrottleManager throttleManager)
        {
            List <IThrottleOperation> newOperations = new List <IThrottleOperation>();

            foreach (object operation in operations)
            {
                newOperations.Add((IThrottleOperation)operation);
            }

            throttleManager.SubmitOperations(newOperations);
        }
Пример #5
0
 internal PSRemotingJob(string[] computerNames, List<IThrottleOperation> computerNameHelpers, string remoteCommand, int throttleLimit, string name) : base(remoteCommand, name)
 {
     this.moreData = true;
     this.hideComputerName = true;
     this.throttleManager = new ThrottleManager();
     this._syncObject = new object();
     foreach (ExecutionCmdletHelperComputerName name2 in computerNameHelpers)
     {
         PSRemotingChildJob item = new PSRemotingChildJob(remoteCommand, name2, this.throttleManager);
         item.StateChanged += new EventHandler<JobStateEventArgs>(this.HandleChildJobStateChanged);
         item.JobUnblocked += new EventHandler(this.HandleJobUnblocked);
         base.ChildJobs.Add(item);
     }
     this.CommonInit(throttleLimit, computerNameHelpers);
 }
Пример #6
0
		internal PSWmiJob(Cmdlet cmds, string[] computerName, int throttleLimt, string command) : base(command, null)
		{
			this.throttleManager = new ThrottleManager();
			this.syncObject = new object();
			base.PSJobTypeName = "WmiJob";
			this.throttleManager.ThrottleLimit = throttleLimt;
			for (int i = 0; i < (int)computerName.Length; i++)
			{
				PSWmiChildJob pSWmiChildJob = new PSWmiChildJob(cmds, computerName[i], this.throttleManager);
				pSWmiChildJob.StateChanged += new EventHandler<JobStateEventArgs>(this.HandleChildJobStateChanged);
				pSWmiChildJob.JobUnblocked += new EventHandler(this.HandleJobUnblocked);
				base.ChildJobs.Add(pSWmiChildJob);
			}
			this.CommonInit(throttleLimt);
		}
Пример #7
0
 internal PSRemotingJob(PSSession[] remoteRunspaceInfos, List<IThrottleOperation> runspaceHelpers, string remoteCommand, int throttleLimit, string name) : base(remoteCommand, name)
 {
     this.moreData = true;
     this.hideComputerName = true;
     this.throttleManager = new ThrottleManager();
     this._syncObject = new object();
     for (int i = 0; i < remoteRunspaceInfos.Length; i++)
     {
         ExecutionCmdletHelperRunspace helper = (ExecutionCmdletHelperRunspace) runspaceHelpers[i];
         PSRemotingChildJob item = new PSRemotingChildJob(remoteCommand, helper, this.throttleManager);
         item.StateChanged += new EventHandler<JobStateEventArgs>(this.HandleChildJobStateChanged);
         item.JobUnblocked += new EventHandler(this.HandleJobUnblocked);
         base.ChildJobs.Add(item);
     }
     this.CommonInit(throttleLimit, runspaceHelpers);
 }
Пример #8
0
 internal PSRemotingChildJob(string remoteCommand, ExecutionCmdletHelper helper, ThrottleManager throttleManager) : base(remoteCommand)
 {
     this.hideComputerName = true;
     this.SyncObject = new object();
     base.UsesResultsCollection = true;
     this.helper = helper;
     this.remoteRunspace = helper.Pipeline.Runspace;
     this.remotePipeline = helper.Pipeline as RemotePipeline;
     this.throttleManager = throttleManager;
     RemoteRunspace remoteRunspace = this.remoteRunspace as RemoteRunspace;
     if ((remoteRunspace != null) && (remoteRunspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen))
     {
         remoteRunspace.URIRedirectionReported += new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported);
     }
     this.AggregateResultsFromHelper(helper);
     this.RegisterThrottleComplete(throttleManager);
 }
Пример #9
0
 internal PSRemotingJob(List<IThrottleOperation> helpers, int throttleLimit, string name, bool aggregateResults) : base(string.Empty, name)
 {
     this.moreData = true;
     this.hideComputerName = true;
     this.throttleManager = new ThrottleManager();
     this._syncObject = new object();
     foreach (ExecutionCmdletHelper helper in helpers)
     {
         PSRemotingChildJob item = new PSRemotingChildJob(helper, this.throttleManager, aggregateResults);
         item.StateChanged += new EventHandler<JobStateEventArgs>(this.HandleChildJobStateChanged);
         item.JobUnblocked += new EventHandler(this.HandleJobUnblocked);
         base.ChildJobs.Add(item);
     }
     base.CloseAllStreams();
     base.SetJobState(JobState.Disconnected);
     this.throttleManager.ThrottleLimit = throttleLimit;
     this.throttleManager.SubmitOperations(helpers);
     this.throttleManager.EndSubmitOperations();
 }
Пример #10
0
 internal PSInvokeExpressionSyncJob(List<IThrottleOperation> operations, ThrottleManager throttleManager)
 {
     base.UsesResultsCollection = true;
     base.Results.AddRef();
     this.throttleManager = throttleManager;
     base.RegisterThrottleComplete(this.throttleManager);
     foreach (IThrottleOperation operation in operations)
     {
         ExecutionCmdletHelper item = operation as ExecutionCmdletHelper;
         RemoteRunspace runspace = item.Pipeline.Runspace as RemoteRunspace;
         if ((runspace != null) && (runspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen))
         {
             runspace.URIRedirectionReported += new EventHandler<RemoteDataEventArgs<Uri>>(this.HandleURIDirectionReported);
             runspace.StateChanged += new EventHandler<RunspaceStateEventArgs>(this.HandleRunspaceStateChanged);
         }
         this.helpers.Add(item);
         base.AggregateResultsFromHelper(item);
         RemotePipeline pipeline = item.Pipeline as RemotePipeline;
         this.powershells.Add(pipeline.PowerShell.InstanceId, pipeline.PowerShell);
     }
 }
Пример #11
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);
		}
Пример #12
0
 internal PSRemotingChildJob(ExecutionCmdletHelper helper, ThrottleManager throttleManager, bool aggregateResults = false)
 {
     this.hideComputerName = true;
     this.SyncObject = new object();
     base.UsesResultsCollection = true;
     this.helper = helper;
     this.remotePipeline = helper.Pipeline as RemotePipeline;
     this.remoteRunspace = helper.Pipeline.Runspace;
     this.throttleManager = throttleManager;
     if (aggregateResults)
     {
         this.AggregateResultsFromHelper(helper);
     }
     else
     {
         this.remotePipeline.StateChanged += new EventHandler<PipelineStateEventArgs>(this.HandlePipelineStateChanged);
         this.remotePipeline.Output.DataReady += new EventHandler(this.HandleOutputReady);
         this.remotePipeline.Error.DataReady += new EventHandler(this.HandleErrorReady);
     }
     IThrottleOperation operation = helper;
     operation.OperationComplete += new EventHandler<OperationStateEventArgs>(this.HandleOperationComplete);
     base.SetJobState(JobState.Disconnected, null);
 }
Пример #13
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();
         }
     }
 }
Пример #14
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);
     }
 }
Пример #15
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>();
 }
Пример #16
0
 private void SubmitAndWaitForConnect(List<IThrottleOperation> connectJobOperations)
 {
     using (ThrottleManager manager = new ThrottleManager())
     {
         EventHandler<EventArgs> handler2 = null;
         using (ManualResetEvent connectResult = new ManualResetEvent(false))
         {
             if (handler2 == null)
             {
                 handler2 = (sender, eventArgs) => connectResult.Set();
             }
             EventHandler<EventArgs> handler = handler2;
             manager.ThrottleComplete += handler;
             try
             {
                 manager.ThrottleLimit = 0;
                 manager.SubmitOperations(connectJobOperations);
                 manager.EndSubmitOperations();
                 connectResult.WaitOne();
             }
             finally
             {
                 manager.ThrottleComplete -= handler;
             }
         }
     }
 }
Пример #17
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.throttleManager.Dispose();
         this.operationsComplete.WaitOne();
         this.operationsComplete.Close();
         this.throttleManager.ThrottleComplete -= new EventHandler<EventArgs>(this.HandleThrottleComplete);
         this.throttleManager = null;
         foreach (RemoteRunspace runspace in this.toDispose)
         {
             runspace.Dispose();
         }
         foreach (List<IThrottleOperation> list in this.allOperations)
         {
             foreach (OpenRunspaceOperation operation in list)
             {
                 operation.Dispose();
             }
         }
         this.stream.Dispose();
     }
 }
Пример #18
0
 protected void UnregisterThrottleComplete(ThrottleManager throttleManager)
 {
     throttleManager.ThrottleComplete -= new EventHandler<EventArgs>(this.HandleThrottleComplete);
 }
Пример #19
0
 protected virtual void DoCleanupOnFinished()
 {
     bool flag = false;
     if (!this.cleanupDone)
     {
         lock (this.SyncObject)
         {
             if (!this.cleanupDone)
             {
                 this.cleanupDone = true;
                 flag = true;
             }
         }
     }
     if (flag)
     {
         this.StopAggregateResultsFromHelper(this.helper);
         this.helper.OperationComplete -= new EventHandler<OperationStateEventArgs>(this.HandleOperationComplete);
         this.UnregisterThrottleComplete(this.throttleManager);
         this.throttleManager = null;
     }
 }
Пример #20
0
        /// <summary>
        /// Closes or disconnects all the remote runspaces passed in by the getRunspace
        /// function.  If a remote runspace supports disconnect then it will be disconnected 
        /// rather than closed.
        /// </summary>
        private void CloseOrDisconnectAllRemoteRunspaces(Func<List<RemoteRunspace>> getRunspaces)
        {
            List<RemoteRunspace> runspaces = getRunspaces();
            if (runspaces.Count == 0) { return; }

            // whether the close of all remoterunspaces completed
            using (ManualResetEvent remoteRunspaceCloseCompleted = new ManualResetEvent(false))
            {
                ThrottleManager throttleManager = new ThrottleManager();
                throttleManager.ThrottleComplete += delegate (object sender, EventArgs e)
                {
                    remoteRunspaceCloseCompleted.Set();
                };

                foreach (RemoteRunspace remoteRunspace in runspaces)
                {
                    IThrottleOperation operation = new CloseOrDisconnectRunspaceOperationHelper(remoteRunspace);
                    throttleManager.AddOperation(operation);
                }
                throttleManager.EndSubmitOperations();

                remoteRunspaceCloseCompleted.WaitOne();
            }
        }
Пример #21
0
        /// <summary>
        /// internal dispose method which does the actual disposing
        /// </summary>
        /// <param name="disposing">whether called from dispose or finalize</param>
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                // this call fixes bug Windows 7 #278836
                // by making sure the server is stopped even if it is waiting
                // for further input from this Invoke-Command cmdlet

                this.StopProcessing();
                // wait for all operations to complete
                _operationsComplete.WaitOne();
                _operationsComplete.Dispose();

                if (!_asjob)
                {
                    if (_job != null)
                    {
                        // job will be null in the "InProcess" case
                        _job.Dispose();
                    }

                    _throttleManager.ThrottleComplete -= new EventHandler<EventArgs>(HandleThrottleComplete);
                    _throttleManager.Dispose();
                    _throttleManager = null;
                }

                // clear the invoke command references we have stored
                if (_clearInvokeCommandOnRunspace)
                {
                    ClearInvokeCommandOnRunspaces();
                }

                _input.Dispose();

                lock (_jobSyncObject)
                {
                    if (_disconnectComplete != null)
                    {
                        _disconnectComplete.Dispose();
                        _disconnectComplete = null;
                    }
                }
            }
        } // Dispose
Пример #22
0
        /// <summary>
        /// Disconnects all disconnectable jobs listed in the JobRepository.
        /// </summary>
        private void StopOrDisconnectAllJobs()
        {
            if (JobRepository.Jobs.Count == 0) { return; }
            List<RemoteRunspace> disconnectRunspaces = new List<RemoteRunspace>();

            using (ManualResetEvent jobsStopCompleted = new ManualResetEvent(false))
            {
                ThrottleManager throttleManager = new ThrottleManager();
                throttleManager.ThrottleComplete += delegate (object sender, EventArgs e)
                {
                    jobsStopCompleted.Set();
                };

                foreach (Job job in this.JobRepository.Jobs)
                {
                    // Only stop or disconnect PowerShell jobs.
                    if (job is PSRemotingJob == false)
                    {
                        continue;
                    }

                    if (!job.CanDisconnect)
                    {
                        // If the job cannot be disconnected then add it to
                        // the stop list.
                        throttleManager.AddOperation(new StopJobOperationHelper(job));
                    }
                    else if (job.JobStateInfo.State == JobState.Running)
                    {
                        // Otherwise add disconnectable runspaces to list so that
                        // they can be disconnected.
                        IEnumerable<RemoteRunspace> jobRunspaces = job.GetRunspaces();
                        if (jobRunspaces != null)
                        {
                            disconnectRunspaces.AddRange(jobRunspaces);
                        }
                    }
                } // foreach job

                // Stop jobs.
                throttleManager.EndSubmitOperations();
                jobsStopCompleted.WaitOne();
            } // using jobsStopCompleted

            // Disconnect all disconnectable job runspaces found.
            CloseOrDisconnectAllRemoteRunspaces(() =>
                {
                    return disconnectRunspaces;
                });
        }
Пример #23
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.StopProcessing();
         this.operationsComplete.WaitOne();
         this.operationsComplete.Close();
         if (!this.asjob)
         {
             if (this.job != null)
             {
                 this.job.Dispose();
             }
             this.throttleManager.ThrottleComplete -= new EventHandler<EventArgs>(this.HandleThrottleComplete);
             this.throttleManager.Dispose();
             this.throttleManager = null;
         }
         if (this.clearInvokeCommandOnRunspace)
         {
             this.ClearInvokeCommandOnRunspaces();
         }
         this.input.Dispose();
         lock (this.jobSyncObject)
         {
             if (this.disconnectComplete != null)
             {
                 this.disconnectComplete.Close();
                 this.disconnectComplete = null;
             }
         }
     }
 }
Пример #24
0
 /// <summary>
 /// Internal constructor for initializing WMI jobs, where WMI command is executed a variable
 /// number of times.
 /// </summary>
 internal PSWmiChildJob(Cmdlet cmds, string computerName, ThrottleManager throttleManager, int count)
     : base(null, null)
 {
     UsesResultsCollection = true;
     Location = computerName;
     _throttleManager = throttleManager;
     _wmiSinkArray = new ArrayList();
     ManagementOperationObserver wmiSink = new ManagementOperationObserver();
     _wmiSinkArray.Add(wmiSink);
     _sinkCompleted += count;
     wmiSink.ObjectReady += new ObjectReadyEventHandler(this.NewObject);
     wmiSink.Completed += new CompletedEventHandler(this.JobDone);
     _helper = new WmiAsyncCmdletHelper(this, cmds, computerName, wmiSink, count);
     _helper.WmiOperationState += new EventHandler<WmiJobStateEventArgs>(HandleWMIState);
     _helper.ShutdownComplete += new EventHandler<EventArgs>(JobDoneForWin32Shutdown);
     SetJobState(JobState.NotStarted);
     IThrottleOperation operation = _helper;
     operation.OperationComplete += new EventHandler<OperationStateEventArgs>(HandleOperationComplete);
     throttleManager.ThrottleComplete += new EventHandler<EventArgs>(HandleThrottleComplete);
     throttleManager.AddOperation(operation);
 }
Пример #25
0
 internal static void AddOperation(object operation, ThrottleManager throttleManager)
 {
     throttleManager.AddOperation((IThrottleOperation) operation);
 }
 internal static void AddOperation(object operation, ThrottleManager throttleManager)
 {
     throttleManager.AddOperation((IThrottleOperation)operation);
 }
Пример #27
0
        internal static void SubmitOperations(List<object> operations, ThrottleManager throttleManager)
        {
            List<IThrottleOperation> newOperations = new List<IThrottleOperation>();
            foreach (object operation in operations)
            {
                newOperations.Add((IThrottleOperation)operation);
            }

            throttleManager.SubmitOperations(newOperations);
        }