12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Edge.Core.Parser;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Edge.Core.Processor
- {
- public interface IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
- {
- /// <summary>
- /// The communicator has NOT started yet at this stage.
- /// </summary>
- /// <param name="context"></param>
- void Init(IContext<TRaw, TMessage> context);
- /// <summary>
- /// will be called every time that a message incoming from communicator.
- /// </summary>
- /// <param name="context"></param>
- Task Process(IContext<TRaw, TMessage> context);
- /// <summary>
- /// The method will be called from user for a generic test purpose, should implemented this method
- /// to cover most real life time logic to give user a meaningful and confidence result for how this processor would work
- /// when run for real.
- /// The method was guranteed to be called after DeviceHandler.Init, and Communicator.Start
- /// </summary>
- /// <param name="parameters"></param>
- /// <returns>throw exception to indicates the test failed, otherwise, return a Completed task.</returns>
- Task Test(params object[] parameters) { throw new NotImplementedException("暂不支持测试"); }
- }
- public abstract class TestableActivePollingDeviceHandler<TRaw, TMessage> : IDeviceHandler<TRaw, TMessage> where TMessage : MessageBase
- {
- private IContext<TRaw, TMessage> context;
- public virtual void Init(IContext<TRaw, TMessage> context)
- {
- this.context = context;
- }
- public virtual Task Process(IContext<TRaw, TMessage> context)
- {
- throw new NotImplementedException();
- }
- }
- }
|