12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- namespace Flyinsono.Client.Test.Utilities.Executors
- {
- /// <summary>
- /// This executor will run workers one by one.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class SequenceExecutor<T>:ExecutorBase<T> where T: class
- {
- private readonly Queue<ExecuteWorker<T>> _workers = new Queue<ExecuteWorker<T>>();
- public SequenceExecutor(string name) : base(name)
- {
- }
- public SequenceExecutor(string name, TimeSpan executeDelayTime) : base(name, executeDelayTime)
- {
- }
- /// <summary>
- /// Gets current worker count in queue.
- /// </summary>
- /// <returns></returns>
- protected override int GetWorkerCount()
- {
- return _workers.Count;
- }
- /// <summary>
- /// Add one worker into the queue.
- /// </summary>
- /// <param name="worker"></param>
- protected override void AddWorker(ExecuteWorker<T> worker)
- {
- _workers.Enqueue(worker);
- }
- /// <summary>
- /// Take one worker from the queue.
- /// </summary>
- /// <returns></returns>
- protected override ExecuteWorker<T> TakeWorker()
- {
- return _workers.Dequeue();
- }
- /// <summary>
- /// Gets all workers.
- /// </summary>
- /// <returns></returns>
- protected override IEnumerable<ExecuteWorker<T>> GetWorkers()
- {
- return _workers.ToArray();
- }
-
- /// <summary>
- /// Clear all workers which not stated.
- /// </summary>
- protected override void CancelWorkers()
- {
- _workers.Clear();
- }
- /// <summary>
- /// Get the rest not working workers
- /// </summary>
- /// <returns></returns>
- public IEnumerable<ExecuteWorker<T>> GetRestWorkers()
- {
- return GetWorkers();
- }
- }
- }
|