IFSFManager.cs 277 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616
  1. using FControlFUSIONCF;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Xml;
  9. using System.Xml.Serialization;
  10. using Wayne.FDCPOSLibrary;
  11. using Wayne.FDCPOSLibrary.Configuration;
  12. using Wayne.ForecourtControl.OptBridge;
  13. using Wayne.Lib;
  14. using Wayne.Lib.Log;
  15. namespace Wayne.ForecourtControl.Fusion
  16. {
  17. public class Heartbeat : DisposableBase
  18. {
  19. private readonly Timer heartbeatTimer;
  20. private readonly Timer disconnectionTimer;
  21. public event EventHandler OnHeartbeatTimeout;
  22. public event EventHandler OnHeartbeatInterval;
  23. public long heartbeatTimeout;
  24. public long heartbeatInterval;
  25. public bool tryingConnect;
  26. private IFSFManager ifsfManager;
  27. private readonly DebugLogger debugLogger;
  28. public Heartbeat(IFSFManager _ifsfManager, long _heartbeatInterval, long _heartbeatTimeout)
  29. {
  30. ifsfManager = _ifsfManager;
  31. heartbeatInterval = _heartbeatInterval;
  32. heartbeatTimeout = _heartbeatTimeout;
  33. debugLogger = ifsfManager.DebugLogger;
  34. disconnectionTimer = new Timer(HeartbeatTimeout, null, Timeout.Infinite, Timeout.Infinite);
  35. heartbeatTimer = new Timer(HeartbeatInterval, null, Timeout.Infinite, Timeout.Infinite);
  36. }
  37. private void HeartbeatTimeout(Object state)
  38. {
  39. if (IsDisposed)
  40. {
  41. return;
  42. }
  43. if (debugLogger.IsActive())
  44. debugLogger.Add("Heartbeat Timeout");
  45. if (OnHeartbeatTimeout != null)
  46. OnHeartbeatTimeout.Invoke(this, null);
  47. if (heartbeatTimeout > 0)
  48. {
  49. disconnectionTimer.Change(heartbeatTimeout, Timeout.Infinite);
  50. }
  51. }
  52. private void HeartbeatInterval(Object state)
  53. {
  54. if (IsDisposed)
  55. {
  56. return;
  57. }
  58. if (OnHeartbeatInterval != null)
  59. OnHeartbeatInterval.Invoke(this, null);
  60. }
  61. public void ResetDisconnectionTimeout()
  62. {
  63. if (IsDisposed)
  64. {
  65. return;
  66. }
  67. // read HeartbeatTimeout config parameter
  68. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "HeartbeatTimeout");
  69. try
  70. {
  71. if (sValue.Length > 0)
  72. heartbeatTimeout = Convert.ToInt32(sValue);
  73. }
  74. catch (Exception ex)
  75. {
  76. if (debugLogger.IsActive())
  77. debugLogger.Add(string.Format("Exception reading heartbeatTimeout: {0}", ex));
  78. }
  79. if (heartbeatTimeout > 0)
  80. {
  81. disconnectionTimer.Change(heartbeatTimeout, Timeout.Infinite);
  82. }
  83. }
  84. public void Restart()
  85. {
  86. if (IsDisposed)
  87. {
  88. return;
  89. }
  90. // start sending heartbeat when receive logon and send
  91. if (heartbeatInterval > 0)
  92. {
  93. heartbeatTimer.Change(heartbeatInterval, Timeout.Infinite);
  94. }
  95. }
  96. public void Stop()
  97. {
  98. if (IsDisposed)
  99. {
  100. return;
  101. }
  102. heartbeatTimer.Change(Timeout.Infinite, Timeout.Infinite);
  103. }
  104. public void NotifyDisconnection()
  105. {
  106. if (IsDisposed)
  107. {
  108. return;
  109. }
  110. heartbeatTimer.Change(Timeout.Infinite, Timeout.Infinite);
  111. tryingConnect = true;
  112. disconnectionTimer.Change(Timeout.Infinite, Timeout.Infinite);
  113. Restart();
  114. }
  115. public void SetReconnected()
  116. {
  117. if (IsDisposed)
  118. {
  119. return;
  120. }
  121. tryingConnect = false;
  122. }
  123. protected override void DoDispose()
  124. {
  125. heartbeatTimer.Dispose();
  126. disconnectionTimer.Dispose();
  127. }
  128. }
  129. #region Event Args
  130. public class DeviceStateChangedEventArgs : EventArgs
  131. {
  132. public string deviceType;
  133. public int deviceId;
  134. public LogicalDeviceState state;
  135. public LogicalDeviceState substate;
  136. public string lockingAS;
  137. public int nozzleUp;
  138. public DeviceStateChangedEventArgs(string _deviceType, int _deviceId, LogicalDeviceState _state, LogicalDeviceState _substate, string _lockingAS, int _nozzleUp)
  139. {
  140. deviceType = _deviceType;
  141. deviceId = _deviceId;
  142. state = _state;
  143. substate = _substate;
  144. lockingAS = _lockingAS;
  145. nozzleUp = _nozzleUp;
  146. }
  147. }
  148. public class VIRStateChangedEventArgs : EventArgs
  149. {
  150. public int deviceId;
  151. public string virId;
  152. public DeviceConnectionState state;
  153. public VIRStateChangedEventArgs(int _deviceId, string _virId, DeviceConnectionState _state)
  154. {
  155. deviceId = _deviceId;
  156. virId = _virId;
  157. state = _state;
  158. }
  159. }
  160. public class FuelModeChangedEventArgs : EventArgs
  161. {
  162. public string deviceType;
  163. public int deviceId;
  164. public int mode;
  165. public FuelModeChangedEventArgs(string _deviceType, int _deviceId, int _mode)
  166. {
  167. deviceType = _deviceType;
  168. deviceId = _deviceId;
  169. mode = _mode;
  170. }
  171. }
  172. public class OperationModeChangedEventArgs : EventArgs
  173. {
  174. public string deviceType;
  175. public int deviceId;
  176. public ushort mode;
  177. public OperationModeChangedEventArgs(string _deviceType, int _deviceId, ushort _mode)
  178. {
  179. deviceType = _deviceType;
  180. deviceId = _deviceId;
  181. mode = _mode;
  182. }
  183. }
  184. public class CurrentFuellingStatusEventArgs : EventArgs
  185. {
  186. public string deviceType;
  187. public int deviceId;
  188. public int nozzleId;
  189. public decimal volume;
  190. public decimal amount;
  191. public decimal price;
  192. public string authAS;
  193. /// <summary>
  194. /// The fuel period id of the current fuelling
  195. /// </summary>
  196. public int FuelPeriodSequenceNo { get; set; }
  197. /// <summary>
  198. /// The AuthorizationId
  199. /// </summary>
  200. public int ReleaseId { get; set; }
  201. /// <summary>
  202. /// The TransactionSeqNo
  203. /// </summary>
  204. public int TransactionId { get; set; }
  205. /// <summary>
  206. /// The Reserving Device Id
  207. /// </summary>
  208. public int ReservingDeviceId { get; set; }
  209. public CurrentFuellingStatusEventArgs(string _deviceType, int _deviceId, int _nozzleId, decimal _volume, decimal _amount, decimal _price, string _authAS)
  210. {
  211. deviceType = _deviceType;
  212. deviceId = _deviceId;
  213. nozzleId = _nozzleId;
  214. volume = _volume;
  215. amount = _amount;
  216. price = _price;
  217. authAS = _authAS;
  218. }
  219. }
  220. public class FuelPointTotalsEventArgs : EventArgs
  221. {
  222. public int requestId;
  223. public bool overallResult;
  224. public string deviceType;
  225. public int deviceId;
  226. public int nozzleId;
  227. public decimal volume;
  228. public decimal amount;
  229. public decimal price;
  230. public string originalTransactionData;
  231. public FuelPointTotalsEventArgs(int _requestId, bool _overallResult, string _deviceType, int _deviceId, int _nozzleId, decimal _volume, decimal _amount, decimal _price, string _originalTransactionData)
  232. {
  233. requestId = _requestId;
  234. overallResult = _overallResult;
  235. deviceType = _deviceType;
  236. deviceId = _deviceId;
  237. nozzleId = _nozzleId;
  238. volume = _volume;
  239. amount = _amount;
  240. price = _price;
  241. originalTransactionData = _originalTransactionData;
  242. }
  243. }
  244. public class FuelSaleTrxEventArgs : EventArgs
  245. {
  246. public int transactionId;
  247. public int fuellingSeqNo;
  248. public Wayne.FDCPOSLibrary.FuellingState transactionStatus;
  249. public int completionReason;
  250. public string deviceType;
  251. public int deviceId;
  252. public int nozzleId;
  253. public decimal volume;
  254. public decimal amount;
  255. public decimal price;
  256. public int fuelMode;
  257. public DateTime trxStartDateTime;
  258. public DateTime trxEndDateTime;
  259. public string lockingAS;
  260. public string authAS;
  261. public string DSPFields;
  262. public string CRCMode;
  263. public string MIDLinesNarrow;
  264. public string MIDLinesWide;
  265. public int releaseToken;
  266. public byte reservingDeviceId;
  267. public FuellingType fuellingType;
  268. public string origMessageXml;
  269. /// <summary>
  270. /// The fuel period id for the transaction
  271. /// </summary>
  272. public int FuelPeriodSequenceNo { get; set; }
  273. public FuelSaleTrxEventArgs(int _transactionId, int _fuellingSeqNo, Wayne.FDCPOSLibrary.FuellingState _transactionStatus,
  274. int _completionReason, string _deviceType, int _deviceId, int _nozzleId, decimal _volume, decimal _amount,
  275. decimal _price, int _fuelMode, DateTime _trxStartDateTime, DateTime _trxEndDateTime, string _lockingAS,
  276. string _authAS, string _DSPFields, string _CRCMode, string _MIDLinesNarrow,
  277. string _MIDLinesWide, int _releaseToken, byte _reservingDeviceId, FuellingType _fuellingType,
  278. string _originalMessageXml = null)
  279. {
  280. transactionId = _transactionId;
  281. fuellingSeqNo = _fuellingSeqNo;
  282. transactionStatus = _transactionStatus;
  283. completionReason = _completionReason;
  284. deviceType = _deviceType;
  285. deviceId = _deviceId;
  286. nozzleId = _nozzleId;
  287. volume = _volume;
  288. amount = _amount;
  289. price = _price;
  290. fuelMode = _fuelMode;
  291. trxStartDateTime = _trxStartDateTime;
  292. trxEndDateTime = _trxEndDateTime;
  293. lockingAS = _lockingAS;
  294. authAS = _authAS;
  295. DSPFields = _DSPFields;
  296. CRCMode = _CRCMode;
  297. MIDLinesNarrow = _MIDLinesNarrow;
  298. MIDLinesWide = _MIDLinesWide;
  299. releaseToken = _releaseToken;
  300. reservingDeviceId = _reservingDeviceId;
  301. fuellingType = _fuellingType;
  302. origMessageXml = _originalMessageXml;
  303. }
  304. }
  305. public class ChangeFuelPriceEventArgs : EventArgs
  306. {
  307. public int productId;
  308. public int mode;
  309. public decimal oldPrice;
  310. public decimal newPrice;
  311. public ChangeFuelPriceEventArgs(int _productId, int _mode, decimal _oldPrice, decimal _newPrice)
  312. {
  313. productId = _productId;
  314. mode = _mode;
  315. oldPrice = _oldPrice;
  316. newPrice = _newPrice;
  317. }
  318. }
  319. public class DeviceAlarmEventArgs : EventArgs
  320. {
  321. public string deviceType;
  322. public int deviceId;
  323. public int alarmId;
  324. public string alarmDescr;
  325. public DeviceAlarmEventArgs(string _deviceType, int _deviceId, int _alarmId, string _alarmDescr)
  326. {
  327. deviceType = _deviceType;
  328. deviceId = _deviceId;
  329. alarmId = _alarmId;
  330. alarmDescr = _alarmDescr;
  331. }
  332. }
  333. public class VersionInfoEventArgs : EventArgs
  334. {
  335. public string release;
  336. public string version;
  337. public string hotfix;
  338. public VersionInfoEventArgs(string _release, string _version, string _hotfix)
  339. {
  340. version = _version;
  341. release = _release;
  342. hotfix = _hotfix;
  343. }
  344. }
  345. public class TankDataEventArgs : EventArgs
  346. {
  347. int DeviceID;
  348. int TankNo;
  349. string Type;
  350. int ManualMode;
  351. decimal AverageTemp;
  352. decimal GrossStandardVolume;
  353. decimal ObservedDensity;
  354. decimal ProductLevel;
  355. decimal TotalObservedVolume;
  356. decimal WaterLevel;
  357. int TPStatus;
  358. public TankDataEventArgs(int _DeviceID, int _TankNo, string _Type, int _ManualMode,
  359. decimal _AverageTemp, decimal _GrossStandardVolume, decimal _ObservedDensity,
  360. decimal _ProductLevel, decimal _TotalObservedVolume, decimal _WaterLevel, int _TPStatus)
  361. {
  362. DeviceID = _DeviceID;
  363. TankNo = _TankNo;
  364. Type = _Type;
  365. ManualMode = _ManualMode;
  366. AverageTemp = _AverageTemp;
  367. GrossStandardVolume = _GrossStandardVolume;
  368. ObservedDensity = _ObservedDensity;
  369. ProductLevel = _ProductLevel;
  370. TotalObservedVolume = _TotalObservedVolume;
  371. WaterLevel = _WaterLevel;
  372. TPStatus = _TPStatus;
  373. }
  374. }
  375. public class OptReadEventArgs : EventArgs
  376. {
  377. public string deviceType;
  378. public int deviceId;
  379. public byte[] message;
  380. public OptReadEventArgs(string _deviceType, int _deviceId, byte[] _message)
  381. {
  382. deviceType = _deviceType;
  383. deviceId = _deviceId;
  384. message = _message;
  385. }
  386. }
  387. #endregion
  388. public class IFSFManager : DisposableBase
  389. {
  390. public ServiceRequest serviceRequestLogOn;
  391. private IFSFSockets _clientSocket;
  392. public IFSFSockets clientSocket
  393. {
  394. get { return _clientSocket; }
  395. }
  396. private Heartbeat _heartbeat;
  397. public Heartbeat heartbeat
  398. {
  399. get { return _heartbeat; }
  400. }
  401. private FUSIONManager manager;
  402. public bool authentificationErrorRetry;
  403. public event EventHandler<DeviceStateChangedEventArgs> OnDeviceStateChange;
  404. public event EventHandler<VIRStateChangedEventArgs> OnVirStateChange;
  405. public event EventHandler<FuelModeChangedEventArgs> OnFuelModeChange;
  406. public event EventHandler<OperationModeChangedEventArgs> OnOperationModeChange;
  407. public event EventHandler<CurrentFuellingStatusEventArgs> OnCurrentFuellingStatus;
  408. public event EventHandler<FuelPointTotalsEventArgs> OnFuelPointTotals;
  409. public event EventHandler<FuelSaleTrxEventArgs> OnFuelSaleTrx;
  410. public event EventHandler<DeviceAlarmEventArgs> OnDeviceAlarm;
  411. public event EventHandler<VersionInfoEventArgs> OnVersionInfo;
  412. public event EventHandler<ChangeFuelPriceEventArgs> OnChangeFuelPrice;
  413. public event EventHandler<FuelSaleTrxEventArgs> OnLockFuelSaleTrx;
  414. public event EventHandler<FuelSaleTrxEventArgs> OnUnlockFuelSaleTrx;
  415. public event EventHandler<FuelSaleTrxEventArgs> OnClearFuelSaleTrx;
  416. public event EventHandler<FuelSaleTrxEventArgs> OnGetAvailableFuelSaleTrx;
  417. public event EventHandler<FuelSaleTrxEventArgs> OnGetFuelSaleTrxDetails;
  418. public event EventHandler<OptReadEventArgs> OnOptRead;
  419. public event EventHandler<TankDataEventArgs> OnTankData;
  420. public event EventHandler<EventArgs> OnConfigurationChange;
  421. public event EventHandler<EventArgs> OnTwinMasterReady;
  422. private readonly Dictionary<int, int> unsolicitedFPStateChangeDictionary = new Dictionary<int, int>();
  423. private readonly DebugLogger debugLogger;
  424. public DebugLogger DebugLogger { get { return debugLogger; } }
  425. public IFSFManager(FUSIONManager manager, int id)
  426. {
  427. debugLogger = manager.DebugLogger;
  428. this._clientSocket = new IFSFSockets(id, this);
  429. this._clientSocket.OnResponseTimeout += new EventHandler(_clientSocket_OnResponseTimeout);
  430. this.manager = manager;
  431. this._heartbeat = new Heartbeat(this, this._clientSocket.heartbeatInterval, this._clientSocket.heartbeatTimeout);
  432. heartbeat.OnHeartbeatInterval += new EventHandler(heartbeat_OnHeartbeatInterval);
  433. heartbeat.OnHeartbeatTimeout += new EventHandler(heartbeat_OnHeartbeatTimeout);
  434. authentificationErrorRetry = true;
  435. }
  436. private void DebugLog(string s)
  437. {
  438. if (debugLogger.IsActive())
  439. debugLogger.Add(s);
  440. }
  441. public static void ArrayResize<T>(ref T[] array, int newSize)
  442. {
  443. int oldSize = (array == null) ? 0 : array.Length;
  444. T[] newArray = new T[newSize];
  445. int preserveLength = System.Math.Min(oldSize, newSize);
  446. for (int i = 0; i < preserveLength; i++)
  447. newArray[i] = array[i];
  448. array = newArray;
  449. }
  450. public LogicalDeviceState convertLogicalDeviceState(string state)
  451. {
  452. if (state == LogicalDeviceState.FDC_CALLING.ToString())
  453. return LogicalDeviceState.FDC_CALLING;
  454. else if (state == LogicalDeviceState.FDC_CONFIGURE.ToString())
  455. return LogicalDeviceState.FDC_CONFIGURE;
  456. else if (state == LogicalDeviceState.FDC_DISABLED.ToString())
  457. return LogicalDeviceState.FDC_DISABLED;
  458. else if (state == LogicalDeviceState.FDC_ERRORSTATE.ToString())
  459. return LogicalDeviceState.FDC_ERRORSTATE;
  460. else if (state == LogicalDeviceState.FDC_FUELLING.ToString())
  461. return LogicalDeviceState.FDC_FUELLING;
  462. else if (state == LogicalDeviceState.FDC_INVALIDSTATE.ToString())
  463. return LogicalDeviceState.FDC_INVALIDSTATE;
  464. else if (state == LogicalDeviceState.FDC_LOCKED.ToString())
  465. return LogicalDeviceState.FDC_LOCKED;
  466. else if (state == LogicalDeviceState.FDC_OFFLINE.ToString())
  467. return LogicalDeviceState.FDC_OFFLINE;
  468. else if (state == LogicalDeviceState.FDC_OUTOFORDER.ToString())
  469. return LogicalDeviceState.FDC_OUTOFORDER;
  470. else if (state == LogicalDeviceState.FDC_READY.ToString())
  471. return LogicalDeviceState.FDC_READY;
  472. else if (state == LogicalDeviceState.FDC_REQUESTED.ToString())
  473. return LogicalDeviceState.FDC_REQUESTED;
  474. else if (state == LogicalDeviceState.FDC_STARTED.ToString())
  475. return LogicalDeviceState.FDC_STARTED;
  476. else if (state == LogicalDeviceState.FDC_SUSPENDED.ToString())
  477. return LogicalDeviceState.FDC_SUSPENDED;
  478. else if (state == LogicalDeviceState.FDC_TEST.ToString())
  479. return LogicalDeviceState.FDC_TEST;
  480. else if (state == LogicalDeviceState.FDC_SUSPENDED_STARTED.ToString())
  481. return LogicalDeviceState.FDC_SUSPENDED_STARTED;
  482. else if (state == LogicalDeviceState.FDC_SUSPENDED_FUELLING.ToString())
  483. return LogicalDeviceState.FDC_SUSPENDED_FUELLING;
  484. else if (state == LogicalDeviceState.FDC_CLOSED.ToString())
  485. return LogicalDeviceState.FDC_CLOSED;
  486. else if (state == LogicalDeviceState.FDC_AUTHORISED.ToString())
  487. return LogicalDeviceState.FDC_AUTHORISED;
  488. else if (state == LogicalDeviceState.FDC_FUELLING_TERMINATED.ToString())
  489. return LogicalDeviceState.FDC_FUELLING_TERMINATED;
  490. return 0;
  491. }
  492. private Wayne.FDCPOSLibrary.FuellingState convertFuellingState(string state)
  493. {
  494. if (state == Wayne.FDCPOSLibrary.FuellingState.Locked.ToString())
  495. return Wayne.FDCPOSLibrary.FuellingState.Locked;
  496. else if (state == Wayne.FDCPOSLibrary.FuellingState.Payable.ToString())
  497. return Wayne.FDCPOSLibrary.FuellingState.Payable;
  498. else if (state == Wayne.FDCPOSLibrary.FuellingState.Paid.ToString() || state == Wayne.FDCPOSLibrary.FuellingState.Cleared.ToString())
  499. return Wayne.FDCPOSLibrary.FuellingState.Paid;
  500. return 0;
  501. }
  502. private int convertCompletionReason(string reason)
  503. {
  504. // Fusion 4.4
  505. if (reason == Wayne.FDCPOSLibrary.CompletionReason.NormalCompletion.ToString())
  506. return (int)Wayne.FDCPOSLibrary.CompletionReason.NormalCompletion;
  507. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.AuthorizationTimeout.ToString())
  508. return (int)Wayne.FDCPOSLibrary.CompletionReason.AuthorizationTimeout;
  509. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.FuellingTimeout.ToString())
  510. return (int)Wayne.FDCPOSLibrary.CompletionReason.FuellingTimeout;
  511. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.NoFlowTimeout.ToString())
  512. return (int)Wayne.FDCPOSLibrary.CompletionReason.NoFlowTimeout;
  513. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpDisconnected.ToString())
  514. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpDisconnected;
  515. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpStopped.ToString())
  516. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpStopped;
  517. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpGenericError.ToString())
  518. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpGenericError;
  519. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpPulserError.ToString())
  520. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpPulserError;
  521. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpLowLevelError.ToString())
  522. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpLowLevelError;
  523. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpDisplayError.ToString())
  524. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpDisplayError;
  525. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpCalculationError.ToString())
  526. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpCalculationError;
  527. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpAntiSpillError.ToString())
  528. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpAntiSpillError;
  529. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpBlenderError.ToString())
  530. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpBlenderError;
  531. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PumpVaporRecoveryError.ToString())
  532. return (int)Wayne.FDCPOSLibrary.CompletionReason.PumpVaporRecoveryError;
  533. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.ZeroFilling.ToString())
  534. return (int)Wayne.FDCPOSLibrary.CompletionReason.ZeroFilling;
  535. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.PresetOverrun.ToString())
  536. return (int)Wayne.FDCPOSLibrary.CompletionReason.PresetOverrun;
  537. else if (reason == Wayne.FDCPOSLibrary.CompletionReason.ReadFromTotalizers.ToString())
  538. return (int)Wayne.FDCPOSLibrary.CompletionReason.ReadFromTotalizers;
  539. // Fusion 4.3
  540. return Convert.ToInt32(reason);
  541. }
  542. public static string getClientID(string workstationID, string applicationSender)
  543. {
  544. return workstationID + "-" + applicationSender;
  545. }
  546. public void Disconnect()
  547. {
  548. clientSocket.Disconnect();
  549. clientSocket.mainConnectionState = DeviceConnectionState.Disconnected;
  550. if (heartbeat != null)
  551. heartbeat.NotifyDisconnection();
  552. }
  553. private void _clientSocket_OnResponseTimeout(object sender, EventArgs e)
  554. {
  555. }
  556. private void heartbeat_OnHeartbeatTimeout(object sender, EventArgs e)
  557. {
  558. DebugLog("Heartbeat Timeout - disconnecting");
  559. Disconnect();
  560. clientSocket.mainConnectionState = DeviceConnectionState.Disconnected;
  561. }
  562. private void heartbeat_OnHeartbeatInterval(object sender, EventArgs e)
  563. {
  564. Heartbeat();
  565. }
  566. public string ReadResponse(string myString, int msglength, ref OverallResult result) //StreamReader networkStream)
  567. {
  568. string requestType = "";
  569. int requestId = 0;
  570. try
  571. {
  572. requestType = GetRequestType("RequestType", myString);
  573. requestId = GetRequestID("RequestID", myString);
  574. }
  575. catch (Exception ex)
  576. {
  577. DebugLog(string.Format("Unable to get request type or id - Exception! {0}", ex));
  578. //result = OverallResult.Failure;
  579. }
  580. if (result != OverallResult.Success)
  581. {
  582. DebugLog(string.Format("ReadResponse ERROR result='{0}'", result));
  583. }
  584. else
  585. {
  586. if (requestType == "")
  587. {
  588. DebugLog(string.Format("ReadResponse INVALID requestType='{0}', requestId={1}", requestType, requestId));
  589. result = OverallResult.FormatError;
  590. }
  591. int UTFlength = System.Text.Encoding.UTF8.GetBytes(myString).Length;
  592. if (result == OverallResult.Success && UTFlength != msglength)
  593. {
  594. DebugLog(string.Format("ReadResponse header='{0}' != msgLength={1}, requestType='{2}', requestId={3}", msglength, UTFlength, requestType, requestId));
  595. result = OverallResult.FormatError;
  596. }
  597. else
  598. {
  599. try
  600. {
  601. DebugLog(string.Format("ReadResponse init: requestType='{0}', requestId={1}", requestType, requestId));
  602. if (requestType == "LogOn")
  603. {
  604. ServiceResponseLogOn sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseLogOn>(myString, ref result);
  605. LogOnResp(sr.RequestIDNumber, sr.OverallResult, sr.Value, sr.FDCdata[0].FDCTimeStamp);
  606. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  607. }
  608. else if (requestType == "LogOff")
  609. {
  610. ServiceResponseLogOff sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseLogOff>(myString, ref result);
  611. LogOffResp(sr.RequestIDNumber, sr.OverallResult);
  612. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  613. }
  614. else if (requestType == "VersionInfo")
  615. {
  616. ServiceResponseVersionInfo sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseVersionInfo>(myString, ref result);
  617. VersionInfoResp(sr.RequestIDNumber, sr.OverallResult, sr);
  618. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  619. }
  620. else if (requestType == "StartForecourt")
  621. {
  622. ServiceResponseStartForecourt sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseStartForecourt>(myString, ref result);
  623. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].ErrorCode;
  624. StartForecourtResp(sr.RequestIDNumber, sr.OverallResult, errorCode);
  625. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  626. }
  627. else if (requestType == "TwinOpenMaster")
  628. {
  629. ServiceResponseTwinOpenMaster sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseTwinOpenMaster>(myString, ref result);
  630. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].ErrorCode;
  631. TwinOpenMasterResp(sr.RequestIDNumber, sr.OverallResult, errorCode);
  632. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  633. }
  634. else if (requestType == "StopForecourt")
  635. {
  636. ServiceResponseStopForecourt sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseStopForecourt>(myString, ref result);
  637. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].ErrorCode;
  638. StopForecourtResp(sr.RequestIDNumber, sr.OverallResult, errorCode);
  639. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  640. }
  641. else if (requestType == "GetCurrentFuellingStatus")
  642. {
  643. ServiceResponseGetCurrentFuellingStatus sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetCurrentFuellingStatus>(myString, ref result);
  644. GetCurrentFuellingStatusResp(sr.RequestIDNumber, sr.OverallResult, sr);
  645. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  646. }
  647. else if (requestType == "GetTotals")
  648. {
  649. ServiceResponseGetFuelPointTotals sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFuelPointTotals>(myString, ref result);
  650. GetFuelPointTotalsResp(sr.RequestIDNumber, sr.OverallResult, sr, myString);
  651. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  652. }
  653. else if (requestType == "GetDeviceState")
  654. {
  655. ServiceResponseGetDeviceState sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetDeviceState>(myString, ref result);
  656. GetDeviceStateResp(sr.RequestIDNumber, sr.OverallResult, sr);
  657. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  658. }
  659. else if (requestType == "GetFPState")
  660. {
  661. ServiceResponseGetFPState sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFPState>(myString, ref result);
  662. GetFPStateResp(sr.RequestIDNumber, sr.OverallResult, sr);
  663. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  664. }
  665. else if (requestType == "GetTPState")
  666. {
  667. ServiceResponseGetTPState sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetTPState>(myString, ref result);
  668. GetTPStateResp(sr.RequestIDNumber, sr.OverallResult, sr);
  669. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  670. }
  671. else if (requestType == "GetPPState")
  672. {
  673. ServiceResponseGetPPState sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetPPState>(myString, ref result);
  674. GetPPStateResp(sr.RequestIDNumber, sr.OverallResult, sr);
  675. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  676. }
  677. else if (requestType == "GetVIRState")
  678. {
  679. ServiceResponseGetVIRState sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetVIRState>(myString, ref result);
  680. GetVIRStateResp(sr.RequestIDNumber, sr.OverallResult, sr);
  681. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  682. }
  683. else if (requestType == "TerminateFuelling")
  684. {
  685. ServiceResponseTerminateFuelling sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseTerminateFuelling>(myString, ref result);
  686. TerminateFuellingResp(sr.RequestIDNumber, sr.OverallResult, sr);
  687. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  688. }
  689. else if (requestType == "AuthoriseFuelPoint")
  690. {
  691. ServiceResponseAuthoriseFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseAuthoriseFuelPoint>(myString, ref result);
  692. AuthoriseFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  693. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  694. }
  695. else if (requestType == "ChangeFuelMode")
  696. {
  697. ServiceResponseChangeFuelMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseChangeFuelMode>(myString, ref result);
  698. ChangeFuelModeResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  699. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  700. }
  701. else if (requestType == "ChangeFPFuelMode")
  702. {
  703. ServiceResponseChangeFPFuelMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseChangeFPFuelMode>(myString, ref result);
  704. ChangeFuelModeResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  705. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  706. }
  707. else if (requestType == "ChangeFuelPrice")
  708. {
  709. ServiceResponseChangeFuelPrice sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseChangeFuelPrice>(myString, ref result);
  710. ChangeFuelPriceResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  711. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  712. }
  713. else if (requestType == "LockFuelSaleTrx")
  714. {
  715. ServiceResponseLockFuelSaleTrx sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseLockFuelSaleTrx>(myString, ref result);
  716. LockFuelSaleTrxResp(sr.RequestIDNumber, sr.OverallResult, sr);
  717. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  718. }
  719. else if (requestType == "UnlockFuelSaleTrx")
  720. {
  721. ServiceResponseUnlockFuelSaleTrx sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseUnlockFuelSaleTrx>(myString, ref result);
  722. UnlockFuelSaleTrxResp(sr.RequestIDNumber, sr.OverallResult, sr);
  723. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  724. }
  725. else if (requestType == "ClearFuelSaleTrx")
  726. {
  727. ServiceResponseClearFuelSaleTrx sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseClearFuelSaleTrx>(myString, ref result);
  728. ClearFuelSaleTrxResp(sr.RequestIDNumber, sr.OverallResult, sr);
  729. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  730. }
  731. else if (requestType == "GetAvailableFuelSaleTrxs")
  732. {
  733. ServiceResponseGetAvailableFuelSaleTrxs sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetAvailableFuelSaleTrxs>(myString, ref result);
  734. GetAvailableFuelSaleTrxsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  735. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  736. }
  737. else if (requestType == "GetFuelSaleTrxDetails")
  738. {
  739. string res = "";
  740. if (FDCGlobal.ProtocolVersion == FDCVersion.V0003)
  741. {
  742. ServiceResponseGetFuelSaleTrxDetailsV03 sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFuelSaleTrxDetailsV03>(myString, ref result);
  743. GetFuelSaleTrxDetailsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  744. res = sr.OverallResult;
  745. }
  746. else
  747. {
  748. ServiceResponseGetFuelSaleTrxDetails sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFuelSaleTrxDetails>(myString, ref result);
  749. GetFuelSaleTrxDetailsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  750. res = sr.OverallResult;
  751. }
  752. result = FDCConvert.OverallResultToInt(res);
  753. }
  754. else if (requestType == "GetProductTable")
  755. {
  756. ServiceResponseGetProductTable sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetProductTable>(myString, ref result);
  757. GetProductTableResp(sr.RequestIDNumber, sr.OverallResult, sr);
  758. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  759. }
  760. else if (requestType == "GetModeTable")
  761. {
  762. ServiceResponseGetModeTable sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetModeTable>(myString, ref result);
  763. GetModeTableResp(sr.RequestIDNumber, sr.OverallResult, sr);
  764. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  765. }
  766. else if (requestType == "GetFuelMode")
  767. {
  768. ServiceResponseGetFuelMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFuelMode>(myString, ref result);
  769. GetFuelModeResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  770. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  771. }
  772. else if (requestType == "GetFPFuelMode")
  773. {
  774. ServiceResponseGetFPFuelMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFPFuelMode>(myString, ref result);
  775. GetFuelModeResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  776. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  777. }
  778. else if (requestType == "GetConfiguration")
  779. {
  780. ServiceResponseGetConfiguration sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetConfiguration>(myString, ref result);
  781. GetConfigurationResp(sr.RequestIDNumber, sr.OverallResult, sr);
  782. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  783. }
  784. else if (requestType == "GetDSPConfiguration")
  785. {
  786. ServiceResponseGetDSPConfiguration sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetDSPConfiguration>(myString, ref result);
  787. GetDSPConfigurationResp(sr.RequestIDNumber, sr.OverallResult, sr);
  788. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  789. }
  790. else if (requestType == "GetTLGConfiguration")
  791. {
  792. ServiceResponseGetTLGConfiguration sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetTLGConfiguration>(myString, ref result);
  793. GetTLGConfigurationResp(sr.RequestIDNumber, sr.OverallResult, sr);
  794. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  795. }
  796. else if (requestType == "GetPPConfiguration")
  797. {
  798. ServiceResponseGetPPConfiguration sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetPPConfiguration>(myString, ref result);
  799. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  800. }
  801. else if (requestType == "SetConfiguration")
  802. {
  803. ServiceResponseSetConfiguration sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseSetConfiguration>(myString, ref result);
  804. SetConfigurationResp(sr.RequestIDNumber, sr.OverallResult, sr);
  805. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  806. }
  807. else if (requestType == "LockNozzle")
  808. {
  809. ServiceResponseLockNozzle sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseLockNozzle>(myString, ref result);
  810. LockNozzleResp(sr.RequestIDNumber, sr.OverallResult, sr);
  811. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  812. }
  813. else if (requestType == "UnlockNozzle")
  814. {
  815. ServiceResponseUnlockNozzle sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseUnlockNozzle>(myString, ref result);
  816. UnlockNozzleResp(sr.RequestIDNumber, sr.OverallResult, sr);
  817. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  818. }
  819. else if (requestType == "GetCountrySettings")
  820. {
  821. ServiceResponseGetCountrySettings sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetCountrySettings>(myString, ref result);
  822. GetCountrySettingsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  823. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  824. }
  825. else if (requestType == "GetDSPLimits")
  826. {
  827. ServiceResponseGetDSPLimits sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetDSPLimits>(myString, ref result);
  828. GetDSPLimitsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  829. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  830. }
  831. else if (requestType == "ChangeDSPLimits")
  832. {
  833. ServiceResponseChangeDSPLimits sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseChangeDSPLimits>(myString, ref result);
  834. ChangeDSPLimitsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  835. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  836. }
  837. else if (requestType == "SuspendFuelling")
  838. {
  839. ServiceResponseSuspendFuelling sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseSuspendFuelling>(myString, ref result);
  840. SuspendFuellingResp(sr.RequestIDNumber, sr.OverallResult, sr);
  841. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  842. }
  843. else if (requestType == "ResumeFuelling")
  844. {
  845. ServiceResponseResumeFuelling sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseResumeFuelling>(myString, ref result);
  846. ResumeFuellingResp(sr.RequestIDNumber, sr.OverallResult, sr);
  847. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  848. }
  849. else if (requestType == "LockTank")
  850. {
  851. ServiceResponseLockTank sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseLockTank>(myString, ref result);
  852. LockTankResp(sr.RequestIDNumber, sr.OverallResult, sr);
  853. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  854. }
  855. else if (requestType == "UnlockTank")
  856. {
  857. ServiceResponseUnlockTank sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseUnlockTank>(myString, ref result);
  858. UnlockTankResp(sr.RequestIDNumber, sr.OverallResult, sr);
  859. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  860. }
  861. else if (requestType == "GetTankData")
  862. {
  863. ServiceResponseGetTankData sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetTankData>(myString, ref result);
  864. GetTankDataResp(sr.RequestIDNumber, sr.OverallResult, sr, myString);
  865. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  866. }
  867. else if (requestType == "GetTankReconciliation")
  868. {
  869. ServiceResponseGetTankReconciliation sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetTankReconciliation>(myString, ref result);
  870. GetTankReconciliationResp(sr.RequestIDNumber, sr.OverallResult, sr, myString);
  871. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  872. }
  873. else if (requestType == "GetTankDelivery")
  874. {
  875. ServiceResponseGetTankDelivery sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetTankDelivery>(myString, ref result);
  876. GetTankDeliveryResp(sr.RequestIDNumber, sr.OverallResult, sr, myString);
  877. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  878. }
  879. else if (requestType == "ReserveFuelPoint")
  880. {
  881. ServiceResponseReserveFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseReserveFuelPoint>(myString, ref result);
  882. ReserveFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  883. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  884. }
  885. else if (requestType == "FreeFuelPoint")
  886. {
  887. ServiceResponseFreeFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseFreeFuelPoint>(myString, ref result);
  888. FreeFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  889. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  890. }
  891. else if (requestType == "StartFuelPointTest")
  892. {
  893. ServiceResponseStartFuelPointTest sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseStartFuelPointTest>(myString, ref result);
  894. StartFuelPointTestResp(sr.RequestIDNumber, sr.OverallResult, sr);
  895. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  896. }
  897. else if (requestType == "EndFuelPointTest")
  898. {
  899. ServiceResponseEndFuelPointTest sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseEndFuelPointTest>(myString, ref result);
  900. EndFuelPointTestResp(sr.RequestIDNumber, sr.OverallResult, sr);
  901. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  902. }
  903. else if (requestType == "OpenFuelPoint")
  904. {
  905. ServiceResponseOpenFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseOpenFuelPoint>(myString, ref result);
  906. OpenFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  907. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  908. }
  909. else if (requestType == "CloseFuelPoint")
  910. {
  911. ServiceResponseCloseFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseCloseFuelPoint>(myString, ref result);
  912. CloseFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  913. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  914. }
  915. else if (requestType == "OpenDevice")
  916. {
  917. ServiceResponseOpenDevice sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseOpenDevice>(myString, ref result);
  918. OpenDeviceResp(sr.RequestIDNumber, sr.OverallResult, sr);
  919. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  920. }
  921. else if (requestType == "CloseDevice")
  922. {
  923. ServiceResponseCloseDevice sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseCloseDevice>(myString, ref result);
  924. CloseDeviceResp(sr.RequestIDNumber, sr.OverallResult, sr);
  925. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  926. }
  927. else if (requestType == "SetDeviceAlarm")
  928. {
  929. ServiceResponseSetDeviceAlarm sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseSetDeviceAlarm>(myString, ref result);
  930. SetDeviceAlarmResp(sr.RequestIDNumber, sr.OverallResult, sr);
  931. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  932. }
  933. else if (requestType == "OPTAdd")
  934. {
  935. ServiceResponseOPTAdd sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseOPTAdd>(myString, ref result);
  936. OptAddResp(sr.RequestIDNumber, sr.OverallResult, sr);
  937. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  938. }
  939. else if (requestType == "OPTRemove")
  940. {
  941. ServiceResponseOPTRemove sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseOPTRemove>(myString, ref result);
  942. OptRemoveResp(sr.RequestIDNumber, sr.OverallResult, sr);
  943. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  944. }
  945. else if (requestType == "OPTWrite")
  946. {
  947. ServiceResponseOPTWrite sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseOPTWrite>(myString, ref result);
  948. OptWriteResp(sr.RequestIDNumber, sr.OverallResult, sr);
  949. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  950. }
  951. else if (requestType == "ConfigStart")
  952. {
  953. ServiceResponseConfigStart sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseConfigStart>(myString, ref result);
  954. if (FUSIONConfigFactory.getConfigurator() != null)
  955. FUSIONConfigFactory.getConfigurator().ConfigStartResp(sr.RequestIDNumber, sr.OverallResult, sr);
  956. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  957. }
  958. else if (requestType == "DefProducts")
  959. {
  960. ServiceResponseDefProducts sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefProducts>(myString, ref result);
  961. if (FUSIONConfigFactory.getConfigurator() != null)
  962. FUSIONConfigFactory.getConfigurator().DefProductsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  963. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  964. }
  965. else if (requestType == "DefGrades")
  966. {
  967. ServiceResponseDefGrades sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefGrades>(myString, ref result);
  968. if (FUSIONConfigFactory.getConfigurator() != null)
  969. FUSIONConfigFactory.getConfigurator().DefGradesResp(sr.RequestIDNumber, sr.OverallResult, sr);
  970. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  971. }
  972. else if (requestType == "DefTanks")
  973. {
  974. ServiceResponseDefTanks sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefTanks>(myString, ref result);
  975. if (FUSIONConfigFactory.getConfigurator() != null)
  976. FUSIONConfigFactory.getConfigurator().DefTanksResp(sr.RequestIDNumber, sr.OverallResult, sr);
  977. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  978. }
  979. else if (requestType == "DefTankSuctions")
  980. {
  981. ServiceResponseDefTankSuctions sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefTankSuctions>(myString, ref result);
  982. if (FUSIONConfigFactory.getConfigurator() != null)
  983. FUSIONConfigFactory.getConfigurator().DefTankSuctionsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  984. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  985. }
  986. else if (requestType == "DefFPFuelModes")
  987. {
  988. ServiceResponseDefFuelMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefFuelMode>(myString, ref result);
  989. if (FUSIONConfigFactory.getConfigurator() != null)
  990. FUSIONConfigFactory.getConfigurator().DefFuelModeResp(sr.RequestIDNumber, sr.OverallResult, sr);
  991. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  992. }
  993. else if (requestType == "DefFCFuelMode")
  994. {
  995. ServiceResponseDefFuellingMode sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefFuellingMode>(myString, ref result);
  996. if (FUSIONConfigFactory.getConfigurator() != null)
  997. FUSIONConfigFactory.getConfigurator().DefFuellingModeResp(sr.RequestIDNumber, sr.OverallResult, sr);
  998. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  999. }
  1000. else if (requestType == "DefFuelPoints")
  1001. {
  1002. ServiceResponseDefFuelPoints sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefFuelPoints>(myString, ref result);
  1003. if (FUSIONConfigFactory.getConfigurator() != null)
  1004. FUSIONConfigFactory.getConfigurator().DefFuelPointsResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1005. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1006. }
  1007. else if (requestType == "DefPricePoles")
  1008. {
  1009. ServiceResponseDefPricePole sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefPricePole>(myString, ref result);
  1010. if (FUSIONConfigFactory.getConfigurator() != null)
  1011. FUSIONConfigFactory.getConfigurator().DefPricePoleResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1012. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1013. }
  1014. else if (requestType == "DefTankMonitors")
  1015. {
  1016. ServiceResponseDefTankMonitor sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefTankMonitor>(myString, ref result);
  1017. if (FUSIONConfigFactory.getConfigurator() != null)
  1018. FUSIONConfigFactory.getConfigurator().DefTankMonitorResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1019. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1020. }
  1021. else if (requestType == "DefFPOperationModes")
  1022. {
  1023. ServiceResponseDefFPOperationModes sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseDefFPOperationModes>(myString, ref result);
  1024. if (FUSIONConfigFactory.getConfigurator() != null)
  1025. FUSIONConfigFactory.getConfigurator().DefFPOperationModesResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1026. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1027. }
  1028. else if (requestType == "ConfigEnd")
  1029. {
  1030. ServiceResponseConfigEnd sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseConfigEnd>(myString, ref result);
  1031. if (FUSIONConfigFactory.getConfigurator() != null)
  1032. FUSIONConfigFactory.getConfigurator().ConfigEndResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1033. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1034. }
  1035. else if (requestType == "GetFuelPrice")
  1036. {
  1037. ServiceResponseGetFuelPrices sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseGetFuelPrices>(myString, ref result);
  1038. GetFuelPricesResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1039. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1040. }
  1041. else if (requestType == "CloseReconciliationPeriod")
  1042. {
  1043. ServiceResponseCloseReconciliationPeriod sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseCloseReconciliationPeriod>(myString, ref result);
  1044. CloseReconciliationPeriodResp(sr.RequestIDNumber, sr.OverallResult, sr.FDCdata);
  1045. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1046. }
  1047. else if (requestType == "StopFuelPoint")
  1048. {
  1049. ServiceResponseStopFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseStopFuelPoint>(myString, ref result);
  1050. StopFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1051. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1052. }
  1053. else if (requestType == "StartFuelPoint")
  1054. {
  1055. ServiceResponseStartFuelPoint sr = clientSocket.ifsfMessages.Deserialize<ServiceResponseStartFuelPoint>(myString, ref result);
  1056. StartFuelPointResp(sr.RequestIDNumber, sr.OverallResult, sr);
  1057. result = FDCConvert.OverallResultToInt(sr.OverallResult);
  1058. }
  1059. else
  1060. {
  1061. }
  1062. DebugLog(string.Format("ReadResponse end: requestType={0}, requestId={1}", requestType, requestId));
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. DebugLog(string.Format("ReadResponse RequestType='{0}', requestId={1} Exception! {2}", requestType, requestId, ex));
  1067. result = OverallResult.Failure;
  1068. }
  1069. }
  1070. }
  1071. if (result != OverallResult.Success)
  1072. {
  1073. if (result != OverallResult.NoData)
  1074. {
  1075. string deviceType = "";
  1076. int deviceId = 0;
  1077. int alarmId = 0;
  1078. string alarmmsg = string.Format("Error '{0}' receiving Response for requestId:'{1}', requestType:'{2}'", result.ToString(), requestId, requestType);
  1079. OnDeviceAlarm(this, new DeviceAlarmEventArgs(deviceType, deviceId, alarmId, alarmmsg));
  1080. }
  1081. }
  1082. return requestType;
  1083. }
  1084. public string ReadMessage(string myString, int msglength, ref OverallResult result)
  1085. {
  1086. if (result != OverallResult.Success)
  1087. {
  1088. DebugLog(string.Format("ReadMessage ERROR result='{0}'", result));
  1089. }
  1090. string requestType = GetRequestType("MessageType", myString);
  1091. int requestId = GetRequestID("MessageID", myString);
  1092. DebugLog(string.Format("ReadMessage init: MessageType='{0}', requestId={1}", requestType, requestId));
  1093. if (requestType == "")
  1094. {
  1095. DebugLog(string.Format("ReadMessage INVALID requestType='{0}', requestId={1}", requestType, requestId));
  1096. return requestType;
  1097. }
  1098. int UTFlength = System.Text.Encoding.UTF8.GetBytes(myString).Length;
  1099. if (UTFlength != msglength)
  1100. {
  1101. DebugLog(string.Format("ReadMessage header='{0}' != msgLength={1}", msglength, UTFlength));
  1102. result = OverallResult.FormatError;
  1103. return requestType;
  1104. }
  1105. try
  1106. {
  1107. switch (requestType)
  1108. {
  1109. case "FDCHeartBeat":
  1110. {
  1111. HeartbeatMsg();
  1112. }
  1113. break;
  1114. case "FDCReady":
  1115. case "FDC_Ready":
  1116. {
  1117. HeartbeatMsg();
  1118. }
  1119. break;
  1120. case "FDCStarted":
  1121. {
  1122. FDCMessageStarted msg = clientSocket.ifsfMessages.Deserialize<FDCMessageStarted>(myString, ref result);
  1123. FDCStartedMsg(msg);
  1124. }
  1125. break;
  1126. case "TwinMasterIsOn":
  1127. {
  1128. FDCMessageTwinMasterIsOn msg = clientSocket.ifsfMessages.Deserialize<FDCMessageTwinMasterIsOn>(myString, ref result);
  1129. TwinMasterReadyMsg(msg);
  1130. }
  1131. break;
  1132. case "FDCStopped":
  1133. {
  1134. FDCMessageStopped msg = clientSocket.ifsfMessages.Deserialize<FDCMessageStopped>(myString, ref result);
  1135. FDCStoppedMsg(msg);
  1136. }
  1137. break;
  1138. case "DeviceStateChange":
  1139. {
  1140. FDCMessageDeviceStateChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageDeviceStateChange>(myString, ref result);
  1141. DeviceStateChangeMsg(msg);
  1142. }
  1143. break;
  1144. case "FPStateChange":
  1145. {
  1146. FDCMessageFPStateChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFPStateChange>(myString, ref result);
  1147. FPStateChangeMsg(msg);
  1148. }
  1149. break;
  1150. case "TPStateChange":
  1151. {
  1152. FDCMessageTPStateChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageTPStateChange>(myString, ref result);
  1153. TPStateChangeMsg(msg);
  1154. }
  1155. break;
  1156. case "VIRStateChange":
  1157. {
  1158. FDCMessageVIRStateChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageVIRStateChange>(myString, ref result);
  1159. VIRStateChangeMsg(msg);
  1160. }
  1161. break;
  1162. case "FuelPointCurrentFuellingStatus":
  1163. {
  1164. FDCMessageCurrentFuellingStatus msg = clientSocket.ifsfMessages.Deserialize<FDCMessageCurrentFuellingStatus>(myString, ref result);
  1165. CurrentFuellingStatusMsg(msg);
  1166. }
  1167. break;
  1168. case "DeviceAlarm":
  1169. {
  1170. FDCMessageDeviceAlarm msg = clientSocket.ifsfMessages.Deserialize<FDCMessageDeviceAlarm>(myString, ref result);
  1171. DeviceAlarmMsg(msg);
  1172. }
  1173. break;
  1174. case "FuelSaleTrx":
  1175. {
  1176. FDCMessageFuelSaleTrx msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFuelSaleTrx>(myString, ref result);
  1177. FuelSaleTrxMsg(msg, myString);
  1178. }
  1179. break;
  1180. case "FuelPriceChange":
  1181. {
  1182. FDCMessageFuelPriceChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFuelPriceChange>(myString, ref result);
  1183. FuelPriceChangeMsg(msg);
  1184. }
  1185. break;
  1186. case "FuelModeChange":
  1187. {
  1188. FDCMessageFuelModeChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFuelModeChange>(myString, ref result);
  1189. FuelModeChangeMsg(msg.FDCdata[0]);
  1190. }
  1191. break;
  1192. case "FPModeChange":
  1193. {
  1194. FDCMessageFPModeChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFPModeChange>(myString, ref result);
  1195. FuelModeChangeMsg(msg.FDCdata[0]);
  1196. }
  1197. break;
  1198. case "FDCExceptionMsg":
  1199. {
  1200. FDCMessageFDCExceptionMsg msg = clientSocket.ifsfMessages.Deserialize<FDCMessageFDCExceptionMsg>(myString, ref result);
  1201. FDCExceptionMsg(msg);
  1202. }
  1203. break;
  1204. case "ConfigurationChange":
  1205. {
  1206. FDCMessageConfigurationChange msg = clientSocket.ifsfMessages.Deserialize<FDCMessageConfigurationChange>(myString, ref result);
  1207. FDCMessageConfigurationChangeMsg(msg);
  1208. }
  1209. break;
  1210. case "OPTRead":
  1211. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  1212. {
  1213. FDCMessageOPTReadV07 msg = clientSocket.ifsfMessages.Deserialize<FDCMessageOPTReadV07>(myString, ref result);
  1214. OptReadMsg(msg);
  1215. }
  1216. else
  1217. {
  1218. FDCMessageOPTRead msg = clientSocket.ifsfMessages.Deserialize<FDCMessageOPTRead>(myString, ref result);
  1219. OptReadMsg(msg);
  1220. }
  1221. break;
  1222. }
  1223. DebugLog("ReadMessage end");
  1224. }
  1225. catch (Exception ex)
  1226. {
  1227. DebugLog(string.Format("ReadMessage MessageType='{0}', requestId={1} Exception! {2}", requestType, requestId, ex));
  1228. }
  1229. return requestType;
  1230. }
  1231. private string GetRequestType(string typeField, string myString)
  1232. {
  1233. string requestType = "";
  1234. try
  1235. {
  1236. int pos;
  1237. if ((pos = myString.IndexOf(typeField)) >= 0)
  1238. {
  1239. int si = myString.IndexOf('\"', pos) + 1;
  1240. int ei = myString.IndexOf('\"', si);
  1241. requestType = myString.Substring(si, ei - si);
  1242. }
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. DebugLog("Exception! " + ex);
  1247. }
  1248. return requestType;
  1249. }
  1250. private int GetRequestID(string typeField, string myString)
  1251. {
  1252. int requestID = 0;
  1253. try
  1254. {
  1255. int pos;
  1256. if ((pos = myString.IndexOf(typeField)) >= 0)
  1257. {
  1258. int si = myString.IndexOf('\"', pos) + 1;
  1259. int ei = myString.IndexOf('\"', si);
  1260. requestID = Convert.ToInt32(myString.Substring(si, ei - si));
  1261. }
  1262. }
  1263. catch (Exception ex)
  1264. {
  1265. DebugLog("Exception! " + ex);
  1266. }
  1267. return requestID;
  1268. }
  1269. public void LogOn(string posInfo, string sFDCDateTime)
  1270. {
  1271. // POS open channel A and send LogOn command
  1272. // FDC open channel B and C and send LogOn response
  1273. LogOn(null, posInfo, sFDCDateTime);
  1274. }
  1275. public void LogOn(byte[][] validationInfoArray, string posInfo, string sFDCDateTime)
  1276. {
  1277. // POS open channel A and send LogOn command
  1278. // FDC open channel B and C and send LogOn response
  1279. try
  1280. {
  1281. DebugLog(string.Format("LogOn init, version={0}", FDCGlobal.ProtocolVersion));
  1282. ServiceRequest logOn;
  1283. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  1284. {
  1285. // create XML ServiceRequest object
  1286. logOn = new ServiceRequestLogOnV07();
  1287. logOn.ApplicationSender = clientSocket.applicationSender;
  1288. logOn.WorkstationID = clientSocket.workstationID;
  1289. ServiceRequestPOSdataLogOnV07 posDataElem = new ServiceRequestPOSdataLogOnV07();
  1290. posDataElem.POSName = "";
  1291. if (sFDCDateTime == "")
  1292. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1293. else
  1294. posDataElem.POSTimeStamp = sFDCDateTime;
  1295. posDataElem.ResponsePort = clientSocket.iIPPortB.ToString();
  1296. posDataElem.UnsolicitedPort = clientSocket.iIPPortC.ToString();
  1297. posDataElem.interfaceVersion = FDCGlobal.VersionToString();
  1298. posDataElem.InterfaceVersion = FDCGlobal.VersionToString();
  1299. if (posInfo != "")
  1300. {
  1301. posDataElem.posInfo = UTF8Encoding.UTF8.GetBytes(posInfo);
  1302. }
  1303. if (validationInfoArray != null)
  1304. posDataElem.ValidationInfo = validationInfoArray;
  1305. ServiceRequestPOSdataLogOnV07[] posDataArray = { posDataElem };
  1306. ((ServiceRequestLogOnV07)logOn).POSdata = posDataArray;
  1307. }
  1308. else
  1309. {
  1310. // create XML ServiceRequest object
  1311. logOn = new ServiceRequestLogOn();
  1312. logOn.ApplicationSender = clientSocket.applicationSender;
  1313. logOn.WorkstationID = clientSocket.workstationID;
  1314. ServiceRequestPOSdataLogOn posDataElem = new ServiceRequestPOSdataLogOn();
  1315. posDataElem.POSName = "";
  1316. if (sFDCDateTime == "")
  1317. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1318. else
  1319. posDataElem.POSTimeStamp = sFDCDateTime;
  1320. posDataElem.ResponsePort = clientSocket.iIPPortB.ToString();
  1321. posDataElem.UnsolicitedPort = clientSocket.iIPPortC.ToString();
  1322. posDataElem.InterfaceVersion = FDCGlobal.VersionToString();
  1323. if (posInfo != "")
  1324. {
  1325. // Get UTF16 bytes and convert UTF16 bytes to UTF8 bytes
  1326. DebugLog(string.Format("EnqueueMessage logOn posInfo='{0}'", posInfo));
  1327. posDataElem.posInfo = posInfo;
  1328. }
  1329. if (validationInfoArray != null)
  1330. {
  1331. posDataElem.ValidationInfo = validationInfoArray;
  1332. }
  1333. // calculate posValidation string
  1334. string posValidationSourceString = logOn.ApplicationSender + logOn.WorkstationID + posDataElem.POSTimeStamp;
  1335. MD5Crypter crypter = new MD5Crypter();
  1336. byte[] posValidationSource = new byte[posValidationSourceString.Length + crypter.getPassphrase().GetLength(0)];
  1337. Array.Copy(System.Text.Encoding.ASCII.GetBytes(posValidationSourceString), posValidationSource, (int)posValidationSourceString.Length);
  1338. Array.Copy(crypter.getPassphrase(), 0, posValidationSource, (int)posValidationSourceString.Length, (int)crypter.getPassphrase().Length);
  1339. byte[] posValidation = crypter.ComputeHash(posValidationSource);
  1340. posDataElem.posValidation = "";
  1341. StringBuilder sb = new StringBuilder(posValidation.Length * 2);
  1342. foreach (byte b in posValidation)
  1343. sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
  1344. posDataElem.posValidation = sb.ToString().ToUpper();
  1345. DebugLog(string.Format("EnqueueMessage logOn posValidationSource='{0}', posValidation='{1}'", System.Text.Encoding.ASCII.GetString(posValidationSource, 0, posValidationSource.Length), posDataElem.posValidation));
  1346. ServiceRequestPOSdataLogOn[] posDataArray = { posDataElem };
  1347. ((ServiceRequestLogOn)logOn).POSdata = posDataArray;
  1348. }
  1349. DebugLog("EnqueueMessage logOn");
  1350. clientSocket.ifsfMessages.EnqueueMessage(logOn, (EventHandler<AsyncCompletedEventArgs>)null, null, null, true, 30000);
  1351. DebugLog("LogOn2 end");
  1352. }
  1353. catch (Exception ex)
  1354. {
  1355. DebugLog("LogOn Exception! " + ex);
  1356. }
  1357. }
  1358. public void LogOnAddValidationInfo(byte[] validationInfo)
  1359. {
  1360. // POS open channel A and send LogOn command
  1361. // FDC open channel B and C and send LogOn response
  1362. try
  1363. {
  1364. if (validationInfo == null)
  1365. {
  1366. DebugLog("LogOnAddValidationInfo: null validationInfo");
  1367. return;
  1368. }
  1369. DebugLog("LogOnAddValidationInfo init");
  1370. if (this._clientSocket.logOnSendCalled && this._clientSocket.validationInfo != null)
  1371. {
  1372. this._clientSocket.validationInfo = null;
  1373. this._clientSocket.logOnSendCalled = false;
  1374. DebugLog("LogOnAddValidationInfo logOnSendCalled=false");
  1375. }
  1376. byte[][] ValidationInfo = this._clientSocket.validationInfo;
  1377. IFSFManager.ArrayResize<byte[]>(ref ValidationInfo, (ValidationInfo != null) ? ValidationInfo.Length + 1 : 1);
  1378. this._clientSocket.validationInfo = ValidationInfo;
  1379. this._clientSocket.validationInfo[this._clientSocket.validationInfo.Length - 1] = new byte[validationInfo.Length];
  1380. this._clientSocket.validationInfo[this._clientSocket.validationInfo.Length - 1] = validationInfo;
  1381. DebugLog("LogOnAddValidationInfo end");
  1382. }
  1383. catch (Exception ex)
  1384. {
  1385. DebugLog("LogOnAddValidationInfo Exception! " + ex);
  1386. }
  1387. }
  1388. public void LogOnSend(string posInfo)
  1389. {
  1390. // POS open channel A and send LogOn command
  1391. // FDC open channel B and C and send LogOn response
  1392. try
  1393. {
  1394. DebugLog("LogOnSend init");
  1395. // create XML ServiceRequest object
  1396. if (serviceRequestLogOn == null)
  1397. {
  1398. LogOn(posInfo, "");
  1399. }
  1400. else
  1401. {
  1402. DebugLog("EnqueueMessage logOn");
  1403. var logOn = serviceRequestLogOn;
  1404. serviceRequestLogOn = null;
  1405. clientSocket.ifsfMessages.EnqueueMessage(logOn, null, null, null, true, 30000);
  1406. }
  1407. this._clientSocket.logOnSendCalled = true;
  1408. DebugLog("LogOnSend end");
  1409. }
  1410. catch (Exception ex)
  1411. {
  1412. DebugLog("LogOnSend Exception! " + ex);
  1413. }
  1414. }
  1415. private void LogOnResp(int requestId, string sOverallResult, string seal, string sFDCTimeStamp)
  1416. {
  1417. try
  1418. {
  1419. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  1420. if (sOverallResult == OverallResult.Success.ToString())
  1421. {
  1422. // must be called after LogOn successful because the server must register the client before receiving messages
  1423. DebugLog(string.Format("Restarting HeartBeat next in {0}", heartbeat.heartbeatInterval));
  1424. heartbeat.SetReconnected();
  1425. heartbeat.Restart();
  1426. GetCountrySettings(null, null, null);
  1427. // check if != Connected becose FDCStart (that set state to Connected) could became before LogOnResp
  1428. if (clientSocket.mainConnectionState != DeviceConnectionState.Connected)
  1429. clientSocket.mainConnectionState = DeviceConnectionState.Connecting;
  1430. if (seal != "" && OnDeviceAlarm != null)
  1431. {
  1432. string deviceType = "";
  1433. int deviceId = 0;
  1434. int alarmId = 2020; // FUSION_IMSG_SEAL
  1435. string alarmmsg = seal;
  1436. OnDeviceAlarm(this, new DeviceAlarmEventArgs(deviceType, deviceId, alarmId, alarmmsg));
  1437. }
  1438. }
  1439. else if (sOverallResult == OverallResult.AuthentificationError.ToString())
  1440. {
  1441. DebugLog(string.Format("authentificationErrorRetry={0}, sFDCTimeStamp={1}", authentificationErrorRetry, sFDCTimeStamp));
  1442. if (authentificationErrorRetry)
  1443. {
  1444. authentificationErrorRetry = false;
  1445. this.LogOn(clientSocket.validationInfo, clientSocket.posInfo, sFDCTimeStamp);
  1446. }
  1447. else if (OnDeviceAlarm != null)
  1448. {
  1449. authentificationErrorRetry = true;
  1450. string deviceType = "";
  1451. int deviceId = 0;
  1452. int alarmId = 1001; //FUSION_E_AUTHENTIFICATION_FAILED
  1453. string alarmmsg = "";
  1454. OnDeviceAlarm(this, new DeviceAlarmEventArgs(deviceType, deviceId, alarmId, alarmmsg));
  1455. }
  1456. }
  1457. }
  1458. catch (Exception ex)
  1459. {
  1460. DebugLog("LogOnResp Exception! " + ex);
  1461. }
  1462. }
  1463. public void LogOff()
  1464. {
  1465. // POS send LogOff command and close channel A
  1466. // FDC send LogOff response and close channel B and C
  1467. try
  1468. {
  1469. DebugLog("LogOff init");
  1470. // create XML ServiceRequest object
  1471. ServiceRequestLogOff logOff = new ServiceRequestLogOff();
  1472. logOff.ApplicationSender = clientSocket.applicationSender;
  1473. logOff.WorkstationID = clientSocket.workstationID;
  1474. ServiceRequestPOSdataLogOff posDataElem = new ServiceRequestPOSdataLogOff();
  1475. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1476. ServiceRequestPOSdataLogOff[] posDataArray = { posDataElem };
  1477. logOff.POSdata = posDataArray;
  1478. DebugLog("EnqueueMessage logOff");
  1479. clientSocket.ifsfMessages.EnqueueMessage(logOff, null, null, null, true, 30000);
  1480. DebugLog("LogOff end");
  1481. }
  1482. catch (Exception ex)
  1483. {
  1484. DebugLog("LogOff Exception! " + ex);
  1485. }
  1486. }
  1487. private void LogOffResp(int requestId, string sOverallResult)
  1488. {
  1489. try
  1490. {
  1491. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  1492. if (sOverallResult == OverallResult.Success.ToString())
  1493. {
  1494. if (clientSocket.mainConnectionState != DeviceConnectionState.Connected || clientSocket.mainConnectionState != DeviceConnectionState.Connecting)
  1495. clientSocket.mainConnectionState = DeviceConnectionState.Disconnecting;
  1496. }
  1497. }
  1498. catch (Exception ex)
  1499. {
  1500. DebugLog("LogOffResp Exception! " + ex);
  1501. }
  1502. }
  1503. private void Heartbeat()
  1504. {
  1505. try
  1506. {
  1507. if (!heartbeat.tryingConnect)
  1508. {
  1509. ServiceRequestHeartbeat heartbeatmsg = new ServiceRequestHeartbeat();
  1510. heartbeatmsg.ApplicationSender = this.clientSocket.applicationSender;
  1511. heartbeatmsg.WorkstationID = this.clientSocket.workstationID;
  1512. ServiceRequestPOSReady srPosready = new ServiceRequestPOSReady();
  1513. srPosready.ApplicationSender = this.clientSocket.applicationSender;
  1514. srPosready.WorkstationID = this.clientSocket.workstationID;
  1515. POSMessagePOSReady msgPOSReady = new POSMessagePOSReady();
  1516. msgPOSReady.ApplicationSender = this.clientSocket.applicationSender;
  1517. msgPOSReady.WorkstationID = this.clientSocket.workstationID;
  1518. DebugLog(string.Format("new POSReady: type={0},id={1}, counter={2}", msgPOSReady.MessageType, msgPOSReady.MessageID, FDCMessage.requestIDConter));
  1519. ServiceRequestPOSdataHeartbeat posDataElem = new ServiceRequestPOSdataHeartbeat();
  1520. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1521. ServiceRequestPOSdataHeartbeat[] posDataArray = { posDataElem };
  1522. heartbeatmsg.POSdata = posDataArray;
  1523. srPosready.POSdata = posDataArray;
  1524. msgPOSReady.POSdata = posDataArray;
  1525. heartbeat.Restart();
  1526. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  1527. clientSocket.ifsfMessages.EnqueueMessage(heartbeatmsg, null, null, null, false, 0);
  1528. else
  1529. clientSocket.ifsfMessages.EnqueueMessage(msgPOSReady, null, null, null, false, 0);
  1530. }
  1531. else
  1532. {
  1533. DebugLog("HeartBeat tryingToConnect");
  1534. var clientSocketRespChannelBThreadObj = this.clientSocket.respChannelBThreadObj;
  1535. if (clientSocketRespChannelBThreadObj != null)
  1536. {
  1537. DebugLog(string.Format("HeartBeat true && {0}", !clientSocketRespChannelBThreadObj.bRunning));
  1538. }
  1539. else
  1540. {
  1541. DebugLog("HeartBeat false ");
  1542. }
  1543. if (clientSocketRespChannelBThreadObj != null && !clientSocketRespChannelBThreadObj.bRunning)
  1544. {
  1545. DebugLog("HeartBeat reconnecting");
  1546. if (this.clientSocket.Connect(""))
  1547. {
  1548. heartbeat.tryingConnect = false;
  1549. DebugLog("HeartBeat Restarting");
  1550. heartbeat.Restart();
  1551. }
  1552. }
  1553. }
  1554. }
  1555. catch (Exception ex)
  1556. {
  1557. DebugLog("HeartBeat Exception! " + ex);
  1558. }
  1559. }
  1560. public void VersionInfo(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1561. {
  1562. try
  1563. {
  1564. // create XML ServiceRequest object
  1565. ServiceRequestVersionInfo sr = new ServiceRequestVersionInfo();
  1566. sr.ApplicationSender = this.clientSocket.applicationSender;
  1567. sr.WorkstationID = this.clientSocket.workstationID;
  1568. ServiceRequestPOSdataVersionInfo posDataElem = new ServiceRequestPOSdataVersionInfo();
  1569. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1570. ServiceRequestPOSdataVersionInfo[] posDataArray = { posDataElem };
  1571. sr.POSdata = posDataArray;
  1572. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1573. }
  1574. catch (Exception ex)
  1575. {
  1576. DebugLog("VersionInfo Exception! " + ex);
  1577. }
  1578. }
  1579. private void VersionInfoResp(int requestId, string sOverallResult, ServiceResponseVersionInfo sr)
  1580. {
  1581. try
  1582. {
  1583. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  1584. if (OnVersionInfo != null)
  1585. {
  1586. OnVersionInfo(this, new VersionInfoEventArgs(sr.FDCdata[0].FDCversion, sr.FDCdata[0].FDCrelease, sr.FDCdata[0].FDChotfix));
  1587. }
  1588. }
  1589. catch (Exception ex)
  1590. {
  1591. DebugLog("VersionInfoResp Exception! " + ex);
  1592. }
  1593. }
  1594. public void StartForecourt(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1595. {
  1596. try
  1597. {
  1598. // create XML ServiceRequest object
  1599. ServiceRequestStartForecourt sr = new ServiceRequestStartForecourt();
  1600. sr.ApplicationSender = this.clientSocket.applicationSender;
  1601. sr.WorkstationID = this.clientSocket.workstationID;
  1602. ServiceRequestPOSdataStartForecourt posDataElem = new ServiceRequestPOSdataStartForecourt();
  1603. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1604. ServiceRequestPOSdataStartForecourt[] posDataArray = { posDataElem };
  1605. sr.POSdata = posDataArray;
  1606. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1607. }
  1608. catch (Exception ex)
  1609. {
  1610. DebugLog("StartForecourt Exception! " + ex);
  1611. }
  1612. }
  1613. public void TwinOpenMaster(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1614. {
  1615. try
  1616. {
  1617. // create XML ServiceRequest object
  1618. ServiceRequestTwinOpenMaster sr = new ServiceRequestTwinOpenMaster();
  1619. sr.ApplicationSender = this.clientSocket.applicationSender;
  1620. sr.WorkstationID = this.clientSocket.workstationID;
  1621. ServiceRequestPOSdataTwinOpenMaster posDataElem = new ServiceRequestPOSdataTwinOpenMaster();
  1622. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1623. ServiceRequestPOSdataTwinOpenMaster[] posDataArray = { posDataElem };
  1624. sr.POSdata = posDataArray;
  1625. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1626. }
  1627. catch (Exception ex)
  1628. {
  1629. DebugLog("TwinOpenMaster Exception! " + ex);
  1630. }
  1631. }
  1632. private void StartForecourtResp(int requestId, string sOverallResult, string errorCode)
  1633. {
  1634. try
  1635. {
  1636. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  1637. }
  1638. catch (Exception ex)
  1639. {
  1640. DebugLog("StartForecourtResp Exception! " + ex);
  1641. }
  1642. }
  1643. private void TwinOpenMasterResp(int requestId, string sOverallResult, string errorCode)
  1644. {
  1645. try
  1646. {
  1647. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  1648. }
  1649. catch (Exception ex)
  1650. {
  1651. DebugLog("TwinOpenMasterResp Exception! " + ex);
  1652. }
  1653. }
  1654. public void StopForecourt(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1655. {
  1656. try
  1657. {
  1658. // create XML ServiceRequest object
  1659. ServiceRequestStopForecourt sr = new ServiceRequestStopForecourt();
  1660. sr.ApplicationSender = this.clientSocket.applicationSender;
  1661. sr.WorkstationID = this.clientSocket.workstationID;
  1662. ServiceRequestPOSdataStopForecourt posDataElem = new ServiceRequestPOSdataStopForecourt();
  1663. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1664. posDataElem.Emergencystop = "false";
  1665. ServiceRequestPOSdataStopForecourt[] posDataArray = { posDataElem };
  1666. sr.POSdata = posDataArray;
  1667. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1668. }
  1669. catch (Exception ex)
  1670. {
  1671. DebugLog("StopForecourt Exception! " + ex);
  1672. }
  1673. }
  1674. private void StopForecourtResp(int requestId, string sOverallResult, string errorCode)
  1675. {
  1676. try
  1677. {
  1678. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  1679. }
  1680. catch (Exception ex)
  1681. {
  1682. DebugLog("StopForecourtResp Exception! " + ex);
  1683. }
  1684. }
  1685. public void GetCurrentFuellingStatus(int pumpId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1686. {
  1687. try
  1688. {
  1689. // create XML ServiceRequest object
  1690. ServiceRequestGetCurrentFuellingStatus sr = new ServiceRequestGetCurrentFuellingStatus();
  1691. sr.ApplicationSender = this.clientSocket.applicationSender;
  1692. sr.WorkstationID = this.clientSocket.workstationID;
  1693. ServiceRequestPOSdataGetCurrentFuellingStatus posDataElem = new ServiceRequestPOSdataGetCurrentFuellingStatus();
  1694. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1695. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1696. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  1697. deviceClass.Type = DeviceType.DT_FuellingPoint;
  1698. posDataElem.DeviceClass = deviceClass;
  1699. ServiceRequestPOSdataGetCurrentFuellingStatus[] posDataArray = { posDataElem };
  1700. sr.POSdata = posDataArray;
  1701. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1702. }
  1703. catch (Exception ex)
  1704. {
  1705. DebugLog("GetCurrentFuellingStatus Exception! " + ex);
  1706. }
  1707. }
  1708. public void GetFuelPointTotals(int pumpId, int nozzleId, EventHandler<AsyncCompletedEventArgs<PumpAccumulatorReading>> requestCompleted, object userToken, object src)
  1709. {
  1710. try
  1711. {
  1712. // create XML ServiceRequest object
  1713. ServiceRequestGetFuelPointTotals sr = new ServiceRequestGetFuelPointTotals();
  1714. sr.ApplicationSender = this.clientSocket.applicationSender;
  1715. sr.WorkstationID = this.clientSocket.workstationID;
  1716. ServiceRequestPOSdataGetFuelPointTotals posDataElem = new ServiceRequestPOSdataGetFuelPointTotals();
  1717. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1718. ServiceRequestDeviceClassGetFuelPointTotals deviceClass = new ServiceRequestDeviceClassGetFuelPointTotals();
  1719. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  1720. deviceClass.NozzleNo = (nozzleId == -1) ? "*" : Convert.ToString(nozzleId);
  1721. deviceClass.Type = DeviceType.DT_FuellingPoint;
  1722. posDataElem.DeviceClass = deviceClass;
  1723. ServiceRequestPOSdataGetFuelPointTotals[] posDataArray = { posDataElem };
  1724. sr.POSdata = posDataArray;
  1725. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<PumpAccumulatorReading>)e);
  1726. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  1727. }
  1728. catch (Exception ex)
  1729. {
  1730. DebugLog("GetFuelPointTotals Exception! " + ex);
  1731. }
  1732. }
  1733. private void GetCurrentFuellingStatusResp(int requestId, string sOverallResult, ServiceResponseGetCurrentFuellingStatus sr)
  1734. {
  1735. try
  1736. {
  1737. DebugLog("GetCurrentFuellingStatusResp init");
  1738. if (OnCurrentFuellingStatus != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1739. {
  1740. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  1741. {
  1742. var deviceClass = sr.FDCdata[0].DeviceClass[i];
  1743. if (!string.IsNullOrEmpty(deviceClass.ReleaseToken) &&
  1744. !string.IsNullOrEmpty(deviceClass.CurrentAmount) &&
  1745. !string.IsNullOrEmpty(deviceClass.CurrentVolume))
  1746. {
  1747. DebugLog(string.Format("type={0}, id={1}, volume={2}, amount={3}", deviceClass.Type,
  1748. deviceClass.DeviceID, deviceClass.CurrentVolume,
  1749. deviceClass.CurrentAmount));
  1750. string deviceType = deviceClass.Type;
  1751. int deviceId = Convert.ToInt16(deviceClass.DeviceID);
  1752. int nozzleId = Convert.ToInt16(deviceClass.CurrentNozzle);
  1753. Decimal volume = FDCConvert.ToDecimal(deviceClass.CurrentVolume);
  1754. Decimal amount = FDCConvert.ToDecimal(deviceClass.CurrentAmount);
  1755. Decimal price = FDCConvert.ToDecimal(deviceClass.CurrentUnitPrice);
  1756. string authAS = deviceClass.AuthorisationApplicationSender;
  1757. var token = AuthReleaseTokenFactory.GenerateToken(deviceClass.ReleaseToken);
  1758. //generate the event payload and add the ReleaseId parsed from the ReleaseToken
  1759. var eventArgs = new CurrentFuellingStatusEventArgs(deviceType, deviceId, nozzleId, volume,
  1760. amount, price, authAS)
  1761. {
  1762. ReleaseId = token.AuthorizationId,
  1763. ReservingDeviceId = token.TerminalId,
  1764. TransactionId = Convert.ToInt32(deviceClass.TransactionSeqNo),
  1765. FuelPeriodSequenceNo = Convert.ToInt32(deviceClass.FuelPeriodSequenceNo)
  1766. };
  1767. OnCurrentFuellingStatus(this, eventArgs);
  1768. }
  1769. else
  1770. {
  1771. DebugLog("fuelling status data empty");
  1772. }
  1773. }
  1774. }
  1775. DebugLog("GetCurrentFuellingStatusResp end");
  1776. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  1777. }
  1778. catch (Exception ex)
  1779. {
  1780. DebugLog("GetCurrentFuellingStatusResp Exception! " + ex);
  1781. }
  1782. }
  1783. private void GetFuelPointTotalsResp(int requestId, string sOverallResult, ServiceResponseGetFuelPointTotals sr, string originalXml)
  1784. {
  1785. try
  1786. {
  1787. DebugLog("GetFuelPointTotalsResp init");
  1788. if (OnFuelPointTotals != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1789. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  1790. {
  1791. DebugLog(string.Format("type={0}, id={1}, volume={2}, amount={3}", sr.FDCdata[0].DeviceClass[i].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].Volume, sr.FDCdata[0].DeviceClass[i].Amount));
  1792. string deviceType = sr.FDCdata[0].DeviceClass[i].Type;
  1793. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  1794. int nozzleId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].NozzleNo);
  1795. Decimal volume = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].Volume);
  1796. Decimal amount = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].Amount);
  1797. Decimal price = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].UnitPrice);
  1798. OnFuelPointTotals(this, new FuelPointTotalsEventArgs(requestId, sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString(),
  1799. deviceType, deviceId, nozzleId, volume, amount, price, originalXml));
  1800. }
  1801. DebugLog("GetFuelPointTotalsResp end");
  1802. }
  1803. catch (Exception ex)
  1804. {
  1805. DebugLog("GetFuelPointTotalsResp Exception! " + ex);
  1806. }
  1807. }
  1808. public void GetDeviceState(string deviceType, int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  1809. {
  1810. try
  1811. {
  1812. DebugLog(string.Format("GetDeviceState init: deviceId={0}, deviceType={1}", deviceId, deviceType));
  1813. // create XML ServiceRequest object
  1814. if (deviceType == DeviceType.DT_FuellingPoint)
  1815. {
  1816. ServiceRequestGetFPState sr = new ServiceRequestGetFPState();
  1817. sr.ApplicationSender = this.clientSocket.applicationSender;
  1818. sr.WorkstationID = this.clientSocket.workstationID;
  1819. ServiceRequestPOSdataGetDeviceState posDataElem = new ServiceRequestPOSdataGetDeviceState();
  1820. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1821. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1822. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  1823. deviceClass.Type = deviceType;
  1824. posDataElem.DeviceClass = deviceClass;
  1825. ServiceRequestPOSdataGetDeviceState[] posDataArray = { posDataElem };
  1826. sr.POSdata = posDataArray;
  1827. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1828. }
  1829. else if (deviceType == DeviceType.DT_TankProbe || deviceType == DeviceType.DT_TankLevelGauge)
  1830. {
  1831. ServiceRequestGetTPState sr = new ServiceRequestGetTPState();
  1832. sr.ApplicationSender = this.clientSocket.applicationSender;
  1833. sr.WorkstationID = this.clientSocket.workstationID;
  1834. ServiceRequestPOSdataGetDeviceState posDataElem = new ServiceRequestPOSdataGetDeviceState();
  1835. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1836. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1837. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  1838. deviceClass.Type = deviceType;
  1839. posDataElem.DeviceClass = deviceClass;
  1840. ServiceRequestPOSdataGetDeviceState[] posDataArray = { posDataElem };
  1841. sr.POSdata = posDataArray;
  1842. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1843. }
  1844. else if (deviceType == DeviceType.DT_Vir)
  1845. {
  1846. ServiceRequestGetVIRState sr = new ServiceRequestGetVIRState();
  1847. sr.ApplicationSender = this.clientSocket.applicationSender;
  1848. sr.WorkstationID = this.clientSocket.workstationID;
  1849. ServiceRequestPOSdataGetDeviceState posDataElem = new ServiceRequestPOSdataGetDeviceState();
  1850. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1851. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1852. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  1853. deviceClass.Type = deviceType;
  1854. posDataElem.DeviceClass = deviceClass;
  1855. ServiceRequestPOSdataGetDeviceState[] posDataArray = { posDataElem };
  1856. sr.POSdata = posDataArray;
  1857. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1858. }
  1859. else if (deviceType == DeviceType.DT_PricePole || deviceType == DeviceType.DT_PricePolePoint)
  1860. {
  1861. ServiceRequestGetPPState sr = new ServiceRequestGetPPState();
  1862. sr.ApplicationSender = this.clientSocket.applicationSender;
  1863. sr.WorkstationID = this.clientSocket.workstationID;
  1864. ServiceRequestPOSdataGetDeviceState posDataElem = new ServiceRequestPOSdataGetDeviceState();
  1865. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1866. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1867. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  1868. deviceClass.Type = deviceType;
  1869. posDataElem.DeviceClass = deviceClass;
  1870. ServiceRequestPOSdataGetDeviceState[] posDataArray = { posDataElem };
  1871. sr.POSdata = posDataArray;
  1872. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1873. }
  1874. else
  1875. {
  1876. ServiceRequestGetDeviceState sr = new ServiceRequestGetDeviceState();
  1877. sr.ApplicationSender = this.clientSocket.applicationSender;
  1878. sr.WorkstationID = this.clientSocket.workstationID;
  1879. ServiceRequestPOSdataGetDeviceState posDataElem = new ServiceRequestPOSdataGetDeviceState();
  1880. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  1881. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  1882. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  1883. deviceClass.Type = deviceType;
  1884. posDataElem.DeviceClass = deviceClass;
  1885. ServiceRequestPOSdataGetDeviceState[] posDataArray = { posDataElem };
  1886. sr.POSdata = posDataArray;
  1887. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  1888. }
  1889. DebugLog("GetDeviceState end");
  1890. }
  1891. catch (Exception ex)
  1892. {
  1893. DebugLog("GetDeviceState Exception! " + ex);
  1894. }
  1895. }
  1896. private void GetDeviceStateResp(int requestId, string sOverallResult, ServiceResponseGetDeviceState sr)
  1897. {
  1898. try
  1899. {
  1900. if (OnDeviceStateChange != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1901. {
  1902. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  1903. {
  1904. DebugLog(string.Format("GetDeviceStateResp type={0}, id={1}, state={2}, substate={3}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].LogicalState, sr.FDCdata[0].DeviceClass[i].LogicalSubState));
  1905. string deviceType = sr.FDCdata[0].DeviceClass[i].Type;
  1906. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  1907. LogicalDeviceState state = this.convertLogicalDeviceState(!string.IsNullOrEmpty(sr.FDCdata[0].DeviceClass[i].LogicalState) ? sr.FDCdata[0].DeviceClass[i].LogicalState : sr.FDCdata[0].DeviceClass[i].DeviceState.DeviceState);
  1908. LogicalDeviceState substate = convertLogicalDeviceState(!string.IsNullOrEmpty(sr.FDCdata[0].DeviceClass[i].LogicalSubState) ? sr.FDCdata[0].DeviceClass[i].LogicalSubState : sr.FDCdata[0].DeviceClass[i].DeviceSubState);
  1909. int nozzleUp = 0;
  1910. if (sr.FDCdata[0].DeviceClass[i].Nozzle != null)
  1911. {
  1912. foreach (NozzleStateClass nozzleState in sr.FDCdata[0].DeviceClass[i].Nozzle)
  1913. {
  1914. if (nozzleState.LogicalNozzle == "NozzleUp")
  1915. nozzleUp = Convert.ToInt32(nozzleState.NozzleNo);
  1916. }
  1917. }
  1918. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, substate, "", nozzleUp));
  1919. }
  1920. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  1921. }
  1922. DebugLog("GetDeviceStateResp end");
  1923. }
  1924. catch (Exception ex)
  1925. {
  1926. DebugLog("GetDeviceStateResp Exception! " + ex);
  1927. }
  1928. }
  1929. private void GetFPStateResp(int requestId, string sOverallResult, ServiceResponseGetFPState sr)
  1930. {
  1931. try
  1932. {
  1933. if (OnDeviceStateChange != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1934. {
  1935. if (sOverallResult == OverallResult.Success.ToString())
  1936. {
  1937. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  1938. {
  1939. DebugLog(string.Format("GetFPStateResp type={0}, id={1}, state={2}, substate={3}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].DeviceState, sr.FDCdata[0].DeviceClass[i].DeviceSubState));
  1940. string deviceType = sr.FDCdata[0].DeviceClass[i].Type;
  1941. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  1942. LogicalDeviceState state = this.convertLogicalDeviceState(sr.FDCdata[0].DeviceClass[i].DeviceState.DeviceState);
  1943. LogicalDeviceState substate = convertLogicalDeviceState(sr.FDCdata[0].DeviceClass[i].DeviceSubState);
  1944. if (!string.IsNullOrEmpty(sr.FDCdata[0].DeviceClass[i].DeviceState.Stopped) && XmlConvert.ToBoolean(sr.FDCdata[0].DeviceClass[i].DeviceState.Stopped))
  1945. substate = LogicalDeviceState.FDC_STOPPED;
  1946. string lockingAS = sr.FDCdata[0].DeviceClass[i].LockingApplicationSender;
  1947. int nozzleUp = 0;
  1948. if (sr.FDCdata[0].DeviceClass[i].Nozzle != null)
  1949. {
  1950. foreach (NozzleStateClass nozzleState in sr.FDCdata[0].DeviceClass[i].Nozzle)
  1951. {
  1952. if (nozzleState.LogicalNozzle == "NozzleUp")
  1953. nozzleUp = Convert.ToInt32(nozzleState.NozzleNo);
  1954. }
  1955. }
  1956. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, substate, lockingAS, nozzleUp));
  1957. }
  1958. }
  1959. else
  1960. DebugLog(string.Format("overallResult={0}", sOverallResult));
  1961. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  1962. }
  1963. DebugLog("GetFPStateResp end");
  1964. }
  1965. catch (Exception ex)
  1966. {
  1967. DebugLog("GetFPStateResp Exception! " + ex);
  1968. }
  1969. }
  1970. private void GetTPStateResp(int requestId, string sOverallResult, ServiceResponseGetTPState sr)
  1971. {
  1972. try
  1973. {
  1974. if (OnDeviceStateChange != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1975. {
  1976. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  1977. {
  1978. DebugLog(string.Format("GetTPStateResp type={0}, id={1}, state={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].DeviceState));
  1979. string deviceType = sr.FDCdata[0].DeviceClass[i].Type;
  1980. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  1981. LogicalDeviceState state = this.convertLogicalDeviceState(sr.FDCdata[0].DeviceClass[i].DeviceState.DeviceState);
  1982. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, LogicalDeviceState.FDC_UNDEFINED, "", 0));
  1983. }
  1984. }
  1985. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  1986. DebugLog("GetTPStateResp end");
  1987. }
  1988. catch (Exception ex)
  1989. {
  1990. DebugLog("GetTPStateResp Exception! " + ex);
  1991. }
  1992. }
  1993. private void GetPPStateResp(int requestId, string sOverallResult, ServiceResponseGetPPState sr)
  1994. {
  1995. try
  1996. {
  1997. if (OnDeviceStateChange != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  1998. {
  1999. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  2000. {
  2001. DebugLog(string.Format("GetPPStateResp type={0}, id={1}, state={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].DeviceState));
  2002. }
  2003. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  2004. }
  2005. DebugLog("GetPPStateResp end");
  2006. }
  2007. catch (Exception ex)
  2008. {
  2009. DebugLog("GetPPStateResp Exception! " + ex);
  2010. }
  2011. }
  2012. private void GetVIRStateResp(int requestId, string sOverallResult, ServiceResponseGetVIRState sr)
  2013. {
  2014. try
  2015. {
  2016. if (OnVirStateChange != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  2017. {
  2018. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  2019. {
  2020. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  2021. if (sr.FDCdata[0].DeviceClass[i].Vir != null)
  2022. {
  2023. foreach (VIRStateClass virState in sr.FDCdata[0].DeviceClass[i].Vir)
  2024. {
  2025. DebugLog(string.Format("GetVIRStateResp type={0}, id={1}, virId={2}, state={3}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID, virState.VirID, virState.DeviceState));
  2026. LogicalDeviceState state = this.convertLogicalDeviceState(virState.DeviceState);
  2027. DeviceConnectionState deviceState;
  2028. if (state == LogicalDeviceState.FDC_READY)
  2029. deviceState = DeviceConnectionState.Connected;
  2030. else if (state == LogicalDeviceState.FDC_OFFLINE)
  2031. deviceState = DeviceConnectionState.Disconnected;
  2032. else
  2033. deviceState = DeviceConnectionState.Unknown;
  2034. OnVirStateChange(this, new VIRStateChangedEventArgs(deviceId, virState.VirID, deviceState));
  2035. }
  2036. }
  2037. }
  2038. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  2039. }
  2040. DebugLog("GetVIRStateResp end");
  2041. }
  2042. catch (Exception ex)
  2043. {
  2044. DebugLog("GetVIRStateResp Exception! " + ex);
  2045. }
  2046. }
  2047. public void TerminateFuelling(int pumpId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2048. {
  2049. try
  2050. {
  2051. // create XML ServiceRequest object
  2052. ServiceRequestTerminateFuelling sr = new ServiceRequestTerminateFuelling();
  2053. sr.ApplicationSender = this.clientSocket.applicationSender;
  2054. sr.WorkstationID = this.clientSocket.workstationID;
  2055. ServiceRequestPOSdataTerminateFuelling posDataElem = new ServiceRequestPOSdataTerminateFuelling();
  2056. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2057. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  2058. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2059. deviceClass.Type = DeviceType.DT_FuellingPoint;
  2060. deviceClass.CreateZeroSale = Convert.ToString(false);
  2061. posDataElem.DeviceClass = deviceClass;
  2062. ServiceRequestPOSdataTerminateFuelling[] posDataArray = { posDataElem };
  2063. sr.POSdata = posDataArray;
  2064. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2065. }
  2066. catch (Exception ex)
  2067. {
  2068. DebugLog("TerminateFuelling Exception! " + ex);
  2069. }
  2070. }
  2071. private void TerminateFuellingResp(int requestId, string sOverallResult, ServiceResponseTerminateFuelling sr)
  2072. {
  2073. try
  2074. {
  2075. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  2076. DebugLog(string.Format("TerminateFuellingResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  2077. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  2078. }
  2079. catch (Exception ex)
  2080. {
  2081. DebugLog("TerminateFuellingResp Exception! " + ex);
  2082. }
  2083. }
  2084. public void AuthoriseFuelPoint(int pumpId, int transactionId, FuellingType fuellingType, byte reservingDeviceId, IAuthorizeParameters authParams, EventHandler<AsyncCompletedEventArgs<long>> requestCompleted, object userToken, object src)
  2085. {
  2086. try
  2087. {
  2088. DebugLog(String.Format("ISFSManager.AuthoriseFuelPoint: pumpId={0}, fuellingType={1}, reservingDeviceId={2}, request={3}, Token={4} Src={5}",
  2089. pumpId, fuellingType, reservingDeviceId, requestCompleted, userToken, src));
  2090. DebugLog(
  2091. String.Format(
  2092. "ISFSManager.AuthoriseFuelPoint: authParams: PresetType={0}, PresetValue={1}, LockToClient={2}, Prepay={3}, ConsentGiven={4}, PriceGroup={5}, AllowedFuelGrade={6}, FuelGradeMaxVolume={7}",
  2093. authParams.PresetType, authParams.PresetValue, authParams.LockToReleaseClient, authParams.Prepay,
  2094. authParams.ConsentGiven, authParams.PriceGroup, authParams.AllowedFuelGrade,
  2095. authParams.FuelGradeMaxVolume));
  2096. // create XML ServiceRequest object
  2097. ServiceRequestAuthoriseFuelPoint sr = new ServiceRequestAuthoriseFuelPoint();
  2098. sr.ApplicationSender = this.clientSocket.applicationSender;
  2099. sr.WorkstationID = this.clientSocket.workstationID;
  2100. ServiceRequestPOSdataAuthoriseFuelPoint posDataElem = new ServiceRequestPOSdataAuthoriseFuelPoint();
  2101. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2102. ServiceRequestDeviceClassAuthoriseFuelPoint authFP = new ServiceRequestDeviceClassAuthoriseFuelPoint();
  2103. authFP.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2104. authFP.Type = DeviceType.DT_FuellingPoint;
  2105. if (authParams.PresetType == PresetType.Amount)
  2106. {
  2107. authFP.MaxTrxVolume = FDCConvert.ToString((Decimal)0);
  2108. authFP.MaxTrxAmount = FDCConvert.ToString(authParams.PresetValue);
  2109. }
  2110. else
  2111. {
  2112. authFP.MaxTrxVolume = FDCConvert.ToString(authParams.PresetValue);
  2113. authFP.MaxTrxAmount = FDCConvert.ToString((Decimal)0);
  2114. }
  2115. authFP.LockFuelSaleTrx = Convert.ToString(authParams.LockToReleaseClient);
  2116. //Token is a composition of the terminal id and release id, this token is echoed back when the transaction is completed
  2117. //Terminal Id is only needed for outdoor or prepaid transactions. All other have Terminal Id = 0.
  2118. //Receipt no is only used for prepaid transactions,
  2119. var terminalId = 0;
  2120. if (fuellingType == FuellingType.OptCardPaid || fuellingType == FuellingType.OptCashPaid)
  2121. terminalId = reservingDeviceId;
  2122. if (fuellingType == FuellingType.Prepaid)
  2123. terminalId = authParams.PrepayReceiptNo / 10000;
  2124. var token = AuthReleaseTokenFactory.GenerateToken(
  2125. terminalId,
  2126. transactionId,
  2127. fuellingType == FuellingType.Prepaid ? (int?)(authParams.PrepayReceiptNo % 10000) : null);
  2128. authFP.ReleaseToken = token.ToString();
  2129. authFP.ReservingDeviceId = Convert.ToString(reservingDeviceId);
  2130. authFP.FuellingType = Convert.ToString((int)fuellingType);
  2131. if (authParams.Prepay)
  2132. {
  2133. var prepaidTrx = new PrepaidTrxElementClass();
  2134. prepaidTrx.IsPrepaid = Convert.ToString(true);
  2135. authFP.PrepaidTrx = prepaidTrx;
  2136. }
  2137. if (authParams.ConsentGiven)
  2138. authFP.ConsentGiven = Convert.ToString(true);
  2139. authFP.ProcessZeroSale = Convert.ToString(authParams.ProcessZeroSale);
  2140. authFP.ApplyAuthPresetRetries = Convert.ToString(authParams.ApplyAuthPresetRetries);
  2141. var modeNo = manager.forecourtControl.ForecourtConfiguration.GetFuelMode(fuellingType, authParams.PriceGroup);
  2142. DebugLog(String.Format("ISFSManager.AuthoriseFuelPoint.configuration.GetFuelMode: fuellingType={0}, PriceGroup={1}, modeNo={2}",
  2143. fuellingType, authParams.PriceGroup, modeNo));
  2144. var pump = src as IPump;
  2145. if (pump != null)
  2146. {
  2147. if ((pump.State == PumpState.Idle || pump.State == PumpState.Calling) && fuellingType == FuellingType.Postpaid)
  2148. {
  2149. // Authorized in advance for self service. Change fuel mode to use the specific one
  2150. modeNo = manager.forecourtControl.ForecourtConfiguration.GetFuelMode(authParams.PriceGroup, true);
  2151. DebugLog(String.Format("ISFSManager.AuthoriseFuelPoint.configuration.GetFuelMode: fuellingType={0}, PriceGroup=Postpaid, modeNo={1}",
  2152. fuellingType, modeNo));
  2153. }
  2154. }
  2155. authFP.FuelMode = new FuelModeElementClass() { ModeNo = modeNo.ToString() };
  2156. ReleasedProductsClass products = new ReleasedProductsClass();
  2157. AllowedFuelGrades fgs = (AllowedFuelGrades)(authParams.AllowedFuelGrade);
  2158. FuelGradeMaxVolumes vols = (FuelGradeMaxVolumes)(authParams.FuelGradeMaxVolume);
  2159. int count = 0;
  2160. products.Product = new ProductElementClass[fgs.Count];
  2161. for (int iFuelGrade = 0; iFuelGrade < fgs.Count; iFuelGrade++)
  2162. {
  2163. if (fgs[iFuelGrade])
  2164. {
  2165. products.Product[count] = new ProductElementClass();
  2166. products.Product[count].ProductNo = Convert.ToString(iFuelGrade); //productNo = iFuelGrade(product index) + 1
  2167. if ((iFuelGrade < vols.Count) && vols[iFuelGrade].HasValue)
  2168. products.Product[count].MaxTrxVolume = FDCConvert.ToString((decimal)vols[iFuelGrade]);
  2169. count++;
  2170. }
  2171. }
  2172. authFP.ReleasedProducts = products;
  2173. posDataElem.DeviceClass = authFP;
  2174. ServiceRequestPOSdataAuthoriseFuelPoint[] posDataArray = { posDataElem };
  2175. sr.POSdata = posDataArray;
  2176. //Transaction ID is sent in response from the proxy delegate.
  2177. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, new AsyncCompletedEventArgs<long>(e.Success, transactionId, e.UserToken));
  2178. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  2179. }
  2180. catch (Exception ex)
  2181. {
  2182. DebugLog("AuthoriseFuelPoint Exception! " + ex);
  2183. }
  2184. }
  2185. private void AuthoriseFuelPointResp(int requestId, string sOverallResult, ServiceResponseAuthoriseFuelPoint sr)
  2186. {
  2187. try
  2188. {
  2189. DebugLog("AuthoriseFuelPointResp init");
  2190. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].DeviceClass.ErrorCode;
  2191. if ((errorCode == ErrorCode.ERRCD_OK.ToString()) && (sOverallResult == OverallResult.Success.ToString()))
  2192. {
  2193. // Ok so far, but wait for unsolicited FPStateChange before making decision about success.
  2194. DebugLog(string.Format("Waiting for unsolicited FPStateChange, RequestId={0}.", requestId));
  2195. unsolicitedFPStateChangeDictionary[Convert.ToInt16(sr.FDCdata[0].DeviceClass.DeviceID)] = requestId;
  2196. }
  2197. else
  2198. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, false);
  2199. DebugLog("AuthoriseFuelPointResp end");
  2200. }
  2201. catch (Exception ex)
  2202. {
  2203. DebugLog("AuthoriseFuelPointResp Exception! " + ex);
  2204. }
  2205. }
  2206. public void ChangeFuelMode(int pumpId, int mode, ushort? operationMode, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2207. {
  2208. try
  2209. {
  2210. // create XML ServiceRequest object
  2211. ServiceRequestChangeFuelMode sr = new ServiceRequestChangeFuelMode();
  2212. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  2213. sr.RequestType = "ChangeFuelMode";
  2214. else
  2215. sr.RequestType = "ChangeFPFuelMode";
  2216. sr.ApplicationSender = this.clientSocket.applicationSender;
  2217. sr.WorkstationID = this.clientSocket.workstationID;
  2218. ServiceRequestPOSdataChangeFuelMode posDataElem = new ServiceRequestPOSdataChangeFuelMode();
  2219. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2220. ServiceRequestDeviceClassChangeFuelMode deviceClass = new ServiceRequestDeviceClassChangeFuelMode();
  2221. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2222. deviceClass.Type = DeviceType.DT_FuellingPoint;
  2223. deviceClass.FuelMode = new FuelModeElementClass();
  2224. deviceClass.FuelMode.ModeNo = Convert.ToString(mode);
  2225. if (operationMode.HasValue)
  2226. {
  2227. deviceClass.FuelMode.OperationModeSpecified = true;
  2228. deviceClass.FuelMode.OperationMode = (ushort)operationMode;
  2229. }
  2230. ServiceRequestDeviceClassChangeFuelMode[] deviceClassArray = { deviceClass };
  2231. posDataElem.DeviceClass = deviceClassArray;
  2232. ServiceRequestPOSdataChangeFuelMode[] posDataArray = { posDataElem };
  2233. sr.POSdata = posDataArray;
  2234. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2235. }
  2236. catch (Exception ex)
  2237. {
  2238. DebugLog("ChangeFuelMode Exception! " + ex);
  2239. }
  2240. }
  2241. public void ChangeFuelModeAdd(ServiceRequestChangeFuelMode sr, int pumpId, int mode, ushort? operationMode, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2242. {
  2243. // create XML ServiceRequest object
  2244. sr.ApplicationSender = this.clientSocket.applicationSender;
  2245. sr.WorkstationID = this.clientSocket.workstationID;
  2246. DebugLog(string.Format("ChangeFuelModeAdd init: sr.ApplicationSender={0}, sr.WorkstationID={1}, pumpId={2}, mode={3}", sr.ApplicationSender, sr.WorkstationID, pumpId, mode));
  2247. ServiceRequestPOSdataChangeFuelMode POSDataElem;
  2248. if (sr.POSdata != null)
  2249. POSDataElem = sr.POSdata[0];
  2250. else
  2251. {
  2252. ServiceRequestPOSdataChangeFuelMode[] POSDataArray = null;
  2253. DebugLog(string.Format("ChangeFuelModeAdd: new ServiceRequestPOSdataChangeFuelMode"));
  2254. POSDataElem = new ServiceRequestPOSdataChangeFuelMode();
  2255. ArrayResize(ref POSDataArray, 1);
  2256. POSDataArray[POSDataArray.Length - 1] = POSDataElem;
  2257. POSDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2258. sr.POSdata = POSDataArray;
  2259. }
  2260. ServiceRequestDeviceClassChangeFuelMode devicemode = null;
  2261. if (POSDataElem.DeviceClass != null)
  2262. {
  2263. foreach (ServiceRequestDeviceClassChangeFuelMode devicemodeTemp in POSDataElem.DeviceClass)
  2264. if (devicemodeTemp.DeviceID == Convert.ToString(pumpId) && devicemodeTemp.ModeNo == Convert.ToString(mode))
  2265. {
  2266. devicemode = devicemodeTemp;
  2267. DebugLog(string.Format("ChangeFuelModeAdd: device/mode found"));
  2268. }
  2269. }
  2270. if (devicemode == null)
  2271. {
  2272. DebugLog(string.Format("ChangeFuelModeAdd: new mode"));
  2273. devicemode = new ServiceRequestDeviceClassChangeFuelMode();
  2274. devicemode.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2275. devicemode.Type = DeviceType.DT_FuellingPoint;
  2276. devicemode.FuelMode = new FuelModeElementClass();
  2277. devicemode.FuelMode.ModeNo = Convert.ToString(mode);
  2278. if (operationMode.HasValue)
  2279. {
  2280. devicemode.FuelMode.OperationModeSpecified = true;
  2281. devicemode.FuelMode.OperationMode = (ushort)operationMode;
  2282. }
  2283. ServiceRequestDeviceClassChangeFuelMode[] devicemodeArray = POSDataElem.DeviceClass;
  2284. ArrayResize(ref devicemodeArray, (devicemodeArray != null) ? devicemodeArray.Length + 1 : 1);
  2285. DebugLog(string.Format("ChangeFuelModeAdd: resize devidemodeArray to '{0}' items", devicemodeArray.Length));
  2286. devicemodeArray[devicemodeArray.Length - 1] = devicemode;
  2287. POSDataElem.DeviceClass = devicemodeArray;
  2288. }
  2289. DebugLog("ChangeFuelModeAdd end");
  2290. }
  2291. public void ChangeFuelModeSend(ServiceRequestChangeFuelMode sr, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2292. {
  2293. DebugLog(string.Format("ChangeFuelModeSend init: sr.ApplicationSender={0}, sr.WorkstationID={1}", sr.ApplicationSender, sr.WorkstationID));
  2294. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2295. DebugLog(string.Format("ChangeFuelModeSend end: sr.ApplicationSender={0}, sr.WorkstationID={1}", sr.ApplicationSender, sr.WorkstationID));
  2296. }
  2297. private void ChangeFuelModeResp(int requestId, string sOverallResult, ServiceResponseFDCdataChangeFuelMode[] fdcData)
  2298. {
  2299. try
  2300. {
  2301. DebugLog(string.Format("ChangeFuelModeResp init, sOverallResult={0}", sOverallResult));
  2302. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  2303. if (fdcData[0] != null && fdcData[0].DeviceClass != null)
  2304. {
  2305. for (int i = 0; i < fdcData[0].DeviceClass.Length; i++)
  2306. {
  2307. if (fdcData[0].DeviceClass[i].ErrorCode != null && fdcData[0].DeviceClass[i].ErrorCode != ErrorCode.ERRCD_OK.ToString() && fdcData[0].DeviceClass[i].ErrorCode != ErrorCode.ERRCD_NO.ToString())
  2308. {
  2309. DebugLog(string.Format("ChangeFuelModeResp type={0}, id={1}, errorCode={2}", fdcData[0].DeviceClass[i].Type, fdcData[0].DeviceClass[i].DeviceID, fdcData[0].DeviceClass[i].ErrorCode));
  2310. string deviceType = fdcData[0].DeviceClass[i].Type;
  2311. int deviceId = Convert.ToInt16(fdcData[0].DeviceClass[i].DeviceID);
  2312. int alarmId = -1;
  2313. string alarmmsg = "Error " + fdcData[0].DeviceClass[i].ErrorCode + " changing fuel mode";
  2314. OnDeviceAlarm.Fire(this, new DeviceAlarmEventArgs(deviceType, deviceId, alarmId, alarmmsg));
  2315. }
  2316. }
  2317. }
  2318. DebugLog("ChangeFuelModeResp end");
  2319. }
  2320. catch (Exception ex)
  2321. {
  2322. DebugLog("ChangeFuelModeResp Exception! " + ex);
  2323. }
  2324. }
  2325. public void ChangeFuelPrice(int productId, Decimal price, int mode, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2326. {
  2327. try
  2328. {
  2329. // create XML ServiceRequest object
  2330. ServiceRequestChangeFuelPrice sr = new ServiceRequestChangeFuelPrice();
  2331. sr.ApplicationSender = this.clientSocket.applicationSender;
  2332. sr.WorkstationID = this.clientSocket.workstationID;
  2333. ServiceRequestPOSdataChangeFuelPrice posDataElem = new ServiceRequestPOSdataChangeFuelPrice();
  2334. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2335. ServiceRequestProductChangeFuelPrice[] products = new ServiceRequestProductChangeFuelPrice[1];
  2336. ServiceRequestProductChangeFuelPrice product = new ServiceRequestProductChangeFuelPrice();
  2337. product.ProductNo = (productId == -1) ? "*" : Convert.ToString(productId);
  2338. ServiceRequestFuelModeChangeFuelPrice[] fuelModes = new ServiceRequestFuelModeChangeFuelPrice[1];
  2339. ServiceRequestFuelModeChangeFuelPrice fuelMode = new ServiceRequestFuelModeChangeFuelPrice();
  2340. fuelMode.PriceNew = FDCConvert.ToString(price);
  2341. fuelMode.ModeNo = Convert.ToString(mode);
  2342. fuelModes[0] = fuelMode;
  2343. product.FuelMode = fuelModes;
  2344. products[0] = product;
  2345. posDataElem.Product = products;
  2346. ServiceRequestPOSdataChangeFuelPrice[] posDataArray = { posDataElem };
  2347. sr.POSdata = posDataArray;
  2348. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2349. }
  2350. catch (Exception ex)
  2351. {
  2352. DebugLog("ChangeFuelPrice Exception! " + ex);
  2353. }
  2354. }
  2355. public void ChangeFuelPriceAdd(ServiceRequestChangeFuelPrice sr, int productId, Decimal price, int mode)
  2356. {
  2357. // create XML ServiceRequest object
  2358. sr.ApplicationSender = this.clientSocket.applicationSender;
  2359. sr.WorkstationID = this.clientSocket.workstationID;
  2360. DebugLog(string.Format("ChangeFuelPriceAdd init: sr.ApplicationSender={0}, sr.WorkstationID={1}, productId={2}, price={3}, mode={4}", sr.ApplicationSender, sr.WorkstationID, productId, price, mode));
  2361. ServiceRequestPOSdataChangeFuelPrice POSDataElem;
  2362. if (sr.POSdata != null)
  2363. POSDataElem = sr.POSdata[0];
  2364. else
  2365. {
  2366. ServiceRequestPOSdataChangeFuelPrice[] POSDataArray = null;
  2367. DebugLog("ChangeFuelPriceAdd: new ServiceRequestPOSdataChangeFuelPrice");
  2368. POSDataElem = new ServiceRequestPOSdataChangeFuelPrice();
  2369. ArrayResize(ref POSDataArray, 1);
  2370. POSDataArray[POSDataArray.Length - 1] = POSDataElem;
  2371. POSDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2372. sr.POSdata = POSDataArray;
  2373. }
  2374. ServiceRequestProductChangeFuelPrice product = null;
  2375. if (POSDataElem.Product != null)
  2376. {
  2377. foreach (ServiceRequestProductChangeFuelPrice productTemp in POSDataElem.Product)
  2378. if (productTemp.ProductNo == Convert.ToString(productId) && productTemp.ModeNo == Convert.ToString(mode))
  2379. {
  2380. product = productTemp;
  2381. DebugLog("ChangeFuelPriceAdd: product found");
  2382. }
  2383. }
  2384. if (product == null && productId > 0)
  2385. {
  2386. DebugLog("ChangeFuelPriceAdd: new product");
  2387. product = new ServiceRequestProductChangeFuelPrice();
  2388. product.ProductNo = (productId == -1) ? "*" : Convert.ToString(productId);
  2389. ServiceRequestProductChangeFuelPrice[] productArray = POSDataElem.Product;
  2390. ArrayResize(ref productArray, (productArray != null) ? productArray.Length + 1 : 1);
  2391. DebugLog(string.Format("ChangeFuelPriceAdd: resize product to '{0}' items", productArray.Length));
  2392. productArray[productArray.Length - 1] = product;
  2393. POSDataElem.Product = productArray;
  2394. }
  2395. ServiceRequestFuelModeChangeFuelPrice fuelMode = null;
  2396. if (product.FuelMode != null)
  2397. {
  2398. foreach (ServiceRequestFuelModeChangeFuelPrice fuelModeTemp in product.FuelMode)
  2399. if (product.ProductNo == Convert.ToString(productId) && fuelModeTemp.ModeNo == Convert.ToString(mode))
  2400. {
  2401. fuelMode = fuelModeTemp;
  2402. DebugLog("ChangeFuelPriceAdd: fuelMode found");
  2403. }
  2404. }
  2405. if (fuelMode == null && mode > 0)
  2406. {
  2407. fuelMode = new ServiceRequestFuelModeChangeFuelPrice();
  2408. fuelMode.PriceNew = FDCConvert.ToString(price);
  2409. fuelMode.ModeNo = Convert.ToString(mode);
  2410. ServiceRequestFuelModeChangeFuelPrice[] fuelModeArray = product.FuelMode;
  2411. ArrayResize(ref fuelModeArray, (fuelModeArray != null) ? fuelModeArray.Length + 1 : 1);
  2412. DebugLog(string.Format("ChangeFuelPriceAdd: resize fuelMode to '{0}' items", fuelModeArray.Length));
  2413. fuelModeArray[fuelModeArray.Length - 1] = fuelMode;
  2414. product.FuelMode = fuelModeArray;
  2415. }
  2416. DebugLog(string.Format("ChangeFuelPriceAdd end: sr.ApplicationSender={0}, sr.WorkstationID={1}", sr.ApplicationSender, sr.WorkstationID));
  2417. }
  2418. public void ChangeFuelPriceSend(ServiceRequestChangeFuelPrice sr, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2419. {
  2420. DebugLog(string.Format("ChangeFuelPriceSend init: sr.ApplicationSender={0}, sr.WorkstationID={1}", sr.ApplicationSender, sr.WorkstationID));
  2421. if (sr.POSdata == null)
  2422. {
  2423. sr.ApplicationSender = this.clientSocket.applicationSender;
  2424. sr.WorkstationID = this.clientSocket.workstationID;
  2425. var posDataArray = new ServiceRequestPOSdataChangeFuelPrice[1];
  2426. DebugLog("ChangeFuelPriceAdd: new ServiceRequestPOSdataChangeFuelPrice");
  2427. var posDataElem = new ServiceRequestPOSdataChangeFuelPrice();
  2428. posDataArray[0] = posDataElem;
  2429. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2430. sr.POSdata = posDataArray;
  2431. }
  2432. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2433. DebugLog(string.Format("ChangeFuelPriceSend end: sr.ApplicationSender={0}, sr.WorkstationID={1}", sr.ApplicationSender, sr.WorkstationID));
  2434. }
  2435. public void CloseReconciliationPeriodAsyncSend(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2436. {
  2437. try
  2438. {
  2439. // create XML ServiceRequest object
  2440. var sr = new ServiceRequestCloseReconciliationPeriod();
  2441. sr.ApplicationSender = this.clientSocket.applicationSender;
  2442. sr.WorkstationID = this.clientSocket.workstationID;
  2443. var posDataElem = new ServiceRequestPOSdataCloseReconciliationPeriod();
  2444. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2445. ServiceRequestPOSdataCloseReconciliationPeriod[] posDataArray = { posDataElem };
  2446. sr.POSdata = posDataArray;
  2447. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2448. }
  2449. catch (Exception ex)
  2450. {
  2451. DebugLog("CloseReconciliationPeriodAsyncSend Exception! " + ex);
  2452. }
  2453. }
  2454. private void ChangeFuelPriceResp(int requestId, string sOverallResult, ServiceResponseFDCdataChangeFuelPrice[] fdcData)
  2455. {
  2456. try
  2457. {
  2458. DebugLog("ChangeFuelPriceResp init");
  2459. string errorCode = (fdcData[0].FDCStatus != null) ? fdcData[0].FDCStatus : fdcData[0].ErrorCode;
  2460. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  2461. DebugLog("ChangeFuelPriceResp end");
  2462. }
  2463. catch (Exception ex)
  2464. {
  2465. DebugLog("ChangeFuelPriceResp Exception! " + ex);
  2466. }
  2467. }
  2468. private void CloseReconciliationPeriodResp(int requestId, string sOverallResult, ServiceResponseFDCdataCloseReconciliationPeriod[] fdcData)
  2469. {
  2470. try
  2471. {
  2472. DebugLog("CloseReconciliationPeriodResp init");
  2473. if (fdcData != null)
  2474. {
  2475. string errorCode = fdcData[0].FDCStatus ?? fdcData[0].ErrorCode;
  2476. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  2477. }
  2478. else
  2479. {
  2480. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, false);
  2481. }
  2482. DebugLog("CloseReconciliationPeriodResp end");
  2483. }
  2484. catch (Exception ex)
  2485. {
  2486. DebugLog("CloseReconciliationPeriodResp Exception! " + ex);
  2487. }
  2488. }
  2489. public void LockFuelSaleTrx(int pumpId, int transactionNo, int releaseToken, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2490. {
  2491. try
  2492. {
  2493. ServiceRequestLockFuelSaleTrx sr = new ServiceRequestLockFuelSaleTrx();
  2494. sr.ApplicationSender = this.clientSocket.applicationSender;
  2495. sr.WorkstationID = this.clientSocket.workstationID;
  2496. ServiceRequestPOSdataBaseFuelSaleTrx posDataElem = new ServiceRequestPOSdataBaseFuelSaleTrx();
  2497. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2498. ServiceRequestDeviceClassBaseFuelSaleTrx deviceClass = new ServiceRequestDeviceClassBaseFuelSaleTrx();
  2499. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2500. deviceClass.Type = DeviceType.DT_FuellingPoint;
  2501. deviceClass.TransactionSeqNo = Convert.ToString(transactionNo);
  2502. posDataElem.DeviceClass = deviceClass;
  2503. ServiceRequestPOSdataBaseFuelSaleTrx[] posDataArray = { posDataElem };
  2504. sr.POSdata = posDataArray;
  2505. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2506. }
  2507. catch (Exception ex)
  2508. {
  2509. DebugLog("LockFuelSaleTrx Exception! " + ex);
  2510. }
  2511. }
  2512. private void LockFuelSaleTrxResp(int requestId, string sOverallResult, ServiceResponseLockFuelSaleTrx sr)
  2513. {
  2514. try
  2515. {
  2516. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  2517. DebugLog(string.Format("LockFuelSaleTrxResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  2518. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  2519. DebugLog("LockFuelSaleTrxResp end");
  2520. }
  2521. catch (Exception ex)
  2522. {
  2523. DebugLog("LockFuelSaleTrxResp Exception! " + ex);
  2524. }
  2525. }
  2526. public void UnlockFuelSaleTrx(int pumpId, int transactionNo, int releaseToken, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2527. {
  2528. try
  2529. {
  2530. ServiceRequestUnlockFuelSaleTrx sr = new ServiceRequestUnlockFuelSaleTrx();
  2531. sr.ApplicationSender = this.clientSocket.applicationSender;
  2532. sr.WorkstationID = this.clientSocket.workstationID;
  2533. ServiceRequestPOSdataBaseFuelSaleTrx posDataElem = new ServiceRequestPOSdataBaseFuelSaleTrx();
  2534. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2535. ServiceRequestDeviceClassBaseFuelSaleTrx deviceClass = new ServiceRequestDeviceClassBaseFuelSaleTrx();
  2536. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2537. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint;
  2538. deviceClass.TransactionSeqNo = Convert.ToString(transactionNo);
  2539. posDataElem.DeviceClass = deviceClass;
  2540. ServiceRequestPOSdataBaseFuelSaleTrx[] posDataArray = { posDataElem };
  2541. sr.POSdata = posDataArray;
  2542. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2543. }
  2544. catch (Exception ex)
  2545. {
  2546. DebugLog("UnlockFuelSaleTrx Exception! " + ex);
  2547. }
  2548. }
  2549. private void UnlockFuelSaleTrxResp(int requestId, string sOverallResult, ServiceResponseUnlockFuelSaleTrx sr)
  2550. {
  2551. try
  2552. {
  2553. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].DeviceClass.ErrorCode;
  2554. DebugLog(string.Format("UnlockFuelSaleTrxResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  2555. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  2556. DebugLog("UnlockFuelSaleTrxResp end");
  2557. }
  2558. catch (Exception ex)
  2559. {
  2560. DebugLog("UnlockFuelSaleTrxResp Exception! " + ex);
  2561. }
  2562. }
  2563. public void ClearFuelSaleTrx(int pumpId, int transactionNo, int releaseToken, string note, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2564. {
  2565. try
  2566. {
  2567. ServiceRequestClearFuelSaleTrx sr = new ServiceRequestClearFuelSaleTrx();
  2568. sr.ApplicationSender = this.clientSocket.applicationSender;
  2569. sr.WorkstationID = this.clientSocket.workstationID;
  2570. ServiceRequestPOSdataClearFuelSaleTrx posDataElem = new ServiceRequestPOSdataClearFuelSaleTrx();
  2571. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2572. ServiceRequestDeviceClassClearFuelSaleTrx deviceClass = new ServiceRequestDeviceClassClearFuelSaleTrx();
  2573. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2574. deviceClass.Type = DeviceType.DT_FuellingPoint;
  2575. deviceClass.TransactionSeqNo = Convert.ToString(transactionNo);
  2576. // ignored by Fusion
  2577. //deviceClass.FuelSaleNote = note;
  2578. posDataElem.DeviceClass = deviceClass;
  2579. ServiceRequestPOSdataClearFuelSaleTrx[] posDataArray = { posDataElem };
  2580. sr.POSdata = posDataArray;
  2581. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2582. }
  2583. catch (Exception ex)
  2584. {
  2585. DebugLog("ClearFuelSaleTrx Exception! " + ex);
  2586. }
  2587. }
  2588. private void ClearFuelSaleTrxResp(int requestId, string sOverallResult, ServiceResponseClearFuelSaleTrx sr)
  2589. {
  2590. try
  2591. {
  2592. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].DeviceClass.ErrorCode;
  2593. DebugLog(string.Format("ClearFuelSaleTrxResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  2594. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  2595. DebugLog("ClearFuelSaleTrxResp end");
  2596. }
  2597. catch (Exception ex)
  2598. {
  2599. DebugLog("ClearFuelSaleTrxResp Exception! " + ex);
  2600. }
  2601. }
  2602. public void SendConfig(string commandFileName, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2603. {
  2604. clientSocket.SendConfig(commandFileName);
  2605. }
  2606. public void GetAvailableFuelSaleTrxs(int pumpId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2607. {
  2608. try
  2609. {
  2610. // create XML ServiceRequest object
  2611. ServiceRequestGetAvailableFuelSaleTrxs sr = new ServiceRequestGetAvailableFuelSaleTrxs();
  2612. sr.ApplicationSender = this.clientSocket.applicationSender;
  2613. sr.WorkstationID = this.clientSocket.workstationID;
  2614. ServiceRequestPOSdataGetAvailableFuelSaleTrxs posDataElem = new ServiceRequestPOSdataGetAvailableFuelSaleTrxs();
  2615. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2616. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  2617. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2618. deviceClass.Type = DeviceType.DT_FuellingPoint;
  2619. posDataElem.DeviceClass = deviceClass;
  2620. ServiceRequestPOSdataGetAvailableFuelSaleTrxs[] posDataArray = { posDataElem };
  2621. sr.POSdata = posDataArray;
  2622. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2623. }
  2624. catch (Exception ex)
  2625. {
  2626. DebugLog("GetAvailableFuelSaleTrxs Exception! " + ex);
  2627. }
  2628. }
  2629. private void GetAvailableFuelSaleTrxsResp(int requestId, string sOverallResult, ServiceResponseGetAvailableFuelSaleTrxs sr)
  2630. {
  2631. try
  2632. {
  2633. DebugLog("GetAvailableFuelSaleTrxsResp init");
  2634. if (sr.FDCdata == null || sr.FDCdata[0].DeviceClass == null)
  2635. {
  2636. DebugLog("no fuel sale available - end");
  2637. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true);
  2638. return;
  2639. }
  2640. if (OnGetAvailableFuelSaleTrx != null && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  2641. {
  2642. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  2643. {
  2644. if (sr.FDCdata[0].DeviceClass[i].ErrorCode != null && sr.FDCdata[0].DeviceClass[i].ErrorCode == ErrorCode.ERRCD_OK.ToString())
  2645. {
  2646. string deviceType = sr.FDCdata[0].DeviceClass[i].Type;
  2647. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  2648. int transactionNo = Convert.ToInt32(sr.FDCdata[0].DeviceClass[i].TransactionSeqNo);
  2649. int releaseToken;
  2650. try
  2651. {
  2652. releaseToken = Int32.Parse(sr.FDCdata[0].DeviceClass[i].ReleaseToken, System.Globalization.NumberStyles.HexNumber);
  2653. }
  2654. catch (Exception ex)
  2655. {
  2656. releaseToken = 0;
  2657. }
  2658. OnGetAvailableFuelSaleTrx(this, new FuelSaleTrxEventArgs(transactionNo, 0, 0, 0, deviceType, deviceId, 0, 0, 0, 0, 0,
  2659. DateTime.Now, DateTime.Now, "", "", null, null, null, null, releaseToken, 0, FuellingType.Unknown));
  2660. int timeout = 0;
  2661. string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "GetFuelSaleTrxDetailTimeout");
  2662. if (sValue.Length > 0)
  2663. timeout = Convert.ToInt16(sValue);
  2664. DebugLog(string.Format("GetFuelSaleTrxDetailTimeout={0}", timeout));
  2665. Thread.Sleep(timeout);
  2666. }
  2667. else
  2668. DebugLog(string.Format("Id={0} - Error={1}", sr.FDCdata[0].DeviceClass[i].DeviceID, sr.FDCdata[0].DeviceClass[i].ErrorCode));
  2669. }
  2670. }
  2671. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true);
  2672. DebugLog("GetAvailableFuelSaleTrxsResp end");
  2673. }
  2674. catch (Exception ex)
  2675. {
  2676. DebugLog("GetAvailableFuelSaleTrxsResp Exception! " + ex);
  2677. }
  2678. }
  2679. public void GetFuelSaleTrxDetails(int pumpId, int transactionNo, int releaseToken, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2680. {
  2681. // create XML ServiceRequest object
  2682. try
  2683. {
  2684. ServiceRequestGetFuelSaleTrxDetails sr = new ServiceRequestGetFuelSaleTrxDetails();
  2685. sr.ApplicationSender = this.clientSocket.applicationSender;
  2686. sr.WorkstationID = this.clientSocket.workstationID;
  2687. ServiceRequestPOSdataGetFuelSaleTrxDetails posDataElem = new ServiceRequestPOSdataGetFuelSaleTrxDetails();
  2688. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2689. ServiceRequestDeviceClassGetFuelSaleTrxDetails deviceClass = new ServiceRequestDeviceClassGetFuelSaleTrxDetails();
  2690. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  2691. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint;
  2692. deviceClass.TransactionSeqNo = (transactionNo == -1) ? "*" : Convert.ToString(transactionNo);
  2693. posDataElem.DeviceClass = deviceClass;
  2694. ServiceRequestPOSdataGetFuelSaleTrxDetails[] posDataArray = { posDataElem };
  2695. sr.POSdata = posDataArray;
  2696. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2697. }
  2698. catch (Exception ex)
  2699. {
  2700. DebugLog("GetFuelSaleTrxDetails Exception! " + ex);
  2701. }
  2702. }
  2703. private void GetFuelSaleTrxDetailsResp(int requestId, string sOverallResult, ServiceResponseGetFuelSaleTrxDetails sr)
  2704. {
  2705. try
  2706. {
  2707. DebugLog("GetFuelSaleTrxDetailsResp init");
  2708. if (sr.FDCdata == null || sr.FDCdata[0].DeviceClass == null)
  2709. {
  2710. DebugLog("no fuel sale details - end");
  2711. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true);
  2712. return;
  2713. }
  2714. if ((OnGetFuelSaleTrxDetails != null || OnFuelSaleTrx != null) && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  2715. {
  2716. var serializer = new XmlSerializer(typeof(FDCMessageFuelSaleTrx));
  2717. foreach (ServiceResponseDeviceClassGetFuelSaleTrxDetails deviceClass in sr.FDCdata[0].DeviceClass)
  2718. {
  2719. if (deviceClass.ErrorCode == ErrorCode.ERRCD_OK.ToString())
  2720. {
  2721. DebugLog(string.Format("type={0}, id={1}, nozzle={2}, price={3}, amount={4}, vol={5}, authAS={6}, lockAS={7}",
  2722. deviceClass.Type, deviceClass.DeviceID,
  2723. deviceClass.NozzleNo, deviceClass.UnitPrice, deviceClass.Amount, deviceClass.Volume,
  2724. deviceClass.AuthorisationApplicationSender, deviceClass.LockingApplicationSender));
  2725. string deviceType = deviceClass.Type;
  2726. int deviceId = Convert.ToInt16(deviceClass.DeviceID);
  2727. int nozzleId = Convert.ToInt16(deviceClass.NozzleNo);
  2728. decimal volume = FDCConvert.ToDecimal(deviceClass.Volume);
  2729. decimal amount = FDCConvert.ToDecimal(deviceClass.Amount);
  2730. decimal price = FDCConvert.ToDecimal(deviceClass.UnitPrice);
  2731. int transactionSeqNum = Convert.ToInt32(deviceClass.TransactionSeqNo);
  2732. // if fuelling sequence number not available, use transaction sequence number
  2733. int fuellingSeqNum = string.IsNullOrEmpty(deviceClass.FuellingSequenceNo)
  2734. ? transactionSeqNum
  2735. : Convert.ToInt32(deviceClass.FuellingSequenceNo);
  2736. Wayne.FDCPOSLibrary.FuellingState transactionState = convertFuellingState(deviceClass.State);
  2737. int completionReason = 0;
  2738. int fuelMode = (deviceClass.FuelMode != null && deviceClass.FuelMode.ModeNo != null && deviceClass.FuelMode.ModeNo != "") ? Convert.ToInt32(deviceClass.FuelMode.ModeNo) : 0;
  2739. DateTime trxStartDateTime = Convert.ToDateTime(deviceClass.StartTimeStamp);
  2740. DateTime trxEndDateTime = Convert.ToDateTime(deviceClass.EndTimeStamp);
  2741. string authAS = deviceClass.AuthorisationApplicationSender;
  2742. string lockingAS = deviceClass.LockingApplicationSender;
  2743. string DSPFields = deviceClass.DSPFields;
  2744. string CRCMode = deviceClass.CRCMode;
  2745. string MIDLinesNarrow = deviceClass.MIDLinesNarrow;
  2746. string MIDLinesWide = deviceClass.MIDLinesWide;
  2747. FuellingType fuellingType = (deviceClass.FuellingType == "") ? FuellingType.Unknown : ((FuellingType)Convert.ToInt16(deviceClass.FuellingType));
  2748. if (fuellingType == FuellingType.Unknown)
  2749. {
  2750. DebugLog("Fuelling of unkown type received. Converting to DetectedFromAccumulators!!!");
  2751. fuellingType = FuellingType.DetectedFromAccumulators;
  2752. }
  2753. int releaseToken;
  2754. try
  2755. {
  2756. IReleaseToken token = AuthReleaseTokenFactory.GenerateToken(deviceClass.ReleaseToken);
  2757. releaseToken = token.AuthorizationId;
  2758. }
  2759. catch
  2760. {
  2761. releaseToken = 0;
  2762. }
  2763. byte reservingDeviceId;
  2764. try
  2765. {
  2766. reservingDeviceId = Convert.ToByte(deviceClass.ReservingDeviceId);
  2767. }
  2768. catch (Exception ex)
  2769. {
  2770. reservingDeviceId = 0;
  2771. }
  2772. FDCMessageFDCdataFuelSaleTrx fdcData = new FDCMessageFDCdataFuelSaleTrx()
  2773. {
  2774. FDCTimeStamp = sr.FDCdata[0].FDCTimeStamp,
  2775. DeviceClass = new FDCMessageDeviceClassFuelSaleTrx()
  2776. {
  2777. Amount = deviceClass.Amount,
  2778. AuthorisationApplicationSender = deviceClass.AuthorisationApplicationSender,
  2779. BlendRatio = deviceClass.BlendRatio,
  2780. CompletionReason = "0",
  2781. CRCMode = deviceClass.CRCMode,
  2782. DeviceID = deviceClass.DeviceID,
  2783. DSPFields = deviceClass.DSPFields,
  2784. EndTimeStamp = deviceClass.EndTimeStamp,
  2785. ErrorCode = deviceClass.ErrorCode,
  2786. FuelPeriodSequenceNo = deviceClass.FuelPeriodSequenceNo,
  2787. FuelMode = deviceClass.FuelMode,
  2788. FuellingSequenceNo = deviceClass.FuellingSequenceNo,
  2789. FuellingType = deviceClass.FuellingType,
  2790. LockingApplicationSender = deviceClass.LockingApplicationSender,
  2791. MIDLinesNarrow = deviceClass.MIDLinesNarrow,
  2792. MIDLinesWide = deviceClass.MIDLinesWide,
  2793. MaxTrxAmount = deviceClass.MaxTrxAmount,
  2794. NozzleNo = deviceClass.NozzleNo,
  2795. PrepaidTrx = deviceClass.PrepaidTrx,
  2796. ProductName = deviceClass.ProductName,
  2797. ProductNo = deviceClass.ProductNo,
  2798. ProductNo1 = deviceClass.ProductNo1,
  2799. ProductNo2 = deviceClass.ProductNo2,
  2800. ProductUM = deviceClass.ProductUM,
  2801. PumpNo = deviceClass.PumpNo,
  2802. ReleaseToken = deviceClass.ReleaseToken,
  2803. ReservingDeviceId = deviceClass.ReservingDeviceId,
  2804. StartTimeStamp = deviceClass.StartTimeStamp,
  2805. State = deviceClass.State,
  2806. TransactionSeqNo = deviceClass.TransactionSeqNo,
  2807. Type = deviceClass.Type,
  2808. UnitPrice = deviceClass.UnitPrice,
  2809. Volume = deviceClass.Volume,
  2810. VolumeProduct1 = deviceClass.VolumeProduct1,
  2811. VolumeProduct2 = deviceClass.VolumeProduct2,
  2812. },
  2813. };
  2814. FDCMessageFuelSaleTrx fdcMessageFuelSaleTrx = new FDCMessageFuelSaleTrx()
  2815. {
  2816. MessageType = "FuelSaleTrx",
  2817. ApplicationSender = sr.ApplicationSender,
  2818. WorkstationID = sr.WorkstationID,
  2819. MessageID = sr.RequestID, //?
  2820. FDCdata = new FDCMessageFDCdataFuelSaleTrx[] { fdcData },
  2821. };
  2822. var builder = new StringBuilder();
  2823. using (var writer = new StringWriter(builder))
  2824. {
  2825. serializer.Serialize(writer, fdcMessageFuelSaleTrx);
  2826. }
  2827. string derivedXml = builder.ToString();
  2828. if (OnGetFuelSaleTrxDetails != null)
  2829. {
  2830. var eventPayload = new FuelSaleTrxEventArgs(
  2831. transactionSeqNum,
  2832. fuellingSeqNum,
  2833. transactionState,
  2834. completionReason,
  2835. deviceType,
  2836. deviceId,
  2837. nozzleId,
  2838. volume,
  2839. amount,
  2840. price,
  2841. fuelMode,
  2842. trxStartDateTime,
  2843. trxEndDateTime,
  2844. lockingAS,
  2845. authAS,
  2846. DSPFields,
  2847. CRCMode,
  2848. MIDLinesNarrow,
  2849. MIDLinesWide,
  2850. releaseToken,
  2851. reservingDeviceId,
  2852. fuellingType,
  2853. derivedXml)
  2854. {
  2855. FuelPeriodSequenceNo = Convert.ToInt32(deviceClass.FuelPeriodSequenceNo)
  2856. };
  2857. OnGetFuelSaleTrxDetails(this, eventPayload);
  2858. }
  2859. if (OnFuelSaleTrx != null)
  2860. {
  2861. var eventPayload = new FuelSaleTrxEventArgs(
  2862. transactionSeqNum,
  2863. fuellingSeqNum,
  2864. transactionState,
  2865. completionReason,
  2866. deviceType,
  2867. deviceId,
  2868. nozzleId,
  2869. volume,
  2870. amount,
  2871. price,
  2872. fuelMode,
  2873. trxStartDateTime,
  2874. trxEndDateTime,
  2875. lockingAS,
  2876. authAS,
  2877. DSPFields,
  2878. CRCMode,
  2879. MIDLinesNarrow,
  2880. MIDLinesWide,
  2881. releaseToken,
  2882. reservingDeviceId,
  2883. fuellingType,
  2884. derivedXml)
  2885. {
  2886. FuelPeriodSequenceNo = Convert.ToInt32(deviceClass.FuelPeriodSequenceNo)
  2887. };
  2888. OnFuelSaleTrx(this, eventPayload);
  2889. }
  2890. }
  2891. else
  2892. DebugLog("no fuel sale details anymore");
  2893. }
  2894. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true);
  2895. }
  2896. DebugLog("GetFuelSaleTrxDetailsResp end");
  2897. }
  2898. catch (Exception ex)
  2899. {
  2900. DebugLog("GetFuelSaleTrxDetailsResp Exception! " + ex);
  2901. }
  2902. }
  2903. private void GetFuelSaleTrxDetailsResp(int requestId, string sOverallResult, ServiceResponseGetFuelSaleTrxDetailsV03 sr)
  2904. {
  2905. try
  2906. {
  2907. DebugLog("GetFuelSaleTrxDetailsRespV03 init");
  2908. if (sr.FDCdata == null || sr.FDCdata[0].DeviceClass == null)
  2909. {
  2910. DebugLog("no fuel sale details - end");
  2911. return;
  2912. }
  2913. if ((OnGetFuelSaleTrxDetails != null || OnFuelSaleTrx != null) && sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  2914. {
  2915. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  2916. {
  2917. DebugLog(string.Format("type={0}, id={1}, nozzle={2}, amount={3}, vol={4}",
  2918. sr.FDCdata[0].DeviceClass[i].Type, sr.FDCdata[0].DeviceClass[i].DeviceID,
  2919. sr.FDCdata[0].DeviceClass[i].NozzleNo, sr.FDCdata[0].DeviceClass[i].Amount, sr.FDCdata[0].DeviceClass[i].Volume));
  2920. string deviceType = sr.FDCdata[0].DeviceClass[0].Type;
  2921. int transactionSeqNum = Convert.ToInt32(sr.FDCdata[0].DeviceClass[i].TransactionNo);
  2922. int deviceId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].DeviceID);
  2923. Wayne.FDCPOSLibrary.FuellingState transactionState = convertFuellingState(sr.FDCdata[0].DeviceClass[i].State);
  2924. int completionReason = 0;
  2925. int nozzleId = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].NozzleNo);
  2926. decimal volume = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].Volume);
  2927. decimal amount = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].Amount);
  2928. decimal price = FDCConvert.ToDecimal(sr.FDCdata[0].DeviceClass[i].UnitPrice);
  2929. int fuelMode = Convert.ToInt16(sr.FDCdata[0].DeviceClass[i].FuelMode);
  2930. DateTime trxStartDateTime = Convert.ToDateTime(sr.FDCdata[0].DeviceClass[i].StartTimeStamp);
  2931. DateTime trxEndDateTime = Convert.ToDateTime(sr.FDCdata[0].DeviceClass[i].EndTimeStamp);
  2932. string lockingAS = "";
  2933. string authAS = "";
  2934. string DSPFields = sr.FDCdata[0].DeviceClass[i].DSPFields;
  2935. string CRCMode = sr.FDCdata[0].DeviceClass[i].CRCMode;
  2936. string MIDLinesNarrow = "";
  2937. string MIDLinesWide = "";
  2938. int authId;
  2939. try
  2940. {
  2941. var token = AuthReleaseTokenFactory.GenerateToken(sr.FDCdata[0].DeviceClass[i].ReleaseToken);
  2942. authId = token.AuthorizationId;
  2943. }
  2944. catch
  2945. {
  2946. authId = 0;
  2947. }
  2948. if (OnGetFuelSaleTrxDetails != null)
  2949. OnGetFuelSaleTrxDetails(this, new FuelSaleTrxEventArgs(transactionSeqNum, 0, transactionState, completionReason, deviceType, deviceId, nozzleId, volume, amount, price, fuelMode, trxStartDateTime, trxEndDateTime, lockingAS, authAS, DSPFields, CRCMode, MIDLinesNarrow, MIDLinesWide, authId, 0, FuellingType.Unknown));
  2950. if (OnFuelSaleTrx != null)
  2951. OnFuelSaleTrx(this, new FuelSaleTrxEventArgs(transactionSeqNum, 0, transactionState, completionReason, deviceType, deviceId, nozzleId, volume, amount, price, fuelMode, trxStartDateTime, trxEndDateTime, lockingAS, authAS, DSPFields, CRCMode, MIDLinesNarrow, MIDLinesWide, authId, 0, FuellingType.Unknown));
  2952. }
  2953. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true);
  2954. }
  2955. DebugLog("GetFuelSaleTrxDetailsResp end");
  2956. }
  2957. catch (Exception ex)
  2958. {
  2959. DebugLog("GetFuelSaleTrxDetailsResp Exception! " + ex);
  2960. }
  2961. }
  2962. public void GetProductTable(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  2963. {
  2964. try
  2965. {
  2966. // create XML ServiceRequest object
  2967. ServiceRequestGetProductTable sr = new ServiceRequestGetProductTable();
  2968. sr.ApplicationSender = this.clientSocket.applicationSender;
  2969. sr.WorkstationID = this.clientSocket.workstationID;
  2970. ServiceRequestPOSdataGetProductTable posDataElem = new ServiceRequestPOSdataGetProductTable();
  2971. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  2972. ServiceRequestPOSdataGetProductTable[] posDataArray = { posDataElem };
  2973. sr.POSdata = posDataArray;
  2974. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  2975. }
  2976. catch (Exception ex)
  2977. {
  2978. DebugLog("GetProductTable Exception! " + ex);
  2979. }
  2980. }
  2981. private void GetProductTableResp(int requestId, string sOverallResult, ServiceResponseGetProductTable sr)
  2982. {
  2983. try
  2984. {
  2985. DebugLog("GetProductTableResp init");
  2986. if (sr == null || (sr.OverallResult != OverallResult.Success.ToString() && sr.OverallResult != "") ||
  2987. sr.FDCdata == null || sr.FDCdata.Length == 0 ||
  2988. sr.FDCdata[0].FuelProducts == null || sr.FDCdata[0].FuelProducts.Length == 0 ||
  2989. sr.FDCdata[0].FuelProducts[0].Product == null || sr.FDCdata[0].FuelProducts[0].Product.Length == 0)
  2990. {
  2991. DebugLog("error in ServiceResponseGetProductTable");
  2992. }
  2993. //manage getConfigurationData
  2994. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true, sr);
  2995. DebugLog("GetProductTableResp end");
  2996. }
  2997. catch (Exception ex)
  2998. {
  2999. DebugLog("GetProductTableResp Exception! " + ex);
  3000. }
  3001. }
  3002. public void GetModeTable(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3003. {
  3004. try
  3005. {
  3006. // create XML ServiceRequest object
  3007. ServiceRequestGetModeTable sr = new ServiceRequestGetModeTable();
  3008. sr.ApplicationSender = this.clientSocket.applicationSender;
  3009. sr.WorkstationID = this.clientSocket.workstationID;
  3010. ServiceRequestPOSdataGetModeTable posDataElem = new ServiceRequestPOSdataGetModeTable();
  3011. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3012. ServiceRequestPOSdataGetModeTable[] posDataArray = { posDataElem };
  3013. sr.POSdata = posDataArray;
  3014. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3015. }
  3016. catch (Exception ex)
  3017. {
  3018. DebugLog("GetModeTable Exception! " + ex);
  3019. }
  3020. }
  3021. private void GetModeTableResp(int requestId, string sOverallResult, ServiceResponseGetModeTable sr)
  3022. {
  3023. try
  3024. {
  3025. DebugLog("GetModeTableResp init");
  3026. DebugLog("GetModeTableResp end");
  3027. }
  3028. catch (Exception ex)
  3029. {
  3030. DebugLog("GetModeTableResp Exception! " + ex);
  3031. }
  3032. }
  3033. public void GetFuelMode(int pumpId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3034. {
  3035. try
  3036. {
  3037. // create XML ServiceRequest object
  3038. ServiceRequestGetFuelMode srV07 = new ServiceRequestGetFuelMode();
  3039. ServiceRequestGetFPFuelMode sr = new ServiceRequestGetFPFuelMode();
  3040. srV07.ApplicationSender = this.clientSocket.applicationSender;
  3041. srV07.WorkstationID = this.clientSocket.workstationID;
  3042. sr.ApplicationSender = this.clientSocket.applicationSender;
  3043. sr.WorkstationID = this.clientSocket.workstationID;
  3044. ServiceRequestPOSdataGetFuelMode posDataElem = new ServiceRequestPOSdataGetFuelMode();
  3045. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3046. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3047. deviceClass.DeviceID = (pumpId == -1) ? "*" : Convert.ToString(pumpId);
  3048. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3049. posDataElem.DeviceClass = deviceClass;
  3050. ServiceRequestPOSdataGetFuelMode[] posDataArray = { posDataElem };
  3051. srV07.POSdata = posDataArray;
  3052. sr.POSdata = posDataArray;
  3053. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  3054. clientSocket.ifsfMessages.EnqueueMessage(srV07, requestCompleted, userToken, src, true, 30000);
  3055. else
  3056. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3057. }
  3058. catch (Exception ex)
  3059. {
  3060. DebugLog("GetFuelMode Exception! " + ex);
  3061. }
  3062. }
  3063. private void GetFuelModeResp(int requestId, string sOverallResult, ServiceResponseFDCdataGetFuelMode[] fdcData)
  3064. {
  3065. try
  3066. {
  3067. DebugLog("GetFuelModeResp init");
  3068. if (fdcData == null || fdcData[0].DeviceClass == null)
  3069. {
  3070. DebugLog("no device available - end");
  3071. return;
  3072. }
  3073. // TO ADD
  3074. if (OnFuelModeChange != null)
  3075. {
  3076. string deviceType = fdcData[0].DeviceClass[0].Type;
  3077. int deviceId = Convert.ToInt16(fdcData[0].DeviceClass[0].DeviceID);
  3078. int mode = 0;
  3079. if (fdcData[0].DeviceClass[0].FuelMode.ModeNo != null)
  3080. mode = Convert.ToInt16(fdcData[0].DeviceClass[0].FuelMode.ModeNo);
  3081. else
  3082. mode = Convert.ToInt16(fdcData[0].DeviceClass[0].ModeNo);
  3083. DebugLog("Trigger FuelModeChanged");
  3084. OnFuelModeChange.Fire(this, new FuelModeChangedEventArgs(deviceType, deviceId, mode));
  3085. }
  3086. if (OnOperationModeChange != null)
  3087. {
  3088. var deviceType = fdcData[0].DeviceClass[0].Type;
  3089. int deviceId = Convert.ToInt16(fdcData[0].DeviceClass[0].DeviceID);
  3090. if (fdcData[0].DeviceClass[0].FuelMode.OperationModeSpecified)
  3091. {
  3092. var mode = Convert.ToUInt16(fdcData[0].DeviceClass[0].FuelMode.OperationMode);
  3093. DebugLog("Trigger OperationModeChanged");
  3094. OnOperationModeChange.Fire(this, new OperationModeChangedEventArgs(deviceType, deviceId, mode));
  3095. }
  3096. }
  3097. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  3098. DebugLog("GetFuelModeResp end");
  3099. }
  3100. catch (Exception ex)
  3101. {
  3102. DebugLog("GetFuelModeResp Exception! " + ex);
  3103. }
  3104. }
  3105. public void GetConfiguration(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3106. {
  3107. try
  3108. {
  3109. // create XML ServiceRequest object
  3110. ServiceRequestGetConfiguration sr = new ServiceRequestGetConfiguration();
  3111. sr.ApplicationSender = this.clientSocket.applicationSender;
  3112. sr.WorkstationID = this.clientSocket.workstationID;
  3113. ServiceRequestPOSdataGetConfiguration posDataElem = new ServiceRequestPOSdataGetConfiguration();
  3114. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3115. ServiceRequestPOSdataGetConfiguration[] posDataArray = { posDataElem };
  3116. sr.POSdata = posDataArray;
  3117. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3118. }
  3119. catch (Exception ex)
  3120. {
  3121. DebugLog("GetConfiguration Exception! " + ex);
  3122. }
  3123. }
  3124. private void GetConfigurationResp(int requestId, string sOverallResult, ServiceResponseGetConfiguration sr)
  3125. {
  3126. try
  3127. {
  3128. DebugLog("GetConfigurationResp init: INVALID FOR V7 !");
  3129. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == "Success", sr);
  3130. DebugLog("GetConfigurationResp end");
  3131. }
  3132. catch (Exception ex)
  3133. {
  3134. DebugLog("GetConfigurationResp Exception! " + ex);
  3135. }
  3136. }
  3137. public void GetDSPConfiguration(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3138. {
  3139. try
  3140. {
  3141. // create XML ServiceRequest object
  3142. ServiceRequestGetDSPConfiguration sr = new ServiceRequestGetDSPConfiguration();
  3143. sr.ApplicationSender = this.clientSocket.applicationSender;
  3144. sr.WorkstationID = this.clientSocket.workstationID;
  3145. ServiceRequestPOSdataGetConfiguration posDataElem = new ServiceRequestPOSdataGetConfiguration();
  3146. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3147. ServiceRequestPOSdataGetConfiguration[] posDataArray = { posDataElem };
  3148. sr.POSdata = posDataArray;
  3149. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3150. }
  3151. catch (Exception ex)
  3152. {
  3153. DebugLog("GetDSPConfiguration Exception! " + ex);
  3154. }
  3155. }
  3156. private void GetDSPConfigurationResp(int requestId, string sOverallResult, ServiceResponseGetDSPConfiguration sr)
  3157. {
  3158. try
  3159. {
  3160. DebugLog("GetDSPConfigurationResp init");
  3161. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId,
  3162. sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString(), sr);
  3163. DebugLog("GetDSPConfigurationResp end");
  3164. }
  3165. catch (Exception ex)
  3166. {
  3167. DebugLog("GetDSPConfigurationResp Exception! " + ex);
  3168. }
  3169. }
  3170. public void GetTLGConfiguration(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3171. {
  3172. try
  3173. {
  3174. // create XML ServiceRequest object
  3175. ServiceRequestGetTLGConfiguration sr = new ServiceRequestGetTLGConfiguration();
  3176. sr.ApplicationSender = this.clientSocket.applicationSender;
  3177. sr.WorkstationID = this.clientSocket.workstationID;
  3178. ServiceRequestPOSdataGetConfiguration posDataElem = new ServiceRequestPOSdataGetConfiguration();
  3179. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3180. ServiceRequestPOSdataGetConfiguration[] posDataArray = { posDataElem };
  3181. sr.POSdata = posDataArray;
  3182. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3183. }
  3184. catch (Exception ex)
  3185. {
  3186. DebugLog("GetTLGConfiguration Exception! " + ex);
  3187. }
  3188. }
  3189. private void GetTLGConfigurationResp(int requestId, string sOverallResult, ServiceResponseGetTLGConfiguration sr)
  3190. {
  3191. try
  3192. {
  3193. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString(), sr);
  3194. DebugLog("GetTLGConfigurationResp end");
  3195. }
  3196. catch (Exception ex)
  3197. {
  3198. DebugLog("GetTLGConfigurationResp Exception! " + ex);
  3199. }
  3200. }
  3201. private void SetConfigurationResp(int requestId, string sOverallResult, ServiceResponseSetConfiguration sr)
  3202. {
  3203. try
  3204. {
  3205. DebugLog("SetConfigurationResp init");
  3206. DebugLog("SetConfigurationResp end");
  3207. }
  3208. catch (Exception ex)
  3209. {
  3210. DebugLog("SetConfigurationResp Exception! " + ex);
  3211. }
  3212. }
  3213. public void LockNozzle(int deviceId, int nozzleNo, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3214. {
  3215. try
  3216. {
  3217. // create XML ServiceRequest object
  3218. ServiceRequestLockNozzle sr = new ServiceRequestLockNozzle();
  3219. sr.ApplicationSender = this.clientSocket.applicationSender;
  3220. sr.WorkstationID = this.clientSocket.workstationID;
  3221. ServiceRequestPOSdataLockNozzle posDataElem = new ServiceRequestPOSdataLockNozzle();
  3222. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3223. ServiceRequestDeviceClassLockNozzle deviceClass = new ServiceRequestDeviceClassLockNozzle();
  3224. deviceClass.DeviceID = Convert.ToString(deviceId);
  3225. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3226. deviceClass.NozzleNo = (nozzleNo == -1) ? "*" : Convert.ToString(nozzleNo);
  3227. posDataElem.DeviceClass = deviceClass;
  3228. ServiceRequestPOSdataLockNozzle[] posDataArray = { posDataElem };
  3229. sr.POSdata = posDataArray;
  3230. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3231. }
  3232. catch (Exception ex)
  3233. {
  3234. DebugLog("LockNozzle Exception! " + ex);
  3235. }
  3236. }
  3237. private void LockNozzleResp(int requestId, string sOverallResult, ServiceResponseLockNozzle sr)
  3238. {
  3239. try
  3240. {
  3241. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  3242. DebugLog(string.Format("LockNozzleResp type={0}, id={1}, nozzleNo={2}, errorCode={3}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, sr.FDCdata[0].DeviceClass.NozzleNo, errorCode));
  3243. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == FDCPOSLibrary.OverallResult.Success.ToString());
  3244. DebugLog(string.Format("LockNozzleResp end"));
  3245. }
  3246. catch (Exception ex)
  3247. {
  3248. DebugLog("LockNozzleResp Exception! " + ex);
  3249. }
  3250. }
  3251. public void UnlockNozzle(int deviceId, int nozzleNo, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3252. {
  3253. try
  3254. {
  3255. // create XML ServiceRequest object
  3256. ServiceRequestUnlockNozzle sr = new ServiceRequestUnlockNozzle();
  3257. sr.ApplicationSender = this.clientSocket.applicationSender;
  3258. sr.WorkstationID = this.clientSocket.workstationID;
  3259. ServiceRequestPOSdataUnlockNozzle posDataElem = new ServiceRequestPOSdataUnlockNozzle();
  3260. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3261. ServiceRequestDeviceClassUnlockNozzle deviceClass = new ServiceRequestDeviceClassUnlockNozzle();
  3262. deviceClass.DeviceID = Convert.ToString(deviceId);
  3263. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint;
  3264. deviceClass.NozzleNo = (nozzleNo == -1) ? "*" : Convert.ToString(nozzleNo);
  3265. posDataElem.DeviceClass = deviceClass;
  3266. ServiceRequestPOSdataUnlockNozzle[] posDataArray = { posDataElem };
  3267. sr.POSdata = posDataArray;
  3268. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3269. }
  3270. catch (Exception ex)
  3271. {
  3272. DebugLog("UnlockNozzle Exception! " + ex);
  3273. }
  3274. }
  3275. private void UnlockNozzleResp(int requestId, string sOverallResult, ServiceResponseUnlockNozzle sr)
  3276. {
  3277. try
  3278. {
  3279. string errorCode = (sr.FDCdata[0].FDCStatus != null) ? sr.FDCdata[0].FDCStatus : sr.FDCdata[0].DeviceClass.ErrorCode;
  3280. DebugLog(string.Format("UnlockNozzleResp type={0}, id={1}, nozzleNo={2}, errorCode{3}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, sr.FDCdata[0].DeviceClass.NozzleNo, errorCode));
  3281. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3282. DebugLog("UnlockNozzleResp end");
  3283. }
  3284. catch (Exception ex)
  3285. {
  3286. DebugLog("UnlockNozzleResp Exception! " + ex);
  3287. }
  3288. }
  3289. public void GetCountrySettings(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3290. {
  3291. try
  3292. {
  3293. // create XML ServiceRequest object
  3294. ServiceRequestGetCountrySettings sr = new ServiceRequestGetCountrySettings();
  3295. sr.ApplicationSender = this.clientSocket.applicationSender;
  3296. sr.WorkstationID = this.clientSocket.workstationID;
  3297. ServiceRequestPOSdataGetCountrySettings posDataElem = new ServiceRequestPOSdataGetCountrySettings();
  3298. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3299. ServiceRequestPOSdataGetCountrySettings[] posDataArray = { posDataElem };
  3300. sr.POSdata = posDataArray;
  3301. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3302. }
  3303. catch (Exception ex)
  3304. {
  3305. DebugLog("GetCountrySettings Exception! " + ex);
  3306. }
  3307. }
  3308. private void GetCountrySettingsResp(int requestId, string sOverallResult, ServiceResponseGetCountrySettings sr)
  3309. {
  3310. try
  3311. {
  3312. DebugLog("GetCountrySettingsResp init");
  3313. if (sr.FDCdata[0].DecimalSign != null)
  3314. FDCConvert.DecimalSeparator = sr.FDCdata[0].DecimalSign;
  3315. if (sr.FDCdata[0].ThousandDelimiter != null)
  3316. FDCConvert.ThousandSeparator = sr.FDCdata[0].ThousandDelimiter;
  3317. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, true, sr);
  3318. this.clientSocket.mainConnectionState = DeviceConnectionState.Connected;
  3319. DebugLog(string.Format("GetCountrySettingsResp end: DecimalSeparator={0}, ThousandSeparator={1}, connectionState={2}", FDCConvert.DecimalSeparator, FDCConvert.ThousandSeparator, this.clientSocket.mainConnectionState));
  3320. }
  3321. catch (Exception ex)
  3322. {
  3323. DebugLog("GetCountrySettingsResp Exception! " + ex);
  3324. }
  3325. }
  3326. public void GetDSPLimits(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3327. {
  3328. try
  3329. {
  3330. // create XML ServiceRequest object
  3331. ServiceRequestGetDSPLimits sr = new ServiceRequestGetDSPLimits();
  3332. sr.ApplicationSender = this.clientSocket.applicationSender;
  3333. sr.WorkstationID = this.clientSocket.workstationID;
  3334. ServiceRequestPOSdataGetDSPLimits posDataElem = new ServiceRequestPOSdataGetDSPLimits();
  3335. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3336. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3337. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  3338. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser;
  3339. posDataElem.DeviceClass = deviceClass;
  3340. ServiceRequestPOSdataGetDSPLimits[] posDataArray = { posDataElem };
  3341. sr.POSdata = posDataArray;
  3342. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3343. }
  3344. catch (Exception ex)
  3345. {
  3346. DebugLog("GetDSPLimits Exception! " + ex);
  3347. }
  3348. }
  3349. private void GetDSPLimitsResp(int requestId, string sOverallResult, ServiceResponseGetDSPLimits sr)
  3350. {
  3351. try
  3352. {
  3353. if (sr.FDCdata[0] != null && sr.FDCdata[0].DeviceClass != null)
  3354. for (int i = 0; i < sr.FDCdata[0].DeviceClass.Length; i++)
  3355. {
  3356. DebugLog(string.Format("GetDSPLimitsResp type={0}, id={1}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[i].DeviceID));
  3357. }
  3358. DebugLog("GetDSPLimitsResp end");
  3359. }
  3360. catch (Exception ex)
  3361. {
  3362. DebugLog("GetDSPLimitsResp Exception! " + ex);
  3363. }
  3364. }
  3365. public void ChangeDSPLimits(int deviceId, int productNo, int modeNo, double maxTrxAmount, double maxTrxVolume, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3366. {
  3367. try
  3368. {
  3369. // create XML ServiceRequest object
  3370. ServiceRequestChangeDSPLimits sr = new ServiceRequestChangeDSPLimits();
  3371. sr.ApplicationSender = this.clientSocket.applicationSender;
  3372. sr.WorkstationID = this.clientSocket.workstationID;
  3373. ServiceRequestPOSdataChangeDSPLimits posDataElem = new ServiceRequestPOSdataChangeDSPLimits();
  3374. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3375. ServiceRequestDeviceClassChangeDSPLimits deviceClass = new ServiceRequestDeviceClassChangeDSPLimits();
  3376. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  3377. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser;
  3378. deviceClass.ProductNo = Convert.ToString(productNo);
  3379. deviceClass.ModeNo = Convert.ToString(modeNo);
  3380. System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo();
  3381. provider.NumberDecimalSeparator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
  3382. provider.NumberGroupSeparator = System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator;
  3383. provider.NumberGroupSizes = System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSizes;
  3384. deviceClass.MaxTrxAmount = string.Format(provider, "{0:F2}", maxTrxAmount);
  3385. provider.NumberDecimalDigits = 3;
  3386. deviceClass.MaxTrxVolume = string.Format(provider, "{0:F3}", maxTrxVolume);
  3387. posDataElem.DeviceClass = deviceClass;
  3388. ServiceRequestPOSdataChangeDSPLimits[] posDataArray = { posDataElem };
  3389. sr.POSdata = posDataArray;
  3390. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3391. }
  3392. catch (Exception ex)
  3393. {
  3394. DebugLog("ChangeDSPLimits Exception! " + ex);
  3395. }
  3396. }
  3397. private void ChangeDSPLimitsResp(int requestId, string sOverallResult, ServiceResponseChangeDSPLimits sr)
  3398. {
  3399. try
  3400. {
  3401. DebugLog("ChangeDSPLimitsResp init");
  3402. DebugLog("ChangeDSPLimitsResp end");
  3403. }
  3404. catch (Exception ex)
  3405. {
  3406. DebugLog("ChangeDSPLimitsResp Exception! " + ex);
  3407. }
  3408. }
  3409. public void SuspendFuelling(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3410. {
  3411. try
  3412. {
  3413. // create XML ServiceRequest object
  3414. ServiceRequestSuspendFuelling sr = new ServiceRequestSuspendFuelling();
  3415. sr.ApplicationSender = this.clientSocket.applicationSender;
  3416. sr.WorkstationID = this.clientSocket.workstationID;
  3417. ServiceRequestPOSdataSuspendFuelling posDataElem = new ServiceRequestPOSdataSuspendFuelling();
  3418. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3419. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3420. deviceClass.DeviceID = Convert.ToString(deviceId);
  3421. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3422. posDataElem.DeviceClass = deviceClass;
  3423. ServiceRequestPOSdataSuspendFuelling[] posDataArray = { posDataElem };
  3424. sr.POSdata = posDataArray;
  3425. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3426. }
  3427. catch (Exception ex)
  3428. {
  3429. DebugLog("SuspendFuelling Exception! " + ex);
  3430. }
  3431. }
  3432. private void SuspendFuellingResp(int requestId, string sOverallResult, ServiceResponseSuspendFuelling sr)
  3433. {
  3434. try
  3435. {
  3436. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3437. DebugLog(string.Format("SuspendFuellingResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3438. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3439. DebugLog("SuspendFuellingResp end");
  3440. }
  3441. catch (Exception ex)
  3442. {
  3443. DebugLog("SuspendFuellingResp Exception! " + ex);
  3444. }
  3445. }
  3446. public void ResumeFuelling(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3447. {
  3448. try
  3449. {
  3450. // create XML ServiceRequest object
  3451. ServiceRequestResumeFuelling sr = new ServiceRequestResumeFuelling();
  3452. sr.ApplicationSender = this.clientSocket.applicationSender;
  3453. sr.WorkstationID = this.clientSocket.workstationID;
  3454. ServiceRequestPOSdataResumeFuelling posDataElem = new ServiceRequestPOSdataResumeFuelling();
  3455. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3456. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3457. deviceClass.DeviceID = Convert.ToString(deviceId);
  3458. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3459. posDataElem.DeviceClass = deviceClass;
  3460. ServiceRequestPOSdataResumeFuelling[] posDataArray = { posDataElem };
  3461. sr.POSdata = posDataArray;
  3462. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3463. }
  3464. catch (Exception ex)
  3465. {
  3466. DebugLog("ResumeFuelling Exception! " + ex);
  3467. }
  3468. }
  3469. private void ResumeFuellingResp(int requestId, string sOverallResult, ServiceResponseResumeFuelling sr)
  3470. {
  3471. try
  3472. {
  3473. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3474. DebugLog(string.Format("ResumeFuellingResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3475. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3476. DebugLog("ResumeFuellingResp end");
  3477. }
  3478. catch (Exception ex)
  3479. {
  3480. DebugLog("ResumeFuellingResp Exception! " + ex);
  3481. }
  3482. }
  3483. public void StopFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3484. {
  3485. try
  3486. {
  3487. // create XML ServiceRequest object
  3488. ServiceRequestStopFuelPoint sr = new ServiceRequestStopFuelPoint();
  3489. sr.ApplicationSender = this.clientSocket.applicationSender;
  3490. sr.WorkstationID = this.clientSocket.workstationID;
  3491. ServiceRequestPOSdataStopFuelPoint posDataElem = new ServiceRequestPOSdataStopFuelPoint();
  3492. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3493. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3494. deviceClass.DeviceID = Convert.ToString(deviceId);
  3495. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3496. deviceClass.CreateZeroSale = Convert.ToString(false);
  3497. if (src is FUSIONPump)
  3498. {
  3499. FUSIONPump p = (FUSIONPump)src;
  3500. if (p.State == PumpState.Fuelling)
  3501. deviceClass.CreateZeroSale = Convert.ToString(true);
  3502. }
  3503. posDataElem.DeviceClass = deviceClass;
  3504. ServiceRequestPOSdataStopFuelPoint[] posDataArray = { posDataElem };
  3505. sr.POSdata = posDataArray;
  3506. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3507. }
  3508. catch (Exception ex)
  3509. {
  3510. DebugLog("StopFuelPoint Exception! " + ex);
  3511. }
  3512. }
  3513. private void StopFuelPointResp(int requestId, string sOverallResult, ServiceResponseStopFuelPoint sr)
  3514. {
  3515. try
  3516. {
  3517. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3518. DebugLog(string.Format("StopFuelPointResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3519. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3520. DebugLog("StopFuelPointResp end");
  3521. }
  3522. catch (Exception ex)
  3523. {
  3524. DebugLog("StopFuelPointResp Exception! " + ex);
  3525. }
  3526. }
  3527. public void StartFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3528. {
  3529. try
  3530. {
  3531. // create XML ServiceRequest object
  3532. ServiceRequestStartFuelPoint sr = new ServiceRequestStartFuelPoint();
  3533. sr.ApplicationSender = this.clientSocket.applicationSender;
  3534. sr.WorkstationID = this.clientSocket.workstationID;
  3535. ServiceRequestPOSdataStartFuelPoint posDataElem = new ServiceRequestPOSdataStartFuelPoint();
  3536. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3537. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3538. deviceClass.DeviceID = Convert.ToString(deviceId);
  3539. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3540. posDataElem.DeviceClass = deviceClass;
  3541. ServiceRequestPOSdataStartFuelPoint[] posDataArray = { posDataElem };
  3542. sr.POSdata = posDataArray;
  3543. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3544. }
  3545. catch (Exception ex)
  3546. {
  3547. DebugLog("StartFuelPoint Exception! " + ex);
  3548. }
  3549. }
  3550. private void StartFuelPointResp(int requestId, string sOverallResult, ServiceResponseStartFuelPoint sr)
  3551. {
  3552. try
  3553. {
  3554. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3555. DebugLog(string.Format("StartFuelPointResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3556. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3557. DebugLog("StartFuelPointResp end");
  3558. }
  3559. catch (Exception ex)
  3560. {
  3561. DebugLog("StartFuelPointResp Exception! " + ex);
  3562. }
  3563. }
  3564. public void LockTank(int deviceId, int tankNo, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3565. {
  3566. try
  3567. {
  3568. // create XML ServiceRequest object
  3569. ServiceRequestLockTank sr = new ServiceRequestLockTank();
  3570. sr.ApplicationSender = this.clientSocket.applicationSender;
  3571. sr.WorkstationID = this.clientSocket.workstationID;
  3572. ServiceRequestPOSdataLockTank posDataElem = new ServiceRequestPOSdataLockTank();
  3573. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3574. ServiceRequestDeviceClassLockTank deviceClass = new ServiceRequestDeviceClassLockTank();
  3575. deviceClass.DeviceID = Convert.ToString(deviceId);
  3576. deviceClass.TankNo = Convert.ToString(tankNo);
  3577. deviceClass.Type = DeviceType.DT_TankProbe;
  3578. posDataElem.DeviceClass = deviceClass;
  3579. ServiceRequestPOSdataLockTank[] posDataArray = { posDataElem };
  3580. sr.POSdata = posDataArray;
  3581. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3582. }
  3583. catch (Exception ex)
  3584. {
  3585. DebugLog("LockTank Exception! " + ex);
  3586. }
  3587. }
  3588. private void LockTankResp(int requestId, string sOverallResult, ServiceResponseLockTank sr)
  3589. {
  3590. try
  3591. {
  3592. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3593. DebugLog(string.Format("LockTankResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3594. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3595. DebugLog("LockTankResp end");
  3596. }
  3597. catch (Exception ex)
  3598. {
  3599. DebugLog("LockTankResp Exception! " + ex);
  3600. }
  3601. }
  3602. public void UnlockTank(int deviceId, int tankNo, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3603. {
  3604. try
  3605. {
  3606. // create XML ServiceRequest object
  3607. ServiceRequestUnlockTank sr = new ServiceRequestUnlockTank();
  3608. sr.ApplicationSender = this.clientSocket.applicationSender;
  3609. sr.WorkstationID = this.clientSocket.workstationID;
  3610. ServiceRequestPOSdataUnlockTank posDataElem = new ServiceRequestPOSdataUnlockTank();
  3611. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3612. ServiceRequestDeviceClassUnlockTank deviceClass = new ServiceRequestDeviceClassUnlockTank();
  3613. deviceClass.DeviceID = Convert.ToString(deviceId);
  3614. deviceClass.TankNo = Convert.ToString(tankNo);
  3615. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe;
  3616. posDataElem.DeviceClass = deviceClass;
  3617. ServiceRequestPOSdataUnlockTank[] posDataArray = { posDataElem };
  3618. sr.POSdata = posDataArray;
  3619. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3620. }
  3621. catch (Exception ex)
  3622. {
  3623. DebugLog("UnlockTank Exception! " + ex);
  3624. }
  3625. }
  3626. private void UnlockTankResp(int requestId, string sOverallResult, ServiceResponseUnlockTank sr)
  3627. {
  3628. try
  3629. {
  3630. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  3631. DebugLog(string.Format("UnlockTankResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass[0].Type, sr.FDCdata[0].DeviceClass[0].DeviceID, errorCode));
  3632. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  3633. DebugLog("UnlockTankResp end");
  3634. }
  3635. catch (Exception ex)
  3636. {
  3637. DebugLog("UnlockTankResp Exception! " + ex);
  3638. }
  3639. }
  3640. public void GetTankData(int deviceId, int tankNo, EventHandler<AsyncCompletedEventArgs<ITankReadingEx>> requestCompleted, object userToken, object src)
  3641. {
  3642. try
  3643. {
  3644. // create XML ServiceRequest object
  3645. ServiceRequestGetTankData sr = new ServiceRequestGetTankData();
  3646. sr.ApplicationSender = this.clientSocket.applicationSender;
  3647. sr.WorkstationID = this.clientSocket.workstationID;
  3648. ServiceRequestPOSdataGetTankData posDataElem = new ServiceRequestPOSdataGetTankData();
  3649. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3650. ServiceRequestDeviceClassGetTankData deviceClass = new ServiceRequestDeviceClassGetTankData();
  3651. deviceClass.DeviceID = (deviceId == -1) ? "*" : Convert.ToString(deviceId);
  3652. // Not standard
  3653. deviceClass.Type = DeviceType.DT_TankProbe;
  3654. posDataElem.DeviceClass = deviceClass;
  3655. ServiceRequestPOSdataGetTankData[] posDataArray = { posDataElem };
  3656. sr.POSdata = posDataArray;
  3657. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<ITankReadingEx>)e);
  3658. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  3659. }
  3660. catch (Exception ex)
  3661. {
  3662. DebugLog("GetTankData Exception! " + ex);
  3663. }
  3664. }
  3665. private void GetTankDataResp(int requestId, string sOverallResult, ServiceResponseGetTankData sr, string originalXml)
  3666. {
  3667. try
  3668. {
  3669. ServiceResponseDeviceClassGetTankData tankdata = sr.FDCdata[0].DeviceClass[0];
  3670. DebugLog(string.Format("GetTankDataResp init: tank={0}, date={1}", tankdata.TankNo, sr.FDCdata[0].FDCTimeStamp));
  3671. DateTime date;
  3672. try
  3673. {
  3674. date = Convert.ToDateTime(sr.FDCdata[0].FDCTimeStamp);
  3675. }
  3676. catch (Exception ex)
  3677. {
  3678. DebugLog("GetTankDataResp: Exception! " + ex);
  3679. DebugLog("GetTankDataResp: set datetime to now");
  3680. date = DateTime.Now;
  3681. }
  3682. string errorCode = sr.FDCdata[0].FDCStatus ?? tankdata.ErrorCode;
  3683. ProbeState probeState = (errorCode != ErrorCode.ERRCD_OK.ToString()) ||
  3684. tankdata.DeviceState != null && convertLogicalDeviceState(tankdata.DeviceState) != LogicalDeviceState.FDC_READY ? ProbeState.Failed : ProbeState.Ok;
  3685. FUSIONTankReading tankreading;
  3686. if (probeState == ProbeState.Ok)
  3687. {
  3688. tankreading = new FUSIONTankReading(Convert.ToInt32(tankdata.TankNo),
  3689. probeState,
  3690. date,
  3691. FDCConvert.ToDecimal(
  3692. tankdata.MeasurementData.ProductLevel) / 1000,
  3693. FDCConvert.ToDecimal(
  3694. tankdata.MeasurementData
  3695. .TotalObservedVolume),
  3696. 0,
  3697. FDCConvert.ToDecimal(
  3698. tankdata.MeasurementData.WaterLevel) / 1000,
  3699. FDCConvert.ToDecimal(
  3700. tankdata.MeasurementData.WaterVolume),
  3701. FDCConvert.ToDecimal(
  3702. tankdata.MeasurementData.AverageTemp),
  3703. UnitOfMeasure.Liters,
  3704. UnitOfMeasure.Liters,
  3705. false,
  3706. originalXml);
  3707. DebugLog(string.Format("GetTankDataResp data received: tank={0}, state={1}, fuelLevel={2}, fuelVolume={3}, waterLevel={4}, waterVolume={5}, temperature={6}",
  3708. tankdata.TankNo, tankdata.MeasurementData.TPStatus,
  3709. tankdata.MeasurementData.ProductLevel,
  3710. tankdata.MeasurementData.TotalObservedVolume,
  3711. tankdata.MeasurementData.WaterLevel,
  3712. tankdata.MeasurementData.WaterVolume,
  3713. tankdata.MeasurementData.AverageTemp));
  3714. }
  3715. else
  3716. {
  3717. tankreading = new FUSIONTankReading(Convert.ToInt32(tankdata.TankNo),
  3718. probeState,
  3719. date,
  3720. 0,
  3721. 0,
  3722. 0,
  3723. 0,
  3724. 0,
  3725. 0,
  3726. UnitOfMeasure.Liters,
  3727. UnitOfMeasure.Liters,
  3728. false,
  3729. originalXml);
  3730. DebugLog(string.Format("GetTankDataResp data received: tank={0}, probestate={1}",
  3731. tankdata.TankNo, probeState));
  3732. }
  3733. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString(), (ITankReadingEx)tankreading);
  3734. DebugLog("GetTankDataResp end");
  3735. }
  3736. catch (Exception ex)
  3737. {
  3738. DebugLog("GetTankDataResp Exception! " + ex);
  3739. }
  3740. }
  3741. public void GetTankReconciliation(int deviceId, EventHandler<AsyncCompletedEventArgs<ITankReconciliation>> requestCompleted, object userToken, object src)
  3742. {
  3743. try
  3744. {
  3745. // create XML ServiceRequest object
  3746. ServiceRequestGetTankReconciliation sr = new ServiceRequestGetTankReconciliation();
  3747. sr.ApplicationSender = this.clientSocket.applicationSender;
  3748. sr.WorkstationID = this.clientSocket.workstationID;
  3749. ServiceRequestPOSdataGetTankReconciliation posDataElem = new ServiceRequestPOSdataGetTankReconciliation();
  3750. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3751. ServiceRequestDeviceClassGetTankReconciliation deviceClass = new ServiceRequestDeviceClassGetTankReconciliation();
  3752. deviceClass.DeviceID = deviceId.ToString();
  3753. deviceClass.Type = DeviceType.DT_TankProbe;
  3754. posDataElem.DeviceClass = deviceClass;
  3755. ServiceRequestPOSdataGetTankReconciliation[] posDataArray = { posDataElem };
  3756. sr.POSdata = posDataArray;
  3757. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<ITankReconciliation>)e);
  3758. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  3759. }
  3760. catch (Exception ex)
  3761. {
  3762. DebugLog("GetTankReconciliation Exception! " + ex);
  3763. }
  3764. }
  3765. private void GetTankReconciliationResp(int requestId, string sOverallResult, ServiceResponseGetTankReconciliation sr, string originalXml)
  3766. {
  3767. try
  3768. {
  3769. DebugLog("GetTankReconciliation init");
  3770. var tankReconciliation = new TankReconciliation(originalXml);
  3771. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString(), (ITankReconciliation)tankReconciliation);
  3772. DebugLog("GetTank ReconciliationResp end");
  3773. }
  3774. catch (Exception ex)
  3775. {
  3776. DebugLog("GetTankReconciliation Exception! " + ex);
  3777. }
  3778. }
  3779. public void GetTankDelivery(int deviceId, EventHandler<AsyncCompletedEventArgs<ITankDelivery>> requestCompleted, object userToken, object src)
  3780. {
  3781. try
  3782. {
  3783. // create XML ServiceRequest object
  3784. ServiceRequestGetTankDelivery sr = new ServiceRequestGetTankDelivery();
  3785. sr.ApplicationSender = this.clientSocket.applicationSender;
  3786. sr.WorkstationID = this.clientSocket.workstationID;
  3787. ServiceRequestPOSdataGetTankDelivery posDataElem = new ServiceRequestPOSdataGetTankDelivery();
  3788. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3789. ServiceRequestDeviceClassGetTankDelivery deviceClass = new ServiceRequestDeviceClassGetTankDelivery();
  3790. deviceClass.DeviceID = deviceId.ToString();
  3791. deviceClass.Type = DeviceType.DT_TankProbe;
  3792. posDataElem.DeviceClass = deviceClass;
  3793. ServiceRequestPOSdataGetTankDelivery[] posDataArray = { posDataElem };
  3794. sr.POSdata = posDataArray;
  3795. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<ITankDelivery>)e);
  3796. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  3797. }
  3798. catch (Exception ex)
  3799. {
  3800. DebugLog("GetTankDelivery Exception! " + ex);
  3801. }
  3802. }
  3803. private void GetTankDeliveryResp(int requestId, string sOverallResult, ServiceResponseGetTankDelivery sr, string originalXml)
  3804. {
  3805. try
  3806. {
  3807. DebugLog("GetTankDelivery init");
  3808. var tankDelivery = new TankDelivery(originalXml);
  3809. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString(), (ITankDelivery)tankDelivery);
  3810. DebugLog("GetTankDeliveryResp end");
  3811. }
  3812. catch (Exception ex)
  3813. {
  3814. DebugLog("GetTankDelivery Exception! " + ex);
  3815. }
  3816. }
  3817. public void GetPumpTotals(ServiceRequestDeviceClassGetFuelPointTotals deviceClass, EventHandler<AsyncCompletedEventArgs<PumpAccumulatorReading>> requestCompleted, object userToken, object src)
  3818. {
  3819. try
  3820. {
  3821. // create XML ServiceRequest object
  3822. DebugLog("Request all pump totals from Fusion");
  3823. var sr = new ServiceRequestGetFuelPointTotals();
  3824. sr.ApplicationSender = this.clientSocket.applicationSender;
  3825. sr.WorkstationID = this.clientSocket.workstationID;
  3826. var posDataElem = new ServiceRequestPOSdataGetFuelPointTotals();
  3827. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3828. posDataElem.DeviceClass = deviceClass;
  3829. ServiceRequestPOSdataGetFuelPointTotals[] posDataArray = { posDataElem };
  3830. sr.POSdata = posDataArray;
  3831. EventHandler<AsyncCompletedEventArgs> completed = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<PumpAccumulatorReading>)e);
  3832. clientSocket.ifsfMessages.EnqueueMessage(sr, completed, userToken, src, true, 30000);
  3833. }
  3834. catch (Exception ex)
  3835. {
  3836. DebugLog("GetFuelPrices Exception! " + ex);
  3837. }
  3838. }
  3839. public void GetFuelPrices(EventHandler<AsyncCompletedEventArgs<IList<IFuelPriceReading>>> requestCompleted, object userToken, object src)
  3840. {
  3841. try
  3842. {
  3843. // create XML ServiceRequest object
  3844. DebugLog("Request all prices from Fusion");
  3845. var sr = new ServiceRequestGetFuelPrices();
  3846. sr.ApplicationSender = this.clientSocket.applicationSender;
  3847. sr.WorkstationID = this.clientSocket.workstationID;
  3848. var posDataElem = new ServiceRequestPOSdataGetFuelPrices();
  3849. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3850. var product = new ServiceRequestProductGetFuelPrices();
  3851. product.ProductNo = "*";
  3852. var products = new ServiceRequestProductGetFuelPrices[] { product };
  3853. posDataElem.Product = products;
  3854. ServiceRequestPOSdataGetFuelPrices[] posDataArray = { posDataElem };
  3855. sr.POSdata = posDataArray;
  3856. EventHandler<AsyncCompletedEventArgs> completed = (sender, e) => requestCompleted(sender, (AsyncCompletedEventArgs<IList<IFuelPriceReading>>)e);
  3857. clientSocket.ifsfMessages.EnqueueMessage(sr, completed, userToken, src, true, 30000);
  3858. }
  3859. catch (Exception ex)
  3860. {
  3861. DebugLog("GetFuelPrices Exception! " + ex);
  3862. }
  3863. }
  3864. private void GetFuelPricesResp(int requestId, string sOverallResult, ServiceResponseGetFuelPrices sr)
  3865. {
  3866. try
  3867. {
  3868. DebugLog("GetFuelPriceResp: init");
  3869. var fuelPriceReadings = new List<IFuelPriceReading>();
  3870. if (sr.FDCdata != null && sr.FDCdata[0].Prices != null && sr.FDCdata[0].Prices.Length > 0)
  3871. {
  3872. DebugLog("GetFuelPriceResp: Prices received from Fusion");
  3873. foreach (var product in sr.FDCdata[0].Prices)
  3874. {
  3875. if (product.FuelPrice != null && product.FuelPrice.Length > 0)
  3876. {
  3877. foreach (var mode in product.FuelPrice)
  3878. {
  3879. int productNo = Convert.ToInt32(product.ProductNo);
  3880. decimal price = FDCConvert.ToDecimal(mode.Price);
  3881. string fuelName = product.ProductName;
  3882. var priceGroup = manager.forecourtControl.ForecourtConfiguration.GetPriceGroup(Convert.ToInt32(mode.ModeNo), FuellingType.OptCardPaid);
  3883. if (string.IsNullOrEmpty(fuelName))
  3884. fuelName = string.Empty;
  3885. DebugLog(string.Format("GetFuelPricesResp: Grade={0}, PriceGroup={1} , Price={2} , FuelName={3}",
  3886. productNo, priceGroup, price, fuelName));
  3887. fuelPriceReadings.Add(new FuelPriceReading(productNo, priceGroup, price, fuelName));
  3888. }
  3889. }
  3890. }
  3891. }
  3892. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString(), (IList<IFuelPriceReading>)fuelPriceReadings);
  3893. DebugLog("GetFuelPricesResp end");
  3894. }
  3895. catch (Exception ex)
  3896. {
  3897. DebugLog("GetFuelPricesResp Exception! " + ex);
  3898. }
  3899. }
  3900. public void ReserveFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3901. {
  3902. try
  3903. {
  3904. // create XML ServiceRequest object
  3905. ServiceRequestReserveFuelPoint sr = new ServiceRequestReserveFuelPoint();
  3906. sr.ApplicationSender = this.clientSocket.applicationSender;
  3907. sr.WorkstationID = this.clientSocket.workstationID;
  3908. ServiceRequestPOSdataReserveFuelPoint posDataElem = new ServiceRequestPOSdataReserveFuelPoint();
  3909. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3910. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3911. deviceClass.DeviceID = Convert.ToString(deviceId);
  3912. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3913. posDataElem.DeviceClass = deviceClass;
  3914. ServiceRequestPOSdataReserveFuelPoint[] posDataArray = { posDataElem };
  3915. sr.POSdata = posDataArray;
  3916. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3917. }
  3918. catch (Exception ex)
  3919. {
  3920. DebugLog("ReserveFuelPoint Exception! " + ex);
  3921. }
  3922. }
  3923. private void ReserveFuelPointResp(int requestId, string sOverallResult, ServiceResponseReserveFuelPoint sr)
  3924. {
  3925. try
  3926. {
  3927. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  3928. DebugLog(string.Format("ReserveFuelPointResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  3929. if ((errorCode == ErrorCode.ERRCD_OK.ToString()) && (sOverallResult == OverallResult.Success.ToString()))
  3930. {
  3931. // Ok so far, but wait for unsolicited FPStateChange before making decision about success.
  3932. DebugLog(string.Format("Waiting for unsolicited FPStateChange, RequestId={0}.", requestId));
  3933. unsolicitedFPStateChangeDictionary[Convert.ToInt16(sr.FDCdata[0].DeviceClass.DeviceID)] = requestId;
  3934. }
  3935. else
  3936. {
  3937. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, false);
  3938. DebugLog("ReserveFuelPointResp end");
  3939. }
  3940. }
  3941. catch (Exception ex)
  3942. {
  3943. DebugLog("ReserveFuelPointResp Exception! " + ex);
  3944. }
  3945. }
  3946. public void FreeFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3947. {
  3948. try
  3949. {
  3950. // create XML ServiceRequest object
  3951. ServiceRequestFreeFuelPoint sr = new ServiceRequestFreeFuelPoint();
  3952. sr.ApplicationSender = this.clientSocket.applicationSender;
  3953. sr.WorkstationID = this.clientSocket.workstationID;
  3954. ServiceRequestPOSdataFreeFuelPoint posDataElem = new ServiceRequestPOSdataFreeFuelPoint();
  3955. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3956. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3957. deviceClass.DeviceID = Convert.ToString(deviceId);
  3958. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint;
  3959. posDataElem.DeviceClass = deviceClass;
  3960. ServiceRequestPOSdataFreeFuelPoint[] posDataArray = { posDataElem };
  3961. sr.POSdata = posDataArray;
  3962. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3963. }
  3964. catch (Exception ex)
  3965. {
  3966. DebugLog("FreeFuelPoint Exception! " + ex);
  3967. }
  3968. }
  3969. public void StartFuelPointTest(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3970. {
  3971. try
  3972. {
  3973. // create XML ServiceRequest object
  3974. ServiceRequestStartFuelPointTest sr = new ServiceRequestStartFuelPointTest();
  3975. sr.ApplicationSender = this.clientSocket.applicationSender;
  3976. sr.WorkstationID = this.clientSocket.workstationID;
  3977. ServiceRequestPOSdataStartFuelPointTest posDataElem = new ServiceRequestPOSdataStartFuelPointTest();
  3978. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  3979. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  3980. deviceClass.DeviceID = Convert.ToString(deviceId);
  3981. deviceClass.Type = DeviceType.DT_FuellingPoint;
  3982. posDataElem.DeviceClass = deviceClass;
  3983. ServiceRequestPOSdataStartFuelPointTest[] posDataArray = { posDataElem };
  3984. sr.POSdata = posDataArray;
  3985. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  3986. }
  3987. catch (Exception ex)
  3988. {
  3989. DebugLog("StartFuelPointTest Exception! " + ex);
  3990. }
  3991. }
  3992. public void EndFuelPointTest(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  3993. {
  3994. try
  3995. {
  3996. // create XML ServiceRequest object
  3997. ServiceRequestEndFuelPointTest sr = new ServiceRequestEndFuelPointTest();
  3998. sr.ApplicationSender = this.clientSocket.applicationSender;
  3999. sr.WorkstationID = this.clientSocket.workstationID;
  4000. ServiceRequestPOSdataEndFuelPointTest posDataElem = new ServiceRequestPOSdataEndFuelPointTest();
  4001. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4002. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  4003. deviceClass.DeviceID = Convert.ToString(deviceId);
  4004. deviceClass.Type = DeviceType.DT_FuellingPoint;
  4005. posDataElem.DeviceClass = deviceClass;
  4006. ServiceRequestPOSdataEndFuelPointTest[] posDataArray = { posDataElem };
  4007. sr.POSdata = posDataArray;
  4008. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4009. }
  4010. catch (Exception ex)
  4011. {
  4012. DebugLog("EndFuelPointTest Exception! " + ex);
  4013. }
  4014. }
  4015. public void OpenFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4016. {
  4017. try
  4018. {
  4019. // create XML ServiceRequest object
  4020. ServiceRequestOpenFuelPoint sr = new ServiceRequestOpenFuelPoint();
  4021. sr.ApplicationSender = this.clientSocket.applicationSender;
  4022. sr.WorkstationID = this.clientSocket.workstationID;
  4023. ServiceRequestPOSdataOpenFuelPoint posDataElem = new ServiceRequestPOSdataOpenFuelPoint();
  4024. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4025. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  4026. deviceClass.DeviceID = Convert.ToString(deviceId);
  4027. deviceClass.Type = DeviceType.DT_FuellingPoint;
  4028. posDataElem.DeviceClass = deviceClass;
  4029. ServiceRequestPOSdataOpenFuelPoint[] posDataArray = { posDataElem };
  4030. sr.POSdata = posDataArray;
  4031. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4032. }
  4033. catch (Exception ex)
  4034. {
  4035. DebugLog("OpenFuelPoint Exception! " + ex);
  4036. }
  4037. }
  4038. public void OpenDevice(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4039. {
  4040. try
  4041. {
  4042. // create XML ServiceRequest object
  4043. ServiceRequestOpenDevice sr = new ServiceRequestOpenDevice();
  4044. sr.ApplicationSender = this.clientSocket.applicationSender;
  4045. sr.WorkstationID = this.clientSocket.workstationID;
  4046. ServiceRequestPOSdataOpenFuelPoint posDataElem = new ServiceRequestPOSdataOpenFuelPoint();
  4047. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4048. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  4049. deviceClass.DeviceID = Convert.ToString(deviceId);
  4050. deviceClass.Type = DeviceType.DT_FuellingPoint;
  4051. posDataElem.DeviceClass = deviceClass;
  4052. ServiceRequestPOSdataOpenFuelPoint[] posDataArray = { posDataElem };
  4053. sr.POSdata = posDataArray;
  4054. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4055. }
  4056. catch (Exception ex)
  4057. {
  4058. DebugLog("Exception! " + ex);
  4059. }
  4060. }
  4061. public void CloseFuelPoint(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4062. {
  4063. try
  4064. {
  4065. // create XML ServiceRequest object
  4066. ServiceRequestCloseFuelPoint sr = new ServiceRequestCloseFuelPoint();
  4067. sr.ApplicationSender = this.clientSocket.applicationSender;
  4068. sr.WorkstationID = this.clientSocket.workstationID;
  4069. ServiceRequestPOSdataCloseFuelPoint posDataElem = new ServiceRequestPOSdataCloseFuelPoint();
  4070. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4071. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  4072. deviceClass.DeviceID = Convert.ToString(deviceId);
  4073. deviceClass.Type = Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint;
  4074. posDataElem.DeviceClass = deviceClass;
  4075. ServiceRequestPOSdataCloseFuelPoint[] posDataArray = { posDataElem };
  4076. sr.POSdata = posDataArray;
  4077. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4078. }
  4079. catch (Exception ex)
  4080. {
  4081. DebugLog("CloseFuelPoint Exception! " + ex);
  4082. }
  4083. }
  4084. public void CloseDevice(int deviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4085. {
  4086. try
  4087. {
  4088. // create XML ServiceRequest object
  4089. ServiceRequestCloseDevice sr = new ServiceRequestCloseDevice();
  4090. sr.ApplicationSender = this.clientSocket.applicationSender;
  4091. sr.WorkstationID = this.clientSocket.workstationID;
  4092. ServiceRequestPOSdataCloseFuelPoint posDataElem = new ServiceRequestPOSdataCloseFuelPoint();
  4093. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4094. ServiceRequestDeviceClass deviceClass = new ServiceRequestDeviceClass();
  4095. deviceClass.DeviceID = Convert.ToString(deviceId);
  4096. deviceClass.Type = DeviceType.DT_FuellingPoint;
  4097. posDataElem.DeviceClass = deviceClass;
  4098. ServiceRequestPOSdataCloseFuelPoint[] posDataArray = { posDataElem };
  4099. sr.POSdata = posDataArray;
  4100. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4101. }
  4102. catch (Exception ex)
  4103. {
  4104. DebugLog("CloseDevice Exception! " + ex);
  4105. }
  4106. }
  4107. public void SetDeviceAlarm(string deviceType, int deviceId, IEnumerable<int> alarmCodes, IEnumerable<string> alarmMsgs, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4108. {
  4109. try
  4110. {
  4111. var alarms = new List<ServiceRequestDeviceAlarmMsg>();
  4112. if (alarmCodes != null && alarmMsgs != null)
  4113. {
  4114. if (alarmCodes.Count() == alarmMsgs.Count())
  4115. {
  4116. for (int i = 0; i < alarmCodes.Count(); i++)
  4117. {
  4118. var alarmElem = new ServiceRequestDeviceAlarmMsg
  4119. {
  4120. Number = Convert.ToString(alarmCodes.ElementAt(i)),
  4121. Text = alarmMsgs.ElementAt(i)
  4122. };
  4123. alarms.Add(alarmElem);
  4124. }
  4125. }
  4126. else
  4127. {
  4128. foreach (var alarmCode in alarmCodes)
  4129. {
  4130. var alarmElem = new ServiceRequestDeviceAlarmMsg
  4131. {
  4132. Number = Convert.ToString(alarmCode),
  4133. Text = alarmMsgs.First()
  4134. };
  4135. alarms.Add(alarmElem);
  4136. }
  4137. }
  4138. }
  4139. var deviceClass = new ServiceRequestDeviceClassSetDeviceAlarm
  4140. {
  4141. DeviceID = Convert.ToString(deviceId),
  4142. Type = deviceType,
  4143. AlarmMsg = alarms.ToArray()
  4144. };
  4145. var posDataElem = new ServiceRequestPOSdataSetDeviceAlarm
  4146. {
  4147. POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat),
  4148. DeviceClass = deviceClass
  4149. };
  4150. // create XML ServiceRequest object
  4151. var sr = new ServiceRequestSetDeviceAlarm
  4152. {
  4153. ApplicationSender = this.clientSocket.applicationSender,
  4154. WorkstationID = this.clientSocket.workstationID,
  4155. POSdata = new[] { posDataElem }
  4156. };
  4157. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4158. }
  4159. catch (Exception ex)
  4160. {
  4161. DebugLog("SetDeviceAlarm Exception! " + ex);
  4162. }
  4163. }
  4164. public void SetDeviceAlarm(string deviceType, int deviceId, int alarmCode, string alarmMsg, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4165. {
  4166. SetDeviceAlarm(deviceType, deviceId, new[] { alarmCode }, new[] { alarmMsg }, requestCompleted, userToken, src);
  4167. }
  4168. private void FreeFuelPointResp(int requestId, string sOverallResult, ServiceResponseFreeFuelPoint sr)
  4169. {
  4170. try
  4171. {
  4172. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  4173. DebugLog(string.Format("FreeFuelPointResp type={0}, id={1}, errorCode={2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  4174. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4175. }
  4176. catch (Exception ex)
  4177. {
  4178. DebugLog("FreeFuelPointResp Exception! " + ex);
  4179. }
  4180. }
  4181. private void StartFuelPointTestResp(int requestId, string sOverallResult, ServiceResponseStartFuelPointTest sr)
  4182. {
  4183. try
  4184. {
  4185. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  4186. DebugLog(string.Format("StartFuelPointTestResp type={0}, id={1}, errorCode{2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  4187. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4188. DebugLog("StartFuelPointTestResp end");
  4189. }
  4190. catch (Exception ex)
  4191. {
  4192. DebugLog("StartFuelPointTestResp Exception! " + ex);
  4193. }
  4194. }
  4195. private void EndFuelPointTestResp(int requestId, string sOverallResult, ServiceResponseEndFuelPointTest sr)
  4196. {
  4197. try
  4198. {
  4199. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass.ErrorCode;
  4200. DebugLog(string.Format("EndFuelPointTestResp type={0}, id={1}, errorCode{2}", sr.FDCdata[0].DeviceClass.Type, sr.FDCdata[0].DeviceClass.DeviceID, errorCode));
  4201. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4202. DebugLog("EndFuelPointTestResp end");
  4203. }
  4204. catch (Exception ex)
  4205. {
  4206. DebugLog("EndFuelPointTestResp Exception! " + ex);
  4207. }
  4208. }
  4209. private void OpenFuelPointResp(int requestId, string sOverallResult, ServiceResponseOpenFuelPoint sr)
  4210. {
  4211. try
  4212. {
  4213. string errorCode = sr.FDCdata[0].FDCStatus;
  4214. DebugLog(string.Format("OpenFuelPointResp requestId={0}, errorCode={1}", requestId, errorCode));
  4215. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4216. DebugLog("OpenFuelPointResp end");
  4217. }
  4218. catch (Exception ex)
  4219. {
  4220. DebugLog("OpenFuelPointResp Exception! " + ex);
  4221. }
  4222. }
  4223. private void CloseFuelPointResp(int requestId, string sOverallResult, ServiceResponseCloseFuelPoint sr)
  4224. {
  4225. try
  4226. {
  4227. string errorCode = sr.FDCdata[0].FDCStatus;
  4228. DebugLog(string.Format("CloseFuelPointResp requestId={0}, errorCode={1}", requestId, errorCode));
  4229. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4230. DebugLog("CloseFuelPointResp end");
  4231. }
  4232. catch (Exception ex)
  4233. {
  4234. DebugLog("CloseFuelPointResp Exception! " + ex);
  4235. }
  4236. }
  4237. private void OpenDeviceResp(int requestId, string sOverallResult, ServiceResponseOpenDevice sr)
  4238. {
  4239. try
  4240. {
  4241. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  4242. DebugLog(string.Format("OpenDeviceResp requestId={0}, errorCode={1}", requestId, errorCode));
  4243. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4244. DebugLog("OpenDeviceResp end");
  4245. }
  4246. catch (Exception ex)
  4247. {
  4248. DebugLog("OpenDeviceResp Exception! " + ex);
  4249. }
  4250. }
  4251. private void CloseDeviceResp(int requestId, string sOverallResult, ServiceResponseCloseDevice sr)
  4252. {
  4253. try
  4254. {
  4255. string errorCode = sr.FDCdata[0].FDCStatus ?? sr.FDCdata[0].DeviceClass[0].ErrorCode;
  4256. DebugLog(string.Format("CloseDeviceResp requestId={0}, errorCode={1}", requestId, errorCode));
  4257. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4258. DebugLog("CloseDeviceResp end");
  4259. }
  4260. catch (Exception ex)
  4261. {
  4262. DebugLog("CloseDeviceResp Exception! " + ex);
  4263. }
  4264. }
  4265. private void SetDeviceAlarmResp(int requestId, string sOverallResult, ServiceResponseSetDeviceAlarm sr)
  4266. {
  4267. try
  4268. {
  4269. string errorCode = sr.FDCdata[0].FDCStatus;
  4270. DebugLog(string.Format("SetDeviceAlarmResp requestId={0}, errorCode={1}", requestId, errorCode));
  4271. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString() && sOverallResult == OverallResult.Success.ToString());
  4272. DebugLog("SetDeviceAlarmResp end");
  4273. }
  4274. catch (Exception ex)
  4275. {
  4276. DebugLog("SetDeviceAlarmResp Exception! " + ex);
  4277. }
  4278. }
  4279. public void OptAddSerialPort(int optId, string port, int baudRate, int dataBit, int stopBit, int parity, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4280. {
  4281. try
  4282. {
  4283. DebugLog(string.Format("OptAddSerialPort init: tp={0}, port={1}", optId, port));
  4284. // create XML ServiceRequest object
  4285. ServiceRequestOPTAdd sr = new ServiceRequestOPTAdd();
  4286. sr.ApplicationSender = this.clientSocket.applicationSender;
  4287. sr.WorkstationID = this.clientSocket.workstationID;
  4288. ServiceRequestPOSdataOPTAdd posDataElem = new ServiceRequestPOSdataOPTAdd();
  4289. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4290. ServiceRequestDeviceClassOPTAdd optadd = new ServiceRequestDeviceClassOPTAdd();
  4291. optadd.DeviceID = (optId == -1) ? "*" : Convert.ToString(optId);
  4292. optadd.Type = DeviceType.DT_OutdoorPaymentTerminal;
  4293. ServiceRequestDeviceClassSerialPortOPTAdd serialPort = new ServiceRequestDeviceClassSerialPortOPTAdd();
  4294. serialPort.Port = port;
  4295. serialPort.BaudRate = Convert.ToString(baudRate);
  4296. serialPort.DataBit = Convert.ToString(dataBit);
  4297. serialPort.StopBit = Convert.ToString(stopBit);
  4298. serialPort.Parity = Convert.ToString(parity);
  4299. optadd.serialPort = serialPort;
  4300. posDataElem.DeviceClass = optadd;
  4301. ServiceRequestPOSdataOPTAdd[] posDataArray = { posDataElem };
  4302. sr.POSdata = posDataArray;
  4303. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4304. DebugLog(string.Format("OptAddSerialPort end: tp={0}, port={1}", optId, port));
  4305. }
  4306. catch (Exception ex)
  4307. {
  4308. DebugLog("OptAddSerialPort Exception! " + ex);
  4309. }
  4310. }
  4311. public void OptAddTCP(int optId, string address, int port, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4312. {
  4313. try
  4314. {
  4315. // create XML ServiceRequest object
  4316. ServiceRequestOPTAdd sr = new ServiceRequestOPTAdd();
  4317. sr.ApplicationSender = this.clientSocket.applicationSender;
  4318. sr.WorkstationID = this.clientSocket.workstationID;
  4319. ServiceRequestPOSdataOPTAdd posDataElem = new ServiceRequestPOSdataOPTAdd();
  4320. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4321. ServiceRequestDeviceClassOPTAdd optadd = new ServiceRequestDeviceClassOPTAdd();
  4322. optadd.DeviceID = (optId == -1) ? "*" : Convert.ToString(optId);
  4323. optadd.Type = Wayne.FDCPOSLibrary.DeviceType.DT_OutdoorPaymentTerminal;
  4324. ServiceRequestDeviceClassTCPOPTAdd tcp = new ServiceRequestDeviceClassTCPOPTAdd();
  4325. tcp.Address = address;
  4326. tcp.Port = Convert.ToString(port);
  4327. optadd.tcp = tcp;
  4328. posDataElem.DeviceClass = optadd;
  4329. ServiceRequestPOSdataOPTAdd[] posDataArray = { posDataElem };
  4330. sr.POSdata = posDataArray;
  4331. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4332. }
  4333. catch (Exception ex)
  4334. {
  4335. DebugLog("OptAddTCP Exception! " + ex);
  4336. }
  4337. }
  4338. private void OptAddResp(int requestId, string sOverallResult, ServiceResponseOPTAdd sr)
  4339. {
  4340. try
  4341. {
  4342. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  4343. }
  4344. catch (Exception ex)
  4345. {
  4346. DebugLog("OptAddResp Exception! " + ex);
  4347. }
  4348. }
  4349. public void OptRemove(int optId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, object src)
  4350. {
  4351. try
  4352. {
  4353. // create XML ServiceRequest object
  4354. ServiceRequestOPTRemove sr = new ServiceRequestOPTRemove();
  4355. sr.ApplicationSender = this.clientSocket.applicationSender;
  4356. sr.WorkstationID = this.clientSocket.workstationID;
  4357. ServiceRequestPOSdataOPTRemove posDataElem = new ServiceRequestPOSdataOPTRemove();
  4358. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4359. ServiceRequestDeviceClassOPTRemove optRemove = new ServiceRequestDeviceClassOPTRemove();
  4360. optRemove.DeviceID = (optId == -1) ? "*" : Convert.ToString(optId);
  4361. optRemove.Type = DeviceType.DT_OutdoorPaymentTerminal;
  4362. posDataElem.DeviceClass = optRemove;
  4363. ServiceRequestPOSdataOPTRemove[] posDataArray = { posDataElem };
  4364. sr.POSdata = posDataArray;
  4365. clientSocket.ifsfMessages.EnqueueMessage(sr, requestCompleted, userToken, src, true, 30000);
  4366. }
  4367. catch (Exception ex)
  4368. {
  4369. DebugLog("OptRemove Exception! " + ex);
  4370. }
  4371. }
  4372. private void OptRemoveResp(int requestId, string sOverallResult, ServiceResponseOPTRemove sr)
  4373. {
  4374. try
  4375. {
  4376. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  4377. }
  4378. catch (Exception ex)
  4379. {
  4380. DebugLog("OptRemoveResp Exception! " + ex);
  4381. }
  4382. }
  4383. public void OptWrite(int optId, byte[] message, EventHandler<OptWriteCompletedEventArgs> requestCompleted, object userToken, object src)
  4384. {
  4385. try
  4386. {
  4387. // create XML ServiceRequest object
  4388. if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
  4389. {
  4390. ServiceRequestOPTWriteV07 sr = new ServiceRequestOPTWriteV07();
  4391. sr.ApplicationSender = this.clientSocket.applicationSender;
  4392. sr.WorkstationID = this.clientSocket.workstationID;
  4393. ServiceRequestPOSdataOPTWriteV07 posDataElem = new ServiceRequestPOSdataOPTWriteV07();
  4394. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4395. ServiceRequestDeviceClassOPTWriteV07 optwrite = new ServiceRequestDeviceClassOPTWriteV07();
  4396. optwrite.DeviceID = (optId == -1) ? "*" : Convert.ToString(optId);
  4397. optwrite.Type = DeviceType.DT_OutdoorPaymentTerminal;
  4398. optwrite.Message = message;
  4399. posDataElem.DeviceClass = optwrite;
  4400. ServiceRequestPOSdataOPTWriteV07[] posDataArray = { posDataElem };
  4401. sr.POSdata = posDataArray;
  4402. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (OptWriteCompletedEventArgs)e);
  4403. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  4404. }
  4405. else
  4406. {
  4407. ServiceRequestOPTWrite sr = new ServiceRequestOPTWrite();
  4408. sr.ApplicationSender = this.clientSocket.applicationSender;
  4409. sr.WorkstationID = this.clientSocket.workstationID;
  4410. ServiceRequestPOSdataOPTWrite posDataElem = new ServiceRequestPOSdataOPTWrite();
  4411. posDataElem.POSTimeStamp = DateTime.Now.ToString(FDCConvert.DateFormat);
  4412. ServiceRequestDeviceClassOPTWrite optwrite = new ServiceRequestDeviceClassOPTWrite();
  4413. optwrite.DeviceID = (optId == -1) ? "*" : Convert.ToString(optId);
  4414. optwrite.Type = DeviceType.DT_OutdoorPaymentTerminal;
  4415. optwrite.Message = Encoding.UTF8.GetString(message, 0, message.GetLength(0)); ;
  4416. posDataElem.DeviceClass = optwrite;
  4417. ServiceRequestPOSdataOPTWrite[] posDataArray = { posDataElem };
  4418. sr.POSdata = posDataArray;
  4419. EventHandler<AsyncCompletedEventArgs> proxy = (sender, e) => requestCompleted(sender, (OptWriteCompletedEventArgs)e);
  4420. clientSocket.ifsfMessages.EnqueueMessage(sr, proxy, userToken, src, true, 30000);
  4421. }
  4422. }
  4423. catch (Exception ex)
  4424. {
  4425. DebugLog("OptWrite Exception! " + ex);
  4426. }
  4427. }
  4428. private void OptWriteResp(int requestId, string sOverallResult, ServiceResponseOPTWrite sr)
  4429. {
  4430. try
  4431. {
  4432. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, sOverallResult == OverallResult.Success.ToString());
  4433. }
  4434. catch (Exception ex)
  4435. {
  4436. DebugLog("OptWriteResp Exception! " + ex);
  4437. }
  4438. }
  4439. private void HeartbeatMsg()
  4440. {
  4441. try
  4442. {
  4443. // when the heartbeat is received the disconnection timer is reset (the timer that is activated when the heartbeat is no more received)
  4444. DebugLog("Heartbeat message received");
  4445. heartbeat.ResetDisconnectionTimeout();
  4446. }
  4447. catch (Exception ex)
  4448. {
  4449. DebugLog("HeartbeatMsg Exception! " + ex);
  4450. }
  4451. }
  4452. private void DeviceStateChangeMsg(FDCMessageDeviceStateChange msg)
  4453. {
  4454. try
  4455. {
  4456. DebugLog(string.Format("DeviceStateChangeMsg init: type={0}, id={1}, state={2}, substate={3}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, msg.FDCdata[0].DeviceClass[0].LogicalState, msg.FDCdata[0].DeviceClass[0].LogicalSubState));
  4457. if (OnDeviceStateChange != null)
  4458. {
  4459. string deviceType = msg.FDCdata[0].DeviceClass[0].Type;
  4460. int deviceId = Convert.ToInt16(msg.FDCdata[0].DeviceClass[0].DeviceID);
  4461. LogicalDeviceState state = convertLogicalDeviceState(msg.FDCdata[0].DeviceClass[0].LogicalState);
  4462. LogicalDeviceState substate = convertLogicalDeviceState(msg.FDCdata[0].DeviceClass[0].LogicalSubState);
  4463. int nozzleUp = 0;
  4464. if (msg.FDCdata[0].DeviceClass[0].Nozzle != null)
  4465. {
  4466. foreach (NozzleStateClass nozzleState in msg.FDCdata[0].DeviceClass[0].Nozzle)
  4467. {
  4468. if (nozzleState.LogicalNozzle == "NozzleUp")
  4469. nozzleUp = Convert.ToInt32(nozzleState.NozzleNo);
  4470. }
  4471. }
  4472. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, substate, "", nozzleUp));
  4473. }
  4474. DebugLog("DeviceStateChangeMsg end");
  4475. }
  4476. catch (Exception ex)
  4477. {
  4478. DebugLog("DeviceStateChangeMsg Exception! " + ex);
  4479. }
  4480. }
  4481. private void FPStateChangeMsg(FDCMessageFPStateChange msg)
  4482. {
  4483. try
  4484. {
  4485. DebugLog(string.Format("FPStateChangeMsg: type={0}, id={1}, state={2}, substate={3}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, msg.FDCdata[0].DeviceClass[0].DeviceState, msg.FDCdata[0].DeviceClass[0].DeviceSubState));
  4486. int deviceId = Convert.ToInt16(msg.FDCdata[0].DeviceClass[0].DeviceID);
  4487. int requestId;
  4488. if (unsolicitedFPStateChangeDictionary.TryGetValue(deviceId, out requestId)) // Waiting for unsolicited FPStateChange?
  4489. {
  4490. string errorCode = msg.FDCdata[0].DeviceClass[0].ErrorCode;
  4491. DebugLog(string.Format("Got unsolicited FPStateChange mapped to RequestId={0}, ErrorCode={1}", requestId, errorCode));
  4492. clientSocket.ifsfMessages.asyncResponseManager.SendResponse(requestId, errorCode == ErrorCode.ERRCD_OK.ToString());
  4493. unsolicitedFPStateChangeDictionary.Remove(deviceId);
  4494. }
  4495. if (OnDeviceStateChange != null)
  4496. {
  4497. string deviceType = msg.FDCdata[0].DeviceClass[0].Type;
  4498. LogicalDeviceState state = convertLogicalDeviceState(msg.FDCdata[0].DeviceClass[0].DeviceState.DeviceState);
  4499. LogicalDeviceState substate = convertLogicalDeviceState(msg.FDCdata[0].DeviceClass[0].DeviceSubState);
  4500. if (!string.IsNullOrEmpty(msg.FDCdata[0].DeviceClass[0].DeviceState.Stopped) && XmlConvert.ToBoolean(msg.FDCdata[0].DeviceClass[0].DeviceState.Stopped))
  4501. substate = LogicalDeviceState.FDC_STOPPED;
  4502. string lockingAS = msg.FDCdata[0].DeviceClass[0].LockingApplicationSender;
  4503. int nozzleUp = 0;
  4504. if (msg.FDCdata[0].DeviceClass[0].Nozzle != null)
  4505. {
  4506. foreach (NozzleStateClass nozzleState in msg.FDCdata[0].DeviceClass[0].Nozzle)
  4507. {
  4508. if (nozzleState.LogicalNozzle == "NozzleUp")
  4509. nozzleUp = Convert.ToInt32(nozzleState.NozzleNo);
  4510. }
  4511. }
  4512. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, substate, lockingAS, nozzleUp));
  4513. }
  4514. DebugLog("FPStateChangeMsg end");
  4515. }
  4516. catch (Exception ex)
  4517. {
  4518. DebugLog("FPStateChangeMsg Exception! " + ex);
  4519. }
  4520. }
  4521. private void TPStateChangeMsg(FDCMessageTPStateChange msg)
  4522. {
  4523. try
  4524. {
  4525. DebugLog(string.Format("TPStateChangeMsg init: type={0}, id={1}, state={2}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, msg.FDCdata[0].DeviceClass[0].DeviceState));
  4526. if (OnDeviceStateChange != null)
  4527. {
  4528. string deviceType = msg.FDCdata[0].DeviceClass[0].Type;
  4529. int deviceId = Convert.ToInt16(msg.FDCdata[0].DeviceClass[0].DeviceID);
  4530. LogicalDeviceState state = convertLogicalDeviceState(msg.FDCdata[0].DeviceClass[0].DeviceState.DeviceState);
  4531. OnDeviceStateChange.Invoke(this, new DeviceStateChangedEventArgs(deviceType, deviceId, state, LogicalDeviceState.FDC_UNDEFINED, "", 0));
  4532. }
  4533. DebugLog("TPStateChangeMsg end");
  4534. }
  4535. catch (Exception ex)
  4536. {
  4537. DebugLog("TPStateChangeMsg Exception! " + ex);
  4538. }
  4539. }
  4540. private void VIRStateChangeMsg(FDCMessageVIRStateChange msg)
  4541. {
  4542. try
  4543. {
  4544. DebugLog(string.Format("VIRStateChangeMsg init: type={0}, id={1}, state={2}, substate={3}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, msg.FDCdata[0].DeviceClass[0].DeviceState, msg.FDCdata[0].DeviceClass[0].DeviceSubState));
  4545. if (OnVirStateChange != null)
  4546. {
  4547. int deviceId = Convert.ToInt16(msg.FDCdata[0].DeviceClass[0].DeviceID);
  4548. if (msg.FDCdata[0].DeviceClass[0].Vir != null)
  4549. {
  4550. foreach (VIRStateClass virState in msg.FDCdata[0].DeviceClass[0].Vir)
  4551. {
  4552. var state = convertLogicalDeviceState(virState.DeviceState);
  4553. DeviceConnectionState deviceState;
  4554. if (state == LogicalDeviceState.FDC_READY)
  4555. deviceState = DeviceConnectionState.Connected;
  4556. else if (state == LogicalDeviceState.FDC_OFFLINE)
  4557. deviceState = DeviceConnectionState.Disconnected;
  4558. else
  4559. deviceState = DeviceConnectionState.Unknown;
  4560. DebugLog(string.Format("VIRStateChangeMsg: type={0}, id={1}, virID={2}, virstate={3}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, virState.VirID, virState.DeviceState));
  4561. OnVirStateChange(this, new VIRStateChangedEventArgs(deviceId, virState.VirID, deviceState));
  4562. }
  4563. }
  4564. }
  4565. else
  4566. DebugLog("OnVirStateChange == null");
  4567. DebugLog("VIRStateChangeMsg end");
  4568. }
  4569. catch (Exception ex)
  4570. {
  4571. DebugLog("VIRStateChangeMsg Exception! " + ex);
  4572. }
  4573. }
  4574. private void FDCStoppedMsg(FDCMessageStopped msg)
  4575. {
  4576. try
  4577. {
  4578. DebugLog("FDCStoppedMsg init");
  4579. this.clientSocket.mainConnectionState = DeviceConnectionState.Connecting;
  4580. DebugLog("FDCStoppedMsg end");
  4581. }
  4582. catch (Exception ex)
  4583. {
  4584. DebugLog("FDCStoppedMsg Exception! " + ex);
  4585. }
  4586. }
  4587. private void FDCStartedMsg(FDCMessageStarted msg)
  4588. {
  4589. try
  4590. {
  4591. DebugLog("FDCStartedMsg init");
  4592. DebugLog("FDCStartedMsg end");
  4593. }
  4594. catch (Exception ex)
  4595. {
  4596. DebugLog("FDCStartedMsg Exception! " + ex);
  4597. }
  4598. }
  4599. private void TwinMasterReadyMsg(FDCMessageTwinMasterIsOn msg)
  4600. {
  4601. try
  4602. {
  4603. DebugLog("TwinMasterReadyMsg init");
  4604. if (OnTwinMasterReady != null)
  4605. OnTwinMasterReady(this, null);
  4606. DebugLog("TwinMasterReadyMsg end");
  4607. }
  4608. catch (Exception ex)
  4609. {
  4610. DebugLog("TwinMasterReadyMsg Exception! " + ex);
  4611. }
  4612. }
  4613. private void CurrentFuellingStatusMsg(FDCMessageCurrentFuellingStatus msg)
  4614. {
  4615. try
  4616. {
  4617. DebugLog(string.Format("CurrentFuellingStatusMsg init: type={0}, id={1}, volume={2}, amount={3}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID, msg.FDCdata[0].DeviceClass[0].CurrentVolume, msg.FDCdata[0].DeviceClass[0].CurrentAmount));
  4618. if (OnCurrentFuellingStatus != null)
  4619. {
  4620. var deviceClass = msg.FDCdata[0].DeviceClass[0];
  4621. string deviceType = deviceClass.Type;
  4622. int deviceId = Convert.ToInt16(deviceClass.DeviceID);
  4623. int nozzleId;
  4624. nozzleId = Convert.ToInt16(deviceClass.CurrentNozzleNo);
  4625. if (nozzleId == 0)
  4626. nozzleId = Convert.ToInt16(deviceClass.NozzleNo);
  4627. Decimal volume;
  4628. volume = FDCConvert.ToDecimal(deviceClass.CurrentVolume);
  4629. if (volume == 0)
  4630. volume = FDCConvert.ToDecimal(deviceClass.Volume);
  4631. Decimal amount;
  4632. amount = FDCConvert.ToDecimal(deviceClass.CurrentAmount);
  4633. if (amount == 0)
  4634. amount = FDCConvert.ToDecimal(deviceClass.Amount);
  4635. Decimal price;
  4636. price = FDCConvert.ToDecimal(deviceClass.CurrentUnitPrice);
  4637. if (price == 0)
  4638. price = FDCConvert.ToDecimal(deviceClass.UnitPrice);
  4639. int releaseId;
  4640. int reservingDeviceId;
  4641. try
  4642. {
  4643. var token = AuthReleaseTokenFactory.GenerateToken(deviceClass.ReleaseToken);
  4644. releaseId = token.AuthorizationId;
  4645. reservingDeviceId = token.TerminalId;
  4646. }
  4647. catch
  4648. {
  4649. releaseId = 0;
  4650. reservingDeviceId = 0;
  4651. }
  4652. var eventArgs = new CurrentFuellingStatusEventArgs(deviceType, deviceId, nozzleId, volume, amount,
  4653. price, "")
  4654. {
  4655. ReleaseId = releaseId,
  4656. ReservingDeviceId = reservingDeviceId,
  4657. TransactionId = Convert.ToInt32(deviceClass.TransactionSeqNo),
  4658. FuelPeriodSequenceNo = Convert.ToInt32(deviceClass.FuelPeriodSequenceNo)
  4659. };
  4660. OnCurrentFuellingStatus(this, eventArgs);
  4661. }
  4662. DebugLog("CurrentFuellingStatusMsg end");
  4663. }
  4664. catch (Exception ex)
  4665. {
  4666. DebugLog("CurrentFuellingStatusMsg Exception! " + ex);
  4667. }
  4668. }
  4669. private void DeviceAlarmMsg(FDCMessageDeviceAlarm msg)
  4670. {
  4671. try
  4672. {
  4673. DebugLog(string.Format("DeviceAlarmMsg init: type={0}, id={1}", msg.FDCdata[0].DeviceClass[0].Type, msg.FDCdata[0].DeviceClass[0].DeviceID));
  4674. foreach (FDCMessageDeviceAlarmDeviceClass device in msg.FDCdata[0].DeviceClass)
  4675. {
  4676. var deviceType = device.Type;
  4677. int deviceId = Convert.ToInt16(device.DeviceID);
  4678. if (device.AlarmMsg != null && device.AlarmMsg.Length > 0)
  4679. {
  4680. foreach (FDCMessageDeviceAlarmMsg alarmmsg in device.AlarmMsg)
  4681. {
  4682. if (OnDeviceAlarm != null)
  4683. {
  4684. int alarmId = Convert.ToInt32(alarmmsg.Number);
  4685. OnDeviceAlarm(this, new DeviceAlarmEventArgs(deviceType, deviceId, alarmId, alarmmsg.Text));
  4686. }
  4687. }
  4688. }
  4689. else if (deviceType == "TP") // send empty message for Tank Probe
  4690. {
  4691. if (OnDeviceAlarm != null)
  4692. {
  4693. OnDeviceAlarm(this, new DeviceAlarmEventArgs(deviceType, deviceId, 0, ""));
  4694. }
  4695. }
  4696. }
  4697. DebugLog("DeviceAlarmMsg end");
  4698. }
  4699. catch (Exception ex)
  4700. {
  4701. DebugLog("DeviceAlarmMsg Exception! " + ex);
  4702. }
  4703. }
  4704. private void FuelSaleTrxMsg(FDCMessageFuelSaleTrx msg, string originalMessageXml)
  4705. {
  4706. try
  4707. {
  4708. DebugLog("FuelSaleTrxMsg init");
  4709. if (msg != null && msg.FDCdata != null && msg.FDCdata[0] != null && msg.FDCdata[0].DeviceClass != null)
  4710. {
  4711. FDCMessageDeviceClassFuelSaleTrx deviceClass = msg.FDCdata[0].DeviceClass;
  4712. if (OnFuelSaleTrx != null)
  4713. {
  4714. DebugLog(string.Format("FuelSaleTrxMsg type={0}, id={1}, nozzle={2}, price={3}, amount={4}, vol={5}, authAS={6}, lockAS={7}",
  4715. deviceClass.Type, deviceClass.DeviceID,
  4716. deviceClass.NozzleNo, deviceClass.UnitPrice, deviceClass.Amount, deviceClass.Volume,
  4717. deviceClass.AuthorisationApplicationSender, deviceClass.LockingApplicationSender));
  4718. string deviceType = deviceClass.Type;
  4719. int deviceId = Convert.ToInt16(deviceClass.DeviceID);
  4720. int nozzleId = Convert.ToInt16(deviceClass.NozzleNo);
  4721. Decimal volume = FDCConvert.ToDecimal(deviceClass.Volume);
  4722. Decimal amount = FDCConvert.ToDecimal(deviceClass.Amount);
  4723. Decimal price = FDCConvert.ToDecimal(deviceClass.UnitPrice);
  4724. int transactionSeqNum = Convert.ToInt32(deviceClass.TransactionSeqNo);
  4725. // if fuelling sequence number not available, use transaction sequence number
  4726. int fuellingSeqNum = string.IsNullOrEmpty(deviceClass.FuellingSequenceNo)
  4727. ? transactionSeqNum
  4728. : Convert.ToInt32(deviceClass.FuellingSequenceNo);
  4729. Wayne.FDCPOSLibrary.FuellingState transactionState = convertFuellingState(deviceClass.State);
  4730. int completionReason = string.IsNullOrEmpty(deviceClass.CompletionReason) ? 0 : convertCompletionReason(deviceClass.CompletionReason);
  4731. int fuelMode = (deviceClass.FuelMode != null && deviceClass.FuelMode.ModeNo != null && deviceClass.FuelMode.ModeNo != "") ? Convert.ToInt32(deviceClass.FuelMode.ModeNo) : 0;
  4732. DateTime trxStartDateTime = Convert.ToDateTime(deviceClass.StartTimeStamp);
  4733. DateTime trxEndDateTime = Convert.ToDateTime(deviceClass.EndTimeStamp);
  4734. string authAS = deviceClass.AuthorisationApplicationSender;
  4735. string lockingAS = deviceClass.LockingApplicationSender;
  4736. string DSPFields = deviceClass.DSPFields;
  4737. string CRCMode = deviceClass.CRCMode;
  4738. string MIDLinesNarrow = deviceClass.MIDLinesNarrow;
  4739. string MIDLinesWide = deviceClass.MIDLinesWide;
  4740. FuellingType fuellingType = (deviceClass.FuellingType == "") ? FuellingType.Unknown : ((FuellingType)Convert.ToInt16(deviceClass.FuellingType));
  4741. if (fuellingType == FuellingType.Unknown)
  4742. {
  4743. DebugLog("Fuelling of unkown type received. Converting to DetectedFromAccumulators!!!");
  4744. fuellingType = FuellingType.DetectedFromAccumulators;
  4745. }
  4746. int releaseToken;
  4747. try
  4748. {
  4749. IReleaseToken token = AuthReleaseTokenFactory.GenerateToken(deviceClass.ReleaseToken);
  4750. releaseToken = token.AuthorizationId;
  4751. }
  4752. catch
  4753. {
  4754. releaseToken = 0;
  4755. }
  4756. byte reservingDeviceId;
  4757. try
  4758. {
  4759. reservingDeviceId = Convert.ToByte(deviceClass.ReservingDeviceId);
  4760. }
  4761. catch (Exception ex)
  4762. {
  4763. reservingDeviceId = 0;
  4764. DebugLog("FuelSaleTrxMsg Exception! cannot convert ReservingDeviceId to Int32");
  4765. }
  4766. var eventPayload = new FuelSaleTrxEventArgs(
  4767. transactionSeqNum,
  4768. fuellingSeqNum,
  4769. transactionState,
  4770. completionReason,
  4771. deviceType,
  4772. deviceId,
  4773. nozzleId,
  4774. volume,
  4775. amount,
  4776. price,
  4777. fuelMode,
  4778. trxStartDateTime,
  4779. trxEndDateTime,
  4780. lockingAS,
  4781. authAS,
  4782. DSPFields,
  4783. CRCMode,
  4784. MIDLinesNarrow,
  4785. MIDLinesWide,
  4786. releaseToken,
  4787. reservingDeviceId,
  4788. fuellingType,
  4789. originalMessageXml)
  4790. {
  4791. FuelPeriodSequenceNo = Convert.ToInt32(deviceClass.FuelPeriodSequenceNo)
  4792. };
  4793. OnFuelSaleTrx(this, eventPayload);
  4794. }
  4795. else
  4796. DebugLog("FuelSaleTrxMsg OnFuelSaleTrx == null");
  4797. }
  4798. else
  4799. {
  4800. if (msg == null)
  4801. DebugLog("FuelSaleTrxMsg msg == null");
  4802. else if (msg.FDCdata == null)
  4803. DebugLog("FuelSaleTrxMsg msg.FDCdata == null");
  4804. else if (msg.FDCdata[0] == null)
  4805. DebugLog("FuelSaleTrxMsg msg.FDCdata[0] == null");
  4806. else if (msg.FDCdata[0].DeviceClass == null)
  4807. DebugLog("FuelSaleTrxMsg msg.FDCdata[0].DeviceClass == null");
  4808. }
  4809. DebugLog("FuelSaleTrxMsg end");
  4810. }
  4811. catch (Exception ex)
  4812. {
  4813. DebugLog("FuelSaleTrxMsg Exception! " + ex);
  4814. }
  4815. }
  4816. private void FuelPriceChangeMsg(FDCMessageFuelPriceChange msg)
  4817. {
  4818. try
  4819. {
  4820. DebugLog(string.Format("FuelPriceChangeMsg init: product={0}, modeno={1}, newprice={2}, oldprice={3}",
  4821. msg.FDCdata[0].Product[0].ProductNo,
  4822. msg.FDCdata[0].Product[0].FuelMode.ModeNo,
  4823. msg.FDCdata[0].Product[0].FuelMode.NewPrice,
  4824. msg.FDCdata[0].Product[0].FuelMode.OldPrice));
  4825. if (OnChangeFuelPrice != null)
  4826. {
  4827. OnChangeFuelPrice(this, new ChangeFuelPriceEventArgs(Convert.ToInt32(msg.FDCdata[0].Product[0].ProductNo), Convert.ToInt32(msg.FDCdata[0].Product[0].FuelMode.ModeNo),
  4828. FDCConvert.ToDecimal(msg.FDCdata[0].Product[0].FuelMode.OldPrice), FDCConvert.ToDecimal(msg.FDCdata[0].Product[0].FuelMode.NewPrice)));
  4829. }
  4830. DebugLog("FuelPriceChangeMsg end");
  4831. }
  4832. catch (Exception ex)
  4833. {
  4834. DebugLog("FuelPriceChangeMsg Exception! " + ex);
  4835. }
  4836. }
  4837. private void FuelModeChangeMsg(FDCMessageFDCdataFuelModeChange fdcData)
  4838. {
  4839. try
  4840. {
  4841. DebugLog("FuelModeChangeMsg init");
  4842. foreach (FDCMessageDeviceClassFuelModeChange device in fdcData.DeviceClass)
  4843. {
  4844. if (OnFuelModeChange != null)
  4845. {
  4846. string deviceType = fdcData.DeviceClass[0].Type;
  4847. int deviceId = Convert.ToInt16(fdcData.DeviceClass[0].DeviceID);
  4848. int mode;
  4849. if (fdcData.DeviceClass[0].FuelMode.ModeNo != null)
  4850. mode = Convert.ToInt16(fdcData.DeviceClass[0].FuelMode.ModeNo);
  4851. else
  4852. mode = Convert.ToInt16(fdcData.DeviceClass[0].ModeNo);
  4853. OnFuelModeChange(this, new FuelModeChangedEventArgs(deviceType, deviceId, mode));
  4854. }
  4855. if (OnOperationModeChange != null)
  4856. {
  4857. //TODO Why is only first item in array used?
  4858. if (fdcData.DeviceClass[0].FuelMode != null && fdcData.DeviceClass[0].FuelMode.OperationModeSpecified)//TODO Is enough?
  4859. {
  4860. OnOperationModeChange.Fire(this,
  4861. new OperationModeChangedEventArgs(fdcData.DeviceClass[0].Type,
  4862. Convert.ToInt16(fdcData.DeviceClass[0].DeviceID), fdcData.DeviceClass[0].FuelMode.OperationMode));
  4863. }
  4864. }
  4865. }
  4866. DebugLog("FuelModeChangeMsg end");
  4867. }
  4868. catch (Exception ex)
  4869. {
  4870. DebugLog("FuelModeChangeMsg Exception! " + ex);
  4871. }
  4872. }
  4873. private void FDCExceptionMsg(FDCMessageFDCExceptionMsg msg)
  4874. {
  4875. try
  4876. {
  4877. DebugLog("FDCExceptionMsg init");
  4878. DebugLog("FDCExceptionMsg end");
  4879. }
  4880. catch (Exception ex)
  4881. {
  4882. DebugLog("FDCExceptionMsg Exception! " + ex);
  4883. }
  4884. }
  4885. private void FDCMessageConfigurationChangeMsg(FDCMessageConfigurationChange msg)
  4886. {
  4887. try
  4888. {
  4889. DebugLog("FDCMessageConfigurationChangeMsg init");
  4890. OnConfigurationChange.Invoke(this, null);
  4891. DebugLog("FDCMessageConfigurationChangeMsg end");
  4892. }
  4893. catch (Exception ex)
  4894. {
  4895. DebugLog("FDCMessageConfigurationChangeMsg Exception! " + ex);
  4896. }
  4897. }
  4898. private void OptReadMsg(FDCMessageOPTRead msg)
  4899. {
  4900. try
  4901. {
  4902. DebugLog("OptReadMsg init");
  4903. foreach (FDCMessageDeviceClassOPTRead optdata in msg.FDCdata[0].DeviceClass)
  4904. {
  4905. if (OnOptRead != null)
  4906. {
  4907. string deviceType = optdata.Type;
  4908. byte[] databytes = ASCIIEncoding.ASCII.GetBytes(optdata.Message); ;
  4909. DebugLog(string.Format("type={0}, id={1}, msg={2}", optdata.Type, optdata.DeviceID, optdata.Message));
  4910. int deviceId = Convert.ToInt16(optdata.DeviceID);
  4911. OnOptRead(this, new OptReadEventArgs(deviceType, deviceId, databytes));
  4912. }
  4913. }
  4914. DebugLog("OptReadMsg end");
  4915. }
  4916. catch (Exception ex)
  4917. {
  4918. DebugLog("OptReadMsg Exception! " + ex);
  4919. }
  4920. }
  4921. private void OptReadMsg(FDCMessageOPTReadV07 msg)
  4922. {
  4923. try
  4924. {
  4925. DebugLog("OptReadMsg init");
  4926. foreach (FDCMessageDeviceClassOPTReadV07 optdata in msg.FDCdata[0].DeviceClass)
  4927. {
  4928. if (OnOptRead != null)
  4929. {
  4930. string deviceType = optdata.Type;
  4931. ASCIIEncoding encoding = new ASCIIEncoding();
  4932. DebugLog(string.Format("type={0}, id={1}, msg={2}", optdata.Type, optdata.DeviceID, encoding.GetString(optdata.Message, 0, optdata.Message.Length)));
  4933. int deviceId = Convert.ToInt16(optdata.DeviceID);
  4934. byte[] message = optdata.Message;
  4935. OnOptRead(this, new OptReadEventArgs(deviceType, deviceId, message));
  4936. }
  4937. }
  4938. DebugLog("OptReadMsg end");
  4939. }
  4940. catch (Exception ex)
  4941. {
  4942. DebugLog("OptReadMsg Exception! " + ex);
  4943. }
  4944. }
  4945. protected override void DoDispose()
  4946. {
  4947. _heartbeat.Dispose();
  4948. }
  4949. }
  4950. }