FUSIONFuelling.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. using System;
  2. using System.Globalization;
  3. using Wayne.Lib;
  4. using Wayne.Lib.Log;
  5. namespace Wayne.ForecourtControl.Fusion
  6. {
  7. /*internal*/
  8. public class FUSIONFuelling : IFuellingEx
  9. {
  10. // Fields
  11. private decimal amount;
  12. private long authorizationId;
  13. private DateTime completionDateTime;
  14. private int completionReason;
  15. private int fuelGrade;
  16. private int transactionId;
  17. private int fuellingSequenceNumber;
  18. private int fuelPeriodId;
  19. private FUSIONManager manager;
  20. private int nfsFillingType;
  21. private FUSIONPump nfsPump;
  22. private INozzle nozzle;
  23. private PresetType presetType;
  24. private decimal presetValue;
  25. private decimal price;
  26. private PriceGroup priceGroup;
  27. private decimal quantity;
  28. private int reservedBy;
  29. private int authorizedBy;
  30. private FuellingState state;
  31. private FuellingType type;
  32. private ushort _CRC;
  33. private string signedReceiptLines;
  34. private string signedReceiptLinesWide;
  35. private byte reservingDeviceId;
  36. private FuellingType reservingType;
  37. internal string origMessageXml = null;
  38. private readonly DebugLogger debugLogger;
  39. // Methods
  40. internal FUSIONFuelling(FUSIONManager manager, FUSIONPump pump)
  41. {
  42. this.manager = manager;
  43. this.nfsPump = pump;
  44. this.fuelGrade = 1;
  45. this.presetType = PresetType.Amount;
  46. this.priceGroup = ForecourtControl.PriceGroup.Unknown;
  47. this.WritableReservedBy = 0;
  48. this.WritableAuthorizedBy = 0;
  49. this.WritableState = FuellingState.Unknown;
  50. debugLogger = manager.DebugLogger;
  51. }
  52. internal void Dispose()
  53. {
  54. this.manager = null;
  55. }
  56. private void DebugLog(string s)
  57. {
  58. if (debugLogger.IsActive())
  59. debugLogger.Add(s);
  60. }
  61. /// <summary>
  62. /// Gets the orig message XML.
  63. /// </summary>
  64. /// <value>
  65. /// The orig message XML.
  66. /// </value>
  67. public string OrigMessageXml
  68. {
  69. get { return origMessageXml; }
  70. }
  71. public void ReserveAsync(EventHandler<AsyncCompletedEventArgs> fuellingReserveCompleted, object userToken)
  72. {
  73. // call LockFuelSaleTrx
  74. // this.WritableReservedBy = this.manager.Id;
  75. this.manager.ifsfManager.LockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.TransactionId, (int)(this.AuthorizationId), fuellingReserveCompleted, userToken, this);
  76. }
  77. private void SendFillingRequest(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, ushort fid)
  78. {
  79. throw new NotImplementedException("SendFillingRequest - TODO");
  80. }
  81. public void SetAsPaidAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  82. {
  83. // call ClearFuelSaleTrx
  84. DebugLog(string.Format("SetAsPaidAsync: transactionId={0}, fuellingSequenceNumber={1}, State={2}", this.transactionId, this.fuellingSequenceNumber, State));
  85. this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.TransactionId, (int)(this.AuthorizationId), "", requestCompleted, userToken, this);
  86. }
  87. public void SetAsPaidAsync(string note, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  88. {
  89. // call ClearFuelSaleTrx
  90. DebugLog(string.Format("SetAsPaidAsync: transactionId={0}, fuellingSequenceNumber={1}, State={2}", this.transactionId, this.fuellingSequenceNumber, State));
  91. this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.TransactionId, (int)(this.AuthorizationId), note, requestCompleted, userToken, this);
  92. }
  93. public override string ToString()
  94. {
  95. return this.ToString("", CultureInfo.InvariantCulture);
  96. }
  97. public string ToString(IFormatProvider provider)
  98. {
  99. return this.ToString("", provider);
  100. }
  101. public string ToString(string format)
  102. {
  103. return this.ToString(format, CultureInfo.InvariantCulture);
  104. }
  105. public string ToString(string format, IFormatProvider provider)
  106. {
  107. return ("Fuelling, Pump=" + this.nfsPump.Id.ToString(CultureInfo.InvariantCulture) + " SqN=" + this.fuellingSequenceNumber.ToString(CultureInfo.InvariantCulture) + " AuthId=" + this.authorizationId.ToString(CultureInfo.InvariantCulture));
  108. }
  109. public void TransferAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  110. {
  111. // does nothing on transfer operation but setting fuelling on state Transferred
  112. DebugLog(string.Format("TransferAsync: transactionId={0}, fuellingSequenceNumber={1}, State={2}", this.transactionId, this.fuellingSequenceNumber, State));
  113. if (this.State != FuellingState.Transferred)
  114. {
  115. this.WritableState = FuellingState.Transferred;
  116. this.nfsPump.FireFuellingStateChange(this, this.WritableState);
  117. }
  118. if (requestCompleted != null)
  119. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  120. }
  121. public void UndoTransferAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  122. {
  123. // does nothing on undotransfer operation but resetting fuelling on state PayableTransaction
  124. if (this.State == FuellingState.Transferred)
  125. this.WritableState = FuellingState.PayableTransaction;
  126. if (requestCompleted != null)
  127. requestCompleted(this, new AsyncCompletedEventArgs(true, userToken));
  128. }
  129. public void UnreserveAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  130. {
  131. // call UnlockFuelSaleTrx
  132. //this.WritableReservedBy = 0;
  133. this.manager.ifsfManager.UnlockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.TransactionId, (int)(this.AuthorizationId), requestCompleted, userToken, this);
  134. }
  135. // Properties
  136. public decimal Amount
  137. {
  138. get
  139. {
  140. return this.amount;
  141. }
  142. }
  143. public long AuthorizationId
  144. {
  145. get
  146. {
  147. return this.authorizationId;
  148. }
  149. }
  150. public DateTime CompletionDateTime
  151. {
  152. get
  153. {
  154. return this.completionDateTime;
  155. }
  156. }
  157. public int CompletionReason
  158. {
  159. get
  160. {
  161. return this.completionReason;
  162. }
  163. }
  164. private bool Disposed
  165. {
  166. get
  167. {
  168. return (this.manager == null);
  169. }
  170. }
  171. public int FuelGrade
  172. {
  173. get
  174. {
  175. if (manager.FuelGradeShift != 0)
  176. return this.fuelGrade + manager.FuelGradeShift;
  177. else
  178. return this.fuelGrade;
  179. }
  180. }
  181. public int TransactionId
  182. {
  183. get
  184. {
  185. return this.transactionId;
  186. }
  187. }
  188. public int FuellingSequenceNumber
  189. {
  190. get
  191. {
  192. return this.fuellingSequenceNumber;
  193. }
  194. }
  195. public int FuelPeriodId
  196. {
  197. get
  198. {
  199. return this.fuelPeriodId;
  200. }
  201. }
  202. internal int NfsFillingType
  203. {
  204. get
  205. {
  206. return this.nfsFillingType;
  207. }
  208. set
  209. {
  210. this.nfsFillingType = value;
  211. }
  212. }
  213. public INozzle Nozzle
  214. {
  215. get
  216. {
  217. return this.nozzle;
  218. }
  219. }
  220. public PresetType PresetType
  221. {
  222. get
  223. {
  224. return this.presetType;
  225. }
  226. }
  227. public decimal PresetValue
  228. {
  229. get
  230. {
  231. return this.presetValue;
  232. }
  233. }
  234. public decimal Price
  235. {
  236. get
  237. {
  238. return this.price;
  239. }
  240. }
  241. public int PriceGroup
  242. {
  243. get
  244. {
  245. return (int)this.priceGroup;
  246. }
  247. }
  248. public IPump Pump
  249. {
  250. get
  251. {
  252. return this.nfsPump;
  253. }
  254. }
  255. public PumpAccumulatorReading PumpAccumulator
  256. {
  257. get
  258. {
  259. return null;
  260. }
  261. }
  262. public decimal Quantity
  263. {
  264. get
  265. {
  266. return this.quantity;
  267. }
  268. }
  269. public int ReservedBy
  270. {
  271. get
  272. {
  273. return this.reservedBy;
  274. }
  275. }
  276. public int AuthorizedBy
  277. {
  278. get
  279. {
  280. return this.authorizedBy;
  281. }
  282. }
  283. public FuellingState State
  284. {
  285. get
  286. {
  287. return this.state;
  288. }
  289. }
  290. public FuellingType Type
  291. {
  292. get
  293. {
  294. return this.type;
  295. }
  296. }
  297. public ushort CRC
  298. {
  299. get
  300. {
  301. return this._CRC;
  302. }
  303. }
  304. public string SignedReceiptLines
  305. {
  306. get
  307. {
  308. return this.signedReceiptLines;
  309. }
  310. }
  311. public string SignedReceiptLinesWide
  312. {
  313. get
  314. {
  315. return this.signedReceiptLinesWide;
  316. }
  317. }
  318. public byte ReservingDeviceId
  319. {
  320. get { return reservingDeviceId; }
  321. }
  322. internal decimal WritableAmount
  323. {
  324. get
  325. {
  326. return this.amount;
  327. }
  328. set
  329. {
  330. this.amount = value;
  331. }
  332. }
  333. internal long WritableAuthorizationId
  334. {
  335. get
  336. {
  337. return this.authorizationId;
  338. }
  339. set
  340. {
  341. this.authorizationId = value;
  342. }
  343. }
  344. internal DateTime WritableCompletionDateTime
  345. {
  346. get
  347. {
  348. return this.completionDateTime;
  349. }
  350. set
  351. {
  352. this.completionDateTime = value;
  353. }
  354. }
  355. internal int WritableCompletionReason
  356. {
  357. get
  358. {
  359. return this.completionReason;
  360. }
  361. set
  362. {
  363. this.completionReason = value;
  364. }
  365. }
  366. internal int WritableFuelGrade
  367. {
  368. get
  369. {
  370. return this.fuelGrade;
  371. }
  372. set
  373. {
  374. this.fuelGrade = value;
  375. }
  376. }
  377. internal int WritableTransactionId
  378. {
  379. get
  380. {
  381. return this.transactionId;
  382. }
  383. set
  384. {
  385. this.transactionId = value;
  386. }
  387. }
  388. internal int WritableFuellingSequenceNumber
  389. {
  390. get
  391. {
  392. return this.fuellingSequenceNumber;
  393. }
  394. set
  395. {
  396. this.fuellingSequenceNumber = value;
  397. }
  398. }
  399. internal int WritableFuelPeriodId
  400. {
  401. get
  402. {
  403. return this.fuelPeriodId;
  404. }
  405. set
  406. {
  407. this.fuelPeriodId = value;
  408. }
  409. }
  410. internal INozzle WritableNozzle
  411. {
  412. get
  413. {
  414. return this.nozzle;
  415. }
  416. set
  417. {
  418. this.nozzle = value;
  419. }
  420. }
  421. internal PresetType WritablePresetType
  422. {
  423. get
  424. {
  425. return this.presetType;
  426. }
  427. set
  428. {
  429. this.presetType = value;
  430. }
  431. }
  432. internal decimal WritablePresetValue
  433. {
  434. get
  435. {
  436. return this.presetValue;
  437. }
  438. set
  439. {
  440. this.presetValue = value;
  441. }
  442. }
  443. internal decimal WritablePrice
  444. {
  445. get
  446. {
  447. return this.price;
  448. }
  449. set
  450. {
  451. this.price = value;
  452. }
  453. }
  454. internal PriceGroup WritablePriceGroup
  455. {
  456. get
  457. {
  458. return this.priceGroup;
  459. }
  460. set
  461. {
  462. this.priceGroup = value;
  463. }
  464. }
  465. internal decimal WritableQuantity
  466. {
  467. get
  468. {
  469. return this.quantity;
  470. }
  471. set
  472. {
  473. this.quantity = value;
  474. }
  475. }
  476. internal int WritableReservedBy
  477. {
  478. get
  479. {
  480. return this.reservedBy;
  481. }
  482. set
  483. {
  484. this.reservedBy = value;
  485. }
  486. }
  487. internal int WritableAuthorizedBy
  488. {
  489. get
  490. {
  491. return this.authorizedBy;
  492. }
  493. set
  494. {
  495. this.authorizedBy = value;
  496. }
  497. }
  498. internal FuellingState WritableState
  499. {
  500. get
  501. {
  502. return this.state;
  503. }
  504. set
  505. {
  506. this.state = value;
  507. }
  508. }
  509. internal FuellingType WritableType
  510. {
  511. get
  512. {
  513. return this.type;
  514. }
  515. set
  516. {
  517. this.type = value;
  518. }
  519. }
  520. internal ushort WritableCRC
  521. {
  522. get
  523. {
  524. return this._CRC;
  525. }
  526. set
  527. {
  528. this._CRC = value;
  529. }
  530. }
  531. internal string WritableSignedReceiptLines
  532. {
  533. get
  534. {
  535. return this.signedReceiptLines;
  536. }
  537. set
  538. {
  539. this.signedReceiptLines = value;
  540. }
  541. }
  542. internal string WritableSignedReceiptLinesWide
  543. {
  544. get
  545. {
  546. return this.signedReceiptLinesWide;
  547. }
  548. set
  549. {
  550. this.signedReceiptLinesWide = value;
  551. }
  552. }
  553. internal byte WritableReservingDeviceId
  554. {
  555. get { return reservingDeviceId; }
  556. set { reservingDeviceId = value; }
  557. }
  558. internal FuellingType WritableReservingType
  559. {
  560. get { return reservingType; }
  561. set { reservingType = value; }
  562. }
  563. public int convertStatus(int status)
  564. {
  565. // TODO
  566. return status;
  567. }
  568. #region IFuelling Members
  569. public byte PriceRevision
  570. {
  571. get { return 0; }
  572. }
  573. #endregion
  574. }
  575. }