Eps.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
  2. using NozzleLockConfiguration;
  3. using SinochemCarplateService.Models;
  4. using SinochemCloudClient.Models;
  5. using SinoChemFC2PosProxy;
  6. using SinochemInternetPlusApp.EpsTrxCleanup;
  7. using SinochemPosClient.Models;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml.Serialization;
  15. using Wayne.FDCPOSLibrary;
  16. using Wayne.Lib;
  17. using Wayne.Lib.Log;
  18. using WayneChina_IcCardReader_SinoChem.MessageEntity;
  19. using WayneChina_IcCardReader_SinoChem.MessageEntity.Incoming;
  20. namespace SinochemInternetPlusApp
  21. {
  22. public class Eps : IDisposable
  23. {
  24. static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Application");
  25. private IEnumerable<GenericDeviceProcessor<System.String, Edge.Core.Parser.HttpMessageParser.BaseHttpMessage<System.String>>> carPlateProcessors;
  26. private IEnumerable<GenericDeviceProcessor<System.Byte[], WayneChina_IcCardReader_SinoChem.MessageEntity.IcCardReaderMessageBase>> icCardReaderProcessors;
  27. private List<FuelingPoint> fuelingPoints;
  28. private EpsTrxCleanupManager epsTrxCleanupManager;
  29. //protected DebugLogger debugLogger;
  30. private int requestId;
  31. private object requestSyncObj = new object();
  32. #region devices and services
  33. private IEnumerable<IFdcPumpController> pumpControllers;
  34. private Sinochem_CarPlateRecognizeCamera_HuLianWangJia.Handler carPlateServer;
  35. private IEnumerable<WayneChina_IcCardReader_SinoChem.Handler> cardReaderHandlers;
  36. //private FdcCommunicator fccClient;
  37. private CloudManager cloudManager;
  38. private PosManager posManger;
  39. #endregion
  40. #region constants
  41. public int InvalidNozzleId { get { return 9999; } }
  42. #endregion
  43. #region Constructor
  44. public Eps(IEnumerable<int> fpIds, Dictionary<int, IEnumerable<int>> fpNozzlesDict,
  45. IEnumerable<IFdcPumpController> pumpControllers,
  46. IEnumerable<GenericDeviceProcessor<System.String, Edge.Core.Parser.HttpMessageParser.BaseHttpMessage<System.String>>> carPlateProcessors,
  47. IEnumerable<GenericDeviceProcessor<System.Byte[], WayneChina_IcCardReader_SinoChem.MessageEntity.IcCardReaderMessageBase>> icCardReaderProcessors)
  48. {
  49. var identifiableEntity = new IdentifiableEntity(0, "EpsMain", "", null);
  50. fuelingPoints = new List<FuelingPoint>(fpIds.Count());
  51. foreach (int nozzleId in fpIds)
  52. {
  53. fuelingPoints.Add(new FuelingPoint(nozzleId, fpNozzlesDict[nozzleId], this));
  54. }
  55. epsTrxCleanupManager = new EpsTrxCleanupManager(this);
  56. cloudManager = new CloudManager();
  57. posManger = new PosManager();
  58. NozzleLockAccessor.FillinNozzles(fpNozzlesDict);
  59. this.pumpControllers = pumpControllers;
  60. this.carPlateProcessors = carPlateProcessors;
  61. this.icCardReaderProcessors = icCardReaderProcessors;
  62. logger.Info("eps has been constructed");
  63. logger.Info(string.Format($"{this.pumpControllers.Count()} processors were loaded."));
  64. foreach (var proc in this.pumpControllers)
  65. {
  66. logger.Debug(proc.GetType().ToString());
  67. }
  68. }
  69. internal TrxNotificationResponse NotifySuccessfulTrxToPos(EpsTransactionModel model, DebugLogger debugLogger)
  70. {
  71. return posManger.NotifyPosSuccessfulTrx(model, debugLogger);
  72. }
  73. internal PaymentResponse SendPaymentToCloud(EpsTransactionModel currentEpsTrxModel, DebugLogger debugLogger)
  74. {
  75. return cloudManager.Payment(currentEpsTrxModel, debugLogger);
  76. }
  77. internal BalanceInquiryResponse SendBalanceInquiryToCloud(string cardNo, string encryptedPin, string tid, int nozzleId, DebugLogger debugLogger)
  78. {
  79. return cloudManager.BalanceInquiry(cardNo, encryptedPin, tid, nozzleId, debugLogger);
  80. }
  81. #endregion
  82. public void Run()
  83. {
  84. SetupICCardReaderHandler();
  85. if (fuelingPoints != null)
  86. {
  87. foreach (var fp in fuelingPoints)
  88. {
  89. fp.Start();
  90. }
  91. }
  92. epsTrxCleanupManager.Start();
  93. SetupFccClient();
  94. SetupCarplateServer();
  95. }
  96. private void SetupFccClient()
  97. {
  98. //SinoChemFC2PosProxy.EntryPoint.Main(null);
  99. //fccClient = SinoChemFC2PosProxy.EntryPoint.FdcComm;
  100. foreach (var pumpController in this.pumpControllers)
  101. {
  102. pumpController.OnStateChange += (s, a) =>
  103. {
  104. var pump = s as IFdcPumpController;
  105. if (a.NewPumpState == LogicalDeviceState.FDC_CALLING)
  106. {
  107. int sitewiseNozzleId =
  108. SiteConfigUtility.Default.GetSiteLevelNozzleIdByLogicalNozzleId(pump.PumpId, a.StateChangedNozzles.FirstOrDefault()?.LogicalId ?? 0);
  109. this.FccClient_NozzleLifted(sitewiseNozzleId, pump);
  110. }
  111. else if (a.NewPumpState == LogicalDeviceState.FDC_READY)
  112. {
  113. int sitewiseNozzleId =
  114. SiteConfigUtility.Default.GetSiteLevelNozzleIdByLogicalNozzleId(pump.PumpId, a.StateChangedNozzles.FirstOrDefault()?.LogicalId ?? 0);
  115. this.FccClient_NozzleReplaced(sitewiseNozzleId);
  116. }
  117. else if (a.NewPumpState == LogicalDeviceState.FDC_AUTHORISED)
  118. {
  119. int sitewiseNozzleId =
  120. SiteConfigUtility.Default.GetSiteLevelNozzleIdByLogicalNozzleId(pump.PumpId, a.StateChangedNozzles.FirstOrDefault()?.LogicalId ?? 0);
  121. this.FccClient_AuthOk(sitewiseNozzleId, 1999);
  122. }
  123. };
  124. }
  125. foreach (var pumpController in this.pumpControllers)
  126. {
  127. pumpController.OnCurrentFuellingStatusChange += (s, a) =>
  128. {
  129. var pump = s as IFdcPumpController;
  130. if (a.Transaction.Finished)
  131. {
  132. int sitewiseNozzleId =
  133. SiteConfigUtility.Default.GetSiteLevelNozzleIdByLogicalNozzleId(pump.PumpId, a.Transaction.Nozzle.LogicalId);
  134. this.FccClient_FuelingDone(sitewiseNozzleId, a.Transaction.SequenceNumberGeneratedOnPhysicalPump, a.Transaction.Amount, a.Transaction.Volumn, 1999);
  135. }
  136. };
  137. }
  138. //if (fccClient != null)
  139. //{
  140. // //fccClient.NozzleLifted += FccClient_NozzleLifted;
  141. // //fccClient.NozzleReplaced += FccClient_NozzleReplaced;
  142. // fccClient.AuthOk += FccClient_AuthOk;
  143. // fccClient.AuthFailed += FccClient_AuthFailed;
  144. // fccClient.FuelingDone += FccClient_FuelingDone;
  145. //}
  146. //else
  147. //{
  148. // Console.WriteLine("FdcClient not available!!");
  149. //}
  150. }
  151. // find car plate handler and listen to the new car plate event
  152. private void SetupCarplateServer()
  153. {
  154. carPlateServer = carPlateProcessors.Select(proc => (Sinochem_CarPlateRecognizeCamera_HuLianWangJia.Handler)proc.Context.Handler)
  155. .FirstOrDefault();
  156. if (carPlateServer != null)
  157. {
  158. carPlateServer.NewCarPlateScanned += CarPlateServer_NewCarPlateScanned;
  159. carPlateServer.OnMessageReceivedViaFdc += (msg) =>
  160. {
  161. logger.Debug($"fdc message:\n {msg}");
  162. if (msg.Length > 10 && msg.StartsWith("<Tran"))
  163. {
  164. var serializer = new XmlSerializer(typeof(TransactionOperation));
  165. using (var reader = new StringReader(msg))
  166. {
  167. var trxOpRequest = (TransactionOperation)serializer.Deserialize(reader);
  168. if (trxOpRequest != null)
  169. {
  170. foreach (var fp in fuelingPoints)
  171. {
  172. fp.SignalTrxOpRequest(trxOpRequest);
  173. }
  174. }
  175. }
  176. }
  177. else
  178. {
  179. var serializer = new XmlSerializer(typeof(DisplayResponse));
  180. using (var reader = new StringReader(msg))
  181. {
  182. var displayResp = (DisplayResponse)serializer.Deserialize(reader);
  183. logger.Debug($"Display Response, id = {displayResp.RequestId}");
  184. if (displayResp != null && displayResp.OverallResult == ResultType.Success)
  185. {
  186. foreach (var fp in fuelingPoints)
  187. {
  188. if (fp.ContainsRequestId(displayResp.RequestId))
  189. fp.SignalDisplayResponseReceived(displayResp);
  190. }
  191. }
  192. }
  193. }
  194. return new Tuple<string, OverallResult>("DisplayResponse ACK", OverallResult.Success);
  195. };
  196. }
  197. else
  198. {
  199. Console.WriteLine("carPlateServer not found!!!");
  200. logger.Info("carPlateServer not found!!!");
  201. }
  202. }
  203. private void CarPlateServer_NewCarPlateScanned(CarPlateTrxRequest request)
  204. {
  205. int sitewiseNozzleId = InvalidNozzleId;
  206. try
  207. {
  208. sitewiseNozzleId = int.Parse(request.gun);
  209. }
  210. catch (Exception ex)
  211. { }
  212. if (IsNozzleConfiguredOpen(sitewiseNozzleId))
  213. {
  214. var fp = GetFp(sitewiseNozzleId);
  215. fp?.SignalNewCarplate(request);
  216. }
  217. else
  218. {
  219. logger.Info
  220. (string.Format($"Physical nozzle# {sitewiseNozzleId} is closed, so we ignore the car plate event!!!"));
  221. }
  222. }
  223. private void SetupICCardReaderHandler()
  224. {
  225. cardReaderHandlers = icCardReaderProcessors.Select(proc => (WayneChina_IcCardReader_SinoChem.Handler)proc.Context.Handler);
  226. if (cardReaderHandlers != null && cardReaderHandlers.Count() > 0)
  227. {
  228. foreach (var handler in cardReaderHandlers)
  229. {
  230. handler.OnCardReaderMessageReceived += Handler_OnCardReaderMessageReceived;
  231. }
  232. }
  233. else
  234. {
  235. Console.WriteLine("card reader handlers not found!!");
  236. logger.Info("card reader handlers not found!!");
  237. }
  238. }
  239. private void Handler_OnCardReaderMessageReceived(object sender, WayneChina_IcCardReader_SinoChem.CardReaderMessageEventArgs e)
  240. {
  241. logger.Info($"Receiving Card Reader message {e.CardReaderMessage.GetType().ToString()} for FP id = {e.FuelingPointId}");
  242. var targetFP = fuelingPoints.First(_ => _.FuelingPointId == e.FuelingPointId);//GetFp(e.NozzleId);
  243. if (e.CardReaderMessage is ACK)
  244. {
  245. targetFP?.SingalAckReceived((ACK)e.CardReaderMessage);
  246. }
  247. else if (e.CardReaderMessage is SignDataResponse)
  248. {
  249. targetFP?.SignalSignedDataArrived((SignDataResponse)e.CardReaderMessage);
  250. }
  251. else if (e.CardReaderMessage is CardReaderStateEvent)
  252. {
  253. targetFP?.SingalCardReaderStateEvent((CardReaderStateEvent)e.CardReaderMessage);
  254. }
  255. else if (e.CardReaderMessage is CardExternalCheckErrorRequest)
  256. {
  257. targetFP?.SignalCardExternalCheckFailure((CardExternalCheckErrorRequest)e.CardReaderMessage);
  258. }
  259. else if (e.CardReaderMessage is CardOnlineVerificationRequest)
  260. {
  261. targetFP?.SignalCardOnlineVerification((CardOnlineVerificationRequest)e.CardReaderMessage);
  262. }
  263. else if (e.CardReaderMessage is HeartBeat)
  264. {
  265. targetFP?.SignalCardReaderHeartbeat((HeartBeat)e.CardReaderMessage);
  266. }
  267. }
  268. #region Cloud interactions
  269. internal RefundResponse SendRefundToCloud(EpsTransactionModel trxModel, DebugLogger debugLogger)
  270. {
  271. return cloudManager.Refund(trxModel, debugLogger);
  272. }
  273. internal TrxStatusInquiryResponse SendTrxQueryToCloud(EpsTransactionModel trxModel, DebugLogger debugLogger)
  274. {
  275. return cloudManager.TrxStatusInquiry(trxModel, debugLogger);
  276. }
  277. #endregion
  278. #region FDC client interactions
  279. private void FccClient_NozzleReplaced(int sitewiseNozzleId)
  280. {
  281. var fp = GetFp(sitewiseNozzleId);
  282. fp?.SignalNozzleReplaced(sitewiseNozzleId);
  283. }
  284. private void FccClient_AuthFailed(int sitewiseNozzleId)
  285. {
  286. var fp = GetFp(sitewiseNozzleId);
  287. fp?.SignalAuthFailed();
  288. }
  289. private void FccClient_AuthOk(int sitewiseNozzleId, long? authId)
  290. {
  291. var fp = GetFp(sitewiseNozzleId);
  292. fp?.SignalAuthOk(authId);
  293. }
  294. private void FccClient_NozzleLifted(int sitewiseNozzleId, IFdcPumpController callingPump)
  295. {
  296. if (IsNozzleConfiguredOpen(sitewiseNozzleId))
  297. {
  298. var fp = GetFp(sitewiseNozzleId);
  299. fp?.SignalNozzleLifted(callingPump, sitewiseNozzleId);
  300. }
  301. else
  302. {
  303. logger.Info(string.Format($"Physical nozzle# {sitewiseNozzleId} is closed, so we ignore the nozzle lift event!!!"));
  304. }
  305. }
  306. private bool IsNozzleConfiguredOpen(int sitewiseNozzleId)
  307. {
  308. return !NozzleLockAccessor.IsNozzleClosedInTermsOfSale(sitewiseNozzleId);
  309. }
  310. private void FccClient_FuelingDone(int sitewiseNozzleId, int seqNum, decimal fuelAmount, decimal fuelingQty, long authId)
  311. {
  312. var fp = GetFp(sitewiseNozzleId);
  313. fp?.SignalFuelingDone(sitewiseNozzleId, seqNum, fuelAmount, fuelingQty, authId);
  314. }
  315. public void AuthorizePumpAsync(IFdcPumpController callingPump, int sitewiseNozzleId, decimal authAmount)
  316. {
  317. callingPump.AuthorizeWithAmountAsync((int)((double)authAmount * Math.Pow(10, callingPump.AmountDecimalDigits)), 1);
  318. }
  319. #endregion
  320. private void TeardownFccClient()
  321. {
  322. //if (fccClient != null)
  323. //{
  324. // fccClient.NozzleLifted -= FccClient_NozzleLifted;
  325. // fccClient.NozzleReplaced -= FccClient_NozzleReplaced;
  326. // fccClient.AuthOk -= FccClient_AuthOk;
  327. // fccClient.AuthFailed -= FccClient_AuthFailed;
  328. // fccClient.FuelingDone -= FccClient_FuelingDone;
  329. //}
  330. }
  331. public void Shutdown()
  332. {
  333. TeardownCarplateServer();
  334. TeardownCardReaderHandler();
  335. if (fuelingPoints != null)
  336. {
  337. foreach (var fp in fuelingPoints)
  338. {
  339. fp.SignalShutdown();
  340. }
  341. }
  342. }
  343. public WayneChina_IcCardReader_SinoChem.Handler GetHandler(int nozzleId)
  344. {
  345. logger.Info($"Trying to get card reader handler for fueling point: {nozzleId}");
  346. foreach (var handler in cardReaderHandlers)
  347. {
  348. if (handler.SupportedNozzles.Contains(nozzleId))
  349. return handler;
  350. }
  351. return null;
  352. }
  353. private void TeardownCarplateServer()
  354. {
  355. if (carPlateServer != null)
  356. {
  357. carPlateServer.NewCarPlateScanned -= CarPlateServer_NewCarPlateScanned;
  358. }
  359. }
  360. private void TeardownCardReaderHandler()
  361. {
  362. if (cardReaderHandlers != null)
  363. {
  364. foreach (var handler in cardReaderHandlers)
  365. {
  366. handler.OnCardReaderMessageReceived -= Handler_OnCardReaderMessageReceived;
  367. }
  368. }
  369. }
  370. public Sinochem_CarPlateRecognizeCamera_HuLianWangJia.Handler CarPlateHandler => carPlateServer;
  371. public WayneChina_IcCardReader_SinoChem.Handler GetCardReader(int nozzleId)
  372. {
  373. return cardReaderHandlers.FirstOrDefault(h => h.SupportedNozzles.Contains(nozzleId));
  374. }
  375. public FuelingPoint GetFp(int nozzleId)
  376. {
  377. foreach (var fp in fuelingPoints)
  378. {
  379. if (fp.AssociatedNozzles != null && fp.AssociatedNozzles.Contains(nozzleId))
  380. return fp;
  381. }
  382. return null;
  383. }
  384. public FuelingPoint GetFuelingPoint(int fpId)
  385. {
  386. return fuelingPoints?.FirstOrDefault(_ => fpId == _.FuelingPointId);
  387. }
  388. public int GetNextRequestId()
  389. {
  390. lock (requestSyncObj)
  391. {
  392. if (requestId == int.MaxValue)
  393. {
  394. requestId = 0;
  395. }
  396. return requestId++;
  397. }
  398. }
  399. public string CreateDisplayTrxCommand(IEnumerable<EpsTransactionModel> epsTrxList, out int requestId, int i)
  400. {
  401. Display display;
  402. string cmdText = "";
  403. XmlSerializer serializer = new XmlSerializer(typeof(Display));
  404. MemoryStream ms;
  405. StreamReader sr;
  406. display = new Display();
  407. display.ScreenType = ScreenType.ShowTrxList;
  408. display.RequestId = GetNextRequestId();
  409. display.TimeoutSpecified = true;
  410. display.Timeout = 300;
  411. requestId = display.RequestId;
  412. display.PumpInfo = new DisplayPumpInfo
  413. {
  414. Id = 1,
  415. NozzleId = 1
  416. };
  417. int count = epsTrxList.Count();
  418. display.TrxList = new DisplayTrx[epsTrxList.Count()];
  419. for (int index = 0; index < count; index++)
  420. {
  421. display.TrxList[index] = ConvertEpsTrxModelToDisplayTrx(epsTrxList.ToArray()[index]);
  422. }
  423. ms = new MemoryStream();
  424. serializer.Serialize(ms, display);
  425. ms.Position = 0;
  426. sr = new StreamReader(ms, true);
  427. cmdText = sr.ReadToEnd();
  428. ms.Close();
  429. sr.Close();
  430. return cmdText;
  431. }
  432. public DisplayTrx ConvertEpsTrxModelToDisplayTrx(EpsTransactionModel epsTrxModel)
  433. {
  434. TrxStatus state = TrxStatus.ReadyForFillingStart;
  435. if (epsTrxModel.trx_status == EpsTrxStatus.BeforeFueling)
  436. state = TrxStatus.ReadyForFillingStart;
  437. else if (epsTrxModel.trx_status == EpsTrxStatus.BeforePayment)
  438. state = TrxStatus.PendingForPayment;
  439. else if (epsTrxModel.trx_status == EpsTrxStatus.Fueling)
  440. state = TrxStatus.FillingOngoing;
  441. else if (epsTrxModel.trx_status == EpsTrxStatus.FuelingDone)
  442. state = TrxStatus.PendingForPayment;
  443. else if (epsTrxModel.trx_status == EpsTrxStatus.PaymentOk)
  444. state = TrxStatus.Success;
  445. else if (epsTrxModel.trx_status == EpsTrxStatus.PaymentFailed)
  446. state = TrxStatus.Failed;
  447. else if (epsTrxModel.trx_status == EpsTrxStatus.PaymentNeedConfirm)
  448. state = TrxStatus.Failed;
  449. else if (epsTrxModel.trx_status == EpsTrxStatus.PaymentOkButNeedRefund)
  450. state = TrxStatus.Failed;
  451. else if (epsTrxModel.trx_status == EpsTrxStatus.PaymentRefunded)
  452. state = TrxStatus.Failed;
  453. var displayTrx = new DisplayTrx
  454. {
  455. Id = epsTrxModel.id.ToString(),
  456. State = state,
  457. TimeStamp = new DisplayTrxTimeStamp
  458. {
  459. StartTime = epsTrxModel.created_time,
  460. FinishTime = string.IsNullOrEmpty(epsTrxModel.xf_time) ?
  461. epsTrxModel.created_time :
  462. Utilities.CombineDateAndTime(epsTrxModel.xf_date, epsTrxModel.xf_time)
  463. },
  464. MemberInfo = new DisplayTrxMemberInfo
  465. {
  466. Id = epsTrxModel.cardNo_masked,
  467. LicensePlateNo = epsTrxModel.car_number
  468. },
  469. FillingInfo = new DisplayTrxFillingInfo
  470. {
  471. PumpId = 1,
  472. NozzleId = epsTrxModel.jihao,
  473. ProductNo = 1,
  474. UnitPrice = (decimal)epsTrxModel.danjia,
  475. ProductType = epsTrxModel.youpin,
  476. ProductDiscription = "汽油",
  477. Amount = (decimal)epsTrxModel.real_pay_amount,
  478. Volume = (decimal)epsTrxModel.qty,
  479. }
  480. };
  481. return displayTrx;
  482. }
  483. public string CreateDisplayCommand(ScreenType screenType)
  484. {
  485. Display display;
  486. string cmdText = "";
  487. XmlSerializer serializer = new XmlSerializer(typeof(Display));
  488. MemoryStream ms;
  489. StreamReader sr;
  490. switch (screenType)
  491. {
  492. case ScreenType.Idle:
  493. display = new Display();
  494. display.ScreenType = screenType;
  495. display.CompanyContactInfo = new DisplayCompanyContactInfo
  496. {
  497. Tel = "010-59569575",
  498. Address = "世界500强企业\n中国第四大国家石油公司"
  499. };
  500. display.StationInfo = new DisplayStationInfo
  501. {
  502. StationNo = "000001",
  503. StationName = "沈阳望花中街加油加气站"
  504. };
  505. display.PumpInfo = new DisplayPumpInfo
  506. {
  507. Id = 1,
  508. NozzleId = 1
  509. };
  510. ms = new MemoryStream();
  511. serializer.Serialize(ms, display);
  512. ms.Position = 0;
  513. sr = new StreamReader(ms, true);
  514. cmdText = sr.ReadToEnd();
  515. break;
  516. case ScreenType.Welcome:
  517. display = new Display();
  518. display.ScreenType = screenType;
  519. display.CompanyContactInfo = new DisplayCompanyContactInfo
  520. {
  521. Tel = "010-59569575",
  522. Address = "世界500强企业\n中国第四大国家石油公司"
  523. };
  524. display.MemberInfo = new DisplayMemberInfo
  525. {
  526. LicensePlateNo = "京A88888",
  527. Id = "1234567"
  528. };
  529. display.PumpInfo = new DisplayPumpInfo
  530. {
  531. Id = 1,
  532. NozzleId = 1
  533. };
  534. ms = new MemoryStream();
  535. serializer.Serialize(ms, display);
  536. ms.Position = 0;
  537. sr = new StreamReader(ms, true);
  538. cmdText = sr.ReadToEnd();
  539. break;
  540. case ScreenType.ShowTrxList:
  541. display = new Display();
  542. display.ScreenType = screenType;
  543. display.PumpInfo = new DisplayPumpInfo
  544. {
  545. Id = 1,
  546. NozzleId = 1
  547. };
  548. display.TrxList = new DisplayTrx[]
  549. {
  550. new DisplayTrx
  551. {
  552. Id = "100",
  553. FillingInfo = new DisplayTrxFillingInfo
  554. {
  555. Amount = 200,
  556. NozzleId = 1,
  557. ProductType = "95#",
  558. UnitPrice = 6.78m,
  559. Volume = 35,
  560. ProductDiscription = "汽油"
  561. },
  562. MemberInfo = new DisplayTrxMemberInfo
  563. {
  564. LicensePlateNo = "京A88888",
  565. Id = "1234567"
  566. },
  567. State = TrxStatus.Success,
  568. TimeStamp = new DisplayTrxTimeStamp
  569. {
  570. StartTime = DateTime.Now,
  571. FinishTime =DateTime.Now
  572. }
  573. },
  574. new DisplayTrx
  575. {
  576. Id = "101",
  577. FillingInfo = new DisplayTrxFillingInfo
  578. {
  579. Amount = 211,
  580. NozzleId = 1,
  581. ProductType = "95#",
  582. UnitPrice = 6.78m,
  583. Volume = 35,
  584. ProductDiscription = "汽油"
  585. },
  586. MemberInfo = new DisplayTrxMemberInfo
  587. {
  588. LicensePlateNo = "京A88888",
  589. Id = "1234567"
  590. },
  591. State = TrxStatus.Success,
  592. TimeStamp = new DisplayTrxTimeStamp
  593. {
  594. StartTime = DateTime.Now,
  595. FinishTime =DateTime.Now
  596. }
  597. },
  598. new DisplayTrx
  599. {
  600. Id = "102",
  601. FillingInfo = new DisplayTrxFillingInfo
  602. {
  603. Amount = 222,
  604. NozzleId = 1,
  605. ProductType = "95#",
  606. UnitPrice = 6.78m,
  607. Volume = 35,
  608. ProductDiscription = "汽油"
  609. },
  610. MemberInfo = new DisplayTrxMemberInfo
  611. {
  612. LicensePlateNo = "京A88888",
  613. Id = "1234567"
  614. },
  615. State = TrxStatus.Success,
  616. TimeStamp = new DisplayTrxTimeStamp
  617. {
  618. StartTime = DateTime.Now,
  619. FinishTime =DateTime.Now
  620. }
  621. },
  622. new DisplayTrx
  623. {
  624. Id = "103",
  625. FillingInfo = new DisplayTrxFillingInfo
  626. {
  627. Amount = 233,
  628. NozzleId = 1,
  629. ProductType = "95#",
  630. UnitPrice = 6.78m,
  631. Volume = 35,
  632. ProductDiscription = "汽油"
  633. },
  634. MemberInfo = new DisplayTrxMemberInfo
  635. {
  636. LicensePlateNo = "京A88888",
  637. Id = "1234567"
  638. },
  639. State = TrxStatus.Success,
  640. TimeStamp = new DisplayTrxTimeStamp
  641. {
  642. StartTime = DateTime.Now,
  643. FinishTime =DateTime.Now
  644. }
  645. },
  646. new DisplayTrx
  647. {
  648. Id = "104",
  649. FillingInfo = new DisplayTrxFillingInfo
  650. {
  651. Amount = 244,
  652. NozzleId = 1,
  653. ProductType = "95#",
  654. UnitPrice = 6.78m,
  655. Volume = 35,
  656. ProductDiscription = "汽油"
  657. },
  658. MemberInfo = new DisplayTrxMemberInfo
  659. {
  660. LicensePlateNo = "京A88888",
  661. Id = "1234567"
  662. },
  663. State = TrxStatus.Success,
  664. TimeStamp = new DisplayTrxTimeStamp
  665. {
  666. StartTime = DateTime.Now,
  667. FinishTime =DateTime.Now
  668. }
  669. }
  670. };
  671. ms = new MemoryStream();
  672. serializer.Serialize(ms, display);
  673. ms.Position = 0;
  674. sr = new StreamReader(ms, true);
  675. cmdText = sr.ReadToEnd();
  676. break;
  677. case ScreenType.TrxResult:
  678. display = new Display();
  679. display.ScreenType = screenType;
  680. display.PumpInfo = new DisplayPumpInfo
  681. {
  682. Id = 1,
  683. NozzleId = 1
  684. };
  685. display.TrxList = new DisplayTrx[]
  686. {
  687. new DisplayTrx
  688. {
  689. Id = "100",
  690. FillingInfo = new DisplayTrxFillingInfo
  691. {
  692. Amount = 200,
  693. NozzleId = 1,
  694. ProductType = "95#",
  695. UnitPrice = 6.78m,
  696. Volume = 35,
  697. ProductDiscription = "汽油"
  698. },
  699. MemberInfo = new DisplayTrxMemberInfo
  700. {
  701. LicensePlateNo = "京A88888",
  702. Id = "1234567"
  703. },
  704. State = TrxStatus.Success,
  705. TimeStamp = new DisplayTrxTimeStamp
  706. {
  707. StartTime = DateTime.Now,
  708. FinishTime =DateTime.Now
  709. }
  710. }
  711. };
  712. ms = new MemoryStream();
  713. serializer.Serialize(ms, display);
  714. ms.Position = 0;
  715. sr = new StreamReader(ms, true);
  716. cmdText = sr.ReadToEnd();
  717. break;
  718. default:
  719. throw new Exception("Unsupported screen type");
  720. }
  721. return cmdText;
  722. }
  723. #region IDisposable Support
  724. private bool disposedValue = false; // To detect redundant calls
  725. protected virtual void Dispose(bool disposing)
  726. {
  727. if (!disposedValue)
  728. {
  729. if (disposing)
  730. {
  731. // TODO: dispose managed state (managed objects).
  732. if (fuelingPoints != null)
  733. {
  734. foreach (var fp in fuelingPoints)
  735. {
  736. fp.Dispose();
  737. }
  738. }
  739. if (epsTrxCleanupManager != null)
  740. {
  741. epsTrxCleanupManager.Dispose();
  742. }
  743. }
  744. // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
  745. // TODO: set large fields to null.
  746. disposedValue = true;
  747. }
  748. }
  749. // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
  750. // ~Eps() {
  751. // // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
  752. // Dispose(false);
  753. // }
  754. // This code added to correctly implement the disposable pattern.
  755. public void Dispose()
  756. {
  757. // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
  758. Dispose(true);
  759. // TODO: uncomment the following line if the finalizer is overridden above.
  760. // GC.SuppressFinalize(this);
  761. }
  762. #endregion
  763. }
  764. }