Exemplo n.º 1
0
 private void HandleJobStateChanged(object sender, JobStateEventArgs eventArgs)
 {
     if (this.job.IsFinishedState(this.job.JobStateInfo.State))
     {
         this.RaiseOperationCompleteEvent();
     }
 }
Exemplo n.º 2
0
 private void ChildJobStateChangedHandler(object sender, JobStateEventArgs eArgs)
 {
     if (eArgs.JobStateInfo.State != JobState.Disconnected)
     {
         this.RemoveEventCallback();
         this.SendStartComplete();
     }
 }
Exemplo n.º 3
0
 private void HandleChildJobStateChanged(object sender, JobStateEventArgs e)
 {
     this.CheckDisconnectedAndUpdateState(e.JobStateInfo.State, e.PreviousJobStateInfo.State);
     if (e.JobStateInfo.State == JobState.Blocked)
     {
         lock (this._syncObject)
         {
             this.blockedChildJobsCount++;
         }
         base.SetJobState(JobState.Blocked, null);
     }
     else if (base.IsFinishedState(e.JobStateInfo.State))
     {
         if (e.JobStateInfo.State == JobState.Failed)
         {
             this.atleastOneChildJobFailed = true;
         }
         bool flag2 = false;
         lock (this._syncObject)
         {
             this.finishedChildJobsCount++;
             if ((this.finishedChildJobsCount + this.disconnectedChildJobsCount) == base.ChildJobs.Count)
             {
                 flag2 = true;
             }
         }
         if (flag2)
         {
             if (this.disconnectedChildJobsCount > 0)
             {
                 base.SetJobState(JobState.Disconnected);
             }
             else if (this.atleastOneChildJobFailed)
             {
                 base.SetJobState(JobState.Failed);
             }
             else if (this._stopIsCalled)
             {
                 base.SetJobState(JobState.Stopped);
             }
             else
             {
                 base.SetJobState(JobState.Completed);
             }
         }
     }
 }
Exemplo n.º 4
0
        private void noWait_Job2_StateChanged(object sender, JobStateEventArgs e)
        {
            System.Management.Automation.Job job = sender as System.Management.Automation.Job;
            switch (e.JobStateInfo.State)
            {
                case JobState.Completed:
                case JobState.Failed:
                case JobState.Stopped:
                case JobState.Suspended:
                case JobState.Suspending:
                    this.ProcessExecutionErrorsAndReleaseWaitHandle(job);
                    break;

                case JobState.Blocked:
                case JobState.Disconnected:
                    break;

                default:
                    return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the StateChanged event from each of the child job objects
        /// </summary>
        /// <param name="traceClassName"></param>
        /// <param name="e"></param>
        /// <param name="blockedChildJobsCount"></param>
        /// <param name="suspendedChildJobsCount"></param>
        /// <param name="suspendingChildJobsCount"></param>
        /// <param name="finishedChildJobsCount"></param>
        /// <param name="stoppedChildJobsCount"></param>
        /// <param name="childJobsCount"></param>
        /// <param name="computedJobState"></param>
        /// <param name="failedChildJobsCount"></param>
        /// <returns>true if the job state needs to be modified, false otherwise</returns>
        internal static bool ComputeJobStateFromChildJobStates(string traceClassName, JobStateEventArgs e,
            ref int blockedChildJobsCount, ref int suspendedChildJobsCount, ref int suspendingChildJobsCount, ref int finishedChildJobsCount,
                ref int failedChildJobsCount, ref int stoppedChildJobsCount, int childJobsCount,
                    out JobState computedJobState)
        {
            computedJobState = JobState.NotStarted;

            using (PowerShellTraceSource tracer = PowerShellTraceSourceFactory.GetTraceSource())
            {
                if (e.JobStateInfo.State == JobState.Blocked)
                {
                    // increment count of blocked child jobs
                    Interlocked.Increment(ref blockedChildJobsCount);

                    // if any of the child job is blocked, we set state to blocked
                    tracer.WriteMessage(traceClassName, ": JobState is Blocked, at least one child job is blocked.");
                    computedJobState = JobState.Blocked;
                    return true;
                }

                if (e.PreviousJobStateInfo.State == JobState.Blocked)
                {
                    // check if any of the child jobs were unblocked
                    // in which case we need to check if the parent
                    // job needs to be unblocked as well
                    Interlocked.Decrement(ref blockedChildJobsCount);

                    if (blockedChildJobsCount == 0)
                    {
                        tracer.WriteMessage(traceClassName, ": JobState is unblocked, all child jobs are unblocked.");
                        computedJobState = JobState.Running;
                        return true;
                    }

                    return false;
                }

                if (e.PreviousJobStateInfo.State == JobState.Suspended)
                {
                    // decrement count of suspended child jobs
                    // needed to determine when all incomplete child jobs are suspended for parent job state.
                    Interlocked.Decrement(ref suspendedChildJobsCount);
                }

                if (e.PreviousJobStateInfo.State == JobState.Suspending)
                {
                    // decrement count of suspending child jobs
                    // needed to determine when all incomplete child jobs are suspended for parent job state.
                    Interlocked.Decrement(ref suspendingChildJobsCount);
                }

                if (e.JobStateInfo.State == JobState.Suspended)
                {
                    // increment count of suspended child jobs.
                    Interlocked.Increment(ref suspendedChildJobsCount);

                    // We know that at least one child is suspended. If all jobs are either complete or suspended, set the state.
                    if (suspendedChildJobsCount + finishedChildJobsCount == childJobsCount)
                    {
                        tracer.WriteMessage(traceClassName, ": JobState is suspended, all child jobs are suspended.");
                        computedJobState = JobState.Suspended;
                        return true;
                    }

                    // Job state should continue to be running unless:
                    // at least one child is suspended
                    // AND
                    // all child jobs are either suspended or finished.
                    return false;
                }

                if (e.JobStateInfo.State == JobState.Suspending)
                {
                    // increment count of suspending child jobs.
                    Interlocked.Increment(ref suspendingChildJobsCount);

                    // We know that at least one child is suspended. If all jobs are either complete or suspended, set the state.
                    if (suspendedChildJobsCount + finishedChildJobsCount + suspendingChildJobsCount == childJobsCount)
                    {
                        tracer.WriteMessage(traceClassName, ": JobState is suspending, all child jobs are in suspending state.");
                        computedJobState = JobState.Suspending;
                        return true;
                    }

                    // Job state should continue to be running unless:
                    // at least one child is suspended, suspending
                    // AND
                    // all child jobs are either suspended or finished.
                    return false;
                }


                // Ignore state changes which are not resulting in state change to finished.
                // State will be Running once at least one child is running.               
                if ((e.JobStateInfo.State != JobState.Completed && e.JobStateInfo.State != JobState.Failed) && e.JobStateInfo.State != JobState.Stopped)
                {
                    if (e.JobStateInfo.State == JobState.Running)
                    {
                        computedJobState = JobState.Running;
                        return true;
                    }

                    // if the job state is Suspended, we have already returned.
                    // if the job state is NotStarted, do not set the state.
                    // if the job state is blocked, we have already returned.
                    return false;
                }
                if (e.JobStateInfo.State == JobState.Failed)
                {
                    // If any of the child job failed, we set status to failed
                    // we can set it right now and 
                    Interlocked.Increment(ref failedChildJobsCount);
                }

                // If stop has not been called, but a child has been stopped, the parent should
                // reflect the stopped state.
                if (e.JobStateInfo.State == JobState.Stopped)
                {
                    Interlocked.Increment(ref stoppedChildJobsCount);
                }

                bool allChildJobsFinished = false;

                int finishedChildJobsCountNew = Interlocked.Increment(ref finishedChildJobsCount);

                //We are done
                if (finishedChildJobsCountNew == childJobsCount)
                {
                    allChildJobsFinished = true;
                }

                if (allChildJobsFinished)
                {
                    //if any child job failed, set status to failed
                    //If stop was called set, status to stopped
                    //else completed);
                    if (failedChildJobsCount > 0)
                    {
                        tracer.WriteMessage(traceClassName, ": JobState is failed, at least one child job failed.");
                        computedJobState = JobState.Failed;
                        return true;
                    }
                    if (stoppedChildJobsCount > 0)
                    {
                        tracer.WriteMessage(traceClassName, ": JobState is stopped, stop is called.");
                        computedJobState = JobState.Stopped;
                        return true;
                    }
                    tracer.WriteMessage(traceClassName, ": JobState is completed.");
                    computedJobState = JobState.Completed;
                    return true;
                }

                // If not all jobs are finished, one child job may be suspended, even though this job did not finish.
                // At this point, we know finishedChildJobsCountNew != childJobsCount
                if (suspendedChildJobsCount + finishedChildJobsCountNew == childJobsCount)
                {
                    tracer.WriteMessage(traceClassName, ": JobState is suspended, all child jobs are suspended.");
                    computedJobState = JobState.Suspended;
                    return true;
                }

                // If not all jobs are finished, one child job may be suspending, even though this job did not finish.
                // At this point, we know finishedChildJobsCountNew != childJobsCount and finishChildJobsCount + suspendedChilJobsCout != childJobsCount
                if (suspendingChildJobsCount + suspendedChildJobsCount + finishedChildJobsCountNew == childJobsCount)
                {
                    tracer.WriteMessage(traceClassName, ": JobState is suspending, all child jobs are in suspending state.");
                    computedJobState = JobState.Suspending;
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 6
0
        private void noWait_Job2_StateChanged(object sender, JobStateEventArgs e)
        {
            Job job = sender as Job;

            switch (e.JobStateInfo.State)
            {
                case JobState.Completed:
                case JobState.Stopped:
                case JobState.Failed:
                case JobState.Suspended:
                case JobState.Suspending:
                    this.ProcessExecutionErrorsAndReleaseWaitHandle(job);
                    break;
            }
        }
Exemplo n.º 7
0
            private void MonitoredJob_StateChanged(object sender, JobStateEventArgs e)
            {
                Job job = (Job)sender;

                this.CheckIfMonitoredJobIsComplete(job, e.JobStateInfo.State);
            }
Exemplo n.º 8
0
 private void MonitoredJob_StateChanged(object sender, JobStateEventArgs e)
 {
     Job job = (Job) sender;
     this.CheckIfMonitoredJobIsComplete(job, e.JobStateInfo.State);
 }
Exemplo n.º 9
0
 private void HandleJobStateChangedEvent(object sender, JobStateEventArgs stateChangedArgs)
 {
     Job job = sender as Job;
     if (job.IsFinishedState(stateChangedArgs.JobStateInfo.State))
     {
         _debugCollection.Complete();
     }
 }
Exemplo n.º 10
0
 internal static bool ComputeJobStateFromChildJobStates(string traceClassName, JobStateEventArgs e, ref int blockedChildJobsCount, ref int suspendedChildJobsCount, ref int suspendingChildJobsCount, ref int finishedChildJobsCount, ref int failedChildJobsCount, ref int stoppedChildJobsCount, int childJobsCount, out JobState computedJobState)
 {
     computedJobState = JobState.NotStarted;
     using (PowerShellTraceSource source = PowerShellTraceSourceFactory.GetTraceSource())
     {
         if (e.JobStateInfo.State == JobState.Blocked)
         {
             Interlocked.Increment(ref blockedChildJobsCount);
             source.WriteMessage(traceClassName, ": JobState is Blocked, at least one child job is blocked.");
             computedJobState = JobState.Blocked;
             return true;
         }
         if (e.PreviousJobStateInfo.State == JobState.Blocked)
         {
             Interlocked.Decrement(ref blockedChildJobsCount);
             if (blockedChildJobsCount == 0)
             {
                 source.WriteMessage(traceClassName, ": JobState is unblocked, all child jobs are unblocked.");
                 computedJobState = JobState.Running;
                 return true;
             }
             return false;
         }
         if (e.PreviousJobStateInfo.State == JobState.Suspended)
         {
             Interlocked.Decrement(ref suspendedChildJobsCount);
         }
         if (e.PreviousJobStateInfo.State == JobState.Suspending)
         {
             Interlocked.Decrement(ref suspendingChildJobsCount);
         }
         if (e.JobStateInfo.State == JobState.Suspended)
         {
             Interlocked.Increment(ref suspendedChildJobsCount);
             if ((suspendedChildJobsCount + finishedChildJobsCount) == childJobsCount)
             {
                 source.WriteMessage(traceClassName, ": JobState is suspended, all child jobs are suspended.");
                 computedJobState = JobState.Suspended;
                 return true;
             }
             return false;
         }
         if (e.JobStateInfo.State == JobState.Suspending)
         {
             Interlocked.Increment(ref suspendingChildJobsCount);
             if (((suspendedChildJobsCount + finishedChildJobsCount) + suspendingChildJobsCount) == childJobsCount)
             {
                 source.WriteMessage(traceClassName, ": JobState is suspending, all child jobs are in suspending state.");
                 computedJobState = JobState.Suspending;
                 return true;
             }
             return false;
         }
         if (((e.JobStateInfo.State != JobState.Completed) && (e.JobStateInfo.State != JobState.Failed)) && (e.JobStateInfo.State != JobState.Stopped))
         {
             if (e.JobStateInfo.State == JobState.Running)
             {
                 computedJobState = JobState.Running;
                 return true;
             }
             return false;
         }
         if (e.JobStateInfo.State == JobState.Failed)
         {
             Interlocked.Increment(ref failedChildJobsCount);
         }
         if (e.JobStateInfo.State == JobState.Stopped)
         {
             Interlocked.Increment(ref stoppedChildJobsCount);
         }
         bool flag = false;
         int num = Interlocked.Increment(ref finishedChildJobsCount);
         if (num == childJobsCount)
         {
             flag = true;
         }
         if (flag)
         {
             if (failedChildJobsCount > 0)
             {
                 source.WriteMessage(traceClassName, ": JobState is failed, at least one child job failed.");
                 computedJobState = JobState.Failed;
                 return true;
             }
             if (stoppedChildJobsCount > 0)
             {
                 source.WriteMessage(traceClassName, ": JobState is stopped, stop is called.");
                 computedJobState = JobState.Stopped;
                 return true;
             }
             source.WriteMessage(traceClassName, ": JobState is completed.");
             computedJobState = JobState.Completed;
             return true;
         }
         if ((suspendedChildJobsCount + num) == childJobsCount)
         {
             source.WriteMessage(traceClassName, ": JobState is suspended, all child jobs are suspended.");
             computedJobState = JobState.Suspended;
             return true;
         }
         if (((suspendingChildJobsCount + suspendedChildJobsCount) + num) == childJobsCount)
         {
             source.WriteMessage(traceClassName, ": JobState is suspending, all child jobs are in suspending state.");
             computedJobState = JobState.Suspending;
             return true;
         }
     }
     return false;
 }
Exemplo n.º 11
0
 private void ParentJobStateCalculation(JobStateEventArgs e)
 {
     JobState state;
     if (ComputeJobStateFromChildJobStates("ContainerParentJob", e, ref this._blockedChildJobsCount, ref this._suspendedChildJobsCount, ref this._suspendingChildJobsCount, ref this._finishedChildJobsCount, ref this._failedChildJobsCount, ref this._stoppedChildJobsCount, base.ChildJobs.Count, out state))
     {
         if (state != base.JobStateInfo.State)
         {
             if ((base.JobStateInfo.State == JobState.NotStarted) && (state == JobState.Running))
             {
                 base.PSBeginTime = new DateTime?(DateTime.Now);
             }
             if (!base.IsFinishedState(base.JobStateInfo.State) && base.IsPersistentState(state))
             {
                 base.PSEndTime = new DateTime?(DateTime.Now);
             }
             base.SetJobState(state);
         }
         if (this._finishedChildJobsCount == base.ChildJobs.Count)
         {
             StructuredTracer.EndContainerParentJobExecution(base.InstanceId);
         }
     }
 }
Exemplo n.º 12
0
 private void ChildJobStateChangedHandler(object sender, JobStateEventArgs eArgs)
 {
     if (eArgs.JobStateInfo.State != JobState.Disconnected)
     {
         this.RemoveEventCallback();
         this.SendStartComplete();
     }
 }
Exemplo n.º 13
0
        private void OnJobStateChanged(object sender, JobStateEventArgs eventArgs)
        {
            switch (eventArgs.JobStateInfo.State)
            {
                case JobState.Suspended:
                case JobState.Stopped:
                case JobState.Failed:
                case JobState.Completed:
                    {
                        Job2 job = sender as Job2;
                        Debug.Assert(job != null, "Job instance need to passed when StateChanged event is raised");
                        job.StateChanged -= OnJobStateChanged;

                        // start more operations from queue if required
                        Interlocked.Decrement(ref _inProgressCount);
                        // decrement the workflow jobs being serviced perf counter
                        PerfCountersMgr.UpdateCounterByValue(
                            PSWorkflowPerformanceCounterSetInfo.CounterSetId,
                            PSWorkflowPerformanceCounterIds.RunningWorkflowJobsCount,
                            -1);

                        if (Interlocked.Increment(ref _workflowsBeforeGc) >= WorkflowLimitBeforeGc)
                        {
                            RunGarbageCollection(true);
                        }

                        CheckAndStartServicingThread();
                    }
                    break;
            }
        }
Exemplo n.º 14
0
        private void ParentJobStateCalculation(JobStateEventArgs e)
        {
            JobState computedState;
            if (ComputeJobStateFromChildJobStates("ContainerParentJob", e, ref _blockedChildJobsCount, ref _suspendedChildJobsCount, ref _suspendingChildJobsCount,
                    ref _finishedChildJobsCount, ref _failedChildJobsCount, ref _stoppedChildJobsCount, ChildJobs.Count, out computedState))
            {
                if (computedState != JobStateInfo.State)
                {
                    if (JobStateInfo.State == JobState.NotStarted && computedState == JobState.Running)
                    {
                        PSBeginTime = DateTime.Now;
                    }
                    if (!IsFinishedState(JobStateInfo.State) && IsPersistentState(computedState))
                    {
                        PSEndTime = DateTime.Now;
                    }

                    SetJobState(computedState);
                }

                if (_finishedChildJobsCount == ChildJobs.Count)
                {
                    s_structuredTracer.EndContainerParentJobExecution(InstanceId);
                }
            }
        }
Exemplo n.º 15
0
        private void HandleMyStateChanged(object sender, JobStateEventArgs e)
        {
            _tracer.WriteMessage(TraceClassName, "HandleMyStateChanged", Guid.Empty, this,
                                 "NewState: {0}; OldState: {1}", e.JobStateInfo.State.ToString(),
                                 e.PreviousJobStateInfo.State.ToString());

            switch (e.JobStateInfo.State)
            {
                case JobState.Running:
                    {
                        lock (_syncObject)
                        {
                            JobRunning.Set();

                            // Do not create the event if it doesn't already exist. Suspend may never be called.
                            if (_jobSuspendedOrAborted != null)
                                JobSuspendedOrAborted.Reset();
                        }
                    }
                    break;

                case JobState.Suspended:
                    {
                        lock (_syncObject)
                        {
                            JobSuspendedOrAborted.Set();
                            JobRunning.Reset();
                        }
                    }
                    break;
                case JobState.Failed:
                case JobState.Completed:
                case JobState.Stopped:
                    {
                        lock (_syncObject)
                        {
                            JobSuspendedOrAborted.Set();

                            // Do not reset JobRunning when the state is terminal.
                            // No thread should wait on a job transitioning again to
                            // JobState.Running.
                            JobRunning.Set();
                        }
                    }
                    break;
            }
        }
Exemplo n.º 16
0
        private void childJob_StateChanged(object sender, JobStateEventArgs e)
        {
            Dbg.Assert(sender != null, "Only our internal implementation of Job should raise this event and it should make sure that sender != null");
            Dbg.Assert(sender is Job, "Only our internal implementation of Job should raise this event and it should make sure that sender is Job");
            var childJob = (Job)sender;

            if ((e.PreviousJobStateInfo.State == JobState.Blocked) && (e.JobStateInfo.State != JobState.Blocked))
            {
                bool parentJobGotUnblocked = false;
                lock (_lockObject)
                {
                    _countOfBlockedChildJobs--;
                    if (_countOfBlockedChildJobs == 0)
                    {
                        parentJobGotUnblocked = true;
                    }
                }
                if (parentJobGotUnblocked)
                {
                    this.SetJobState(JobState.Running);
                }
            }

            switch (e.JobStateInfo.State)
            {
                // intermediate states
                case JobState.Blocked:
                    lock (_lockObject)
                    {
                        _countOfBlockedChildJobs++;
                    }
                    this.SetJobState(JobState.Blocked);
                    break;

                // 3 finished states
                case JobState.Failed:
                case JobState.Stopped:
                case JobState.Completed:
                    childJob.StateChanged -= childJob_StateChanged;
                    this.MakeRoomForRunningOtherJobs(childJob);
                    lock (_lockObject)
                    {
                        if (e.JobStateInfo.State == JobState.Failed)
                        {
                            _countOfFailedChildJobs++;
                        }
                        else if (e.JobStateInfo.State == JobState.Stopped)
                        {
                            _countOfStoppedChildJobs++;
                        }
                        else if (e.JobStateInfo.State == JobState.Completed)
                        {
                            _countOfSuccessfullyCompletedChildJobs++;
                        }

                        if (_actionsForUnblockingChildAdditions.Count > 0)
                        {
                            Action a = _actionsForUnblockingChildAdditions.Dequeue();
                            if (a != null)
                            {
                                a();
                            }
                        }

                        if (_cmdletMode)
                        {
                            foreach (PSStreamObject streamObject in childJob.Results.ReadAll())
                            {
                                this.Results.Add(streamObject);
                            }
                            this.ChildJobs.Remove(childJob);
                            _setOfChildJobsThatCanAddMoreChildJobs.Remove(childJob.InstanceId);
                            childJob.Dispose();
                        }
                    }
                    this.ReportProgress(minimizeFrequentUpdates: !this.IsThrottlingJobCompleted);
                    break;

                default:
                    // do nothing
                    break;
            }

            this.FigureOutIfThrottlingJobIsCompleted();
        }
Exemplo n.º 17
0
        private void HandleJobStateChanged(object sender, JobStateEventArgs args)
        {
            Job job = sender as Job;

            if (job.IsPersistentState(args.JobStateInfo.State))
            {
                RemoveFromRunningJobList(job);
            }
        }
Exemplo n.º 18
0
		private void HandleMyStateChanged(object sender, JobStateEventArgs e)
		{
			object obj = null;
			string str;
			string[] strArrays = new string[2];
			strArrays[0] = e.JobStateInfo.State.ToString();
			strArrays[1] = e.PreviousJobStateInfo.State.ToString();
			this._tracer.WriteMessage("PSWorkflowJob", "HandleMyStateChanged", this.WorkflowGuidForTraces, this, "NewState: {0}; OldState: {1}", strArrays);
			bool flag = false;
			if (e.PreviousJobStateInfo.State == JobState.NotStarted)
			{
				base.PSBeginTime = new DateTime?(DateTime.Now);
				if (this._definition != null)
				{
					if (this._definition.IsScriptWorkflow)
					{
						str = "script";
					}
					else
					{
						str = "xaml";
					}
					PSSQMAPI.IncrementWorkflowType(str);
				}
				PSSQMAPI.NoteWorkflowStart(base.InstanceId);
			}
			JobState state = e.JobStateInfo.State;
			switch (state)
			{
				case JobState.Running:
				{
					lock (base.SyncRoot)
					{
						this._suspending = false;
						this._resuming = false;
						this.wfSuspendInProgress = false;
					}
					lock (this._syncObject)
					{
						this.JobRunning.Set();
						if (this._jobSuspendedOrAborted != null)
						{
							this.JobSuspendedOrAborted.Reset();
						}
						this._statusMessage = string.Empty;
						goto Label0;
					}
				}
				case JobState.Completed:
				case JobState.Failed:
				case JobState.Stopped:
				{
					base.PSEndTime = new DateTime?(DateTime.Now);
					if (this.JobMetadata.TryGetValue("ParentInstanceId", out obj) && obj as Guid != null)
					{
						PSSQMAPI.IncrementWorkflowStateData((Guid)obj, e.JobStateInfo.State);
					}
					PSSQMAPI.NoteWorkflowEnd(base.InstanceId);
					lock (this._syncObject)
					{
						PSWorkflowJob.StructuredTracer.EndJobLogic(base.InstanceId);
						this.JobSuspendedOrAborted.Set();
						this.JobRunning.Set();
					}
					flag = true;
					goto Label0;
				}
				case JobState.Blocked:
				{
				Label0:
					if (!flag || !this._unloadStreamsOnPersistentState)
					{
						return;
					}
					else
					{
						this._tracer.WriteMessage("PSWorkflowJob", "HandleMyStateChanged", this.WorkflowGuidForTraces, this, "BEGIN Unloading streams from memory", new string[0]);
						this.SelfUnloadJobStreams();
						this._tracer.WriteMessage("PSWorkflowJob", "HandleMyStateChanged", this.WorkflowGuidForTraces, this, "END Unloading streams from memory", new string[0]);
						return;
					}
				}
				case JobState.Suspended:
				{
					lock (base.SyncRoot)
					{
						this._suspending = false;
						this._resuming = false;
						this.wfSuspendInProgress = false;
					}
					base.PSEndTime = new DateTime?(DateTime.Now);
					lock (this._syncObject)
					{
						this.JobSuspendedOrAborted.Set();
						this.JobRunning.Reset();
					}
					flag = true;
					goto Label0;
				}
				default:
				{
					goto Label0;
				}
			}
		}
 private void HandleJobStateChanged(object sender, JobStateEventArgs e)
 {
     if (IsFinishedState(e.JobStateInfo.State))
     {
         // Job transitioned to finished state.
         this.StateChanged -= new EventHandler<JobStateEventArgs>(HandleJobStateChanged);
         DisposeFileWatcher();
     }
 }
Exemplo n.º 20
0
		private void HandleChildJobStateChanged(object sender, JobStateEventArgs e)
		{
			if (e.JobStateInfo.State != JobState.Blocked)
			{
				if (!base.IsFinishedState(e.JobStateInfo.State) || e.JobStateInfo.State == JobState.NotStarted)
				{
					return;
				}
				else
				{
					if (e.JobStateInfo.State == JobState.Failed)
					{
						this.atleastOneChildJobFailed = true;
					}
					bool flag = false;
					lock (this.syncObject)
					{
						PSWmiJob pSWmiJob = this;
						pSWmiJob.finishedChildJobsCount = pSWmiJob.finishedChildJobsCount + 1;
						if (this.finishedChildJobsCount == base.ChildJobs.Count)
						{
						}
					}
					if (flag)
					{
						if (!this.atleastOneChildJobFailed)
						{
							if (!this._stopIsCalled)
							{
								base.SetJobState(JobState.Completed);
							}
							else
							{
								base.SetJobState(JobState.Stopped);
								return;
							}
						}
						else
						{
							base.SetJobState(JobState.Failed);
							return;
						}
					}
					return;
				}
			}
			else
			{
				lock (this.syncObject)
				{
					PSWmiJob pSWmiJob1 = this;
					pSWmiJob1.blockedChildJobsCount = pSWmiJob1.blockedChildJobsCount + 1;
				}
				base.SetJobState(JobState.Blocked, null);
				return;
			}
		}
Exemplo n.º 21
0
        private void HandleMyStateChanged(object sender, JobStateEventArgs e)
        {
            _tracer.WriteMessage(ClassNameTrace, "HandleMyStateChanged", WorkflowGuidForTraces, this,
                                 "NewState: {0}; OldState: {1}", e.JobStateInfo.State.ToString(),
                                 e.PreviousJobStateInfo.State.ToString());
            bool unloadStreams = false;
            if (e.PreviousJobStateInfo.State == JobState.NotStarted)
            {
                PSBeginTime = DateTime.Now;
            }

            switch (e.JobStateInfo.State)
            {
                case JobState.Running:
                    {
                        lock (SyncRoot)
                        {
                            _suspending = false;
                            _resuming = false;
                            wfSuspendInProgress = false;
                        }

                        lock (_syncObject)
                        {
                            JobRunning.Set();

                            // Do not create the event if it doesn't already exist. Suspend may never be called.
                            if (_jobSuspendedOrAborted != null)
                                JobSuspendedOrAborted.Reset();

                            // Clear the message indicating that the job was suspended or that the job was queued
                            // for resume.  The job is now running, and that status is no longer valid.
                            _statusMessage = String.Empty;
                        }
                    }
                    break;

                case JobState.Suspended:
                    {
                        lock (SyncRoot)
                        {
                            _suspending = false;
                            _resuming = false;
                            wfSuspendInProgress = false;
                        }

                        PSEndTime = DateTime.Now;
                        lock (_syncObject)
                        {
                            JobSuspendedOrAborted.Set();
                            JobRunning.Reset();
                        }
                        unloadStreams = true;
                    }
                    break;
                case JobState.Failed:
                case JobState.Completed:
                case JobState.Stopped:
                    {
                        PSEndTime = DateTime.Now;

                        lock (_syncObject)
                        {
                            StructuredTracer.EndJobLogic(InstanceId);
                            JobSuspendedOrAborted.Set();

                            // Do not reset JobRunning when the state is terminal.
                            // No thread should wait on a job transitioning again to
                            // JobState.Running.
                            JobRunning.Set();
                        }
                        unloadStreams = true;
                    }
                    break;
            }

            if (!unloadStreams || !_unloadStreamsOnPersistentState) return;

            _tracer.WriteMessage(ClassNameTrace, "HandleMyStateChanged", WorkflowGuidForTraces, this,
                                 "BEGIN Unloading streams from memory");
            SelfUnloadJobStreams();
            _tracer.WriteMessage(ClassNameTrace, "HandleMyStateChanged", WorkflowGuidForTraces, this,
                                 "END Unloading streams from memory");
        }
Exemplo n.º 22
0
 void data_StateChanged(object sender, JobStateEventArgs e)
 {
     if (e.JobStateInfo.State != JobState.Running)
     { this.WorkLimit.Release(); }
 }
Exemplo n.º 23
0
 private void HandleChildJobStateChanged(object sender, JobStateEventArgs e)
 {
     this.ParentJobStateCalculation(e);
 }
Exemplo n.º 24
0
        private void HandleJobStateChanged(object sender, JobStateEventArgs e)
        {
            JobState state = e.JobStateInfo.State;
            if (state == JobState.Disconnected ||
                state == JobState.Completed ||
                state == JobState.Stopped ||
                state == JobState.Failed)
            {
                _job.StateChanged -= new EventHandler<JobStateEventArgs>(HandleJobStateChanged);
                RemoveConnectionRetryHandler(sender as PSInvokeExpressionSyncJob);

                // Signal that this job has been disconnected, or has ended.
                lock (_jobSyncObject)
                {
                    if (_disconnectComplete != null)
                    {
                        _disconnectComplete.Set();
                    }
                }
            }
        }
Exemplo n.º 25
0
        private void childJob_StateChanged(object sender, JobStateEventArgs e)
        {
            Job completedChildJob = (Job) sender;
            if ((e.PreviousJobStateInfo.State == JobState.Blocked) && (e.JobStateInfo.State != JobState.Blocked))
            {
                bool flag = false;
                lock (this._lockObject)
                {
                    this._countOfBlockedChildJobs--;
                    if (this._countOfBlockedChildJobs == 0)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    base.SetJobState(JobState.Running);
                }
            }
            switch (e.JobStateInfo.State)
            {
                case JobState.Completed:
                case JobState.Failed:
                case JobState.Stopped:
                    completedChildJob.StateChanged -= new EventHandler<JobStateEventArgs>(this.childJob_StateChanged);
                    this.MakeRoomForRunningOtherJobs(completedChildJob);
                    lock (this._lockObject)
                    {
                        if (e.JobStateInfo.State == JobState.Failed)
                        {
                            this._countOfFailedChildJobs++;
                        }
                        else if (e.JobStateInfo.State == JobState.Stopped)
                        {
                            this._countOfStoppedChildJobs++;
                        }
                        else if (e.JobStateInfo.State == JobState.Completed)
                        {
                            this._countOfSuccessfullyCompletedChildJobs++;
                        }
                        if (this._actionsForUnblockingChildAdditions.Count > 0)
                        {
                            Action action = this._actionsForUnblockingChildAdditions.Dequeue();
                            if (action != null)
                            {
                                action();
                            }
                        }
                        if (this._cmdletMode)
                        {
                            foreach (PSStreamObject obj2 in completedChildJob.Results.ReadAll())
                            {
                                base.Results.Add(obj2);
                            }
                            base.ChildJobs.Remove(completedChildJob);
                            this._setOfChildJobsThatCanAddMoreChildJobs.Remove(completedChildJob.InstanceId);
                            completedChildJob.Dispose();
                        }
                    }
                    this.ReportProgress(!this.IsThrottlingJobCompleted);
                    break;

                case JobState.Blocked:
                    lock (this._lockObject)
                    {
                        this._countOfBlockedChildJobs++;
                    }
                    base.SetJobState(JobState.Blocked);
                    break;
            }
            this.FigureOutIfThrottlingJobIsCompleted();
        }
Exemplo n.º 26
0
 private void HandleJobStateChangedEvent(object source, JobStateEventArgs eventArgs)
 {
     System.Management.Automation.Job item = (System.Management.Automation.Job) source;
     lock (this._jobTrackingLock)
     {
         if (eventArgs.JobStateInfo.State == JobState.Blocked)
         {
             this._blockedJobs.Add(item);
         }
         else
         {
             this._blockedJobs.Remove(item);
         }
         if (((this.Force == 0) && item.IsPersistentState(eventArgs.JobStateInfo.State)) || ((this.Force != 0) && item.IsFinishedState(eventArgs.JobStateInfo.State)))
         {
             if (!item.IsFinishedState(eventArgs.JobStateInfo.State))
             {
                 this._warnNotTerminal = true;
             }
             this._finishedJobs.Add(item);
         }
         else
         {
             this._finishedJobs.Remove(item);
         }
         if (this.Any.IsPresent)
         {
             if (this._finishedJobs.Count > 0)
             {
                 this.SetEndProcessingAction(new Action(this.EndProcessingOutputSingleFinishedJob));
             }
             else if (this._blockedJobs.Count == this._jobsToWaitFor.Count)
             {
                 this.SetEndProcessingAction(new Action(this.EndProcessingBlockedJobsError));
             }
         }
         else if (this._finishedJobs.Count == this._jobsToWaitFor.Count)
         {
             this.SetEndProcessingAction(new Action(this.EndProcessingOutputAllFinishedJobs));
         }
         else if (this._blockedJobs.Count > 0)
         {
             this.SetEndProcessingAction(new Action(this.EndProcessingBlockedJobsError));
         }
     }
 }
Exemplo n.º 27
0
 private void ThrottlingJob_StateChanged(object sender, JobStateEventArgs e)
 {
     this.CheckIfThrottlingJobIsComplete();
 }
 void childJob_StateChanged(object sender, JobStateEventArgs e)
 {
     this.SetJobState(e.JobStateInfo.State);            
 }
        private void childJob_StateChanged(object sender, JobStateEventArgs e)
        {
            Dbg.Assert(sender != null, "Only our internal implementation of Job should raise this event and it should make sure that sender != null");
            Dbg.Assert(sender is Job, "Only our internal implementation of Job should raise this event and it should make sure that sender is Job");
            var childJob = (Job)sender;

            if ((e.PreviousJobStateInfo.State == JobState.Blocked) && (e.JobStateInfo.State != JobState.Blocked))
            {
                bool parentJobGotUnblocked = false;
                lock (_lockObject)
                {
                    _countOfBlockedChildJobs--;
                    if (_countOfBlockedChildJobs == 0)
                    {
                        parentJobGotUnblocked = true;
                    }
                }

                if (parentJobGotUnblocked)
                {
                    this.SetJobState(JobState.Running);
                }
            }

            switch (e.JobStateInfo.State)
            {
            // intermediate states
            case JobState.Blocked:
                lock (_lockObject)
                {
                    _countOfBlockedChildJobs++;
                }

                this.SetJobState(JobState.Blocked);
                break;

            // 3 finished states
            case JobState.Failed:
            case JobState.Stopped:
            case JobState.Completed:
                childJob.StateChanged -= childJob_StateChanged;
                this.MakeRoomForRunningOtherJobs(childJob);
                lock (_lockObject)
                {
                    if (e.JobStateInfo.State == JobState.Failed)
                    {
                        _countOfFailedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Stopped)
                    {
                        _countOfStoppedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Completed)
                    {
                        _countOfSuccessfullyCompletedChildJobs++;
                    }

                    if (_actionsForUnblockingChildAdditions.Count > 0)
                    {
                        Action a = _actionsForUnblockingChildAdditions.Dequeue();
                        a?.Invoke();
                    }

                    if (_cmdletMode)
                    {
                        foreach (PSStreamObject streamObject in childJob.Results.ReadAll())
                        {
                            this.Results.Add(streamObject);
                        }

                        this.ChildJobs.Remove(childJob);
                        _setOfChildJobsThatCanAddMoreChildJobs.Remove(childJob.InstanceId);
                        childJob.Dispose();
                    }
                }

                this.ReportProgress(minimizeFrequentUpdates: !this.IsThrottlingJobCompleted);
                break;

            default:
                // do nothing
                break;
            }

            this.FigureOutIfThrottlingJobIsCompleted();
        }
Exemplo n.º 30
0
        private void HandleJobStateChangedEvent(object source, JobStateEventArgs eventArgs)
        {
            Dbg.Assert(source is Job, "Caller should verify source is Job");
            Dbg.Assert(eventArgs != null, "Caller should verify eventArgs != null");

            var job = (Job)source;
            lock (_jobTrackingLock)
            {
                Dbg.Assert(_blockedJobs.All(j => !_finishedJobs.Contains(j)), "Job cannot be in *both* _blockedJobs and _finishedJobs");

                if (eventArgs.JobStateInfo.State == JobState.Blocked)
                {
                    _blockedJobs.Add(job);
                }
                else
                {
                    _blockedJobs.Remove(job);
                }

                // Treat jobs in Disconnected state as finished jobs since the user
                // will have to reconnect the job before more information can be
                // obtained.
                // Suspended jobs require a Resume-Job call. Both of these states are persistent
                // without user interaction.
                // Wait should wait until a job is in a persistent state, OR if the force parameter
                // is specified, until the job is in a finished state, which is a subset of
                // persistent states.
                if (!Force && job.IsPersistentState(eventArgs.JobStateInfo.State) || (Force && job.IsFinishedState(eventArgs.JobStateInfo.State)))
                {
                    if (!job.IsFinishedState(eventArgs.JobStateInfo.State))
                    {
                        _warnNotTerminal = true;
                    }
                    _finishedJobs.Add(job);
                }
                else
                {
                    _finishedJobs.Remove(job);
                }

                Dbg.Assert(_blockedJobs.All(j => !_finishedJobs.Contains(j)), "Job cannot be in *both* _blockedJobs and _finishedJobs");

                if (this.Any.IsPresent)
                {
                    if (_finishedJobs.Count > 0)
                    {
                        this.SetEndProcessingAction(this.EndProcessingOutputSingleFinishedJob);
                    }
                    else if (_blockedJobs.Count == _jobsToWaitFor.Count)
                    {
                        this.SetEndProcessingAction(this.EndProcessingBlockedJobsError);
                    }
                }
                else
                {
                    if (_finishedJobs.Count == _jobsToWaitFor.Count)
                    {
                        this.SetEndProcessingAction(this.EndProcessingOutputAllFinishedJobs);
                    }
                    else if (_blockedJobs.Count > 0)
                    {
                        this.SetEndProcessingAction(this.EndProcessingBlockedJobsError);
                    }
                }
            }
        }
Exemplo n.º 31
0
        private void childJob_StateChanged(object sender, JobStateEventArgs e)
        {
            Job completedChildJob = (Job)sender;

            if ((e.PreviousJobStateInfo.State == JobState.Blocked) && (e.JobStateInfo.State != JobState.Blocked))
            {
                bool flag = false;
                lock (this._lockObject)
                {
                    this._countOfBlockedChildJobs--;
                    if (this._countOfBlockedChildJobs == 0)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    base.SetJobState(JobState.Running);
                }
            }
            switch (e.JobStateInfo.State)
            {
            case JobState.Completed:
            case JobState.Failed:
            case JobState.Stopped:
                completedChildJob.StateChanged -= new EventHandler <JobStateEventArgs>(this.childJob_StateChanged);
                this.MakeRoomForRunningOtherJobs(completedChildJob);
                lock (this._lockObject)
                {
                    if (e.JobStateInfo.State == JobState.Failed)
                    {
                        this._countOfFailedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Stopped)
                    {
                        this._countOfStoppedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Completed)
                    {
                        this._countOfSuccessfullyCompletedChildJobs++;
                    }
                    if (this._actionsForUnblockingChildAdditions.Count > 0)
                    {
                        Action action = this._actionsForUnblockingChildAdditions.Dequeue();
                        if (action != null)
                        {
                            action();
                        }
                    }
                    if (this._cmdletMode)
                    {
                        foreach (PSStreamObject obj2 in completedChildJob.Results.ReadAll())
                        {
                            base.Results.Add(obj2);
                        }
                        base.ChildJobs.Remove(completedChildJob);
                        this._setOfChildJobsThatCanAddMoreChildJobs.Remove(completedChildJob.InstanceId);
                        completedChildJob.Dispose();
                    }
                }
                this.ReportProgress(!this.IsThrottlingJobCompleted);
                break;

            case JobState.Blocked:
                lock (this._lockObject)
                {
                    this._countOfBlockedChildJobs++;
                }
                base.SetJobState(JobState.Blocked);
                break;
            }
            this.FigureOutIfThrottlingJobIsCompleted();
        }
Exemplo n.º 32
0
 private void HandleJobStateChanged(object sender, JobStateEventArgs e)
 {
     switch (e.JobStateInfo.State)
     {
         case JobState.Disconnected:
         case JobState.Completed:
         case JobState.Stopped:
         case JobState.Failed:
             this.job.StateChanged -= new EventHandler<JobStateEventArgs>(this.HandleJobStateChanged);
             this.RemoveConnectionRetryHandler(sender as PSInvokeExpressionSyncJob);
             lock (this.jobSyncObject)
             {
                 if (this.disconnectComplete != null)
                 {
                     this.disconnectComplete.Set();
                 }
             }
             break;
     }
 }
Exemplo n.º 33
0
 private void ThrottlingJob_StateChanged(object sender, JobStateEventArgs e)
 {
     this.CheckIfThrottlingJobIsComplete();
 }
Exemplo n.º 34
0
		private void OnJobStateChanged(object sender, JobStateEventArgs eventArgs)
		{
			JobState state = eventArgs.JobStateInfo.State;
			switch (state)
			{
				case JobState.Completed:
				case JobState.Failed:
				case JobState.Stopped:
				case JobState.Suspended:
				{
					Job2 job2 = sender as Job2;
					job2.StateChanged -= new EventHandler<JobStateEventArgs>(this.OnJobStateChanged);
					Interlocked.Decrement(ref this._inProgressCount);
					PSWorkflowJobManager.PerfCountersMgr.UpdateCounterByValue(PSWorkflowPerformanceCounterSetInfo.CounterSetId, 5, (long)-1, true);
					if (Interlocked.Increment(ref PSWorkflowJobManager._workflowsBeforeGc) >= 125)
					{
						PSWorkflowJobManager.RunGarbageCollection(true);
					}
					this.CheckAndStartServicingThread();
					return;
				}
				case JobState.Blocked:
				{
					return;
				}
				default:
				{
					return;
				}
			}
		}
Exemplo n.º 35
0
        /// <summary>
        /// Handles the StateChanged event from each of the child job objects
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleChildJobStateChanged(object sender, JobStateEventArgs e)
        {
            if (e.JobStateInfo.State == JobState.Blocked)
            {
                // increment count of blocked child jobs
                lock (_syncObject)
                {
                    _blockedChildJobsCount++;
                }
                // if any of the child job is blocked, we set state to blocked
                SetJobState(JobState.Blocked, null);
                return;
            }

            //Ignore state changes which are not resulting in state change to finished.
            if ((!IsFinishedState(e.JobStateInfo.State)) || (e.JobStateInfo.State == JobState.NotStarted))
            {
                return;
            }
            if (e.JobStateInfo.State == JobState.Failed)
            {
                //If any of the child job failed, we set status to failed
                _atleastOneChildJobFailed = true;
            }

            bool allChildJobsFinished = false;
            lock (_syncObject)
            {
                _finishedChildJobsCount++;

                //We are done
                if (_finishedChildJobsCount == ChildJobs.Count)
                {
                    allChildJobsFinished = true;
                }
            }
            if (allChildJobsFinished)
            {
                //if any child job failed, set status to failed
                //If stop was called set, status to stopped
                //else completed
                if (_atleastOneChildJobFailed)
                {
                    SetJobState(JobState.Failed);
                }
                else if (_stopIsCalled == true)
                {
                    SetJobState(JobState.Stopped);
                }
                else
                {
                    SetJobState(JobState.Completed);
                }
            }
        }
Exemplo n.º 36
0
 private void HandleChildJobStateChanged(object sender, JobStateEventArgs e)
 {
     this.CheckDisconnectedAndUpdateState(e.JobStateInfo.State, e.PreviousJobStateInfo.State);
     if (e.JobStateInfo.State == JobState.Blocked)
     {
         lock (this._syncObject)
         {
             this.blockedChildJobsCount++;
         }
         base.SetJobState(JobState.Blocked, null);
     }
     else if (base.IsFinishedState(e.JobStateInfo.State))
     {
         if (e.JobStateInfo.State == JobState.Failed)
         {
             this.atleastOneChildJobFailed = true;
         }
         bool flag2 = false;
         lock (this._syncObject)
         {
             this.finishedChildJobsCount++;
             if ((this.finishedChildJobsCount + this.disconnectedChildJobsCount) == base.ChildJobs.Count)
             {
                 flag2 = true;
             }
         }
         if (flag2)
         {
             if (this.disconnectedChildJobsCount > 0)
             {
                 base.SetJobState(JobState.Disconnected);
             }
             else if (this.atleastOneChildJobFailed)
             {
                 base.SetJobState(JobState.Failed);
             }
             else if (this._stopIsCalled)
             {
                 base.SetJobState(JobState.Stopped);
             }
             else
             {
                 base.SetJobState(JobState.Completed);
             }
         }
     }
 }