TaskItem.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Runtime.CompilerServices;
  2. using System.Threading;
  3. using App.Robot.Station.Logical.Worker;
  4. using Newtonsoft.Json;
  5. namespace App.Robot.Station.Logical
  6. {
  7. public class TaskItem
  8. {
  9. public int id;
  10. public long sumCount = 0;
  11. public long sumFailCount = 0;
  12. public long curCount = 0;
  13. public long failCount = 0;
  14. public long targetCount = 0;
  15. public TaskConfig config { get => config_; set { config_ = value; EventAfterSetConfig(); } }
  16. private TaskConfig config_;
  17. public int RunningThreadCount => worker.RunningThreadCount;
  18. public bool IsRunning => worker.IsRunning;
  19. [JsonIgnore]
  20. public IWorker worker { get; private set; }
  21. void EventAfterSetConfig()
  22. {
  23. var config = config_;
  24. targetCount = config.threadCount * config.loopCountPerThread;
  25. switch (config.type)
  26. {
  27. case "ApiClientAsync": worker = new Worker_ApiClientAsync(this); break;
  28. case "HttpClient": worker = new Worker_HttpClient(this); break;
  29. case "HttpUtil": worker = new Worker_HttpUtil(this); break;
  30. default: config.type = "ApiClient"; worker = new Worker_ApiClient(this); break;
  31. }
  32. }
  33. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  34. public void StepUp(bool success)
  35. {
  36. Interlocked.Increment(ref curCount);
  37. Interlocked.Increment(ref sumCount);
  38. if (!success)
  39. {
  40. Interlocked.Increment(ref sumFailCount);
  41. Interlocked.Increment(ref failCount);
  42. }
  43. }
  44. }
  45. }