/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> /// <param name="context">The TestExecutionContext in which it will run</param> public WorkItem(Test test, TestExecutionContext context) { _test = test; Result = test.MakeTestResult(); _state = WorkItemState.Ready; _context = context; }
/// <summary> /// Method called by the derived class when all work is complete /// </summary> protected void WorkItemComplete() { _state = WorkItemState.Complete; Result.StartTime = Context.StartTime; Result.EndTime = DateTime.UtcNow; long tickCount = Stopwatch.GetTimestamp() - Context.StartTicks; double seconds = (double)tickCount / Stopwatch.Frequency; Result.Duration = seconds; // We add in the assert count from the context. If // this item is for a test case, we are adding the // test assert count to zero. If it's a fixture, we // are adding in any asserts that were run in the // fixture setup or teardown. Each context only // counts the asserts taking place in that context. // Each result accumulates the count from child // results along with it's own asserts. Result.AssertCount += Context.AssertCount; _context.Listener.TestFinished(Result); if (Completed != null) { Completed(this, EventArgs.Empty); } }
/// <summary> /// Sets the work item state. /// </summary> /// <param name="workItemState">The new state.</param> private void SetWorkItemState(WorkItemState workItemState) { lock (this) { _workItemState = workItemState; } }
public ResponseWorkItem ( long id, int externalEntityId, WorkItemState workItemState, SubmissionPriority submissionPriority, byte[] messageBody, bool assigned, bool isRetry, string ownerName, ContextIdentifier contextIdentifier ) : base ( id, externalEntityId, workItemState, submissionPriority, messageBody, assigned, isRetry, ownerName, contextIdentifier ) { }
public static string GetDescription(WorkItemState state) { string desc = (isJa) ? "�쐬�ς�" : "Created"; switch (state) { case WorkItemState.Created: desc = (isJa) ? "�쐬�ς�" : "Created"; break; case WorkItemState.Scheduled: desc = (isJa) ? "�X�P�W���[���ς�" : "Scheduled"; break; case WorkItemState.Queued: desc = (isJa) ? "���[�N�L���[" : "Queued"; break; case WorkItemState.Running: desc = (isJa) ? "���s��" : "Running"; break; case WorkItemState.Failed: desc = (isJa) ? "���s" : "Failed"; break; case WorkItemState.Completed: desc = (isJa) ? "����" : "Completed"; break; default: break; } return desc; }
public EmsWorkItem ( decimal id, int externalEntityId, WorkItemState workItemState, SubmissionPriority submissionPriority, byte[] messageBody, bool assigned, bool isRetry, string ownerName, ContextIdentifier contextIdentifier, EmsReaderQueue queue, Message message ) : base ( id, externalEntityId, workItemState, submissionPriority, messageBody, assigned, isRetry, ownerName, contextIdentifier ) { this.queue = queue; this.message = message; }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> public WorkItem(Test test, FinallyDelegate finallyDelegate) { _test = test; testResult = test.MakeTestResult(); _state = WorkItemState.Ready; finD = finallyDelegate; }
private WorkItemState GetWorkItemState() { lock (this) { if (WorkItemState.Completed == _workItemState) { return(_workItemState); } long nowTicks = DateTime.UtcNow.Ticks; if (WorkItemState.Canceled != _workItemState && nowTicks > _expirationTime) { _workItemState = WorkItemState.Canceled; } if (WorkItemState.InProgress == _workItemState) { return(_workItemState); } if (CanceledCThreadPool.IsCanceled || CanceledWorkItemsGroup.IsCanceled) { return(WorkItemState.Canceled); } return(_workItemState); } }
private static bool IsValidStatesTransition(WorkItemState currentState, WorkItemState nextState) { bool valid = false; switch (currentState) { case WorkItemState.InQueue: valid = (WorkItemState.InProgress == nextState) || (WorkItemState.Canceled == nextState); break; case WorkItemState.InProgress: valid = (WorkItemState.Completed == nextState) || (WorkItemState.Canceled == nextState); break; case WorkItemState.Completed: case WorkItemState.Canceled: // Cannot be changed break; default: // Unknown state Debug.Assert(false); break; } return(valid); }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> /// <param name="context">The TestExecutionContext in which it will run</param> public WorkItem(Test test, TestExecutionContext context) { _test = test; _testResult = test.MakeTestResult(); _state = WorkItemState.Ready; _context = context; }
public void WorkItemStateChanged(IWorkItem workItem, WorkItemState previousState) { OnChangedWorkItemState(workItem, previousState); switch (workItem.State) { case WorkItemState.Scheduled: lock (this) { // Housekeeping chores. ++runningItems; // Now start it. WorkerPool.BeginWork(workItem); } break; case WorkItemState.Running: OnRunningWorkItem(workItem); break; case WorkItemState.Failing: OnFailedWorkItem(workItem); break; case WorkItemState.Completed: bool allDone = false; lock (this) { --runningItems; allDone = queue.Count == 0 && runningItems == 0; } // Tell the world that the workitem has completed. if (queue.Count < ConcurrentLimit / 2 && (ConcurrentLimit- runningItems)*100/ConcurrentLimit > 5 ) { OnCompletedWorkItem(workItem); } // Find some more work. if (allDone) { // Wakeup. //OnAllWorkCompleted(EventArgs.Empty); lock (completed) { Monitor.PulseAll(completed); } } else { DoNextWorkItem(); } break; } }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> /// <param name="context">The context to be used for running this test</param> public WorkItem(Test test, TestExecutionContext context) { _test = test; _context = context.Save(); testResult = test.MakeTestResult(); _command = test.GetTestCommand(); _state = WorkItemState.Ready; }
/// <summary> /// Method called by the derived class when all work is complete /// </summary> protected void WorkItemComplete() { _state = WorkItemState.Complete; if (Completed != null) { Completed(this, EventArgs.Empty); } }
public void GetActualWorkItems_Always_ReturnExpectedItemCount(WorkItemState state, int expectedCount) { var service = CreateWorkItemService(); var result = service.GetActualWorkItems(); Assert.AreEqual(expectedCount, result[state].Count); }
/// <summary> /// Creates a new instance of the <see cref="WorkItem"/> class. /// </summary> protected WorkItem() { Priority = ThreadPriority.Normal; _state = WorkItemState.Created; // Capture the invokers context. uiCulture = Thread.CurrentThread.CurrentUICulture; }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> /// <param name="context">The context to be used for running this test</param> public WorkItem(Test test, TestExecutionContext context) { _test = test; _context = context.Save(); testResult = test.MakeTestResult(); //_command = test.GetTestCommand(); _state = WorkItemState.Ready; }
/// <summary> /// Creates a new instance of the <see cref="WorkItem"/> class. /// </summary> protected WorkItem() { createdTime = DateTime.Now; priority = ThreadPriority.Normal; state = WorkItemState.Created; // Capture the invokers context. uiCulture = Thread.CurrentThread.CurrentUICulture; }
/// <summary> /// Sets the work item's state /// </summary> /// <param name="workItemState">The state to set the work item to</param> private void SetWorkItemState(WorkItemState workItemState) { lock (this) { // if (Thread.CurrentThread != null) // ChoTrace.WriteLine(String.Format("{0}: {1}", Thread.CurrentThread.Name, workItemState)); _workItemState = workItemState; } }
protected override void ValidateStateTransition(WorkItemState current, WorkItemState next) { base.ValidateStateTransition(current, next); if (next == WorkItemState.Completed) { throw new Exception("WorkThreadException testing."); } }
internal void Initialize() { // The _workItemState is changed directly instead of using the SetWorkItemState // method since we don't want to go throught IsValidStateTransition. _workItemState = WorkItemState.InQueue; _workItemCompleted = null; _workItemCompletedRefCount = 0; }
/// <summary> /// Sets the work item's state /// </summary> /// <param name="workItemState">The state to set the work item to</param> private void SetWorkItemState(WorkItemState workItemState) { lock (this) { if (IsValidStatesTransition(_workItemState, workItemState)) { _workItemState = workItemState; } } }
public async Task <IActionResult> Create([Bind("Name,Id")] WorkItemState workItemState) { if (ModelState.IsValid) { _context.Add(workItemState); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(workItemState)); }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> public WorkItem(Test test) { _test = test; Result = test.MakeTestResult(); _state = WorkItemState.Ready; #if !PORTABLE && !SILVERLIGHT && !NETCF TargetApartment = _test.Properties.ContainsKey(PropertyNames.ApartmentState) ? (ApartmentState)_test.Properties.Get(PropertyNames.ApartmentState) : ApartmentState.Unknown; #endif }
public void ModifyState(WorkItemState state, StateReason stateReason) { ValidateStateAndStateReason(state, stateReason); StateReason = stateReason; if (state == WorkItemState.Closed && Effort != null) { ModifyEffort(0, Effort.Completed + Effort.Remaining); } base.ModifyState(state); }
private void RunTest() { _context.CurrentTest = this.Test; _context.CurrentResult = this.Result; _context.Listener.TestStarted(this.Test); _context.StartTime = DateTime.UtcNow; _context.StartTicks = Stopwatch.GetTimestamp(); _context.EstablishExecutionEnvironment(); _state = WorkItemState.Running; PerformWork(); }
/// <summary> /// Raises the <see cref="ChangedWorkItemState"/> event. /// </summary> /// <param name="workItem"> /// The <see cref="IWorkItem"/> that has changed <see cref="IWorkItem.State"/>. /// </param> /// <param name="previousState"> /// One of the <see cref="WorkItemState"/> values indicating the previous state of the <paramref name="workItem"/>. /// </param> /// <remarks> /// The <b>OnChangedWorkItemState</b> method allows derived classes to handle the event without attaching a delegate. This /// is the preferred technique for handling the event in a derived class. /// <para> /// When a derived class calls the <b>OnChangedWorkItemState</b> method, it raises the <see cref="ChangedWorkItemState"/> event by /// invoking the event handler through a delegate. For more information, see /// <a href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpguide/html/cpconProvidingEventFunctionality.htm">Raising an Event</a>. /// </para> /// </remarks> protected virtual void OnChangedWorkItemState(IWorkItem workItem, WorkItemState previousState) { ChangedWorkItemStateEventHandler handler; lock (eventLock) { handler = changedWorkItemState; } if (handler != null) { handler(this, new ChangedWorkItemStateEventArgs(workItem, previousState)); } }
private string GetCssClass() { var isStateDone = WorkItemState.IsDone(State); var isStateCommit = WorkItemState.IsCommited(State); var isStateInProgress = WorkItemState.IsInProgress(State); var stateClass = isStateDone ? "card-outline-success" : (isStateCommit || isStateInProgress ? "card-outline-primary" : null); var cssClass = $"card work-iteration-item {stateClass}".Trim(); return(cssClass); }
internal void Initialize() { // The _workItemState is changed directly instead of using the SetWorkItemState // method since we don't want to go throught IsValidStateTransition. _workItemState = WorkItemState.InQueue; _workItemCompleted = null; _workItemCompletedRefCount = 0; _waitingOnQueueStopwatch = new Stopwatch(); _processingStopwatch = new Stopwatch(); _expirationTime = _workItemInfo.Timeout > 0 ? DateTime.UtcNow.Ticks + _workItemInfo.Timeout * TimeSpan.TicksPerMillisecond : long.MaxValue; }
/// <summary> /// Validate a state transition. /// </summary> /// <param name="currentState"> /// One of the <see cref="WorkItemState"/> values indicating the current <see cref="WorkItemState"/>. /// </param> /// <param name="nextState"> /// One of the <see cref="WorkItemState"/> values indicating the requested <see cref="WorkItemState"/>. /// </param> /// <exception cref="InvalidTransitionException"> /// The transition from <paramref name="current"/> to <paramref name="value"/> is invalid. /// </exception> /// <remarks> /// <b>ValidateStateTransition</b> throws <see cref="InvalidTransitionException"/> if /// the transition from <paramref name="current"/> to <paramref name="value"/> is invalid. /// <para> /// Derived class can use this method for extra validation. /// </para> /// </remarks> protected virtual void ValidateStateTransition(WorkItemState currentState, WorkItemState nextState) { switch (currentState) { case WorkItemState.Completed: break; case WorkItemState.Created: if (nextState == WorkItemState.Scheduled || nextState == WorkItemState.Queued) { return; } break; case WorkItemState.Failing: if (nextState == WorkItemState.Completed) { return; } break; case WorkItemState.Queued: if (nextState == WorkItemState.Scheduled) { return; } break; case WorkItemState.Running: if (nextState == WorkItemState.Completed || nextState == WorkItemState.Failing) { return; } break; case WorkItemState.Scheduled: if (nextState == WorkItemState.Running) { return; } break; default: break; } throw new InvalidTransitionException(this, currentState, nextState); }
public virtual void ModifyState(WorkItemState state) { State = state; DomainEvents.Add(new WorkItemStateModified(state, StateReason, this.GetType().Name)); if (state != WorkItemState.Closed) { return; } var childrenWorkItemsIds = _relatedWorks.Where(r => r.LinkType == LinkType.Child && r.ReferencedWorkItemId.HasValue) .Select(r => r.ReferencedWorkItemId.Value); DomainEvents.Add(new WorkItemClosedEvent(Id, childrenWorkItemsIds, this.GetType().Name)); }
private static void ValidateStateAndStateReason(WorkItemState state, StateReason stateReason) { var invalid = state switch { WorkItemState.New => stateReason != StateReason.New, WorkItemState.Active => stateReason != StateReason.WorkStarted, WorkItemState.Closed => stateReason != StateReason.Completed && stateReason != StateReason.Cut && stateReason != StateReason.Deferred && stateReason != StateReason.Obsolete, WorkItemState.Removed => stateReason != StateReason.RemovedFromTheBacklog, WorkItemState.Resolved => throw new DomainException(nameof(State), $"A {nameof(Task)} does not have a {state} state"), }; if (invalid) { throw new DomainException(nameof(StateReason), "Invalid reason for current state"); } }
/// <summary> /// Validate a state transition. /// </summary> /// <param name="currentState"> /// One of the <see cref="WorkItemState"/> values indicating the current <see cref="WorkItemState"/>. /// </param> /// <param name="nextState"> /// One of the <see cref="WorkItemState"/> values indicating the requested <see cref="WorkItemState"/>. /// </param> /// <exception cref="InvalidTransitionException"> /// The transition from current to value is invalid. /// </exception> /// <remarks> /// <b>ValidateStateTransition</b> throws <see cref="InvalidTransitionException"/> if /// the transition from current to value is invalid. /// <para> /// Derived class can use this method for extra validation. /// </para> /// </remarks> protected virtual void ValidateStateTransition(WorkItemState currentState, WorkItemState nextState) { //I don't think this method is useful but keeping it in here, the retries screw everything up switch (currentState) { case WorkItemState.Completed: //handles rescheduling cases if (nextState == WorkItemState.Scheduled || nextState == WorkItemState.Queued || nextState == WorkItemState.Created || nextState == WorkItemState.Completed ) return; break; case WorkItemState.Created: if (nextState == WorkItemState.Scheduled || nextState == WorkItemState.Queued) return; break; case WorkItemState.Failing: if (nextState == WorkItemState.Completed || nextState == WorkItemState.Scheduled) return; break; case WorkItemState.Queued: if (nextState == WorkItemState.Scheduled) return; break; case WorkItemState.Running: if (nextState == WorkItemState.Completed || nextState == WorkItemState.Failing) return; break; case WorkItemState.Scheduled: if (nextState == WorkItemState.Running) return; break; default: break; } //throw new InvalidTransitionException(this, currentState, nextState); }
public WorkItem(int id , int stepId , String name , WorkItemState state , int priority , DateTime created , DateTime entered , int sessionId ) { Id = id; StepId = stepId; Name = name; Created = created; Entered = entered; SessionId = sessionId; Priority = priority; ItemState = state; }
private static AdoWebHookMessage GenerateUpdatedMessage(int workItemId, WorkItemState oldState, WorkItemState active) { return(new AdoWebHookMessage() { eventType = "workitem.updated", resource = new Resource() { workItemId = workItemId, fields = new Fields() { SystemState = new StringChange() { oldValue = oldState.ToString(), newValue = active.ToString(), } } } }); }
private void DoNothing(WorkItemState state) { WorkItemState workItemState = (WorkItemState)state; _workingStates.Add(workItemState.QueueUsageEntry, workItemState.QueueUsageEntry); do { if (SmartThreadPool.IsWorkItemCanceled) { break; } Stopwatch stopwatch = Stopwatch.StartNew(); //while (stopwatch.ElapsedMilliseconds < workItemState.SleepDuration); Thread.Sleep(workItemState.SleepDuration); } while (_paused); _workingStates.Remove(workItemState.QueueUsageEntry); //return null; }
public override void Process(TagHelperContext context, TagHelperOutput output) { var isStateDone = WorkItemState.IsDone(State); var isStateCommit = WorkItemState.IsCommited(State); var isStateInProgress = WorkItemState.IsInProgress(State); var stateClass = isStateDone ? "badge-success" : (isStateCommit || isStateInProgress ? "badge-primary" : "badge-default"); var htmlContent = $@" <small> <span class=""badge badge-pill circle {stateClass}""> </span> </small> <code>{State}</code>"; output.Content.SetHtmlContent(htmlContent); output.Attributes.RemoveAll(nameof(State)); }
private static bool IsValidStatesTransition(WorkItemState currentState, WorkItemState nextState) { bool valid = false; switch (currentState) { case WorkItemState.InQueue: valid = (WorkItemState.InProgress == nextState) || (WorkItemState.Canceled == nextState); break; case WorkItemState.InProgress: valid = (WorkItemState.Completed == nextState) || (WorkItemState.Canceled == nextState); break; case WorkItemState.Completed: case WorkItemState.Canceled: // Cannot be changed break; default: // Unknown state Debug.Assert(false); break; } return valid; }
/// <summary> /// Validate a state transition. /// </summary> /// <param name="currentState"> /// One of the <see cref="WorkItemState"/> values indicating the current <see cref="WorkItemState"/>. /// </param> /// <param name="nextState"> /// One of the <see cref="WorkItemState"/> values indicating the requested <see cref="WorkItemState"/>. /// </param> /// <exception cref="InvalidTransitionException"> /// The transition from <paramref name="current"/> to <paramref name="value"/> is invalid. /// </exception> /// <remarks> /// <b>ValidateStateTransition</b> throws <see cref="InvalidTransitionException"/> if /// the transition from <paramref name="current"/> to <paramref name="value"/> is invalid. /// <para> /// Derived class can use this method for extra validation. /// </para> /// </remarks> protected virtual void ValidateStateTransition(WorkItemState currentState, WorkItemState nextState) { switch (currentState) { case WorkItemState.Completed: break; case WorkItemState.Created: if (nextState == WorkItemState.Scheduled || nextState == WorkItemState.Queued) return; break; case WorkItemState.Failing: if (nextState == WorkItemState.Completed) return; break; case WorkItemState.Queued: if (nextState == WorkItemState.Scheduled) return; break; case WorkItemState.Running: if (nextState == WorkItemState.Completed || nextState == WorkItemState.Failing) return; break; case WorkItemState.Scheduled: if (nextState == WorkItemState.Running) return; break; default: break; } throw new InvalidTransitionException(this, currentState, nextState); }
/// <summary> /// Method called by the derived class when all work is complete /// </summary> protected void WorkItemComplete() { finD.Complete(); _state = WorkItemState.Complete; if (Completed != null) Completed(this, EventArgs.Empty); }
/// <summary> /// Initialise a new instance of the <see cref="ChangedWorkItemStateEventArgs"/> class with the /// specified <see cref="IWorkItem"/> and <see cref="WorkItemState">previous state</see>. /// </summary> /// <param name="workItem"> /// The <see cref="IWorkItem"/> associated with the event. /// </param> /// <param name="previousState"> /// One of the <see cref="WorkItemState"/> values indicating the previous state of the /// <paramref name="workItem"/>. /// </param> /// <remarks> /// Use this constructor to create and initialize a new instance of the <see cref="ChangedWorkItemStateEventArgs"/> /// with the specified <paramref name="workItem"/> and <paramref name="previousState"/>. /// </remarks> public ChangedWorkItemStateEventArgs(IWorkItem workItem, WorkItemState previousState) : base(workItem) { this.previousState = previousState; }
protected WorkItem ( decimal id, int externalEntityId, WorkItemState workItemState, SubmissionPriority submissionPriority, byte[] messageBody, bool assigned, bool isRetry, string ownerName, ContextIdentifier contextIdentifier ) { Id = id; ExternalEntityId = externalEntityId; _workItemState = workItemState; _submissionPriority = submissionPriority; _messageBody = messageBody; Assigned = assigned; IsRetry = isRetry; OwnerName = ownerName; _contextIdentifier = contextIdentifier; // _processCode = processCode; // _assignmentToken = assignmentToken; }
/// <summary> /// Invoked by an <see cref="IWorkItem"/> to inform a work queue that its <see cref="IWorkItem.State"/> /// has changed. /// </summary> /// <param name="workItem"> /// The <see cref="IWorkItem"/> that has changed <see cref="IWorkItem.State"/>. /// </param> /// <param name="previousState"> /// One of the <see cref="WorkItemState"/> values indicating the previous state of the <paramref name="workItem"/>. /// </param> /// <remarks> /// The <see cref="ChangedWorkItemState"/> event is raised by calling the /// <see cref="OnChangedWorkItemState"/> method. Then the following actions are performed, /// based on the new <see cref="IWorkItem.State"/> of <paramref name="workItem"/>: /// <list type="table"> /// <listheader> /// <term>State</term> /// <description>Action</description> /// </listheader> /// <item> /// <term><see cref="WorkItemState">Scheduled</see></term> /// <description>Assign the <paramref name="workItem"/> to the <see cref="WorkerPool"/>.</description> /// </item> /// <item> /// <term><see cref="WorkItemState">Running</see></term> /// <description>Raise the <see cref="RunningWorkItem"/> event.</description> /// </item> /// <item> /// <term><see cref="WorkItemState">Failing</see></term> /// <description>Raise the <see cref="FailedWorkItem"/> event.</description> /// </item> /// <item> /// <term><see cref="WorkItemState">Completed</see></term> /// <description>Raise the <see cref="CompletedWorkItem"/> event and schedule the next work item in the queue.</description> /// </item> /// </list> /// </remarks> public void WorkItemStateChanged(IWorkItem workItem, WorkItemState previousState) { OnChangedWorkItemState(workItem, previousState); switch (workItem.State) { case WorkItemState.Scheduled: lock (this) { // Housekeeping chores. ++runningItems; // Now start it. WorkerPool.BeginWork(workItem); } break; case WorkItemState.Running: OnRunningWorkItem(workItem); break; case WorkItemState.Failing: OnFailedWorkItem(workItem); break; case WorkItemState.Completed: bool allDone = false; lock (this) { --runningItems; allDone = queue.Count == 0 && runningItems == 0; } // Tell the world that the workitem has completed. OnCompletedWorkItem(workItem); // Find some more work. if (allDone) { // Wakeup. OnAllWorkCompleted(EventArgs.Empty); lock (completed) { Monitor.PulseAll(completed); } } else { DoNextWorkItem(); } break; } }
private void RunTest() { _context.CurrentTest = this.Test; _context.CurrentResult = this.Result; _context.Listener.TestStarted(this.Test); _context.StartTime = DateTime.UtcNow; _context.StartTicks = Stopwatch.GetTimestamp(); _context.EstablishExecutionEnvironment(); _state = WorkItemState.Running; #if PORTABLE PerformWork(); #else try { PerformWork(); } catch (ThreadAbortException) { //Result.SetResult(ResultState.Cancelled); } #endif }
private WorkItemState GetWorkItemState() { lock (this) { if (WorkItemState.Completed == _workItemState) { return _workItemState; } long nowTicks = DateTime.UtcNow.Ticks; if (WorkItemState.Canceled != _workItemState && nowTicks > _expirationTime) { _workItemState = WorkItemState.Canceled; } if (WorkItemState.InProgress == _workItemState) { return _workItemState; } if (CanceledSmartThreadPool.IsCanceled || CanceledWorkItemsGroup.IsCanceled) { return WorkItemState.Canceled; } return _workItemState; } }
/// <summary> /// Method called by the derived class when all work is complete /// </summary> protected void WorkItemComplete() { _state = WorkItemState.Complete; //long tickCount = Stopwatch.GetTimestamp() - Context.StartTicks; //double seconds = (double)tickCount / Stopwatch.Frequency; //Result.Duration = TimeSpan.FromSeconds(seconds); Result.Duration = DateTime.Now - Context.StartTime; // We add in the assert count from the context. If // this item is for a test case, we are adding the // test assert count to zero. If it's a fixture, we // are adding in any asserts that were run in the // fixture setup or teardown. Each context only // counts the asserts taking place in that context. // Each result accumulates the count from child // results along with it's own asserts. Result.AssertCount += Context.AssertCount; _context.Listener.TestFinished(Result); if (Completed != null) Completed(this, EventArgs.Empty); }
internal void Initialize() { _workItemState = WorkItemState.InQueue; _workItemCompleted = null; _workItemCompletedRefCount = 0; }
/// <summary> /// Sets the work item's state /// </summary> /// <param name="workItemState">The state to set the work item to</param> private void SetWorkItemState(WorkItemState workItemState) { lock(this) { _workItemState = workItemState; } }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> public WorkItem(Test test) { _test = test; Result = test.MakeTestResult(); _state = WorkItemState.Ready; }
public WorkItem(WaitCallback callback, object state) { _callback = callback; _state = state; _workItemState = WorkItemState.InQueue; }
/// <summary> /// Raises the <see cref="ChangedWorkItemState"/> event. /// </summary> /// <param name="workItem"> /// The <see cref="IWorkItem"/> that has changed <see cref="IWorkItem.State"/>. /// </param> /// <param name="previousState"> /// One of the <see cref="WorkItemState"/> values indicating the previous state of the <paramref name="workItem"/>. /// </param> /// <remarks> /// The <b>OnChangedWorkItemState</b> method allows derived classes to handle the event without attaching a delegate. This /// is the preferred technique for handling the event in a derived class. /// <para> /// When a derived class calls the <b>OnChangedWorkItemState</b> method, it raises the <see cref="ChangedWorkItemState"/> event by /// invoking the event handler through a delegate. For more information, see /// <a href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpguide/html/cpconProvidingEventFunctionality.htm">Raising an Event</a>. /// </para> /// </remarks> protected virtual void OnChangedWorkItemState(IWorkItem workItem, WorkItemState previousState) { ChangedWorkItemStateEventHandler handler; lock (eventLock) { handler = changedWorkItemState; } if (handler != null) { handler (this, new ChangedWorkItemStateEventArgs(workItem, previousState)); } }
public WorkItemStateChangedEventArgs(IWorkItem workItem, WorkItemState previousState) : base(workItem) { _previousState = previousState; }