IDeviceHandler.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Edge.Core.Domain.FccOrderInfo;
  2. using Edge.Core.Parser;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Edge.Core.Processor
  10. {
  11. public interface IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
  12. {
  13. /// <summary>
  14. /// The communicator has NOT started yet at this stage.
  15. /// </summary>
  16. /// <param name="context"></param>
  17. void Init(IContext<TRaw, TMessage> context);
  18. /// <summary>
  19. /// will be called every time that a message incoming from communicator.
  20. /// </summary>
  21. /// <param name="context"></param>
  22. Task Process(IContext<TRaw, TMessage> context);
  23. /// <summary>
  24. /// The method will be called from user for a generic test purpose, should implemented this method
  25. /// to cover most real life time logic to give user a meaningful and confidence result for how this processor would work
  26. /// when run for real.
  27. /// The method was guranteed to be called after DeviceHandler.Init, and Communicator.Start
  28. /// </summary>
  29. /// <param name="parameters"></param>
  30. /// <returns>throw exception to indicates the test failed, otherwise, return a Completed task.</returns>
  31. Task Test(params object[] parameters) { throw new NotImplementedException("暂不支持测试"); }
  32. /// <summary>
  33. /// 接收到 MQTT 数据
  34. /// </summary>
  35. /// <param name="message">数据 json </param>
  36. void OnReceiveMqttMessage(string message) { }
  37. /// <summary>
  38. /// 发送二维码信息
  39. /// </summary>
  40. void SendQRCodeAsync() { }
  41. ///// <summary>
  42. ///// 发送实付金额给油机
  43. ///// </summary>
  44. ///// <param name="orderInfo"></param>
  45. //void SendActuallyPaid(FccOrderInfo orderInfo) { }
  46. ///// <summary>
  47. ///// 设置tcp连接客户端,所连接的服务端端口
  48. ///// </summary>
  49. //void SetTcpClient(TcpClient? client,int? serverPort) { }
  50. ///// <summary>
  51. ///// 当与客户端断开链接
  52. ///// </summary>
  53. //void OnTcpDisconnect() { }
  54. }
  55. public abstract class TestableActivePollingDeviceHandler<TRaw, TMessage> : IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
  56. {
  57. private IContext<TRaw, TMessage> context;
  58. public virtual void Init(IContext<TRaw, TMessage> context)
  59. {
  60. this.context = context;
  61. }
  62. public virtual Task Process(IContext<TRaw, TMessage> context)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. }
  67. }