FUSIONForecourtControl.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading;
  8. using Wayne.FDCPOSLibrary;
  9. using Wayne.ForecourtControl.Fusion.ReadDeviceStatus;
  10. using Wayne.Lib;
  11. using Wayne.Lib.Log;
  12. namespace Wayne.ForecourtControl.Fusion
  13. {
  14. public class FUSIONForecourtControl : IForecourtControl, IConnectable, IIdentifiableEntity, IDisposable
  15. {
  16. // Fields
  17. private string clientName;
  18. private string connectionString;
  19. private DeviceConnectionState connectionState = DeviceConnectionState.Disconnected;
  20. private List<IFuelPrice> fuelPriceList = new List<IFuelPrice>();
  21. private int id;
  22. private FUSIONManager _manager;
  23. public FUSIONManager manager
  24. {
  25. get { return _manager; }
  26. }
  27. private List<IPricePole> pricePoleList = new List<IPricePole>();
  28. private List<IPumpEx> pumpList = new List<IPumpEx>();
  29. private List<ITankGroup> tankGroupList = new List<ITankGroup>();
  30. private List<IFuelProduct> fuelProducts = new List<IFuelProduct>();
  31. private int siteMode;
  32. private bool siteOpened;
  33. public ServiceRequestChangeFuelMode srChangeMode = null;
  34. public bool fuelPriceReserved;
  35. public ReadDeviceStatusController DeviceStatusController { get; private set; }
  36. // Events
  37. public event EventHandler<AlarmEventArgs> OnAlarm;
  38. public event EventHandler<ConnectionChangedEventArgs> OnConnectionStateChange;
  39. public event EventHandler<ConfigurationChangeEventArgs> OnConfigurationChange;
  40. public event EventHandler<FuelPriceChangeEventArgs> OnFuelPriceChange;
  41. public event EventHandler<SiteModeChangeEventArgs> OnSiteModeChange;
  42. private readonly DebugLogger debugLogger;
  43. #region Methods
  44. public FUSIONForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds,
  45. IPumpAuthorizationIdGenerator authorizationIdGenerator)
  46. : this(deviceId, managedEntityTypes, managedPumpIds, null, authorizationIdGenerator)
  47. {
  48. }
  49. public FUSIONForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds,
  50. IForecourtConfiguration config, IPumpAuthorizationIdGenerator authorizationIdGenerator)
  51. {
  52. this.id = deviceId;
  53. debugLogger = new DebugLogger(this, true);
  54. ForecourtConfiguration = config;
  55. DebugLog("Creating FUSIONManager");
  56. DeviceStatusController = new ReadDeviceStatusController(this, this);
  57. DeviceStatusController.Initialize();
  58. this._manager = new FUSIONManager(this, managedEntityTypes, managedPumpIds, authorizationIdGenerator, DeviceStatusController);
  59. fuelPriceReserved = false;
  60. siteOpened = true;
  61. DebugLog("Creating ReadDeviceStatusController");
  62. }
  63. private void DebugLog(string s)
  64. {
  65. if (debugLogger.IsActive())
  66. debugLogger.Add(s);
  67. }
  68. public void ActivateFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  69. {
  70. DebugLog("ActivateFuelPricesAsync init");
  71. int iFuelGrade;
  72. decimal price;
  73. ServiceRequestChangeFuelPrice sr = new ServiceRequestChangeFuelPrice();
  74. foreach (FUSIONFuelPrice fuelprice in WritableFuelPriceList)
  75. {
  76. try
  77. {
  78. Monitor.Enter(fuelprice.locker);
  79. iFuelGrade = fuelprice.WritableFuelGrade;
  80. DebugLog(string.Format("fuelGrade={0}, ((FUSIONFuelPrice)fuelprice).Changed={1}", fuelprice.WritableFuelGrade, fuelprice.Changed));
  81. if (fuelprice.Changed)
  82. {
  83. for (int pg = PriceGroup.MinValue; pg <= PriceGroup.MaxValue; pg++)
  84. {
  85. FUSIONFuelPriceAddPricePerPriceGroup pgd = (FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta);
  86. DebugLog(string.Format("pg = {0}, pgd.getChanged(mode)={1}", pg, pgd.getChanged(pg)));
  87. if (pgd.getChanged(pg))
  88. {
  89. price = fuelprice.BasePrice + fuelprice.GeneralPriceDelta +
  90. fuelprice.PriceGroupDelta[pg];
  91. // Get Fuel Modes that use this price group
  92. var fuelModes = manager.forecourtControl.ForecourtConfiguration.GetFuelModes(pg);
  93. foreach (var mode in fuelModes)
  94. {
  95. this._manager.ifsfManager.ChangeFuelPriceAdd(sr, fuelprice.WritableFuelGrade, price,
  96. mode);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. catch (Exception ex)
  103. {
  104. DebugLog("ActivateFuelPricesAsync Exception! " + ex);
  105. }
  106. finally
  107. {
  108. Monitor.Exit(fuelprice.locker);
  109. }
  110. }
  111. this._manager.ifsfManager.ChangeFuelPriceSend(sr, null, null, null);
  112. foreach (IFuelPrice fuelprice in FuelPrices)
  113. {
  114. ((FUSIONFuelPrice)fuelprice).WritableReserved = false;
  115. }
  116. srChangeMode = null;
  117. fuelPriceReserved = false;
  118. if (requestCompleted != null)
  119. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  120. DebugLog("ActivateFuelPricesAsync end");
  121. }
  122. public void SetFuelPriceAsync(IList<IFuelPriceReading> newFuelPrices,
  123. EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  124. {
  125. DebugLog("SetFuelPriceAsync init");
  126. var sr = new ServiceRequestChangeFuelPrice();
  127. foreach (var newFuelPrice in newFuelPrices.OfType<FuelPriceReading>())
  128. {
  129. try
  130. {
  131. var fuelMode =
  132. manager.forecourtControl.ForecourtConfiguration.GetDefaultFuelMode(newFuelPrice.PriceGroup);
  133. DebugLog(string.Format("fuelGrade={0}, fuelprice={1}, mode={2}", newFuelPrice.Fuelgrade, newFuelPrice.Price, fuelMode));
  134. this._manager.ifsfManager.ChangeFuelPriceAdd(sr, newFuelPrice.Fuelgrade, newFuelPrice.Price, fuelMode);
  135. }
  136. catch (Exception ex)
  137. {
  138. DebugLog("SetFuelPriceAsync Exception! " + ex);
  139. }
  140. }
  141. this._manager.ifsfManager.ChangeFuelPriceSend(sr, requestCompleted, userToken, null);
  142. DebugLog("SetFuelPriceAsync end");
  143. }
  144. public void CloseReconciliationPeriodAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted,
  145. object userToken)
  146. {
  147. DebugLog("CloseReconciliationPeriodAsync init");
  148. this._manager.ifsfManager.CloseReconciliationPeriodAsyncSend(requestCompleted, userToken, null);
  149. DebugLog("CloseReconciliationPeriodAsync end");
  150. }
  151. public void Connect(string connectionString)
  152. {
  153. this.connectionString = connectionString;
  154. Thread runConnectThread = new Thread(ConnectThreadProc);
  155. runConnectThread.Start();
  156. }
  157. private void ConnectThreadProc()
  158. {
  159. this.manager.Connect(connectionString);
  160. }
  161. public void Disconnect()
  162. {
  163. this.WritableConnectionState = DeviceConnectionState.Disconnecting;
  164. this.manager.Disconnect();
  165. }
  166. public void Dispose()
  167. {
  168. this.Dispose(true);
  169. GC.SuppressFinalize(this);
  170. }
  171. private void Dispose(bool disposing)
  172. {
  173. if (disposing)
  174. {
  175. DeviceStatusController.Dispose();
  176. FUSIONFactory.Remove(this);
  177. this.manager.Dispose();
  178. debugLogger.Dispose();
  179. }
  180. }
  181. ~FUSIONForecourtControl()
  182. {
  183. this.Dispose(false);
  184. }
  185. internal void FireAlarmEvent(AlarmEventArgs args)
  186. {
  187. if (this.OnAlarm != null)
  188. {
  189. this.OnAlarm(this, args);
  190. }
  191. }
  192. internal void FireConfigurationChangeEvent(ConfigurationChangeEventArgs args)
  193. {
  194. if (this.OnConfigurationChange != null)
  195. {
  196. this.OnConfigurationChange(this, args);
  197. }
  198. }
  199. public void ReserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  200. {
  201. fuelPriceReserved = true;
  202. srChangeMode = new ServiceRequestChangeFuelMode();
  203. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  204. srChangeMode.RequestType = "ChangeFuelMode";
  205. else
  206. srChangeMode.RequestType = "ChangeFPFuelMode";
  207. foreach (IFuelPrice fuelprice in FuelPrices)
  208. {
  209. ((FUSIONFuelPrice)fuelprice).WritableReserved = true;
  210. }
  211. if (requestCompleted != null)
  212. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  213. }
  214. public void SetSiteModeAsync(int siteMode, EventHandler<AsyncCompletedEventArgs> requestCompleted,
  215. object userToken)
  216. {
  217. WritableSiteMode = siteMode;
  218. if (requestCompleted != null)
  219. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  220. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
  221. if (sValue != "")
  222. {
  223. Test();
  224. }
  225. }
  226. public void SetSiteOpenedAsync(bool opened, EventHandler<AsyncCompletedEventArgs> requestCompleted,
  227. object userToken)
  228. {
  229. if (opened)
  230. {
  231. this.manager.ifsfManager.StartForecourt(requestCompleted, userToken, this);
  232. }
  233. else
  234. this.manager.ifsfManager.StopForecourt(requestCompleted, userToken, this);
  235. }
  236. public void Test()
  237. {
  238. int par1 = -1, par2 = -1;
  239. int id = -1;
  240. int trid = -1;
  241. int nozzleId = -1;
  242. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
  243. string[] sElems;
  244. StreamReader sr = new StreamReader(ConfigurationParams.getSINPPath("ini\\") + sValue);
  245. while (sr.Peek() != -1)
  246. {
  247. sValue = sr.ReadLine();
  248. sElems = sValue.Split(',');
  249. try
  250. {
  251. if (sElems.GetLength(0) > 1)
  252. {
  253. try
  254. {
  255. par1 = Convert.ToInt32(sElems[1]);
  256. }
  257. catch (Exception ex)
  258. {
  259. }
  260. }
  261. if (sElems.GetLength(0) > 2)
  262. {
  263. try
  264. {
  265. par2 = Convert.ToInt32(sElems[2]);
  266. }
  267. catch (Exception ex)
  268. {
  269. }
  270. }
  271. sValue = sElems[0];
  272. id = par1;
  273. trid = par2;
  274. }
  275. catch (Exception ex)
  276. {
  277. }
  278. if (sValue == "StartFuelPointTest")
  279. {
  280. manager.ifsfManager.StartFuelPointTest(id, null, null, null);
  281. }
  282. else if (sValue == "EndFuelPointTest")
  283. {
  284. this.manager.ifsfManager.EndFuelPointTest(id, null, null, null);
  285. }
  286. else if (sValue == "CloseFuelPoint")
  287. {
  288. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  289. }
  290. else if (sValue == "OpenFuelPoint")
  291. {
  292. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  293. }
  294. else if (sValue == "AuthoriseFuelPoint")
  295. {
  296. AuthorizeParameters authParams = new AuthorizeParameters();
  297. authParams.PresetType = PresetType.Amount;
  298. authParams.PresetValue = 50;
  299. this.manager.ifsfManager.AuthoriseFuelPoint(id, trid, FuellingType.Unknown, 0, authParams, null,
  300. null, null);
  301. }
  302. else if (sValue == "SuspendFuelling")
  303. {
  304. FUSIONPump pump = this.manager.GetPumpById(id);
  305. if (pump != null)
  306. pump.SuspendAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_SuspendResult), null);
  307. //this.manager.ifsfManager.SuspendFuelling(id, null, null);
  308. }
  309. else if (sValue == "ResumeFuelling")
  310. {
  311. FUSIONPump pump = this.manager.GetPumpById(id);
  312. if (pump != null)
  313. pump.ResumeAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ResumeResult), null);
  314. //this.manager.ifsfManager.ResumeFuelling(id, null, null);
  315. }
  316. else if (sValue == "TerminateFuelling")
  317. {
  318. this.manager.ifsfManager.TerminateFuelling(id, null, null, null);
  319. }
  320. else if (sValue == "LogOff")
  321. {
  322. this.manager.ifsfManager.LogOff();
  323. }
  324. else if (sValue == "LogOn")
  325. {
  326. this.manager.ifsfManager.LogOn("", "");
  327. }
  328. else if (sValue == "GetFuelMode")
  329. {
  330. this.manager.ifsfManager.GetFuelMode(id, null, null, null);
  331. }
  332. else if (sValue == "GetModeTable")
  333. {
  334. this.manager.ifsfManager.GetModeTable(null, null, null);
  335. }
  336. else if (sValue == "ClearFuelSaleTrx")
  337. {
  338. this.manager.ifsfManager.ClearFuelSaleTrx(id, trid, 0, "", null, null, null);
  339. }
  340. else if (sValue == "LockFuelSaleTrx")
  341. {
  342. this.manager.ifsfManager.LockFuelSaleTrx(id, trid, 0, null, null, null);
  343. }
  344. else if (sValue == "UnlockFuelSaleTrx")
  345. {
  346. this.manager.ifsfManager.UnlockFuelSaleTrx(id, trid, 0, null, null, null);
  347. }
  348. else if (sValue == "getCountrySetting")
  349. {
  350. this.manager.ifsfManager.GetCountrySettings(null, null, null);
  351. }
  352. else if (sValue == "GetCurrentFuellingStatus")
  353. {
  354. this.manager.ifsfManager.GetCurrentFuellingStatus(id, null, null, null);
  355. }
  356. else if (sValue == "LockNozzle")
  357. {
  358. this.manager.ifsfManager.LockNozzle(id, nozzleId, null, null, null);
  359. }
  360. else if (sValue == "UnlockNozzle")
  361. {
  362. this.manager.ifsfManager.UnlockNozzle(id, nozzleId, null, null, null);
  363. }
  364. else if (sValue == "GetDeviceState")
  365. {
  366. this.manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser, id, null,
  367. null, null);
  368. }
  369. else if (sValue == "GetFuelPointTotals")
  370. {
  371. nozzleId = par2;
  372. this.manager.ifsfManager.GetFuelPointTotals(id, nozzleId, null, null, null);
  373. }
  374. else if (sValue == "CloseFuelPoint")
  375. {
  376. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  377. }
  378. else if (sValue == "OpenFuelPoint")
  379. {
  380. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  381. }
  382. else if (sValue == "ReserveFuelPoint")
  383. {
  384. FUSIONPump pump = this.manager.GetPumpById(id);
  385. if (pump != null)
  386. pump.ReserveAsync(FuellingType.Unknown, 0,
  387. new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ReserveResult), null);
  388. //this.manager.ifsfManager.ReserveFuelPoint(id, null, null);
  389. }
  390. else if (sValue == "FreeFuelPoint")
  391. {
  392. FUSIONPump pump = this.manager.GetPumpById(id);
  393. if (pump != null)
  394. pump.UnreserveAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_UnreserveResult),
  395. null);
  396. //this.manager.ifsfManager.FreeFuelPoint(id, null, null);
  397. }
  398. else if (sValue == "GetFuelSaleTrxDetails")
  399. {
  400. this.manager.ifsfManager.GetFuelSaleTrxDetails(id, trid, 0, null, null, null);
  401. }
  402. else if (sValue == "GetAvailableFuelSaleTrxs")
  403. {
  404. this.manager.ifsfManager.GetAvailableFuelSaleTrxs(id, null, null, null);
  405. }
  406. else if (sValue == "ChangeFuelMode")
  407. {
  408. int priceGroup = par2;
  409. this.manager.ifsfManager.ChangeFuelMode(id, priceGroup, 0, null, null, null);
  410. }
  411. else if (sValue == "SendConfig")
  412. {
  413. this.manager.ifsfManager.SendConfig(sElems[1], null, null, null);
  414. }
  415. else
  416. {
  417. }
  418. }
  419. sr.Close();
  420. }
  421. private void Test_SuspendResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  422. {
  423. try
  424. {
  425. IPump pump = (IPump)completed.UserToken;
  426. if (pump != null)
  427. {
  428. DebugLog(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  429. }
  430. }
  431. catch (Exception ex)
  432. {
  433. DebugLog(string.Format("EXCEPTION! {0}", ex));
  434. }
  435. }
  436. private void Test_ResumeResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  437. {
  438. try
  439. {
  440. IPump pump = (IPump)completed.UserToken;
  441. if (pump != null)
  442. {
  443. DebugLog(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  444. }
  445. }
  446. catch (Exception ex)
  447. {
  448. DebugLog(string.Format("EXCEPTION! {0}", ex));
  449. }
  450. }
  451. private void Test_ReserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  452. {
  453. try
  454. {
  455. IPump pump = (IPump)completed.UserToken;
  456. if (pump != null)
  457. {
  458. DebugLog(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  459. }
  460. }
  461. catch (Exception ex)
  462. {
  463. DebugLog(string.Format("EXCEPTION! {0}", ex));
  464. }
  465. }
  466. private void Test_UnreserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  467. {
  468. try
  469. {
  470. IPump pump = (IPump)completed.UserToken;
  471. if (pump != null)
  472. {
  473. DebugLog(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  474. }
  475. }
  476. catch (Exception ex)
  477. {
  478. DebugLog(string.Format("EXCEPTION! {0}", ex));
  479. }
  480. }
  481. public override string ToString()
  482. {
  483. return ("Forecourt Control ClientId=" + this.ClientId.ToString(CultureInfo.InvariantCulture));
  484. }
  485. public void UnreserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  486. {
  487. //if (this.manager.forecourtControl.fuelPriceReserved)
  488. // this.manager.ifsfManager.ChangeFuelModeSend(this.manager.forecourtControl.srChangeMode, requestCompleted,
  489. // userToken, this);
  490. foreach (IFuelPrice fuelprice in FuelPrices)
  491. {
  492. ((FUSIONFuelPrice)fuelprice).WritableReserved = false;
  493. }
  494. if (requestCompleted != null && !this.manager.forecourtControl.fuelPriceReserved)
  495. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  496. srChangeMode = null;
  497. fuelPriceReserved = false;
  498. }
  499. #endregion
  500. /// <summary>
  501. /// Get Fuel prices.
  502. /// </summary>
  503. /// <param name="requestCompleted">Delegate that will be called on completion.</param>
  504. /// <param name="userToken">A user supplied object that will be returned in the requestCompleted callback</param>
  505. public void GetFuelPricesAsync(
  506. EventHandler<Wayne.Lib.AsyncCompletedEventArgs<IList<IFuelPriceReading>>> requestCompleted, object userToken)
  507. {
  508. DebugLog("GetFuelPricesAsync init");
  509. this.manager.ifsfManager.GetFuelPrices(requestCompleted, userToken, this);
  510. }
  511. /// <summary>
  512. /// Get Pump Totals.
  513. /// </summary>
  514. /// <param name="requestCompleted">Delegate that will be called on completion.</param>
  515. /// <param name="userToken">A user supplied object that will be returned in the requestCompleted callback</param>
  516. public void GetPumpTotalsAsync(FuelTotalReading totalReading,
  517. EventHandler<AsyncCompletedEventArgs<PumpAccumulatorReading>> requestCompleted, object userToken)
  518. {
  519. DebugLog("GetPumpTotalsAsync init");
  520. this._manager.ifsfManager.GetPumpTotals(totalReading.DeviceClass, requestCompleted, userToken, this);
  521. }
  522. /// <summary>
  523. /// Get Tank reconciliation
  524. /// </summary>
  525. /// <param name="deviceId"></param>
  526. /// <param name="requestCompleted">Delegate that will be called on completion.</param>
  527. /// <param name="userToken">A user supplied object that will be returned in the requestCompleted callback</param>
  528. public void GetTankReconciliationAsync(int deviceId,
  529. EventHandler<Wayne.Lib.AsyncCompletedEventArgs<ITankReconciliation>> requestCompleted, object userToken)
  530. {
  531. DebugLog("GetTankReconciliationAsync init");
  532. this.manager.ifsfManager.GetTankReconciliation(deviceId, requestCompleted, userToken, this);
  533. }
  534. /// <summary>
  535. /// Get Tank delivery
  536. /// </summary>
  537. /// <param name="deviceId"></param>
  538. /// <param name="requestCompleted">Delegate that will be called on completion.</param>
  539. /// <param name="userToken">A user supplied object that will be returned in the requestCompleted callback</param>
  540. public void GetTankDeliveryAsync(int deviceId,
  541. EventHandler<Wayne.Lib.AsyncCompletedEventArgs<ITankDelivery>> requestCompleted, object userToken)
  542. {
  543. DebugLog("GetTankDeliveryAsync init");
  544. this.manager.ifsfManager.GetTankDelivery(deviceId, requestCompleted, userToken, this);
  545. }
  546. #region Properties
  547. public int ClientId
  548. {
  549. get { return int.Parse(this.manager.ifsfManager.clientSocket.applicationSender); }
  550. }
  551. public string ClientName
  552. {
  553. get { return this.clientName; }
  554. }
  555. public DeviceConnectionState ConnectionState
  556. {
  557. get { return this.connectionState; }
  558. }
  559. public string EntitySubType
  560. {
  561. get { return ""; }
  562. }
  563. public string EntityType
  564. {
  565. get { return "FUSIONForecourtControl"; }
  566. }
  567. /// <summary>
  568. /// This is used by the logger and should never be set by inheriting classes
  569. /// </summary>
  570. public string FullEntityName { get; set; }
  571. public ReadOnlyCollection<IFuelPrice> FuelPrices
  572. {
  573. get { return new ReadOnlyCollection<IFuelPrice>(new List<IFuelPrice>(this.fuelPriceList)); }
  574. }
  575. public ReadOnlyCollection<IFuelPriceReading> FuelPriceReadings
  576. {
  577. get { return this.manager.FuelPriceReadings.AsReadOnly(); }
  578. }
  579. public int Id
  580. {
  581. get { return this.id; }
  582. set { id = value; }
  583. }
  584. public IIdentifiableEntity ParentEntity
  585. {
  586. get { return null; }
  587. }
  588. public ReadOnlyCollection<IPricePole> PricePoles
  589. {
  590. get { return this.pricePoleList.AsReadOnly(); }
  591. }
  592. public ReadOnlyCollection<IPumpEx> Pumps
  593. {
  594. get { return this.pumpList.AsReadOnly(); }
  595. }
  596. public ReadOnlyCollection<IFuelProduct> FuelProducts
  597. {
  598. get { return this.WritableFuelProducts.AsReadOnly(); }
  599. }
  600. public int SiteMode
  601. {
  602. get { return this.siteMode; }
  603. }
  604. public bool SiteOpened
  605. {
  606. get { return this.siteOpened; }
  607. }
  608. public ReadOnlyCollection<ITankGroup> TankGroups
  609. {
  610. get { return this.tankGroupList.AsReadOnly(); }
  611. }
  612. internal DeviceConnectionState WritableConnectionState
  613. {
  614. get { return this.connectionState; }
  615. set
  616. {
  617. DebugLog(string.Format("old connectionState={0}, new connectionState={1}", this.connectionState, value));
  618. if (this.connectionState != value)
  619. {
  620. this.connectionState = value;
  621. if (this.OnConnectionStateChange != null)
  622. {
  623. this.OnConnectionStateChange(this, new ConnectionChangedEventArgs(value));
  624. }
  625. }
  626. }
  627. }
  628. internal List<IFuelPrice> WritableFuelPriceList
  629. {
  630. get { return this.fuelPriceList; }
  631. }
  632. internal List<IPricePole> WritablePricePoleList
  633. {
  634. get { return this.pricePoleList; }
  635. }
  636. internal List<IPumpEx> WritablePumpList
  637. {
  638. get { return this.pumpList; }
  639. }
  640. internal List<IFuelProduct> WritableFuelProducts
  641. {
  642. get { return fuelProducts; }
  643. }
  644. internal int WritableSiteMode
  645. {
  646. get
  647. {
  648. return this.siteMode;
  649. }
  650. set
  651. {
  652. if (this.siteMode != value)
  653. {
  654. this.siteMode = value;
  655. if (this.OnSiteModeChange != null)
  656. {
  657. this.OnSiteModeChange(this, new SiteModeChangeEventArgs(this.siteMode, this.siteOpened));
  658. }
  659. }
  660. }
  661. }
  662. internal List<ITankGroup> WritableTankGroupList
  663. {
  664. get { return this.tankGroupList; }
  665. }
  666. public IFuelPrice getFuelPriceByProductId(int productId)
  667. {
  668. foreach (FUSIONFuelPrice fuelprice in WritableFuelPriceList)
  669. {
  670. if (productId == fuelprice.WritableFuelGrade)
  671. return fuelprice;
  672. }
  673. return null;
  674. }
  675. public IForecourtConfiguration ForecourtConfiguration { get; internal set; }
  676. #endregion
  677. #region IForecourtControl Members
  678. public void ReservePumpClusterAsync(int terminalDeviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted,
  679. object userToken)
  680. {
  681. throw new NotImplementedException();
  682. }
  683. public void UnreservePumpClusterAsync(int terminalDeviceId,
  684. EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  685. {
  686. throw new NotImplementedException();
  687. }
  688. public void SendDeviceAlarmAsync(int terminalDeviceId, string deviceClassType, IEnumerable<int> alarmIds,
  689. IEnumerable<string> messages,
  690. EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  691. {
  692. manager.ifsfManager.SetDeviceAlarm(deviceClassType, terminalDeviceId, alarmIds, messages, requestCompleted,
  693. userToken, this);
  694. }
  695. #endregion
  696. public void ReadStatusBeforeSetConnectionState(DeviceConnectionState deviceConnectionState)
  697. {
  698. if (deviceConnectionState == DeviceConnectionState.Connected)
  699. {
  700. DeviceStatusController.Start();
  701. }
  702. else
  703. {
  704. WritableConnectionState = deviceConnectionState;
  705. }
  706. }
  707. }
  708. }