123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using Edge.Core.Configuration;
- using Edge.Core.IndustryStandardInterface.Pump;
- using Edge.Core.Processor;
- using Edge.Core.Processor.Dispatcher.Attributes;
- using Edge.Core.UniversalApi;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wayne.FDCPOSLibrary;
- namespace Bogus_Pump
- {
- [MetaPartsDescriptor(
- "lang-zh-cn:加油机模拟器lang-en-us:Pumps Simulator",
- "lang-zh-cn:用于模拟多个通用加油机(多个Pumps), 自动提枪并等待授权, 然后自动加油,但也可以关闭自动模拟转而接收外部调用来模拟油机行为.lang-en-us:Used for simulate generic pumps, auto timely lift nozzle, wait for authorizing and then start fuelling",
- new[] { "lang-zh-cn:加油机lang-en-us:Pump" })]
- public class PumpHandlerGroupApp : IEnumerable<IFdcPumpController>, IFdcCommunicableController, IAppProcessor, IDisposable
- {
- private IEnumerable<NozzleExtraInfo> nozzleExtraInfos = null;
- private List<PumpHandler> pumpHandlers = new List<PumpHandler>();
- public PumpHandlerGroupApp(int pumpsCount, byte nozzlesCountPerPump, bool enableFuelSimulation)
- {
- pumpHandlers.AddRange(Enumerable.Range(1, pumpsCount).Select(i => new PumpHandler(i, nozzlesCountPerPump, enableFuelSimulation)));
- }
- public string MetaConfigName { get; set; }
- public Func<string, bool> BroadcastMessageViaFdc { get; set; }
- public Func<string, string, string, bool> SendMessageViaFdc { get; set; }
- public Func<string, Tuple<string, OverallResult>> OnMessageReceivedViaFdc { get; set; }
- public void Dispose()
- {
- this.pumpHandlers?.ForEach(ph => ph.Dispose());
- }
- public IEnumerator<IFdcPumpController> GetEnumerator()
- {
- return this.pumpHandlers.GetEnumerator();
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.pumpHandlers.GetEnumerator();
- }
- public void OnFdcServerInit(Dictionary<string, object> parameters)
- {
- if (parameters != null && parameters.TryGetValue("NozzleProductMapping", out object param))
- {
- this.nozzleExtraInfos = param as IEnumerable<NozzleExtraInfo>;
- }
- }
- [UniversalApi]
- public async Task<bool> ChangePumpStateTo(int siteLevelNozzleId, LogicalDeviceState pumpNewState,
- int? amountWithoutDecimalPoint, int? volumeWithoutDecimalPoint, int? priceWithoutDecimalPoint)
- {
- var targetNozzleInfo = this.nozzleExtraInfos.FirstOrDefault(i => i.SiteLevelNozzleId == siteLevelNozzleId);
- if (targetNozzleInfo == null) return false;
- var targetPump = this.pumpHandlers.FirstOrDefault(ph => ph.PumpId == targetNozzleInfo.PumpId);
- if (targetPump == null) return false;
- targetPump.DrivenPumpStateTo((byte?)(targetNozzleInfo.NozzleLogicalId), pumpNewState, amountWithoutDecimalPoint, volumeWithoutDecimalPoint, priceWithoutDecimalPoint);
- return true;
- }
- [UniversalApi]
- public async Task<bool> RaisePumpNewTrx(int siteLevelNozzleId,
- int amountWithoutDecimalPoint, int volumeWithoutDecimalPoint, int priceWithoutDecimalPoint, int trxSeqNumber)
- {
- var targetNozzleInfo = this.nozzleExtraInfos.FirstOrDefault(i => i.SiteLevelNozzleId == siteLevelNozzleId);
- if (targetNozzleInfo == null) return false;
- var targetPump = this.pumpHandlers.FirstOrDefault(ph => ph.PumpId == targetNozzleInfo.PumpId);
- if (targetPump == null) return false;
- targetPump.DrivenPumpRaiseNewTrx((byte?)(targetNozzleInfo.NozzleLogicalId), amountWithoutDecimalPoint, volumeWithoutDecimalPoint, priceWithoutDecimalPoint, trxSeqNumber);
- return true;
- }
- [UniversalApi]
- public async Task<bool> DisplayTextOnPumpScreen(int[] screenIds, int areaId, string text)
- {
- if (BroadcastMessageViaFdc != null)
- {
- var p = new
- {
- source = "fc",
- data = new
- {
- screenIds = screenIds,
- areaId = areaId,
- text = text,
- }
- };
- BroadcastMessageViaFdc(System.Text.Json.JsonSerializer.Serialize(p));
- return true;
- }
- else
- return false;
- }
- }
- }
|