using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Edge.Core.Parser.BinaryParser.MessageEntity; using Edge.Core.Parser; using Edge.Core.Processor; using Edge.Core.IndustryStandardInterface.Pump; using Edge.Core.Processor.Communicator; namespace Edge.Core.Processor { public interface IContext : IDisposable where TMessage : MessageBase { //event EventHandler OnCommunicatorConnected; IDeviceProcessor Processor { get; } IDeviceHandler Handler { get; } ICommunicator Communicator { get; } IIncoming Incoming { get; } IOutgoing Outgoing { get; } } //public interface IBinaryContext : IContext //{ // IHandler Handler { get; } // IDeviceProcessor Processor { get; } // Incoming Incoming { get; } // Outgoing Outgoing { get; } //} public class Context : IContext where TMessage : MessageBase { //public event EventHandler OnCommunicatorConnected; //public event EventHandler OnCommunicatorDisconnected; public IDeviceProcessor Processor { get; } public IDeviceHandler Handler { get; } public ICommunicator Communicator { get; } public IIncoming Incoming { get; } public IOutgoing Outgoing { get; } public Context(IDeviceProcessor processor, IDeviceHandler handler, ICommunicator communicator, IIncoming incoming, IOutgoing outgoing) { this.Processor = processor; this.Communicator = communicator; this.Incoming = incoming;// new HistoryKeepIncoming(10); this.Outgoing = outgoing;// new Outgoing(this); this.Handler = handler; } public void Dispose() { if (this.Incoming is IDisposable idp) idp.Dispose(); if (this.Outgoing is IDisposable odp) odp.Dispose(); } } //public class HttpStringContext : IContext where TMessage : MessageBase //{ // public event EventHandler OnCommunicatorConnected; // public event EventHandler OnCommunicatorDisconnected; // public IHandler Handler { get; } // //public IDeviceProcessor Processor { get; } // public Incoming Incoming { get; } // public Outgoing Outgoing { get; } // public HttpStringContext(IHandler handler, ICommunicator communicator, IDeviceProcessor processor) // { // this.Incoming = new HistoryKeepIncoming(10); // this.Outgoing = new Outgoing(this); // this.Handler = handler; // communicator.OnConnected += (a, b) => // { // var s = this.OnCommunicatorConnected; // s?.Invoke(this, null); // }; // communicator.OnDisconnected += (a, b) => // { // var s = this.OnCommunicatorDisconnected; // s?.Invoke(this, null); // }; // } //} }