示例#1
0
 /// <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;
 }
示例#2
0
        /// <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);
            }
        }
示例#3
0
 /// <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;
 }
示例#6
0
 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;
 }
示例#7
0
 /// <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;
 }
示例#8
0
        /// <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;
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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);
        }
示例#11
0
 /// <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;
 }
示例#12
0
        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;
            }

        }
示例#13
0
 /// <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;
 }
示例#14
0
 /// <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);
        }
示例#16
0
        /// <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;
        }
示例#17
0
 /// <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;
 }
示例#18
0
        /// <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;
        }
示例#19
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 (Thread.CurrentThread != null)
         //					ChoTrace.WriteLine(String.Format("{0}: {1}", Thread.CurrentThread.Name, workItemState));
         _workItemState = workItemState;
     }
 }
示例#20
0
            protected override void ValidateStateTransition(WorkItemState current, WorkItemState next)
            {
                base.ValidateStateTransition(current, next);

                if (next == WorkItemState.Completed)
                {
                    throw new Exception("WorkThreadException testing.");
                }
            }
示例#21
0
        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;
        }
示例#22
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;
         }
     }
 }
示例#23
0
        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));
        }
示例#24
0
        /// <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
        }
示例#25
0
        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);
        }
示例#26
0
文件: WorkItem.cs 项目: smolnym/nunit
        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();
        }
示例#27
0
        /// <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));
            }
        }
示例#28
0
        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);
        }
示例#29
0
        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;
        }
示例#30
0
        /// <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));
        }
示例#32
0
        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");
            }
        }
示例#33
0
        /// <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);
        }
示例#34
0
文件: WorkItem.cs 项目: shelden/weni
 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;
 }
示例#35
0
 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(),
                 }
             }
         }
     });
 }
示例#36
0
        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;
        }
示例#37
0
        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}"">&nbsp;</span>
</small>
<code>{State}</code>";

            output.Content.SetHtmlContent(htmlContent);

            output.Attributes.RemoveAll(nameof(State));
        }
示例#38
0
        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;
        }
示例#39
0
        /// <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);
        }
示例#40
0
文件: Form1.cs 项目: mlabs-pl/stp
        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;
        }
示例#41
0
 /// <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;
 }
示例#43
0
        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;
        }
示例#44
0
        /// <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;
             }
        }
示例#45
0
        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
        }
示例#46
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;
         }
     }
 }
示例#47
0
        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;
            }
        }
示例#48
0
        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;
        }
示例#49
0
        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;
        }
示例#50
0
        /// <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);
        }
示例#51
0
		internal void Initialize()
		{
			_workItemState = WorkItemState.InQueue;
			_workItemCompleted = null;
			_workItemCompletedRefCount = 0;
		}
示例#52
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;
			}
		}
示例#53
0
 /// <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;
 }
示例#54
0
		public WorkItem(WaitCallback callback, object state)
		{
			_callback = callback;
			_state = state;
			_workItemState = WorkItemState.InQueue;
		}
示例#55
0
        /// <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;
 }