using Communicator.HttpServerWebApiCommunicator; using DeviceProcessor; using Newtonsoft.Json; using Parser.HttpMessageParser; using Sinochem_InternetPlus_Display.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web.Http.Results; using Wayne.FDCPOSLibrary; namespace Sinochem_InternetPlus_Display { public class Handler : IHandler>, IFdcCommunicableController { public Guid Id => new Guid(); public Func BroadcastMessageViaFdc { get; set; } public Func> OnMessageReceivedViaFdc { get; set; } private int bindingPumpId; public Handler(int bindingPumpId) { this.bindingPumpId = bindingPumpId; this.OnMessageReceivedViaFdc += (msg) => { Console.WriteLine("I received sth via FDC protocol: " + msg); return new Tuple("thanks for you message", OverallResult.Success); }; } public void Init(IContext> context) { var pump = DeviceControllerBus.Default.OfType().FirstOrDefault(p => p.PumpId == this.bindingPumpId); if (pump != null) pump.OnCurrentFuellingStatusChange += Handler_OnCurrentFuellingStatusChange; } public void Process(IContext> context) { var httpRequest = context.Incoming.Message; Console.WriteLine("I read car plate request: " + httpRequest.Content); //DeviceControllerBus.Default.OfType().First(p => p.PumpId == 1).Authorize(1); CarPlateTrxRequest carPlateTrxRequest = JsonConvert.DeserializeObject(httpRequest.Content); Console.WriteLine(carPlateTrxRequest.car_Number); CarPlateTrxResponse carPlateTrxResponse = new CarPlateTrxResponse { code = "200", message = "this is from Sinochem_CarPlateRecognizeCamera_HuLianWangJia" }; var httpResponse = SimpleHttpOutgoingMessage.CreatedFrom(httpRequest, new OkNegotiatedContentResult(carPlateTrxResponse, context.Incoming.Message.ApiController)); context.Outgoing.Write(httpResponse); // send msg to 15` to show 'pls start fuelling' var isSendSucceed = this.BroadcastMessageViaFdc?.Invoke("pls start fuelling!"); } private void Handler_OnCurrentFuellingStatusChange(object sender, FdcTransactionDoneEventArg e) { // wait for fuelling done if (e.Transaction.Finished) { // send msg to 15` to show 'fuelling is done' var chargeAmount = e.Transaction.Amount; // send msg to cloud to charge. } else { var runningAmount = e.Transaction.Amount; // send msg to 15` to show 'fuelling is in progress' } } } }