123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using Edge.Core.Configuration;
- using Edge.Core.IndustryStandardInterface.Pump;
- using Edge.Core.Processor;
- using Edge.Core.Processor.Dispatcher.Attributes;
- using Edge.Core.UniversalApi;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Wayne.FDCPOSLibrary;
- namespace EagleStar_Pump
- {
- [MetaPartsDescriptor(
- "lang-zh-cn:英高系统数据库lang-en-us:EagleStar System Database",
- "lang-zh-cn:用于连接英高系统数据库,抓取Fairbanks所需要的数据.lang-en-us:Used for connecting to EagleStar system database, auto timely grab the data required by Fairbanks",
- new[] { "lang-zh-cn:加油机lang-en-us:Pump" })]
- public class PumpHandlerGroupApp : IEnumerable<IFdcPumpController>, IFdcCommunicableController, IAppProcessor, IDisposable
- {
- private List<PumpHandler> pumpHandlers = new List<PumpHandler>();
- private ILogger logger = null;
- [ParamsJsonSchemas("PumpGroupCtorParamsJsonSchemas")]
- public PumpHandlerGroupApp(PumpGroupConfiguration pumpGroupConfiguration, IServiceProvider services)
- {
- if (services != null)
- {
- var loggerFactory = services.GetRequiredService<ILoggerFactory>();
- logger = loggerFactory.CreateLogger("DynamicPrivate_PumpHandler");
- }
- logger.LogInformation("EagleStar pump app, Will create.");
- pumpHandlers.Add(new PumpHandler(pumpGroupConfiguration, logger, services));
- }
- 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; }
- private IEnumerable<NozzleExtraInfo> nozzleExtraInfos = null;
- public void Dispose()
- {
- this.pumpHandlers?.ForEach(ph => ph.Dispose());
- }
- public IEnumerator<IFdcPumpController> GetEnumerator()
- {
- return this.pumpHandlers.GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return this.pumpHandlers.GetEnumerator();
- }
- public void Init(IEnumerable<IProcessor> processors)
- {
- }
- 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;
- }
- }
- #region Ctor parameters
- public class PumpGroupConfiguration
- {
- public string DatabaseConnectionString { get; set; }
- public byte AmountDecimalDigits { get; set; }
- public byte VolumeDecimalDigits { get; set; }
- public byte PriceDecimalDigits { get; set; }
- public byte VolumeTotalizerDecimalDigits { get; set; }
- }
- #endregion
- }
|