IDeviceHandler.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /// 发送二维码信息
  34. /// </summary>
  35. void SendQRCodeAsync() { }
  36. /// <summary>
  37. /// 发送实付金额给油机
  38. /// </summary>
  39. /// <param name="orderInfo"></param>
  40. void SendActuallyPaid(FccOrderInfo orderInfo) { }
  41. /// <summary>
  42. /// 设置tcp连接客户端
  43. /// </summary>
  44. void SetTcpClient(TcpClient? client) { }
  45. }
  46. public abstract class TestableActivePollingDeviceHandler<TRaw, TMessage> : IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
  47. {
  48. private IContext<TRaw, TMessage> context;
  49. public virtual void Init(IContext<TRaw, TMessage> context)
  50. {
  51. this.context = context;
  52. }
  53. public virtual Task Process(IContext<TRaw, TMessage> context)
  54. {
  55. throw new NotImplementedException();
  56. }
  57. }
  58. }