using Edge.Core.IndustryStandardInterface.Pump; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Wayne.FDCPOSLibrary; namespace Dfs.WayneChina.GilbarcoDispenserPayTerminal { public class GilbarcoPumpHandler : IFdcPumpController { #region Fields private LogicalNozzle nozzle; private LogicalDeviceState state = LogicalDeviceState.FDC_READY; #endregion #region Properties public string Name => "GilbarcoPumpHandler"; public int PumpId { get; } //Always use 1, since it's controlled by the terminal. public int PumpPhysicalId => 1; public IEnumerable Nozzles => new List { nozzle }; #endregion #region Decimal point settings, China domestic standard is: 2 public int AmountDecimalDigits => 2; public int VolumeDecimalDigits => 2; public int PriceDecimalDigits => 2; public int VolumeTotalizerDecimalDigits => 2; #endregion #region Events public event EventHandler OnStateChange; public event EventHandler OnCurrentFuellingStatusChange; #endregion #region Logger private static NLog.Logger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetLogger("IPosPlusApp"); #endregion #region Construction public GilbarcoPumpHandler(int pumpId) { PumpId = pumpId; nozzle = new LogicalNozzle(pumpId, Convert.ToByte(pumpId), 1, null); } #endregion #region IC card terminal handler public GilbarcoPayTerminalHandler GilbarcoPayTerminalHandler { get; } #endregion #region Methods public Task AuthorizeAsync(byte logicalNozzleId) { return Task.FromResult(true); } public Task AuthorizeWithAmountAsync(int moneyAmountWithoutDecimalPoint, byte logicalNozzleId) { return Task.FromResult(true); } public Task AuthorizeWithVolumeAsync(int volumnWithoutDecimalPoint, byte logicalNozzleId) { return Task.FromResult(true); } public Task ChangeFuelPriceAsync(int newPriceWithoutDecimalPoint, byte logicalNozzleId) { throw new NotImplementedException(); } public Task FuelingRoundUpByAmountAsync(int amount) { return Task.FromResult(true); } public Task FuelingRoundUpByVolumeAsync(int volume) { return Task.FromResult(true); } public Task LockNozzleAsync(byte logicalNozzleId) { return Task.FromResult(true); } public void OnFdcServerInit(Dictionary parameters) { } public Task QueryStatusAsync() { return Task.FromResult(LogicalDeviceState.FDC_READY); } public Task> QueryTotalizerAsync(byte logicalNozzleId) { return Task.FromResult(new Tuple(-1, -1)); } public Task ResumeFuellingAsync() { //Not supported, return false; return Task.FromResult(false); } public Task SuspendFuellingAsync() { //Not supported, return false; return Task.FromResult(false); } public Task UnAuthorizeAsync(byte logicalNozzleId) { //Not supported, return false; return Task.FromResult(false); } public Task UnlockNozzleAsync(byte logicalNozzleId) { return Task.FromResult(true); } #endregion #region Pump State and Fueling Status public void FirePumpStateChange(LogicalDeviceState state) { var logicalNozzle = new LogicalNozzle(PumpId, Convert.ToByte(PumpPhysicalId), 1, null); this.state = state; if (state == LogicalDeviceState.FDC_READY) OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(LogicalDeviceState.FDC_READY)); else OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(state, logicalNozzle)); } public void FireNozzleStateChange(LogicalDeviceState? state) { nozzle = new LogicalNozzle(PumpId, Convert.ToByte(PumpPhysicalId), 1, null); if (state.HasValue) nozzle.LogicalState = state; else nozzle.LogicalState = null; OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(LogicalDeviceState.FDC_READY, nozzle)); } public void FireFuelingStatusChange(FdcTransaction fuelingTransaction) { OnCurrentFuellingStatusChange?.Invoke(this, new FdcTransactionDoneEventArg(fuelingTransaction)); } #endregion } }