FUSIONManager.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Threading;
  6. //using System.Diagnostics;
  7. using Wayne.Lib;
  8. #if _SINP
  9. using Wayne.ForecourtControl.Nfs;
  10. #endif
  11. using Wayne.ForecourtControl.OptBridge;
  12. using Wayne.ForecourtControl.OptBridge.Fusion;
  13. using Wayne.ForecourtControl.Vir.Fusion;
  14. using Wayne.FDCPOSLibrary;
  15. namespace Wayne.ForecourtControl.Fusion
  16. {
  17. internal class FUSIONAsyncMangager : Wayne.Lib.AsyncManager.AsyncManager<ushort>
  18. {
  19. // Fields
  20. private ushort nextSequenceNumber;
  21. private object nextSequenceNumberLock;
  22. // Methods
  23. public FUSIONAsyncMangager(int id, IIdentifiableEntity parentEntity)
  24. : base(id, parentEntity)
  25. {
  26. this.nextSequenceNumber = 1;
  27. this.nextSequenceNumberLock = new object();
  28. }
  29. protected override ushort CreateNextOperationId()
  30. {
  31. lock (this.nextSequenceNumberLock)
  32. {
  33. ushort num2;
  34. this.nextSequenceNumber = (ushort)((num2 = this.nextSequenceNumber) + 1);
  35. return num2;
  36. }
  37. }
  38. // Properties
  39. public override string EntitySubType
  40. {
  41. get
  42. {
  43. return "FUSIONForecourtControl";
  44. }
  45. }
  46. }
  47. public abstract class FUSIONAsyncOperation<TOperationId>
  48. {
  49. // Fields
  50. private DateTime creationDateTime;
  51. private object data;
  52. private TOperationId id;
  53. private object owner;
  54. private object userToken;
  55. // Events
  56. internal event EventHandler OnOperationCompleted;
  57. // Methods
  58. protected internal FUSIONAsyncOperation(object owner, TOperationId id, object userToken, object data)
  59. {
  60. this.creationDateTime = DateTime.Now;
  61. this.owner = owner;
  62. this.id = id;
  63. this.userToken = userToken;
  64. this.data = data;
  65. }
  66. public void Cancel()
  67. {
  68. this.Complete();
  69. }
  70. protected internal void Complete()
  71. {
  72. if (this.OnOperationCompleted != null)
  73. {
  74. this.OnOperationCompleted(this, EventArgs.Empty);
  75. }
  76. }
  77. // Properties
  78. internal DateTime CreationDateTime
  79. {
  80. get
  81. {
  82. return this.creationDateTime;
  83. }
  84. set
  85. {
  86. this.creationDateTime = value;
  87. }
  88. }
  89. public object Data
  90. {
  91. get
  92. {
  93. return this.data;
  94. }
  95. }
  96. public TOperationId Id
  97. {
  98. get
  99. {
  100. return this.id;
  101. }
  102. }
  103. public object Owner
  104. {
  105. get
  106. {
  107. return this.owner;
  108. }
  109. }
  110. public object UserToken
  111. {
  112. get
  113. {
  114. return this.userToken;
  115. }
  116. }
  117. }
  118. public class FUSIONAsyncOperation<TOperationId, TResultEventArgs> : FUSIONAsyncOperation<TOperationId> where TResultEventArgs : EventArgs
  119. {
  120. // Fields
  121. private EventHandler<TResultEventArgs> resultDelegate;
  122. // Methods
  123. internal FUSIONAsyncOperation(object owner, TOperationId id, object userToken, object data, EventHandler<TResultEventArgs> resultDelegate)
  124. : base(owner, id, userToken, data)
  125. {
  126. this.resultDelegate = resultDelegate;
  127. }
  128. public void Complete(TResultEventArgs resultEventArgs)
  129. {
  130. base.Complete();
  131. if (this.resultDelegate != null)
  132. {
  133. this.resultDelegate.Invoke(base.Owner, resultEventArgs);
  134. }
  135. }
  136. public override string ToString()
  137. {
  138. return this.ToString("", CultureInfo.InvariantCulture);
  139. }
  140. public virtual string ToString(IFormatProvider provider)
  141. {
  142. return this.ToString("", provider);
  143. }
  144. public virtual string ToString(string format)
  145. {
  146. return this.ToString(format, CultureInfo.InvariantCulture);
  147. }
  148. public virtual string ToString(string format, IFormatProvider provider)
  149. {
  150. string str;
  151. IIdentifiableEntity owner = base.Owner as IIdentifiableEntity;
  152. if (owner != null)
  153. {
  154. str = IdentifiableEntity.ToString(owner);
  155. }
  156. else
  157. {
  158. str = base.Owner.ToString();
  159. }
  160. return string.Format(CultureInfo.InvariantCulture, "FUSIONAsyncOperation<TOperatorId={0},TResultEventArgs={1}> Owner={2},Id={3},", new object[] { typeof(TOperationId).FullName, typeof(TResultEventArgs).FullName, str, base.Id });
  161. }
  162. }
  163. internal class FUSIONInitializationStatus
  164. {
  165. // Fields
  166. private bool clientPropertySet;
  167. private bool configurationDataRead;
  168. private BitArray pumpStatusRead;
  169. private bool readingConfigurationData;
  170. private bool siteModeRead;
  171. // Methods
  172. public FUSIONInitializationStatus()
  173. {
  174. this.PumpStatusRead = new BitArray(0x20, false);
  175. }
  176. public void Reset()
  177. {
  178. this.ReadingConfigurationData = false;
  179. //this.ConfigurationDataRead = false;
  180. this.ClientPropertySet = false;
  181. this.SiteModeRead = false;
  182. this.PumpStatusRead.SetAll(false);
  183. }
  184. // Properties
  185. public bool ClientPropertySet
  186. {
  187. get
  188. {
  189. return this.clientPropertySet;
  190. }
  191. set
  192. {
  193. this.clientPropertySet = value;
  194. }
  195. }
  196. public bool ConfigurationDataRead
  197. {
  198. get
  199. {
  200. return this.configurationDataRead;
  201. }
  202. set
  203. {
  204. this.configurationDataRead = value;
  205. }
  206. }
  207. public BitArray PumpStatusRead
  208. {
  209. get
  210. {
  211. return this.pumpStatusRead;
  212. }
  213. set
  214. {
  215. this.pumpStatusRead = value;
  216. }
  217. }
  218. public bool ReadingConfigurationData
  219. {
  220. get
  221. {
  222. return this.readingConfigurationData;
  223. }
  224. set
  225. {
  226. this.readingConfigurationData = value;
  227. }
  228. }
  229. public bool SiteModeRead
  230. {
  231. get
  232. {
  233. return this.siteModeRead;
  234. }
  235. set
  236. {
  237. this.siteModeRead = value;
  238. }
  239. }
  240. }
  241. public class FUSIONManager : IIdentifiableEntity, IDisposable
  242. {
  243. // Fields
  244. public IFSFManager ifsfManager;
  245. private ConfigurationReader configurationReader;
  246. //private Dictionary<string, string> connectionStringParamDict;
  247. //private DebugLogger debugLogger;
  248. private bool disposed;
  249. public FUSIONForecourtControl forecourtControl;
  250. private FUSIONInitializationStatus initializationStatus = new FUSIONInitializationStatus();
  251. //private DataSet latestPricesDataSet = new DataSet();
  252. //private ForecourtEntityTypes managedEntityTypes;
  253. private List<int> managedPumpIds;
  254. //private ParameterFormatInfo parserFormatInfo = new ParameterFormatInfo();
  255. //private NfsManagerState state;
  256. public AutoResetEvent versionInfoWakeUpEvent;
  257. public string version;
  258. public string release;
  259. public string hotfix;
  260. public string getFwRelease()
  261. {
  262. return version + "." + release + "." + hotfix;
  263. }
  264. public int IdShift = 0;
  265. public int IdPumpShift = 0;
  266. public int IdNozzleShift = 0;
  267. public int IdTankShift = 0;
  268. private bool shouldSetConnected = false; // a flag to indicate if need to set connection state to be connected
  269. // Methods
  270. public FUSIONManager(FUSIONForecourtControl forecourtControl, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
  271. {
  272. try
  273. {
  274. //Logger.SetConfigFile(@".\LogConfig.xml");
  275. //Logger.RefreshConfig();
  276. Trace.Add(this);
  277. }
  278. catch (Exception ex)
  279. {
  280. Trace.WriteLine("FusionManager Exception - " + ex.Message);
  281. }
  282. this.configurationReader = new ConfigurationReader(this);
  283. //this.state = NfsManagerState.Uninitialized;
  284. this.forecourtControl = forecourtControl;
  285. Trace.WriteLine("starting ...Id = " + this.Id);
  286. //this.managedEntityTypes = managedEntityTypes;
  287. //this.asyncManager = new FUSIONAsyncMangager(this.Id, this);
  288. //this.debugLogger = new DebugLogger(this, true);
  289. this.ifsfManager = new IFSFManager(forecourtControl.Id, forecourtControl.ConfigParam);
  290. //this.clientSocket.ParserDomain = ParserDomain.FillingServer;
  291. //this.clientSocket.OnRpcRead += new EventHandler<RpcEventArgs>(this, (IntPtr)this.clientSocket_OnRpcRead);
  292. this.ifsfManager.clientSocket.OnConnectionStateChange += new EventHandler<ConnectionChangedEventArgs>(clientSocket_OnConnectionStateChange); //new EventHandler<ConnectionChangedEventArgs>(this, (IntPtr)this.clientSocket_OnConnectionStateChange);
  293. this.ifsfManager.OnDeviceStateChange += new EventHandler<DeviceStateChangedEventArgs>(manager_OnDeviceStateChange);
  294. this.ifsfManager.OnVirStateChange += new EventHandler<VIRStateChangedEventArgs>(manager_OnVirStateChange);
  295. this.ifsfManager.OnFuelModeChange += new EventHandler<FuelModeChangedEventArgs>(manager_OnFuelModeChange);
  296. this.ifsfManager.OnCurrentFuellingStatus += new EventHandler<CurrentFuellingStatusEventArgs>(manager_OnCurrentFuellingStatus);
  297. this.ifsfManager.OnFuelPointTotals += new EventHandler<FuelPointTotalsEventArgs>(manager_OnFuelPointTotals);
  298. this.ifsfManager.OnFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnFuelSaleTrx);
  299. this.ifsfManager.OnDeviceAlarm += new EventHandler<DeviceAlarmEventArgs>(manager_OnDeviceAlarm);
  300. this.ifsfManager.OnVersionInfo += new EventHandler<VersionInfoEventArgs>(manager_OnVersionInfo);
  301. this.ifsfManager.OnChangeFuelPrice += new EventHandler<ChangeFuelPriceEventArgs>(manager_OnChangeFuelPrice);
  302. this.ifsfManager.OnLockFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnLockFuelSaleTrx);
  303. this.ifsfManager.OnUnlockFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnUnlockFuelSaleTrx);
  304. this.ifsfManager.OnClearFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnClearFuelSaleTrx);
  305. this.ifsfManager.OnGetAvailableFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnGetAvailableFuelSaleTrx);
  306. this.ifsfManager.OnGetFuelSaleTrxDetails += new EventHandler<FuelSaleTrxEventArgs>(manager_OnGetFuelSaleTrxDetails);
  307. this.ifsfManager.OnGetConfiguration += new EventHandler<GetConfigurationEventArgs>(manager_OnGetConfiguration);
  308. this.ifsfManager.OnConfigurationChange += new EventHandler<EventArgs>(manager_OnConfigurationChange);
  309. this.ifsfManager.OnGetProductTable += new EventHandler<GetProductTableEventArgs>(manager_OnGetProductTable);
  310. this.ifsfManager.OnTankData += new EventHandler<TankDataEventArgs>(manager_OnTankData);
  311. this.ifsfManager.OnTwinMasterReady += new EventHandler<EventArgs>(manager_OnTwinMasterReady);
  312. this.ifsfManager.OnOptRead += new EventHandler<OptReadEventArgs>(manager_OnOptRead);
  313. this.versionInfoWakeUpEvent = new AutoResetEvent(false);
  314. }
  315. private int convertDeviceType(string deviceType)
  316. {
  317. if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser)
  318. return (int)(ForecourtEntityTypes.Pump); //3; // is that Wayne.ForecourtControl.Nfs.ForecourtEntityTypes.Pump ?
  319. else if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_PricePole || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_PricePolePoint)
  320. return (int)(ForecourtEntityTypes.PricePole);
  321. else if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe)
  322. return (int)(ForecourtEntityTypes.Tank);
  323. return 0;
  324. }
  325. private int getAlarmCategory(int alarmId)
  326. {
  327. switch (alarmId)
  328. {
  329. case 1003:
  330. return 0; // Information
  331. //case xxx:
  332. // return 1; // warning
  333. default:
  334. return 1; // Error
  335. }
  336. }
  337. private int convertAlarmCode(int error)
  338. {
  339. return error;
  340. //int AlarmId = 0;
  341. //if (error == 6) // volume or amount decreased
  342. //{
  343. // AlarmId = 219;
  344. //}
  345. //else if (error == 7 || error == 8) // pulser error
  346. //{
  347. // AlarmId = 220;
  348. //}
  349. //else if (error == 9) // zero fuelling - antispandimento
  350. //{
  351. // AlarmId = 212;
  352. //}
  353. //else if (error == 11) // price error
  354. //{
  355. // AlarmId = 211;
  356. //}
  357. //else if (error == 12) // volume or amount garbage
  358. //{
  359. // AlarmId = 219;
  360. //}
  361. //else if (error == 13) // display error
  362. //{
  363. // AlarmId = 215;
  364. //}
  365. //else if (error == 14) // checksum error
  366. //{
  367. // AlarmId = 219;
  368. //}
  369. //return AlarmId;
  370. }
  371. private void clientSocket_OnConnectionStateChange(object sender, ConnectionChangedEventArgs e)
  372. {
  373. Trace.WriteLine("manager clientSocket_OnConnectionStateChange ConnectionState=" + e.ConnectionState);
  374. try
  375. {
  376. if (e.ConnectionState == DeviceConnectionState.Connected)
  377. {
  378. this.initializationStatus.Reset();
  379. shouldSetConnected = true;
  380. // when socket connection is active, start getting configuration
  381. this.InitializeOrhcestrator();
  382. // JDL, AUG-10-10, site is open when FDC connection established.
  383. this.forecourtControl.WritableSiteOpened = true;
  384. }
  385. else if (e.ConnectionState != DeviceConnectionState.Connected)
  386. {
  387. if (e.ConnectionState == DeviceConnectionState.Disconnected)
  388. {
  389. //WJU - do not make reconnection read ConfigurationData again. It should read only first time connection
  390. initializationStatus.ReadingConfigurationData = false;
  391. // JDL, AUG-10-10, set site to closed
  392. this.forecourtControl.WritableSiteOpened = false;
  393. //this.DestroyObjects();
  394. ifsfManager.Disconnect();
  395. if (FUSIONOptFactory.getOptBridge() != null)
  396. {
  397. foreach (IOpt opt in ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).Opts)
  398. {
  399. if (((FUSIONOpt)opt).managedBy == OPTManagedBy.SINP)
  400. ((FUSIONOpt)opt).optTCP.Disconnect();
  401. }
  402. }
  403. foreach (FUSIONPump pump in this.forecourtControl.Pumps)
  404. {
  405. pump.WritableState = PumpState.Inoperative;
  406. }
  407. }
  408. this.forecourtControl.WritableConnectionState = e.ConnectionState;
  409. }
  410. }
  411. catch (Exception ex)
  412. {
  413. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  414. }
  415. }
  416. private void manager_OnDeviceStateChange(object sender, DeviceStateChangedEventArgs e)
  417. {
  418. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  419. {
  420. FUSIONPump pump = this.GetPumpById(e.deviceId);
  421. if (pump != null)
  422. {
  423. PumpState state = pump.convertPumpState(e.state);
  424. Trace.WriteLine(string.Format("pump={0}, State={1}, pump.State={2}, nozzleUp={3}", pump.realId, state, pump.State, e.nozzleUp));
  425. if (pump.State != state)
  426. pump.WritableState = state;
  427. try
  428. {
  429. pump.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : -1;
  430. }
  431. catch (Exception ex)
  432. {
  433. Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
  434. }
  435. foreach (FUSIONNozzle nozzle in pump.Nozzles)
  436. {
  437. Trace.WriteLine(string.Format("pump={0}, nozzle={1}, nozzle.State={2}", pump.realId, nozzle.Id, nozzle.State));
  438. if (nozzle.State == NozzleState.Out && e.nozzleUp != nozzle.Id)
  439. nozzle.State = NozzleState.In;
  440. else if (nozzle.State == NozzleState.In && e.nozzleUp == nozzle.Id)
  441. nozzle.State = NozzleState.Out;
  442. }
  443. }
  444. }
  445. else if (e.deviceType == DeviceType.DT_OutdoorPaymentTerminal)
  446. {
  447. if (FUSIONOptFactory.getOptBridge() == null)
  448. return;
  449. FUSIONOpt opt = ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).GetOptFromId(e.deviceId);
  450. if (opt != null)
  451. {
  452. DeviceConnectionState state;
  453. if (e.state == LogicalDeviceState.FDC_READY) state = DeviceConnectionState.Connected;
  454. else state = DeviceConnectionState.Disconnected;
  455. Trace.WriteLine(string.Format("opt={0}, State={1}", opt.Id, state));
  456. if (opt.ConnectionState != state)
  457. opt.WritableConnectionState = state;
  458. }
  459. }
  460. else if (e.deviceType == DeviceType.DT_TankProbe)
  461. {
  462. FUSIONTank tank = this.getTankByIndex(e.deviceId);
  463. if (e.state == LogicalDeviceState.FDC_READY)
  464. tank.WritableConnectionState = DeviceConnectionState.Connected;
  465. else
  466. tank.WritableConnectionState = DeviceConnectionState.Disconnected;
  467. }
  468. }
  469. private void manager_OnVirStateChange(object sender, VIRStateChangedEventArgs e)
  470. {
  471. FUSIONVir vir = (FUSIONVir)(FUSIONVirFactory.getVir(e.deviceId));
  472. if (vir != null)
  473. {
  474. if (e.state == DeviceConnectionState.Connected)
  475. vir.Connected(e.virId);
  476. else if (e.state == DeviceConnectionState.Disconnected)
  477. vir.Disconnected(e.virId);
  478. else
  479. Trace.WriteLine(string.Format("manager_OnVirStateChange>: vir={0} State={1} NOT managed !", vir.Id, e.state));
  480. }
  481. else
  482. Trace.WriteLine(string.Format("manager_OnVirStateChange: vir={0} NOT FOUND !", e.deviceId));
  483. }
  484. private void manager_OnFuelModeChange(object sender, FuelModeChangedEventArgs e)
  485. {
  486. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  487. {
  488. FUSIONPump pump = this.GetPumpById(e.deviceId);
  489. if (pump != null)
  490. {
  491. int mode = e.mode;
  492. Trace.WriteLine(string.Format("pump={0}, mode={1}", pump.realId, mode));
  493. pump.FireFuelModeChange(mode);
  494. }
  495. }
  496. }
  497. private void manager_OnCurrentFuellingStatus(object sender, CurrentFuellingStatusEventArgs e)
  498. {
  499. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  500. {
  501. try
  502. {
  503. FUSIONPump pump = this.GetPumpById(e.deviceId);
  504. if (pump != null && pump.CurrentFuelling != null)
  505. {
  506. if (e.volume > 0 && e.volume != pump.CurrentFuelling.Quantity && pump.RunningFuellingUpdates)
  507. {
  508. // TODO setting pump current fuelling attributes
  509. FUSIONFuelling currentFuelling = null;
  510. currentFuelling = (FUSIONFuelling)(pump.CurrentFuelling);
  511. currentFuelling.WritablePrice = e.price;
  512. currentFuelling.WritableAmount = e.amount;
  513. currentFuelling.WritableQuantity = e.volume;
  514. if (pump.Nozzles.Count > e.nozzleId - 1 && e.nozzleId > 0)
  515. {
  516. currentFuelling.WritableNozzle = pump.Nozzles[e.nozzleId - 1];
  517. currentFuelling.WritableFuelGrade = pump.Nozzles[e.nozzleId - 1].FuelGrade;
  518. }
  519. else
  520. Trace.WriteLine(String.Format("INVALID Nozzle: '{0}'", e.nozzleId));
  521. pump.FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
  522. }
  523. }
  524. }
  525. catch (Exception ex)
  526. {
  527. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  528. }
  529. }
  530. }
  531. private void manager_OnFuelPointTotals(object sender, FuelPointTotalsEventArgs e)
  532. {
  533. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  534. {
  535. try
  536. {
  537. FUSIONPump pump = this.GetPumpById(e.deviceId);
  538. FUSIONNozzle nozzle = (FUSIONNozzle)(pump.Nozzles[e.nozzleId - 1]);
  539. if (pump != null && nozzle != null)
  540. {
  541. PumpAccumulatorReading pumpAccumulatorReading = new PumpAccumulatorReading(pump, nozzle, 0, PumpAccumulatorReadingType.RequestedReading,
  542. e.volume, e.amount);
  543. this.ifsfManager.clientSocket.ifsfMessages.asyncResponseManager.SendResponse(e.requestId, e.overallResult, pumpAccumulatorReading);
  544. }
  545. }
  546. catch (Exception ex)
  547. {
  548. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  549. }
  550. }
  551. }
  552. private void manager_OnFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
  553. {
  554. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  555. {
  556. try
  557. {
  558. FUSIONPump pump = this.GetPumpById(e.deviceId);
  559. if (pump != null && pump.CurrentFuelling != null)
  560. {
  561. lock (pump.CurrentFuelling)
  562. {
  563. //if (e.volume != pump.CurrentFuelling.Quantity)
  564. Trace.WriteLine(string.Format("pump={0}, pump.Nozzles.Count={1}, e.nozzleId={2}", pump.realId, pump.Nozzles.Count, e.nozzleId));
  565. Trace.WriteLine(String.Format("Transaction state={0}", ((Wayne.FDCPOSLibrary.FuellingState)(e.transactionStatus)).ToString()));
  566. FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId, e.releaseToken));
  567. FUSIONFuelling currentFuelling = (FUSIONFuelling)(pump.CurrentFuelling);
  568. FuellingState fuellingState = FuellingState.Unknown;
  569. if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Locked)
  570. fuellingState = FuellingState.Locked;
  571. else if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Payable)
  572. fuellingState = FuellingState.PayableTransaction;
  573. #if !_USE_OLD_FCONTROL_
  574. else if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Paid)
  575. fuellingState = FuellingState.Paid;
  576. #endif
  577. if (fuelling == null)
  578. {
  579. if (pump.Nozzles.Count > e.nozzleId - 1)//&& e.nozzleId > 0)
  580. {
  581. // TODO possible transaction status to be defined
  582. currentFuelling.WritableCompletionReason = currentFuelling.convertStatus(e.completionReason);
  583. // overwrite the value set when authorising fuelling
  584. currentFuelling.WritableFuellingSequenceNumber = e.transactionId;
  585. currentFuelling.WritableCompletionDateTime = e.trxEndDateTime;
  586. // TODO is fuel mode useful ?
  587. //e.fuelMode
  588. currentFuelling.WritableFuelGrade = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1].FuelGrade : 0;
  589. currentFuelling.WritableState = fuellingState;
  590. currentFuelling.WritablePrice = e.price;
  591. currentFuelling.WritableAmount = e.amount;
  592. if (pump.CurrentFuelling.PresetValue == 0)
  593. {
  594. currentFuelling.WritablePresetType = PresetType.Amount;
  595. currentFuelling.WritablePresetValue = e.amount;
  596. }
  597. currentFuelling.WritableQuantity = e.volume;
  598. currentFuelling.WritableNozzle = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1] : null;
  599. try
  600. {
  601. currentFuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
  602. }
  603. catch (Exception ex)
  604. {
  605. Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
  606. }
  607. try
  608. {
  609. currentFuelling.WritableAuthorizedBy = (e.authAS != null && e.authAS != "") ? Convert.ToInt32(e.authAS) : 0;
  610. }
  611. catch (Exception ex)
  612. {
  613. Trace.WriteLine(string.Format("Exception! cannot convert e.authAS='{0}' to Int32", e.authAS));
  614. }
  615. //currentFuelling.WritableSignedReceiptLines = (e.DSPFields == null) ? "" : e.DSPFields;
  616. currentFuelling.WritableSignedReceiptLines = (e.MIDLinesNarrow == null) ? "" : e.MIDLinesNarrow;
  617. Trace.WriteLine(string.Format("SignedReceiptLines='{0}'", currentFuelling.SignedReceiptLines));
  618. currentFuelling.WritableSignedReceiptLinesWide = (e.MIDLinesWide == null) ? "" : e.MIDLinesWide;
  619. Trace.WriteLine(string.Format("SignedReceiptLinesWide='{0}'", currentFuelling.SignedReceiptLinesWide));
  620. currentFuelling.WritableAuthorizationId = e.releaseToken;
  621. currentFuelling.WritableReservingDeviceId = e.reservingDeviceId;
  622. currentFuelling.WritableType = e.fuellingType;
  623. // add a fuelling to the pump fuellings list
  624. fuelling = new FUSIONFuelling(this, pump);
  625. pump.WritableFuellingList.Add(fuelling);
  626. fuelling.WritableFuellingSequenceNumber = currentFuelling.WritableFuellingSequenceNumber;
  627. fuelling.WritableCompletionReason = currentFuelling.convertStatus(e.completionReason);
  628. fuelling.WritableCompletionDateTime = e.trxEndDateTime;
  629. // TODO is fuel mode useful ?
  630. //e.fuelMode
  631. fuelling.WritablePresetType = currentFuelling.PresetType;
  632. fuelling.WritablePresetValue = currentFuelling.PresetValue;
  633. fuelling.WritableFuelGrade = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1].FuelGrade : 0;
  634. fuelling.WritableState = fuellingState;
  635. fuelling.WritablePrice = e.price;
  636. fuelling.WritableAmount = e.amount;
  637. fuelling.WritableQuantity = e.volume;
  638. fuelling.WritableNozzle = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1] : null;
  639. fuelling.WritableCRC = 0;
  640. fuelling.WritableReservedBy = currentFuelling.WritableReservedBy;
  641. fuelling.WritableAuthorizedBy = currentFuelling.WritableAuthorizedBy;
  642. fuelling.WritableSignedReceiptLines = currentFuelling.WritableSignedReceiptLines;
  643. fuelling.WritableSignedReceiptLinesWide = currentFuelling.WritableSignedReceiptLinesWide;
  644. fuelling.WritableAuthorizationId = e.releaseToken;
  645. fuelling.WritableReservingDeviceId = e.reservingDeviceId;
  646. fuelling.WritableType = currentFuelling.WritableType;
  647. #if !_USE_OLD_FCONTROL_
  648. Trace.WriteLine(String.Format("Firing FuellingStateChange: CurrentFuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, authAS={5}, lockAS={6}, reservingDeviceId={7}",
  649. pump.CurrentFuelling.FuellingSequenceNumber, pump.realId, ((Wayne.FDCPOSLibrary.FuellingState)(pump.CurrentFuelling.State)).ToString(), pump.CurrentFuelling.Quantity, pump.CurrentFuelling.Amount, pump.CurrentFuelling.AuthorizedBy, pump.CurrentFuelling.ReservedBy,
  650. pump.CurrentFuelling.ReservingDeviceId));
  651. #else
  652. Trace.WriteLine(String.Format("Firing FuellingStateChange: CurrentFuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, lockAS={5}",
  653. pump.CurrentFuelling.FuellingSequenceNumber, pump.realId, ((Wayne.FDCPOSLibrary.FuellingState)(pump.CurrentFuelling.State)).ToString(), pump.CurrentFuelling.Quantity, pump.CurrentFuelling.Amount, pump.CurrentFuelling.ReservedBy));
  654. #endif
  655. pump.FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
  656. pump.FireFuellingStateChange(fuelling, fuellingState);
  657. }
  658. else
  659. Trace.WriteLine(String.Format("INVALID Nozzle: '{0}'", e.nozzleId));
  660. }
  661. else
  662. {
  663. // if fuelling exist the only item that can change is the status
  664. //if (fuellingState != fuelling.State)
  665. {
  666. fuelling.WritableState = fuellingState;
  667. try
  668. {
  669. fuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
  670. }
  671. catch (Exception ex)
  672. {
  673. Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
  674. }
  675. if (e.transactionId == currentFuelling.FuellingSequenceNumber)
  676. {
  677. currentFuelling.WritableState = fuellingState;
  678. try
  679. {
  680. currentFuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
  681. }
  682. catch (Exception ex)
  683. {
  684. Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
  685. }
  686. }
  687. Trace.WriteLine(String.Format("Firing FuellingStateChange: fuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, authAS={5}, lockAS={6}",
  688. fuelling.FuellingSequenceNumber, ((FUSIONPump)(fuelling.Pump)).realId, ((Wayne.FDCPOSLibrary.FuellingState)(fuelling.State)).ToString(), fuelling.Quantity, fuelling.Amount, fuelling.AuthorizedBy, fuelling.ReservedBy));
  689. pump.FireFuellingStateChange(fuelling, fuellingState);
  690. #if !_USE_OLD_FCONTROL_
  691. if (fuellingState == FuellingState.Paid)
  692. {
  693. pump.WritableFuellingList.Remove(fuelling);
  694. currentFuelling.WritableType = FuellingType.Unknown;
  695. }
  696. #endif
  697. }
  698. }
  699. }
  700. }
  701. }
  702. catch (Exception ex)
  703. {
  704. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  705. }
  706. }
  707. }
  708. private void manager_OnDeviceAlarm(object sender, DeviceAlarmEventArgs e)
  709. {
  710. //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  711. //{
  712. // FUSIONPump pump = this.GetPumpById(e.deviceId);
  713. // if (pump != null && pump.CurrentFuelling != null)
  714. // {
  715. // pump...FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
  716. // }
  717. //}
  718. int alarmCategory = getAlarmCategory(e.alarmId);
  719. int deviceType = convertDeviceType(e.deviceType);
  720. int deviceId = e.deviceId;
  721. int alarmCode = convertAlarmCode(e.alarmId);
  722. string debugText = e.alarmDescr;
  723. AlarmEventArgs args = new AlarmEventArgs(deviceId, deviceType, alarmCode, alarmCategory, debugText);
  724. // low level alarm code: 4
  725. const int LOWLEVELALARMCODE = 0x1F; //15;
  726. const int NOALARMCODE = 0;
  727. if ((e.deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint || e.deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser) &&
  728. (alarmCode == 0 || alarmCode == LOWLEVELALARMCODE))
  729. {
  730. FUSIONPump pump = this.GetPumpById(deviceId);
  731. Trace.WriteLine(string.Format("pump={0}, deviceType={1}, alarmCode={2}, TankLevelSwitchStatus={3}", deviceId, deviceType, alarmCode, (pump != null) ? pump.TankLevelSwitchStatus.ToString() : "invalid"));
  732. if (pump != null)
  733. {
  734. if (alarmCode == LOWLEVELALARMCODE && pump.TankLevelSwitchStatus != TankLevelSwitchStatus.Low)
  735. {
  736. pump.WritableTankLevelSwitchStatus = TankLevelSwitchStatus.Low;
  737. //this.forecourtControl.FireAlarmEvent(args);
  738. }
  739. else if (alarmCode == NOALARMCODE && pump.TankLevelSwitchStatus == TankLevelSwitchStatus.Low)
  740. {
  741. pump.WritableTankLevelSwitchStatus = TankLevelSwitchStatus.Ok;
  742. this.forecourtControl.FireAlarmEvent(args);
  743. }
  744. }
  745. }
  746. else
  747. this.forecourtControl.FireAlarmEvent(args);
  748. }
  749. private void manager_OnVersionInfo(object sender, VersionInfoEventArgs e)
  750. {
  751. this.release = e.release;
  752. this.version = e.version;
  753. this.hotfix = e.hotfix;
  754. versionInfoWakeUpEvent.Set();
  755. }
  756. private void manager_OnChangeFuelPrice(object sender, ChangeFuelPriceEventArgs e)
  757. {
  758. FUSIONFuelPrice fuelPrice = (FUSIONFuelPrice)this.forecourtControl.getFuelPriceByProductId(e.productId);
  759. if (fuelPrice == null)
  760. return;
  761. try
  762. {
  763. FUSIONFuelPriceAddPricePerPriceGroup pgd = null;
  764. if (fuelPrice != null)
  765. pgd = (FUSIONFuelPriceAddPricePerPriceGroup)(fuelPrice.PriceGroupDelta);
  766. if (pgd != null)
  767. {
  768. Monitor.Enter(fuelPrice.locker);
  769. pgd.setChanged(e.mode, false);
  770. bool resetchange = true;
  771. //for (int mode = pgd.PriceGroupNumbersMin; mode <= pgd.PriceGroupNumbersMax; mode++)
  772. for (int mode = FUSIONFuelPrice.PriceGroupNumbersMin; mode <= FUSIONFuelPrice.PriceGroupNumbersMax; mode++)
  773. {
  774. if (pgd.getChanged(mode))
  775. {
  776. resetchange = false;
  777. break;
  778. }
  779. }
  780. if (resetchange)
  781. fuelPrice.Changed = false;
  782. }
  783. }
  784. catch (Exception ex)
  785. {
  786. Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
  787. }
  788. finally
  789. {
  790. Monitor.Exit(fuelPrice.locker);
  791. }
  792. }
  793. private void manager_OnLockFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
  794. {
  795. //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  796. //{
  797. // FUSIONPump pump = this.GetPumpById(e.deviceId);
  798. // if (pump != null)
  799. // {
  800. // FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId));
  801. // if (fuelling != null)
  802. // {
  803. // fuelling.WritableReservedBy = this.Id;
  804. // }
  805. // }
  806. //}
  807. }
  808. private void manager_OnUnlockFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
  809. {
  810. //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  811. //{
  812. // FUSIONPump pump = this.GetPumpById(e.deviceId);
  813. // if (pump != null)
  814. // {
  815. // FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId));
  816. // if (fuelling != null)
  817. // {
  818. // // TODO what value shoul be set ? at the moment set to '0'
  819. // fuelling.WritableReservedBy = 0;
  820. // }
  821. // }
  822. //}
  823. }
  824. private void manager_OnClearFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
  825. {
  826. // when the transaction is paid it is removed from the pump transaction list
  827. if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
  828. {
  829. FUSIONPump pump = this.GetPumpById(e.deviceId);
  830. if (pump != null)
  831. {
  832. FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId, e.releaseToken));
  833. if (fuelling != null)
  834. {
  835. fuelling.Dispose();
  836. }
  837. }
  838. }
  839. }
  840. private void manager_OnGetAvailableFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
  841. {
  842. this.forecourtControl.manager.ifsfManager.GetFuelSaleTrxDetails(e.deviceId, e.transactionId, e.releaseToken, null, null, null);
  843. }
  844. private void manager_OnGetFuelSaleTrxDetails(object sender, FuelSaleTrxEventArgs e)
  845. {
  846. // do nothing because GetFuelSaleTrxDetails response is managed by OnFuelSaleTrx event
  847. }
  848. private void manager_OnGetProductTable(object sender, GetProductTableEventArgs e)
  849. {
  850. Trace.WriteLine("init");
  851. ConfigurationReader.GetProductTableParam param = new ConfigurationReader.GetProductTableParam(e.sr, this);
  852. configurationReader.ReadProductTable(param);
  853. Trace.WriteLine("end");
  854. }
  855. private void manager_OnTankData(object sender, TankDataEventArgs e)
  856. {
  857. Trace.WriteLine("init");
  858. Trace.WriteLine("end");
  859. }
  860. private void manager_OnGetConfiguration(object sender, GetConfigurationEventArgs e)
  861. {
  862. Trace.WriteLine("manager_OnGetConfiguration init");
  863. ConfigurationReader.GetConfigurationParam param = new ConfigurationReader.GetConfigurationParam(e.sr, this);
  864. if (configurationReader.ReadConfiguration(param))
  865. this.ifsfManager.isConfigRead = true;
  866. Trace.WriteLine("manager_OnGetConfiguration End");
  867. }
  868. private void manager_OnConfigurationChange(object sender, EventArgs e)
  869. {
  870. Trace.WriteLine("manager_OnConfigurationChange - init");
  871. //this.Disconnect();
  872. this.DestroyObjects(false);
  873. this.forecourtControl.WritableConnectionState = DeviceConnectionState.Connecting;
  874. this.initializationStatus.ConfigurationDataRead = false;
  875. this.initializationStatus.ReadingConfigurationData = false;
  876. try
  877. {
  878. if (FUSIONConfigFactory.getConfigurator() != null)
  879. FUSIONConfigFactory.getConfigurator().FireOnConfigurationChanged();
  880. }
  881. catch (Exception ex)
  882. {
  883. }
  884. shouldSetConnected = false;
  885. this.InitializeOrhcestrator();
  886. Trace.WriteLine("End manager_OnConfigurationChange");
  887. }
  888. private void manager_OnTwinMasterReady(object sender, EventArgs e)
  889. {
  890. Trace.WriteLine("init manager_OnTwinMasterReady");
  891. try
  892. {
  893. if (FUSIONTwinFactory.getTwin() != null)
  894. ((FUSIONTwin)(FUSIONTwinFactory.getTwin())).FireOnTwinMasterReady();
  895. else
  896. Trace.WriteLine("manager_OnTwinMasterReady - twin NOT created");
  897. }
  898. catch (Exception ex)
  899. {
  900. }
  901. Trace.WriteLine("End manager_OnTwinMasterReady");
  902. }
  903. private void manager_OnOptRead(object sender, OptReadEventArgs e)
  904. {
  905. Trace.WriteLine("init");
  906. OptReadEventArgs args = new OptReadEventArgs(e.deviceType, e.deviceId, e.message);
  907. if (FUSIONOptFactory.getOptBridge() != null)
  908. ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).FireOnDataRead(e.deviceId, e.message);
  909. Trace.WriteLine("End");
  910. }
  911. protected bool CheckConfiguration(ServiceResponseGetConfiguration sr)
  912. {
  913. Trace.WriteLine("init CheckConfiguration");
  914. bool bResult = true;
  915. foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
  916. {
  917. switch (deviceClass.Type)
  918. {
  919. case Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser:
  920. {
  921. //look for FuellingPoint in actual configuration
  922. if (true && forecourtControl.ConfigParam.IsEMSGVersion)
  923. break;
  924. if (!ConfigPump(deviceClass.DeviceClass[0]))
  925. bResult = false;
  926. }
  927. break;
  928. case Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint:
  929. {
  930. //look for FuellingPoint in actual configuration
  931. if (!ConfigPump(deviceClass))
  932. bResult = false;
  933. }
  934. break;
  935. case Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge:
  936. case Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe:
  937. case Wayne.FDCPOSLibrary.DeviceType.DT_PricePole:
  938. break;
  939. }
  940. }
  941. //look for actual pump in new configuration
  942. bool bPumpFound = false;
  943. foreach (FUSIONPump pump in forecourtControl.WritablePumpList)
  944. {
  945. bPumpFound = false;
  946. foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
  947. {
  948. if (deviceClass.Type != Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint && deviceClass.Type != Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser)
  949. continue;
  950. if (Convert.ToInt32(deviceClass.FPPumpNo) == pump.realId)
  951. {
  952. bPumpFound = true;
  953. break;
  954. }
  955. }
  956. if (!bPumpFound)
  957. {
  958. Trace.WriteLine(string.Format("pump {0} not found in new configuration", pump.realId));
  959. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} not found in new configuration", pump.Id));
  960. this.manager_OnDeviceAlarm(this, arg);
  961. bResult = false;
  962. }
  963. }
  964. Trace.WriteLine("end CheckConfiguration");
  965. return bResult;
  966. }
  967. internal bool ConfigPump(ServiceDeviceClassConfiguration deviceClass)
  968. {
  969. bool bResult = true;
  970. bool bFPFound = false;
  971. foreach (FUSIONPump pump in this.forecourtControl.WritablePumpList)
  972. {
  973. if (pump.realId == Convert.ToInt32(deviceClass.FPPumpNo))
  974. {
  975. bFPFound = true;
  976. bool bNozzleFound = false;
  977. foreach (ServiceNozzleFPDeviceClassConfiguration FPNozzle in deviceClass.FPNozzle)
  978. {
  979. string productNo = (FPNozzle.FPProductId[0].PIFPProductNo != null) ? FPNozzle.FPProductId[0].PIFPProductNo : FPNozzle.FPProductId[0].PIFPProductNo1;
  980. bNozzleFound = false;
  981. foreach (FUSIONNozzle nozzle in pump.Nozzles)
  982. {
  983. if (nozzle.realId == Convert.ToInt32(FPNozzle.FPNozzleNo))
  984. {
  985. bNozzleFound = true;
  986. if (nozzle.FuelGrade != Convert.ToInt32(productNo))
  987. {
  988. Trace.WriteLine(string.Format("pump {0}, nozzle {1}, new product {2}, old product = {3} ", pump.realId, FPNozzle.FPNozzleNo, FPNozzle.FPProductId, nozzle.FuelGrade));
  989. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: nozzle {1} new productNo {2} configured productNo {3}", pump.Id, FPNozzle.FPNozzleNo, productNo, nozzle.FuelGrade));
  990. this.manager_OnDeviceAlarm(this, arg);
  991. bResult = false;
  992. }
  993. break;
  994. }
  995. }
  996. if (!bNozzleFound)
  997. {
  998. Trace.WriteLine(string.Format("pump {0}, nozzle {1}, product {2} not found in actual configuration", pump.realId, FPNozzle.FPNozzleNo, FPNozzle.FPProductId));
  999. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: new nozzle {1} productNo {2} not configured", pump.Id, FPNozzle.FPNozzleNo, productNo));
  1000. this.manager_OnDeviceAlarm(this, arg);
  1001. bResult = false;
  1002. }
  1003. }
  1004. foreach (FUSIONNozzle nozzle in pump.Nozzles)
  1005. {
  1006. bNozzleFound = false;
  1007. foreach (ServiceNozzleFPDeviceClassConfiguration FPNozzle in deviceClass.FPNozzle)
  1008. {
  1009. if (nozzle.realId == Convert.ToInt32(FPNozzle.FPNozzleNo))
  1010. {
  1011. bNozzleFound = true;
  1012. break;
  1013. }
  1014. }
  1015. if (!bNozzleFound)
  1016. {
  1017. Trace.WriteLine(string.Format("pump {0}, nozzle {1}, product {2} not found in new configuration", pump.realId, nozzle.Id, nozzle.FuelGrade));
  1018. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: nozzle {1} productNo {2} not found in new configuration", pump.Id, nozzle.Id, nozzle.FuelGrade));
  1019. this.manager_OnDeviceAlarm(this, arg);
  1020. bResult = false;
  1021. break;
  1022. }
  1023. }
  1024. break;
  1025. }
  1026. }
  1027. if (!bFPFound)
  1028. {
  1029. bResult = false;
  1030. Trace.WriteLine(string.Format("pump {0} not found in old configuration", deviceClass.FPPumpNo));
  1031. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, Convert.ToInt32(deviceClass.FPPumpNo), (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} not found in previous configuration", deviceClass.FPPumpNo));
  1032. this.manager_OnDeviceAlarm(this, arg);
  1033. }
  1034. Trace.WriteLine("end - true");
  1035. return bResult;
  1036. }
  1037. internal bool Connect(string connectionString)
  1038. {
  1039. //if (this.debugLogger.IsActive())
  1040. //{
  1041. // this.debugLogger.Add("Connect, connectionString=" + connectionString);
  1042. //}
  1043. //this.connectionStringParamDict = Strings.ParseConnectionString(connectionString);
  1044. return this.ifsfManager.clientSocket.Connect(connectionString);
  1045. //this.forecourtControl.WritableClientId = this.clientSocket.ClientId;
  1046. //this.forecourtControl.WritableClientName = this.clientSocket.ClientName;
  1047. }
  1048. private void DestroyObjects(bool bDisconnect)
  1049. {
  1050. foreach (FUSIONPump pump in this.forecourtControl.WritablePumpList)
  1051. {
  1052. pump.Dispose();
  1053. }
  1054. this.forecourtControl.WritablePumpList.Clear();
  1055. this.forecourtControl.WritableTankGroupList.Clear();
  1056. this.forecourtControl.WritablePricePoleList.Clear();
  1057. this.forecourtControl.WritableFuelPriceList.Clear();
  1058. if (bDisconnect)
  1059. ifsfManager.Disconnect();
  1060. }
  1061. internal void Disconnect()
  1062. {
  1063. if (FUSIONOptFactory.getOptBridge() != null)
  1064. {
  1065. foreach (IOpt opt in ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).Opts)
  1066. {
  1067. if (((FUSIONOpt)opt).managedBy == OPTManagedBy.SINP)
  1068. ((FUSIONOpt)opt).optTCP.Disconnect();
  1069. else
  1070. this.ifsfManager.OptRemove(opt.Id, null, null, null);
  1071. }
  1072. }
  1073. this.ifsfManager.LogOff();
  1074. //this.DestroyObjects();
  1075. }
  1076. public void Dispose()
  1077. {
  1078. this.Dispose(true);
  1079. GC.SuppressFinalize(this);
  1080. }
  1081. private void Dispose(bool disposing)
  1082. {
  1083. if (!this.disposed)
  1084. {
  1085. this.disposed = true;
  1086. if (disposing)
  1087. {
  1088. if (this.configurationReader != null)
  1089. this.configurationReader.Dispose();
  1090. if (Trace.debugLogger != null)
  1091. Trace.debugLogger.Dispose();
  1092. }
  1093. }
  1094. }
  1095. ~FUSIONManager()
  1096. {
  1097. this.Dispose(false);
  1098. }
  1099. public FUSIONPump GetPumpById(int pumpNumber)
  1100. {
  1101. foreach (FUSIONPump pump in this.forecourtControl.Pumps)
  1102. {
  1103. if (pump.realId == pumpNumber)
  1104. {
  1105. return pump;
  1106. }
  1107. }
  1108. return null;
  1109. }
  1110. public FUSIONTankGroup getTankGroupByIndex(int iTankGroupId)
  1111. {
  1112. foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
  1113. {
  1114. if (tankgroup.Id == iTankGroupId)
  1115. {
  1116. return tankgroup;
  1117. }
  1118. }
  1119. return null;
  1120. }
  1121. public FUSIONTank getTankByIndex(int iTankGroupId, int iTankId)
  1122. {
  1123. foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
  1124. {
  1125. if (tankgroup.Id == iTankGroupId)
  1126. {
  1127. foreach (FUSIONTank tank in tankgroup.Tanks)
  1128. {
  1129. if (tank.Id /*oppure tank.realId ?*/ == iTankId)
  1130. return tank;
  1131. }
  1132. }
  1133. }
  1134. return null;
  1135. }
  1136. public FUSIONTank getTankByIndex(int iTankId)
  1137. {
  1138. foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
  1139. {
  1140. foreach (FUSIONTank tank in tankgroup.Tanks)
  1141. {
  1142. if (tank.Id /*oppure tank.realId ?*/ == iTankId)
  1143. return tank;
  1144. }
  1145. }
  1146. return null;
  1147. }
  1148. private void InitializeOrhcestrator()
  1149. {
  1150. Trace.WriteLine("InitializeOrhcestrator init");
  1151. if (!this.disposed) //&& (this.clientSocket.ConnectionState == DeviceConnectionState.Connected))
  1152. {
  1153. if (!this.initializationStatus.ConfigurationDataRead)
  1154. {
  1155. if (!this.initializationStatus.ReadingConfigurationData)
  1156. {
  1157. Trace.WriteLine("calling ReadConfigurationDataAsync");
  1158. shouldSetConnected = false;
  1159. this.initializationStatus.ReadingConfigurationData = true;
  1160. ifsfManager.isConfigRead = false;
  1161. this.configurationReader.ForceStart = true;
  1162. this.configurationReader.ReadConfigurationDataAsync();
  1163. }
  1164. else
  1165. Trace.WriteLine("ReadingConfigurationData");
  1166. }
  1167. }
  1168. if (shouldSetConnected)
  1169. {
  1170. Trace.WriteLine("ConfigurationDataRead");
  1171. this.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
  1172. }
  1173. }
  1174. internal void RequestFillingData(int pumpNumber, bool onlyCurrentFuelling)
  1175. {
  1176. this.ifsfManager.GetCurrentFuellingStatus(pumpNumber, null, null, null);
  1177. }
  1178. // Properties
  1179. public string EntitySubType
  1180. {
  1181. get
  1182. {
  1183. return "";
  1184. }
  1185. }
  1186. public string EntityType
  1187. {
  1188. get
  1189. {
  1190. return "FUSIONManager";
  1191. }
  1192. }
  1193. /// <summary>
  1194. /// This is used by the logger and should never be set by implementing classes
  1195. /// </summary>
  1196. public string FullEntityName { get; set; }
  1197. public int Id
  1198. {
  1199. get
  1200. {
  1201. return this.forecourtControl.Id;
  1202. }
  1203. }
  1204. public IIdentifiableEntity ParentEntity
  1205. {
  1206. get
  1207. {
  1208. return null;
  1209. }
  1210. }
  1211. // Nested Types
  1212. private class ConfigurationReader : IDisposable
  1213. {
  1214. // Fields
  1215. private bool cancelled;
  1216. private FUSIONManager nfsManager;
  1217. private AutoResetEvent readingDoneEvent = new AutoResetEvent(false);
  1218. private bool running;
  1219. // Methods
  1220. public ConfigurationReader(FUSIONManager nfsManager)
  1221. {
  1222. this.nfsManager = nfsManager;
  1223. }
  1224. public void Cancel()
  1225. {
  1226. if (this.running)
  1227. {
  1228. this.cancelled = true;
  1229. }
  1230. }
  1231. public void Dispose()
  1232. {
  1233. this.Dispose(true);
  1234. GC.SuppressFinalize(this);
  1235. }
  1236. protected void Dispose(bool disposing)
  1237. {
  1238. this.Cancel();
  1239. if (disposing)
  1240. {
  1241. this.readingDoneEvent.Close();
  1242. this.readingDoneEvent = null;
  1243. }
  1244. }
  1245. public bool Running
  1246. {
  1247. get { return running; }
  1248. }
  1249. public bool ForceStart { get; set; }
  1250. ~ConfigurationReader()
  1251. {
  1252. this.Dispose(false);
  1253. }
  1254. private void ReadConfigurationData(object o)
  1255. {
  1256. Trace.WriteLine("ReadConfigurationData - init");
  1257. try
  1258. {
  1259. FUSIONManager parentEntity = o as FUSIONManager;
  1260. //TLG parentEntity.ifsfManager.GetConfiguration(null, null, null);
  1261. parentEntity.ifsfManager.GetProductTable(null, null, null);
  1262. }
  1263. finally
  1264. {
  1265. }
  1266. Trace.WriteLine("ReadConfigurationData - end");
  1267. }
  1268. public void ReadConfigurationDataAsync()
  1269. {
  1270. Trace.WriteLine(string.Format("ReadConfigurationDataAsync - Running={0}, ForceStart={1}", running, ForceStart));
  1271. if (ForceStart || (!this.running))
  1272. {
  1273. Trace.WriteLine("ReadConfigurationDataAsync - Start ReadConfigurationData");
  1274. ForceStart = false;
  1275. this.cancelled = false;
  1276. this.readingDoneEvent.Reset();
  1277. this.running = true;
  1278. Trace.WriteLine("ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReadConfigurationData), this.nfsManager);");
  1279. ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReadConfigurationData), this.nfsManager);
  1280. }
  1281. else
  1282. {
  1283. Trace.WriteLine("ReadConfigurationDataAsync() was called already!");
  1284. }
  1285. }
  1286. public void ReadProductTable(object o)
  1287. {
  1288. if (o == null)
  1289. return;
  1290. GetProductTableParam param = (GetProductTableParam)o;
  1291. ServiceResponseGetProductTable sr = param.sr;
  1292. FUSIONManager parentEntity = param.nfsManager;
  1293. if (sr == null || (sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString() && sr.OverallResult != "") ||
  1294. sr.FDCdata == null || sr.FDCdata.Length == 0 ||
  1295. sr.FDCdata[0].FuelProducts == null || sr.FDCdata[0].FuelProducts.Length == 0 ||
  1296. sr.FDCdata[0].FuelProducts[0].Product == null || sr.FDCdata[0].FuelProducts[0].Product.Length == 0)
  1297. {
  1298. Trace.WriteLine(string.Format("errore in ServiceResponseGetProductTable"));
  1299. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, "Error in GetProductTable");
  1300. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1301. parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
  1302. this.running = false;
  1303. this.readingDoneEvent.Set();
  1304. return;
  1305. }
  1306. try
  1307. {
  1308. try
  1309. {
  1310. if (parentEntity.forecourtControl.WritableFuelPriceList.Count > 0)
  1311. {
  1312. bool bAlarm = false;
  1313. Trace.WriteLine(string.Format("forecourtControl.WritableFuelPriceList.Count = {0}, verify prices", parentEntity.forecourtControl.WritableFuelPriceList.Count));
  1314. //verify product numberl
  1315. if (parentEntity.forecourtControl.WritableFuelPriceList.Count != sr.FDCdata[0].FuelProducts[0].Product.Length)
  1316. {
  1317. Trace.WriteLine(string.Format("forecourtControl.WritableFuelPriceList.Count = {0}, sr.FDCData[0].FuelProducts.Lenght = {1}", parentEntity.forecourtControl.WritableFuelPriceList.Count, sr.FDCdata[0].FuelProducts.Length));
  1318. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product number received ({0}) differs from product number cofigured ({1})", sr.FDCdata[0].FuelProducts[0].Product.Length, parentEntity.forecourtControl.WritableFuelPriceList.Count));
  1319. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1320. bAlarm = true;
  1321. }
  1322. foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
  1323. {
  1324. bool bFound = false;
  1325. foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
  1326. {
  1327. if (Convert.ToInt32(product.ProductNo) == fuelprice.FuelGrade)
  1328. {
  1329. bFound = true;
  1330. break;
  1331. }
  1332. }
  1333. if (!bFound)
  1334. {
  1335. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product {0} not present in new configuration", fuelprice.FuelGrade));
  1336. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1337. bAlarm = true;
  1338. break;
  1339. }
  1340. }
  1341. foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
  1342. {
  1343. bool bFound = false;
  1344. foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
  1345. {
  1346. if (Convert.ToInt32(product.ProductNo) == fuelprice.FuelGrade)
  1347. {
  1348. bFound = true;
  1349. break;
  1350. }
  1351. }
  1352. if (!bFound)
  1353. {
  1354. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product {0} not present in previous configuration", product.ProductNo));
  1355. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1356. bAlarm = true;
  1357. break;
  1358. }
  1359. }
  1360. return;
  1361. }
  1362. foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
  1363. {
  1364. FUSIONFuelPrice fuelprice = new FUSIONFuelPrice(Convert.ToInt32(product.ProductNo));
  1365. parentEntity.forecourtControl.WritableFuelPriceList.Add(fuelprice);
  1366. }
  1367. }
  1368. catch (Exception exception)
  1369. {
  1370. //managed in readConfiguration
  1371. //initializationStatus.ReadingConfigurationData = false;
  1372. }
  1373. }
  1374. finally
  1375. {
  1376. }
  1377. //if (!nfsManager.forecourtControl.ConfigParam.IsEMSGVersion)
  1378. {
  1379. parentEntity.ifsfManager.GetDSPConfiguration(null, null, null);
  1380. }
  1381. //else
  1382. //{
  1383. // parentEntity.ifsfManager.GetConfiguration(null, null, null);
  1384. //}
  1385. Trace.WriteLine("end");
  1386. }
  1387. public bool ReadConfiguration(object o)
  1388. {
  1389. Trace.WriteLine("init ReadConfiguration");
  1390. if (o == null)
  1391. return false;
  1392. GetConfigurationParam param = (GetConfigurationParam)o;
  1393. ServiceResponseGetConfiguration sr = param.sr;
  1394. FUSIONManager parentEntity = param.nfsManager;
  1395. bool end = true;
  1396. try
  1397. {
  1398. if (sr == null || ((sr.RequestType == "GetDSPConfiguration" || sr.RequestType == "GetConfiguration") && sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString()) ||
  1399. (sr.RequestType == "GetTLGConfiguration" && sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString() && sr.OverallResult != FDCPOSLibrary.OverallResult.NoData.ToString() && sr.OverallResult != FDCPOSLibrary.OverallResult.WrongConfiguration.ToString()) ||
  1400. sr.FDCdata == null || sr.FDCdata.Length == 0 ||
  1401. ((sr.RequestType == "GetDSPConfiguration" || sr.RequestType == "GetConfiguration") && (sr.FDCdata[0].DeviceClass == null || sr.FDCdata[0].DeviceClass.Length == 0)))
  1402. {
  1403. Trace.WriteLine(string.Format("end ReadConfiguration - errore in ServiceResponseGetConfiguration"));
  1404. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("error in Getconfiguration"));
  1405. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1406. parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
  1407. return false;
  1408. }
  1409. try
  1410. {
  1411. if (parentEntity.forecourtControl.WritablePumpList.Count > 0 && (sr.RequestType == "GetConfiguration" || sr.RequestType == "GetDSPConfiguration"))
  1412. {
  1413. Trace.WriteLine(string.Format("end ReadConfiguration - forecourtControl.WritablePumpList.Count = {0}, call CheckConfiguration", parentEntity.forecourtControl.WritablePumpList.Count));
  1414. if (!parentEntity.CheckConfiguration(sr))
  1415. {
  1416. Trace.WriteLine(string.Format("Configurazione Fusion != Configurazione interna, send Alarm"));
  1417. //TODO SendAlarm
  1418. }
  1419. return false;
  1420. }
  1421. else if (parentEntity.forecourtControl.WritableTankGroupList.Count > 0 && sr.RequestType == "GetTLGConfiguration")
  1422. {
  1423. Trace.WriteLine(string.Format("forecourtControl.WritablePumpList.Count = {0}, call CheckConfiguration", parentEntity.forecourtControl.WritablePumpList.Count));
  1424. if (!parentEntity.CheckConfiguration(sr))
  1425. {
  1426. Trace.WriteLine(string.Format("Configurazione Fusion != Configurazione interna, send Alarm"));
  1427. //TODO SendAlarm
  1428. return false;
  1429. }
  1430. }
  1431. if (sr.FDCdata[0].DeviceClass != null)
  1432. {
  1433. foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
  1434. {
  1435. switch (deviceClass.Type)
  1436. {
  1437. case Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser:
  1438. {
  1439. //if (nfsManager.forecourtControl.ConfigParam.IsEMSGVersion)
  1440. //{
  1441. // break;
  1442. //}
  1443. ReadPumpConfiguration(parentEntity, deviceClass.DeviceClass[0]);
  1444. }
  1445. break;
  1446. case Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint:
  1447. {
  1448. ReadPumpConfiguration(parentEntity, deviceClass);
  1449. }
  1450. break;
  1451. case Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge: //DT_TankProbe:
  1452. {
  1453. Trace.WriteLine(string.Format("DT_TankLevelGauge.Add id={0}", deviceClass.DeviceID));
  1454. foreach (ServiceDeviceClassConfiguration nestedDevice in deviceClass.DeviceClass)
  1455. {
  1456. // only 1 tankgroup per product will be created
  1457. FUSIONTankGroup tankgroup = parentEntity.getTankGroupByIndex(Convert.ToInt32(nestedDevice.TPProductNo));
  1458. if (tankgroup == null)
  1459. {
  1460. tankgroup = new FUSIONTankGroup(parentEntity, Convert.ToInt32(nestedDevice.TPProductNo), Convert.ToInt32(nestedDevice.TPProductNo));
  1461. parentEntity.forecourtControl.WritableTankGroupList.Add(tankgroup);
  1462. }
  1463. FUSIONTank tank = new FUSIONTank(parentEntity, Convert.ToInt32(nestedDevice.TPTankNo), tankgroup);
  1464. tankgroup.WritableTankList.Add(tank);
  1465. Trace.WriteLine(string.Format("WritableTankList.Add tank={0}", tank.realId));
  1466. // TODO assign tank properties
  1467. // ...
  1468. }
  1469. }
  1470. break;
  1471. }
  1472. }
  1473. }
  1474. if (this.cancelled)
  1475. {
  1476. Trace.WriteLine("end ReadConfiguration - this.cancelled");
  1477. return false;
  1478. }
  1479. if (sr.RequestType == "GetDSPConfiguration")
  1480. {
  1481. //parentEntity.ifsfManager.GetTLGConfiguration(null, null, null);
  1482. end = false;
  1483. //return false;
  1484. }
  1485. //parentEntity.initializationStatus.ConfigurationDataRead = true;
  1486. }
  1487. catch (Exception exception)
  1488. {
  1489. parentEntity.initializationStatus.ReadingConfigurationData = false;
  1490. Trace.WriteLine(string.Format("Exception! : {0}", exception.Message));
  1491. //Logger.AddEntry(new ExceptionLogEntry(parentEntity, ErrorLogSeverity.RecoverableDataLoss, "Exception in ReadConfigurationData ", exception));
  1492. }
  1493. finally
  1494. {
  1495. if (end)
  1496. {
  1497. Trace.WriteLine("ReadConfiguration finally");
  1498. this.running = false;
  1499. this.readingDoneEvent.Set();
  1500. }
  1501. }
  1502. //FG, MAR-15-2011, bug fix #28041; trigger to GetConfiguration again if there's no pump on FM.
  1503. if (parentEntity.forecourtControl.WritablePumpList.Count == 0)
  1504. {
  1505. return false;
  1506. }
  1507. parentEntity.shouldSetConnected = false;
  1508. parentEntity.InitializeOrhcestrator();
  1509. // TODO codice temporaneo if (this.OnConnectionStateChange != null)
  1510. parentEntity.initializationStatus.ConfigurationDataRead = true;
  1511. Trace.WriteLine("WritableConnectionState = DeviceConnectionState.Connected");
  1512. parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
  1513. }
  1514. finally
  1515. {
  1516. if (end)
  1517. {
  1518. Trace.WriteLine("ReadConfiguration finally");
  1519. this.running = false;
  1520. this.readingDoneEvent.Set();
  1521. }
  1522. }
  1523. Trace.WriteLine("ReadConfiguration - end");
  1524. return true;
  1525. }
  1526. internal void ReadPumpConfiguration(FUSIONManager parentEntity, ServiceDeviceClassConfiguration deviceClass)
  1527. {
  1528. FUSIONPump pump = new FUSIONPump(parentEntity);
  1529. pump.WritableParentDevice = parentEntity.forecourtControl;
  1530. pump.WritableCapFuelGradeSelected = false;
  1531. pump.WritableCapNozzleDetection = false;
  1532. pump.WritableCapSetLight = false;
  1533. pump.WritableCapSuspendFuelling = false;
  1534. pump.WritablePumpId = Convert.ToInt32(deviceClass.FPPumpNo);
  1535. pump.WritableDeviceName = "Pump " + deviceClass.FPPumpNo;
  1536. foreach (ServiceNozzleFPDeviceClassConfiguration FPnozzle in deviceClass.FPNozzle)
  1537. {
  1538. string productNo = (FPnozzle.FPProductId[0].PIFPProductNo != null) ? FPnozzle.FPProductId[0].PIFPProductNo : FPnozzle.FPProductId[0].PIFPProductNo1;
  1539. FUSIONNozzle nozzle = new FUSIONNozzle(Convert.ToInt32(FPnozzle.FPNozzleNo), pump);
  1540. nozzle.FuelGrade = Convert.ToInt32(productNo);
  1541. bool bFound = false;
  1542. foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
  1543. {
  1544. if (fuelprice.FuelGrade == Convert.ToInt32(productNo))
  1545. {
  1546. bFound = true;
  1547. break;
  1548. }
  1549. }
  1550. if (!bFound)
  1551. {
  1552. DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} nozzle {1}: product {2} is not a valid productNo", pump.Id, nozzle.Id, FPnozzle.FPProductId[0].PIFPProductNo));
  1553. parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
  1554. }
  1555. pump.WritableNozzleList.Add(nozzle);
  1556. }
  1557. parentEntity.forecourtControl.WritablePumpList.Add(pump);
  1558. Trace.WriteLine(string.Format("WritablePumpList.Add pump={0}", pump.realId));
  1559. }
  1560. public class GetProductTableParam
  1561. {
  1562. public FUSIONManager nfsManager;
  1563. public ServiceResponseGetProductTable sr;
  1564. public GetProductTableParam(ServiceResponseGetProductTable _sr, FUSIONManager _nfsManager)
  1565. {
  1566. sr = _sr;
  1567. nfsManager = _nfsManager;
  1568. }
  1569. }
  1570. public class GetConfigurationParam
  1571. {
  1572. public FUSIONManager nfsManager;
  1573. public ServiceResponseGetConfiguration sr;
  1574. public GetConfigurationParam(ServiceResponseGetConfiguration _sr, FUSIONManager _nfsManager)
  1575. {
  1576. sr = _sr;
  1577. nfsManager = _nfsManager;
  1578. }
  1579. }
  1580. }
  1581. }
  1582. }