IDeviceHandler.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Edge.Core.Parser;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Edge.Core.Processor
  8. {
  9. public interface IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
  10. {
  11. /// <summary>
  12. /// The communicator has NOT started yet at this stage.
  13. /// </summary>
  14. /// <param name="context"></param>
  15. void Init(IContext<TRaw, TMessage> context);
  16. /// <summary>
  17. /// will be called every time that a message incoming from communicator.
  18. /// </summary>
  19. /// <param name="context"></param>
  20. Task Process(IContext<TRaw, TMessage> context);
  21. /// <summary>
  22. /// The method will be called from user for a generic test purpose, should implemented this method
  23. /// to cover most real life time logic to give user a meaningful and confidence result for how this processor would work
  24. /// when run for real.
  25. /// The method was guranteed to be called after DeviceHandler.Init, and Communicator.Start
  26. /// </summary>
  27. /// <param name="parameters"></param>
  28. /// <returns>throw exception to indicates the test failed, otherwise, return a Completed task.</returns>
  29. Task Test(params object[] parameters) { throw new NotImplementedException("暂不支持测试"); }
  30. }
  31. public abstract class TestableActivePollingDeviceHandler<TRaw, TMessage> : IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
  32. {
  33. private IContext<TRaw, TMessage> context;
  34. public virtual void Init(IContext<TRaw, TMessage> context)
  35. {
  36. this.context = context;
  37. }
  38. public virtual Task Process(IContext<TRaw, TMessage> context)
  39. {
  40. throw new NotImplementedException();
  41. }
  42. }
  43. }