SchedulerPostMsg.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Aitex.Core.RT.Fsm;
  2. using Aitex.Core.RT.Log;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace CyberX8_RT.Schedulers
  9. {
  10. public class SchedulerPostMsg
  11. {
  12. private enum Step
  13. {
  14. PostMsg,
  15. CheckMsg
  16. }
  17. #region 内部变量
  18. private Step _step = Step.CheckMsg;
  19. private DateTime _postMsgTime = DateTime.Now;
  20. #endregion
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="entity"></param>
  25. public SchedulerPostMsg()
  26. {
  27. }
  28. /// <summary>
  29. /// 重置
  30. /// </summary>
  31. public void Reset()
  32. {
  33. _step = Step.CheckMsg;
  34. _postMsgTime = DateTime.Now;
  35. }
  36. /// <summary>
  37. /// 发送方法
  38. /// </summary>
  39. /// <typeparam name="T"></typeparam>
  40. /// <typeparam name="V"></typeparam>
  41. /// <param name="entity"></param>
  42. /// <param name="currentState"></param>
  43. /// <param name="eEvent"></param>
  44. /// <param name="moduleName"></param>
  45. /// <param name="msg"></param>
  46. /// <param name="confirmState"></param>
  47. /// <param name="args"></param>
  48. /// <returns></returns>
  49. public bool PostMsg<T, V>(Entity entity,int currentState,eEvent eEvent, string moduleName, int msg, int confirmState, params object[] args)
  50. {
  51. if (_step == Step.PostMsg)
  52. {
  53. bool result =entity.CheckToPostMessage<T, V>(eEvent, moduleName, msg, args);
  54. if (result)
  55. {
  56. _postMsgTime = DateTime.Now;
  57. _step = Step.CheckMsg;
  58. }
  59. }
  60. else
  61. {
  62. if (currentState == confirmState)
  63. {
  64. return true;
  65. }
  66. else if (DateTime.Now.Subtract(_postMsgTime).TotalMilliseconds >= 1000)
  67. {
  68. _step = Step.PostMsg;
  69. }
  70. }
  71. return false;
  72. }
  73. }
  74. }