FUSIONForecourtControl.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Threading;
  6. using System.IO;
  7. using Wayne.Lib;
  8. using Wayne.ForecourtControl.Vir.Fusion;
  9. #if _SINP
  10. using Wayne.ForecourtControl.Nfs;
  11. #endif
  12. using Wayne.FDCPOSLibrary;
  13. namespace Wayne.ForecourtControl.Fusion
  14. {
  15. public class FUSIONForecourtControl : IForecourtControl, IConnectable, IIdentifiableEntity, IDisposable
  16. {
  17. // Fields
  18. private string clientName;
  19. private string connectionString;
  20. private DeviceConnectionState connectionState = DeviceConnectionState.Disconnected;
  21. private List<IFuelPrice> fuelPriceList = new List<IFuelPrice>();
  22. private int id;
  23. private FUSIONManager _manager;
  24. public FUSIONManager manager
  25. {
  26. get { return _manager; }
  27. }
  28. private List<IPricePole> pricePoleList = new List<IPricePole>();
  29. private List<IPump> pumpList = new List<IPump>();
  30. private List<ITankGroup> tankGroupList = new List<ITankGroup>();
  31. private int siteMode;
  32. private bool siteOpened;
  33. public ServiceRequestChangeFuelMode srChangeMode = null;
  34. public bool fuelPriceReserved;
  35. public ConfigurationParams ConfigParam;
  36. // Events
  37. public event EventHandler<AlarmEventArgs> OnAlarm;
  38. public event EventHandler<ConnectionChangedEventArgs> OnConnectionStateChange;
  39. public event EventHandler<FuelPriceChangeEventArgs> OnFuelPriceChange;
  40. public event EventHandler<SiteModeChangeEventArgs> OnSiteModeChange;
  41. #region Methods
  42. public FUSIONForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
  43. {
  44. ConfigParam = new ConfigurationParams();
  45. this.id = deviceId;
  46. this._manager = new FUSIONManager(this, managedEntityTypes, managedPumpIds);
  47. fuelPriceReserved = false;
  48. siteOpened = true;
  49. }
  50. public void ActivateFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  51. {
  52. Trace.WriteLine(string.Format("ActivateFuelPricesAsync init"));
  53. int iFuelGrade;
  54. decimal price;
  55. ServiceRequestChangeFuelPrice sr = new ServiceRequestChangeFuelPrice();
  56. foreach (IFuelPrice fuelprice in FuelPrices)
  57. {
  58. try
  59. {
  60. Monitor.Enter(((FUSIONFuelPrice)fuelprice).locker);
  61. iFuelGrade = fuelprice.FuelGrade;
  62. Trace.WriteLine(string.Format("fuelGrade={0}, ((FUSIONFuelPrice)fuelprice).Changed={1}", fuelprice.FuelGrade, ((FUSIONFuelPrice)fuelprice).Changed));
  63. if (((FUSIONFuelPrice)fuelprice).Changed)
  64. {
  65. //for (int mode = ((FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta)).PriceGroupNumbersMin; mode <= ((FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta)).PriceGroupNumbersMax; mode++)
  66. for (int mode = FUSIONFuelPrice.PriceGroupNumbersMin; mode <= FUSIONFuelPrice.PriceGroupNumbersMax; mode++)
  67. {
  68. FUSIONFuelPriceAddPricePerPriceGroup pgd = (FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta);
  69. Trace.WriteLine(string.Format("mode = {0}, pgd.getChanged(mode)={1}", mode, pgd.getChanged(mode)));
  70. if (pgd.getChanged(mode))
  71. {
  72. price = fuelprice.BasePrice + fuelprice.GeneralPriceDelta + fuelprice.PriceGroupDelta[mode];
  73. //this._manager.ifsfManager.ChangeFuelPrice(fuelprice.FuelGrade, price, mode, null, null);
  74. this._manager.ifsfManager.ChangeFuelPriceAdd(sr, fuelprice.FuelGrade, price, mode);
  75. }
  76. }
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  82. }
  83. finally
  84. {
  85. Monitor.Exit(((FUSIONFuelPrice)fuelprice).locker);
  86. }
  87. }
  88. this._manager.ifsfManager.ChangeFuelPriceSend(sr, null, null, null);
  89. if (requestCompleted != null)
  90. requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
  91. Trace.WriteLine(string.Format("ActivateFuelPricesAsync end"));
  92. }
  93. private void ActivateFuelPricesCompleted(object sender, AsyncCompletedEventArgs e)
  94. {
  95. /*TODO AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
  96. if (!(e.UserToken is ushort))
  97. {
  98. throw new Exception("UnreserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
  99. }
  100. this.manager.ReadFuelPrices();
  101. foreach (NfsFuelPrice price in this.fuelPriceList)
  102. {
  103. price.WritableReserved = false;
  104. }
  105. if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
  106. {
  107. operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
  108. }*/
  109. }
  110. public void Connect(string connectionString)
  111. {
  112. // connection state is set to 'connecting' when the logon is terminated
  113. bool bNotifyStateChange = false;
  114. if (this._manager.ifsfManager.clientSocket.ConnectionState != DeviceConnectionState.Disconnected &&
  115. this._manager.ifsfManager.clientSocket.ConnectionState != DeviceConnectionState.Disconnecting)
  116. bNotifyStateChange = true;
  117. //bool res = this.manager.Connect(connectionString);
  118. this.connectionString = connectionString;
  119. Thread runConnectThread = new Thread(new ThreadStart(this.ConnectThreadProc));
  120. runConnectThread.Start();
  121. //if (bNotifyStateChange && OnConnectionStateChange != null)
  122. // this.OnConnectionStateChange.Invoke(this, new ConnectionChangedEventArgs(this._manager.ifsfManager.clientSocket.ConnectionState));
  123. //foreach (FUSIONPump pump in this.Pumps)
  124. //{
  125. // this._manager.ifsfManager.GetDeviceState(pump.Id, null, null);
  126. //}
  127. }
  128. private void ConnectThreadProc()
  129. {
  130. this.manager.Connect(connectionString);
  131. }
  132. public void Disconnect()
  133. {
  134. this.WritableConnectionState = DeviceConnectionState.Disconnecting;
  135. this.manager.Disconnect();
  136. }
  137. public void Dispose()
  138. {
  139. this.Dispose(true);
  140. GC.SuppressFinalize(this);
  141. }
  142. private void Dispose(bool disposing)
  143. {
  144. if (disposing)
  145. {
  146. this.manager.Dispose();
  147. }
  148. }
  149. ~FUSIONForecourtControl()
  150. {
  151. this.Dispose(false);
  152. }
  153. internal void FireAlarmEvent(AlarmEventArgs args)
  154. {
  155. if (this.OnAlarm != null)
  156. {
  157. this.OnAlarm.BeginInvoke(this, args, null, null);
  158. }
  159. }
  160. internal void FireFuelPriceChangeEvent(FuelPriceChangeEventArgs args)
  161. {
  162. if (this.OnFuelPriceChange != null)
  163. {
  164. this.OnFuelPriceChange.BeginInvoke(this, args, null, null);
  165. }
  166. }
  167. public void ReserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  168. {
  169. fuelPriceReserved = true;
  170. srChangeMode = new ServiceRequestChangeFuelMode();
  171. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  172. srChangeMode.RequestType = "ChangeFuelMode";
  173. else
  174. srChangeMode.RequestType = "ChangeFPFuelMode";
  175. foreach (IFuelPrice fuelprice in FuelPrices)
  176. {
  177. ((FUSIONFuelPrice)fuelprice).WritableReserved = true;
  178. }
  179. if (requestCompleted != null)
  180. requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
  181. }
  182. private void ReserveFuelPricesAsyncCompleted(object sender, AsyncCompletedEventArgs e)
  183. {
  184. /*TODO AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
  185. if (!(e.UserToken is ushort))
  186. {
  187. throw new Exception("ReserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
  188. }
  189. this.manager.ReadFuelPrices();
  190. foreach (NfsFuelPrice price in this.fuelPriceList)
  191. {
  192. price.WritableReserved = e.Success;
  193. }
  194. if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
  195. {
  196. operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
  197. }*/
  198. }
  199. public void SetSiteModeAsync(int siteMode, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  200. {
  201. //AsyncOperation<ushort> operation = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, requestCompleted, userToken);
  202. //Function function = new Function(4, new Parameter[] { new PrimitiveParameter(0x66, PrimitiveType.UInt16, operation.Id), new PrimitiveParameter(0x69, PrimitiveType.Byte, siteMode) });
  203. //this.manager.Send(function);
  204. if (siteMode == 99)
  205. {
  206. //This is only for testing purpose
  207. TestMessages();
  208. return;
  209. }
  210. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
  211. if (sValue != "")
  212. {
  213. Test();
  214. return;
  215. }
  216. }
  217. public void SetSiteOpenedAsync(bool opened, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  218. {
  219. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
  220. if (sValue != "")
  221. {
  222. Test();
  223. return;
  224. }
  225. if (opened)
  226. {
  227. this.manager.ifsfManager.StartForecourt(requestCompleted, userToken, this);
  228. }
  229. else
  230. this.manager.ifsfManager.StopForecourt(requestCompleted, userToken, this);
  231. }
  232. public void Test()
  233. {
  234. int par1 = -1, par2 = -1;
  235. int id = -1;
  236. int trid = -1;
  237. int nozzleId = -1;
  238. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
  239. string[] sElems;
  240. StreamReader sr = new StreamReader(ConfigurationParams.getSINPPath("ini\\") + sValue);
  241. while (sr.Peek() != -1)
  242. {
  243. sValue = sr.ReadLine();
  244. sElems = sValue.Split(',');
  245. try
  246. {
  247. if (sElems.GetLength(0) > 1)
  248. {
  249. try
  250. {
  251. par1 = Convert.ToInt32(sElems[1]);
  252. }
  253. catch (Exception ex)
  254. {
  255. }
  256. }
  257. if (sElems.GetLength(0) > 2)
  258. {
  259. try
  260. {
  261. par2 = Convert.ToInt32(sElems[2]);
  262. }
  263. catch (Exception ex)
  264. {
  265. }
  266. }
  267. sValue = sElems[0];
  268. id = par1;
  269. trid = par2;
  270. }
  271. catch (Exception ex)
  272. {
  273. }
  274. if (sValue == "StartFuelPointTest")
  275. {
  276. manager.ifsfManager.StartFuelPointTest(id, null, null, null);
  277. }
  278. else if (sValue == "EndFuelPointTest")
  279. {
  280. this.manager.ifsfManager.EndFuelPointTest(id, null, null, null);
  281. }
  282. else if (sValue == "CloseFuelPoint")
  283. {
  284. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  285. }
  286. else if (sValue == "OpenFuelPoint")
  287. {
  288. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  289. }
  290. else if (sValue == "AuthoriseFuelPoint")
  291. {
  292. AuthorizeParameters authParams = new AuthorizeParameters();
  293. authParams.PresetType = PresetType.Amount;
  294. authParams.PresetValue = 50;
  295. this.manager.ifsfManager.AuthoriseFuelPoint(id, trid, FuellingType.Unknown, 0, authParams, null, null, null);
  296. }
  297. else if (sValue == "SuspendFuelling")
  298. {
  299. FUSIONPump pump = this.manager.GetPumpById(id);
  300. if (pump != null)
  301. pump.SuspendAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_SuspendResult), null);
  302. //this.manager.ifsfManager.SuspendFuelling(id, null, null);
  303. }
  304. else if (sValue == "ResumeFuelling")
  305. {
  306. FUSIONPump pump = this.manager.GetPumpById(id);
  307. if (pump != null)
  308. pump.ResumeAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ResumeResult), null);
  309. //this.manager.ifsfManager.ResumeFuelling(id, null, null);
  310. }
  311. else if (sValue == "TerminateFuelling")
  312. {
  313. this.manager.ifsfManager.TerminateFuelling(id, null, null, null);
  314. }
  315. else if (sValue == "LogOff")
  316. {
  317. this.manager.ifsfManager.LogOff();
  318. }
  319. else if (sValue == "LogOn")
  320. {
  321. this.manager.ifsfManager.LogOn("", "");
  322. }
  323. else if (sValue == "GetFuelMode")
  324. {
  325. this.manager.ifsfManager.GetFuelMode(id, null, null, null);
  326. }
  327. else if (sValue == "GetModeTable")
  328. {
  329. this.manager.ifsfManager.GetModeTable(null, null, null);
  330. }
  331. else if (sValue == "ClearFuelSaleTrx")
  332. {
  333. this.manager.ifsfManager.ClearFuelSaleTrx(id, trid, 0, "", null, null, null);
  334. }
  335. else if (sValue == "LockFuelSaleTrx")
  336. {
  337. this.manager.ifsfManager.LockFuelSaleTrx(id, trid, 0, null, null, null);
  338. }
  339. else if (sValue == "UnlockFuelSaleTrx")
  340. {
  341. this.manager.ifsfManager.UnlockFuelSaleTrx(id, trid, 0, null, null, null);
  342. }
  343. else if (sValue == "getCountrySetting")
  344. {
  345. this.manager.ifsfManager.GetCountrySettings(null, null, null);
  346. }
  347. else if (sValue == "GetCurrentFuellingStatus")
  348. {
  349. this.manager.ifsfManager.GetCurrentFuellingStatus(id, null, null, null);
  350. }
  351. else if (sValue == "LockNozzle")
  352. {
  353. this.manager.ifsfManager.LockNozzle(id, nozzleId, null, null, null);
  354. }
  355. else if (sValue == "UnlockNozzle")
  356. {
  357. this.manager.ifsfManager.UnlockNozzle(id, nozzleId, null, null, null);
  358. }
  359. else if (sValue == "GetDeviceState")
  360. {
  361. this.manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser, id, null, null, null);
  362. }
  363. else if (sValue == "GetFuelPointTotals")
  364. {
  365. nozzleId = par2;
  366. this.manager.ifsfManager.GetFuelPointTotals(id, nozzleId, null, null, null);
  367. }
  368. else if (sValue == "CloseFuelPoint")
  369. {
  370. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  371. }
  372. else if (sValue == "OpenFuelPoint")
  373. {
  374. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  375. }
  376. else if (sValue == "ReserveFuelPoint")
  377. {
  378. FUSIONPump pump = this.manager.GetPumpById(id);
  379. if (pump != null)
  380. pump.ReserveAsync(FuellingType.Unknown, 0, new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ReserveResult), null);
  381. //this.manager.ifsfManager.ReserveFuelPoint(id, null, null);
  382. }
  383. else if (sValue == "FreeFuelPoint")
  384. {
  385. FUSIONPump pump = this.manager.GetPumpById(id);
  386. if (pump != null)
  387. pump.UnreserveAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_UnreserveResult), null);
  388. //this.manager.ifsfManager.FreeFuelPoint(id, null, null);
  389. }
  390. else if (sValue == "GetFuelSaleTrxDetails")
  391. {
  392. this.manager.ifsfManager.GetFuelSaleTrxDetails(id, trid, 0, null, null, null);
  393. }
  394. else if (sValue == "GetAvailableFuelSaleTrxs")
  395. {
  396. this.manager.ifsfManager.GetAvailableFuelSaleTrxs(id, null, null, null);
  397. }
  398. else if (sValue == "ChangeFuelMode")
  399. {
  400. int priceGroup = par2;
  401. this.manager.ifsfManager.ChangeFuelMode(id, priceGroup, null, null, null);
  402. }
  403. else if (sValue == "SendConfig")
  404. {
  405. this.manager.ifsfManager.SendConfig(sElems[1], null, null, null);
  406. }
  407. else
  408. {
  409. }
  410. }
  411. sr.Close();
  412. }
  413. static private void Test_SuspendResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  414. {
  415. try
  416. {
  417. IPump pump = (IPump)completed.UserToken;
  418. if (pump != null)
  419. {
  420. Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  421. }
  422. }
  423. catch (Exception ex)
  424. {
  425. Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
  426. }
  427. }
  428. static private void Test_ResumeResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  429. {
  430. try
  431. {
  432. IPump pump = (IPump)completed.UserToken;
  433. if (pump != null)
  434. {
  435. Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  436. }
  437. }
  438. catch (Exception ex)
  439. {
  440. Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
  441. }
  442. }
  443. static private void Test_ReserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  444. {
  445. try
  446. {
  447. IPump pump = (IPump)completed.UserToken;
  448. if (pump != null)
  449. {
  450. Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  451. }
  452. }
  453. catch (Exception ex)
  454. {
  455. Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
  456. }
  457. }
  458. static private void Test_UnreserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
  459. {
  460. try
  461. {
  462. IPump pump = (IPump)completed.UserToken;
  463. if (pump != null)
  464. {
  465. Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
  466. }
  467. }
  468. catch (Exception ex)
  469. {
  470. Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
  471. }
  472. }
  473. private void TestMessages()
  474. {
  475. int par1 = -1, par2 = -1, par3 = -1;
  476. int id = -1;
  477. int trid = -1;
  478. int nozzleId = -1;
  479. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Messages");
  480. string[] sElems;
  481. StreamReader sr = new StreamReader(ConfigurationParams.getSINPPath("ini\\") + sValue);
  482. while (sr.Peek() != -1)
  483. {
  484. sValue = sr.ReadLine();
  485. sElems = sValue.Split(',');
  486. try
  487. {
  488. if (sElems.GetLength(0) > 1)
  489. {
  490. try
  491. {
  492. par1 = Convert.ToInt32(sElems[1]);
  493. }
  494. catch (Exception ex)
  495. {
  496. }
  497. }
  498. if (sElems.GetLength(0) > 2)
  499. {
  500. try
  501. {
  502. par2 = Convert.ToInt32(sElems[2]);
  503. }
  504. catch (Exception ex)
  505. {
  506. }
  507. }
  508. if (sElems.GetLength(0) > 3)
  509. {
  510. try
  511. {
  512. par3 = Convert.ToInt32(sElems[3]);
  513. }
  514. catch (Exception ex)
  515. {
  516. }
  517. }
  518. sValue = sElems[0];
  519. id = par1;
  520. trid = par2;
  521. nozzleId = par3;
  522. }
  523. catch (Exception ex)
  524. {
  525. }
  526. if (sValue == "StartFuelPointTest")
  527. {
  528. manager.ifsfManager.StartFuelPointTest(id, null, null, null);
  529. }
  530. else if (sValue == "EndFuelPointTest")
  531. {
  532. this.manager.ifsfManager.EndFuelPointTest(id, null, null, null);
  533. }
  534. else if (sValue == "CloseFuelPoint")
  535. {
  536. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  537. }
  538. else if (sValue == "OpenFuelPoint")
  539. {
  540. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  541. }
  542. else if (sValue == "AuthoriseFuelPoint")
  543. {
  544. AuthorizeParameters authParams = new AuthorizeParameters();
  545. authParams.PresetType = PresetType.Amount;
  546. authParams.PresetValue = 50;
  547. this.manager.ifsfManager.AuthoriseFuelPoint(id, trid, FuellingType.OptCardPaid, 0, authParams, null, null, null);
  548. }
  549. else if (sValue == "SuspendFuelling")
  550. {
  551. FUSIONPump pump = this.manager.GetPumpById(id);
  552. if (pump != null)
  553. pump.SuspendAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_SuspendResult), null);
  554. //this.manager.ifsfManager.SuspendFuelling(id, null, null);
  555. }
  556. else if (sValue == "ResumeFuelling")
  557. {
  558. FUSIONPump pump = this.manager.GetPumpById(id);
  559. if (pump != null)
  560. pump.ResumeAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ResumeResult), null);
  561. //this.manager.ifsfManager.ResumeFuelling(id, null, null);
  562. }
  563. else if (sValue == "TerminateFuelling")
  564. {
  565. this.manager.ifsfManager.TerminateFuelling(id, null, null, null);
  566. }
  567. else if (sValue == "LogOff")
  568. {
  569. this.manager.ifsfManager.LogOff();
  570. }
  571. else if (sValue == "LogOn")
  572. {
  573. this.manager.ifsfManager.LogOn("", "");
  574. }
  575. else if (sValue == "GetFuelMode")
  576. {
  577. this.manager.ifsfManager.GetFuelMode(id, null, null, null);
  578. }
  579. else if (sValue == "GetModeTable")
  580. {
  581. this.manager.ifsfManager.GetModeTable(null, null, null);
  582. }
  583. else if (sValue == "ClearFuelSaleTrx")
  584. {
  585. this.manager.ifsfManager.ClearFuelSaleTrx(id, trid, 2, "",null, null, null);
  586. }
  587. else if (sValue == "LockFuelSaleTrx")
  588. {
  589. this.manager.ifsfManager.LockFuelSaleTrx(id, trid, 2, null, null, null);
  590. }
  591. else if (sValue == "UnlockFuelSaleTrx")
  592. {
  593. this.manager.ifsfManager.UnlockFuelSaleTrx(id, trid, 2, null, null, null);
  594. }
  595. else if (sValue == "GetCountrySettings")
  596. {
  597. this.manager.ifsfManager.GetCountrySettings(null, null, null);
  598. }
  599. else if (sValue == "GetCurrentFuellingStatus")
  600. {
  601. this.manager.ifsfManager.GetCurrentFuellingStatus(id, null, null, null);
  602. }
  603. else if (sValue == "LockNozzle")
  604. {
  605. this.manager.ifsfManager.LockNozzle(id, nozzleId, null, null, null);
  606. }
  607. else if (sValue == "UnlockNozzle")
  608. {
  609. this.manager.ifsfManager.UnlockNozzle(id, nozzleId, null, null, null);
  610. }
  611. else if (sValue == "GetDeviceState")
  612. {
  613. this.manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser, id, null, null, null);
  614. }
  615. else if (sValue == "GetFuelPointTotals")
  616. {
  617. nozzleId = par2;
  618. this.manager.ifsfManager.GetFuelPointTotals(id, nozzleId, null, null, null);
  619. }
  620. else if (sValue == "CloseFuelPoint")
  621. {
  622. this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
  623. }
  624. else if (sValue == "OpenFuelPoint")
  625. {
  626. this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
  627. }
  628. else if (sValue == "ReserveFuelPoint")
  629. {
  630. FUSIONPump pump = this.manager.GetPumpById(id);
  631. if (pump != null)
  632. pump.ReserveAsync(FuellingType.Unknown, 0, new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ReserveResult), null);
  633. //this.manager.ifsfManager.ReserveFuelPoint(id, null, null);
  634. }
  635. else if (sValue == "FreeFuelPoint")
  636. {
  637. FUSIONPump pump = this.manager.GetPumpById(id);
  638. if (pump != null)
  639. pump.UnreserveAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_UnreserveResult), null);
  640. //this.manager.ifsfManager.FreeFuelPoint(id, null, null);
  641. }
  642. else if (sValue == "GetFuelSaleTrxDetails")
  643. {
  644. this.manager.ifsfManager.GetFuelSaleTrxDetails(id, trid, 2, null, null, null);
  645. }
  646. else if (sValue == "GetAvailableFuelSaleTrxs")
  647. {
  648. this.manager.ifsfManager.GetAvailableFuelSaleTrxs(id, null, null, null);
  649. }
  650. else if (sValue == "ChangeFuelMode")
  651. {
  652. int priceGroup = par2;
  653. this.manager.ifsfManager.ChangeFuelMode(id, priceGroup, null, null, null);
  654. }
  655. else if (sValue == "SendConfig")
  656. {
  657. this.manager.ifsfManager.SendConfig(sElems[1], null, null, null);
  658. }
  659. else if (sValue == "SetDeviceAlarm")
  660. {
  661. this.manager.ifsfManager.SetDeviceAlarm("1", id, 1, "test alarms", null, null, null);
  662. }
  663. else if (sValue == "ChangeDSPLimits")
  664. {
  665. this.manager.ifsfManager.ChangeDSPLimits(id, 1, 1, 9, 88, null, null, null);
  666. }
  667. else if (sValue == "ChangeFuelPrice")
  668. {
  669. this.manager.ifsfManager.ChangeFuelPrice(id, 3.39m, 1, null, null, null);
  670. }
  671. else if (sValue == "CloseDevice")
  672. {
  673. this.manager.ifsfManager.CloseDevice(id, null, null, null);
  674. }
  675. else if (sValue == "GetConfiguration")
  676. {
  677. this.manager.ifsfManager.GetConfiguration(null, null, null);
  678. }
  679. else if (sValue == "GetDSPLimits")
  680. {
  681. this.manager.ifsfManager.GetDSPLimits(id,null,null,null);
  682. }
  683. //else if (sValue == "GetFPState")
  684. //{
  685. // this.manager.ifsfManager.GetFPStateResp(id null);
  686. //}
  687. //else if (sValue == "GetFPState")
  688. //{
  689. // this.manager.ifsfManager.GetFPStateResp(id null);
  690. //}
  691. else
  692. {
  693. }
  694. }
  695. sr.Close();
  696. }
  697. public override string ToString()
  698. {
  699. return ("Forecourt Control ClientId=" + this.ClientId.ToString(CultureInfo.InvariantCulture));
  700. }
  701. public void UnreserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  702. {
  703. //AsyncOperation<ushort> operation = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, requestCompleted, userToken);
  704. //AsyncOperation<ushort> operation2 = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, new EventHandler<AsyncCompletedEventArgs>(this, (IntPtr)this.UnreserveFuelPricesAsyncCompleted), operation.Id);
  705. //Function function = new Function(6, new Parameter[] { new PrimitiveParameter(0x66, PrimitiveType.UInt16, operation2.Id) });
  706. //this.manager.Send(function);
  707. if (this.manager.forecourtControl.fuelPriceReserved)
  708. this.manager.ifsfManager.ChangeFuelModeSend(this.manager.forecourtControl.srChangeMode, requestCompleted, userToken, this);
  709. foreach (IFuelPrice fuelprice in FuelPrices)
  710. {
  711. ((FUSIONFuelPrice)fuelprice).WritableReserved = false;
  712. }
  713. if (requestCompleted != null && !this.manager.forecourtControl.fuelPriceReserved)
  714. requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
  715. srChangeMode = null;
  716. fuelPriceReserved = false;
  717. }
  718. private void UnreserveFuelPricesAsyncCompleted(object sender, AsyncCompletedEventArgs e)
  719. {
  720. //AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
  721. //if (!(e.UserToken is ushort))
  722. //{
  723. // throw new Exception("UnreserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
  724. //}
  725. //this.manager.ReadFuelPrices();
  726. //foreach (NfsFuelPrice price in this.fuelPriceList)
  727. //{
  728. // price.WritableReserved = false;
  729. //}
  730. //if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
  731. //{
  732. // operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
  733. //}
  734. }
  735. internal void WriteSiteMode(bool newSiteOpen, int newSiteMode)
  736. {
  737. //if ((newSiteMode != this.siteMode) || (newSiteOpen != this.siteOpened))
  738. //{
  739. // this.siteOpened = newSiteOpen;
  740. // this.siteMode = newSiteMode;
  741. // if ((this.OnSiteModeChange != null) && (this.connectionState != DeviceConnectionState.Connecting))
  742. // {
  743. // this.OnSiteModeChange.Invoke(this, new SiteModeChangeEventArgs(this.siteMode, this.siteOpened));
  744. // }
  745. //}
  746. }
  747. #endregion
  748. #region Properties
  749. public int ClientId
  750. {
  751. get { return int.Parse(this.manager.ifsfManager.clientSocket.workstationID); }
  752. }
  753. public string ClientName
  754. {
  755. get
  756. {
  757. return this.clientName;
  758. }
  759. }
  760. public DeviceConnectionState ConnectionState
  761. {
  762. get
  763. {
  764. return this.connectionState;
  765. }
  766. }
  767. public string EntitySubType
  768. {
  769. get
  770. {
  771. return "";
  772. }
  773. }
  774. public string EntityType
  775. {
  776. get
  777. {
  778. return "FUSIONForecourtControl";
  779. }
  780. }
  781. /// <summary>
  782. /// This is used by the logger and should never be set by implementing classes
  783. /// </summary>
  784. public string FullEntityName { get; set; }
  785. public ReadOnlyCollection<IFuelPrice> FuelPrices
  786. {
  787. get
  788. {
  789. return this.fuelPriceList.AsReadOnly();
  790. }
  791. }
  792. public int Id
  793. {
  794. get { return this.id; }
  795. set { id = value; }
  796. }
  797. public IIdentifiableEntity ParentEntity
  798. {
  799. get { return null; }
  800. }
  801. public ReadOnlyCollection<IPricePole> PricePoles
  802. {
  803. get
  804. {
  805. return this.pricePoleList.AsReadOnly();
  806. }
  807. }
  808. public ReadOnlyCollection<IPump> Pumps
  809. {
  810. get
  811. {
  812. return this.pumpList.AsReadOnly();
  813. }
  814. }
  815. public int SiteMode
  816. {
  817. get
  818. {
  819. return this.siteMode;
  820. }
  821. }
  822. public bool SiteOpened
  823. {
  824. get
  825. {
  826. return this.siteOpened;
  827. }
  828. }
  829. public ReadOnlyCollection<ITankGroup> TankGroups
  830. {
  831. get
  832. {
  833. return this.tankGroupList.AsReadOnly();
  834. }
  835. }
  836. internal int WritableClientId
  837. {
  838. get
  839. {
  840. return this.id;
  841. }
  842. set
  843. {
  844. this.id = value;
  845. }
  846. }
  847. internal string WritableClientName
  848. {
  849. get
  850. {
  851. return this.clientName;
  852. }
  853. set
  854. {
  855. this.clientName = value;
  856. }
  857. }
  858. internal DeviceConnectionState WritableConnectionState
  859. {
  860. get
  861. {
  862. return this.connectionState;
  863. }
  864. set
  865. {
  866. Trace.WriteLine(string.Format("old connectionState={0}, new connectionState={1}", this.connectionState, value));
  867. if (this.connectionState != value)
  868. {
  869. this.connectionState = value;
  870. if (connectionState == DeviceConnectionState.Connected)
  871. {
  872. foreach (FUSIONPump pump in Pumps)
  873. {
  874. //foreach (FUSIONFuelling fuelling in pump.Fuellings)
  875. // fuelling.Dispose();
  876. pump.WritableFuellingList.Clear();
  877. //((FUSIONFuelling)pump.CurrentFuelling).Dispose();
  878. }
  879. // read current pump status
  880. //if (ConfigParam.IsEMSGVersion)
  881. //{
  882. manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, -1, null, null, null);
  883. //}
  884. //else
  885. //{
  886. // manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe, -1, null, null, null);
  887. //}
  888. // read current Vir status
  889. //if (FUSIONVirFactory.Virs.Count > 0)
  890. // manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_Vir, -1, null, null, null);
  891. // get the list of offline fuelling
  892. manager.ifsfManager.GetAvailableFuelSaleTrxs(-1, null, null, null);
  893. }
  894. if (this.OnConnectionStateChange != null)
  895. {
  896. this.OnConnectionStateChange.Invoke(this, new ConnectionChangedEventArgs(value));
  897. }
  898. }
  899. }
  900. }
  901. internal List<IFuelPrice> WritableFuelPriceList
  902. {
  903. get
  904. {
  905. return this.fuelPriceList;
  906. }
  907. }
  908. internal List<IPricePole> WritablePricePoleList
  909. {
  910. get
  911. {
  912. return this.pricePoleList;
  913. }
  914. }
  915. internal List<IPump> WritablePumpList
  916. {
  917. get
  918. {
  919. return this.pumpList;
  920. }
  921. }
  922. internal int WritableSiteMode
  923. {
  924. get
  925. {
  926. return this.siteMode;
  927. }
  928. set
  929. {
  930. this.siteMode = value;
  931. }
  932. }
  933. internal bool WritableSiteOpened
  934. {
  935. get
  936. {
  937. return this.siteOpened;
  938. }
  939. set
  940. {
  941. this.siteOpened = value;
  942. }
  943. }
  944. internal List<ITankGroup> WritableTankGroupList
  945. {
  946. get
  947. {
  948. return this.tankGroupList;
  949. }
  950. }
  951. public IFuelPrice getFuelPriceByProductId(int productId)
  952. {
  953. foreach (IFuelPrice fuelprice in FuelPrices)
  954. {
  955. if (productId == fuelprice.FuelGrade)
  956. return fuelprice;
  957. }
  958. return null;
  959. }
  960. #endregion
  961. #region IForecourtControl Members
  962. public void ReservePumpClusterAsync(int terminalDeviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  963. {
  964. throw new NotImplementedException();
  965. }
  966. public void UnreservePumpClusterAsync(int terminalDeviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  967. {
  968. throw new NotImplementedException();
  969. }
  970. #endregion
  971. }
  972. }