EntityTaskBase.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Aitex.Core.RT.Routine;
  4. using MECF.Framework.Common.Equipment;
  5. namespace VirgoRT.Modules
  6. {
  7. public class EntityTaskBase
  8. {
  9. protected Queue<IRoutine> QueueRoutine
  10. {
  11. get { return _routine; }
  12. }
  13. private Queue<IRoutine> _routine = new Queue<IRoutine>();
  14. public Result Start(IRoutine routine)
  15. {
  16. QueueRoutine.Clear();
  17. QueueRoutine.Enqueue(routine);
  18. return QueueRoutine.Peek().Start();
  19. }
  20. public Result TaskStart()
  21. {
  22. if (_routine.Count == 0)
  23. return Result.DONE;
  24. Result ret = Result.DONE;
  25. var lst = _routine.ToList();
  26. for (int i = 0; i < lst.Count; i++)
  27. {
  28. ret = lst[i].Start();
  29. if (ret == Result.DONE)
  30. {
  31. _routine.Dequeue();
  32. continue;
  33. }
  34. else
  35. {
  36. break;
  37. }
  38. }
  39. return Result.RUN;
  40. }
  41. public Result TaskMonitor()
  42. {
  43. if (_routine.Count == 0)
  44. return Result.DONE;
  45. IRoutine routine = _routine.Peek();
  46. Result ret = routine.Monitor();
  47. if (ret == Result.DONE)
  48. {
  49. _routine.Dequeue();
  50. var lst = _routine.ToList();
  51. for (int i = 0; i < lst.Count; i++)
  52. {
  53. ret = lst[i].Start();
  54. if (ret == Result.DONE)
  55. {
  56. _routine.Dequeue();
  57. continue;
  58. }
  59. else
  60. {
  61. break;
  62. }
  63. }
  64. }
  65. return ret;
  66. }
  67. public void Abort()
  68. {
  69. if (_routine != null)
  70. {
  71. _routine.Peek().Abort();
  72. _routine.Clear();
  73. }
  74. }
  75. }
  76. }
  77. namespace VirgoRT
  78. {
  79. abstract class ActionBase
  80. {
  81. private static ushort _id = 100;
  82. //---------------------------------Properties------------------------------------
  83. //
  84. public ushort ID { get; }
  85. public ModuleName Module { get; protected set; }
  86. public virtual ActionStatus Status { get; set; }
  87. public virtual bool IsReady { get; set; }
  88. public bool IsBackground { get; set; }
  89. //--------------------------------Constructor------------------------------------
  90. //
  91. protected ActionBase(ModuleName mod)
  92. {
  93. this.ID = _id++;
  94. this.Module = mod;
  95. this.Status = ActionStatus.Pending;
  96. }
  97. public virtual void Execute()
  98. {
  99. this.Status = ActionStatus.SendCmd;
  100. }
  101. protected virtual void OnPreWork() { }
  102. public virtual void OnPostWork(string data = null) { }
  103. public virtual void OnError(string data = null) { }
  104. }
  105. }