12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049 |
- using System;
- using System.Collections.ObjectModel;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Threading;
- using System.IO;
- using Wayne.Lib;
- using Wayne.ForecourtControl.Vir.Fusion;
- #if _SINP
- using Wayne.ForecourtControl.Nfs;
- #endif
- using Wayne.FDCPOSLibrary;
- namespace Wayne.ForecourtControl.Fusion
- {
- public class FUSIONForecourtControl : IForecourtControl, IConnectable, IIdentifiableEntity, IDisposable
- {
- // Fields
- private string clientName;
- private string connectionString;
- private DeviceConnectionState connectionState = DeviceConnectionState.Disconnected;
- private List<IFuelPrice> fuelPriceList = new List<IFuelPrice>();
- private int id;
- private FUSIONManager _manager;
- public FUSIONManager manager
- {
- get { return _manager; }
- }
- private List<IPricePole> pricePoleList = new List<IPricePole>();
- private List<IPump> pumpList = new List<IPump>();
- private List<ITankGroup> tankGroupList = new List<ITankGroup>();
- private int siteMode;
- private bool siteOpened;
- public ServiceRequestChangeFuelMode srChangeMode = null;
- public bool fuelPriceReserved;
- public ConfigurationParams ConfigParam;
- // Events
- public event EventHandler<AlarmEventArgs> OnAlarm;
- public event EventHandler<ConnectionChangedEventArgs> OnConnectionStateChange;
- public event EventHandler<FuelPriceChangeEventArgs> OnFuelPriceChange;
- public event EventHandler<SiteModeChangeEventArgs> OnSiteModeChange;
- #region Methods
- public FUSIONForecourtControl(int deviceId, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
- {
- ConfigParam = new ConfigurationParams();
- this.id = deviceId;
- this._manager = new FUSIONManager(this, managedEntityTypes, managedPumpIds);
- fuelPriceReserved = false;
-
- siteOpened = true;
- }
- public void ActivateFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- Trace.WriteLine(string.Format("ActivateFuelPricesAsync init"));
- int iFuelGrade;
- decimal price;
- ServiceRequestChangeFuelPrice sr = new ServiceRequestChangeFuelPrice();
- foreach (IFuelPrice fuelprice in FuelPrices)
- {
- try
- {
- Monitor.Enter(((FUSIONFuelPrice)fuelprice).locker);
- iFuelGrade = fuelprice.FuelGrade;
- Trace.WriteLine(string.Format("fuelGrade={0}, ((FUSIONFuelPrice)fuelprice).Changed={1}", fuelprice.FuelGrade, ((FUSIONFuelPrice)fuelprice).Changed));
- if (((FUSIONFuelPrice)fuelprice).Changed)
- {
- //for (int mode = ((FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta)).PriceGroupNumbersMin; mode <= ((FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta)).PriceGroupNumbersMax; mode++)
- for (int mode = FUSIONFuelPrice.PriceGroupNumbersMin; mode <= FUSIONFuelPrice.PriceGroupNumbersMax; mode++)
- {
- FUSIONFuelPriceAddPricePerPriceGroup pgd = (FUSIONFuelPriceAddPricePerPriceGroup)(fuelprice.PriceGroupDelta);
- Trace.WriteLine(string.Format("mode = {0}, pgd.getChanged(mode)={1}", mode, pgd.getChanged(mode)));
- if (pgd.getChanged(mode))
- {
- price = fuelprice.BasePrice + fuelprice.GeneralPriceDelta + fuelprice.PriceGroupDelta[mode];
- //this._manager.ifsfManager.ChangeFuelPrice(fuelprice.FuelGrade, price, mode, null, null);
- this._manager.ifsfManager.ChangeFuelPriceAdd(sr, fuelprice.FuelGrade, price, mode);
- }
- }
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- finally
- {
- Monitor.Exit(((FUSIONFuelPrice)fuelprice).locker);
- }
- }
- this._manager.ifsfManager.ChangeFuelPriceSend(sr, null, null, null);
- if (requestCompleted != null)
- requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
- Trace.WriteLine(string.Format("ActivateFuelPricesAsync end"));
- }
- private void ActivateFuelPricesCompleted(object sender, AsyncCompletedEventArgs e)
- {
- /*TODO AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
- if (!(e.UserToken is ushort))
- {
- throw new Exception("UnreserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
- }
- this.manager.ReadFuelPrices();
- foreach (NfsFuelPrice price in this.fuelPriceList)
- {
- price.WritableReserved = false;
- }
- if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
- {
- operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
- }*/
- }
- public void Connect(string connectionString)
- {
- // connection state is set to 'connecting' when the logon is terminated
- bool bNotifyStateChange = false;
- if (this._manager.ifsfManager.clientSocket.ConnectionState != DeviceConnectionState.Disconnected &&
- this._manager.ifsfManager.clientSocket.ConnectionState != DeviceConnectionState.Disconnecting)
- bNotifyStateChange = true;
- //bool res = this.manager.Connect(connectionString);
- this.connectionString = connectionString;
- Thread runConnectThread = new Thread(new ThreadStart(this.ConnectThreadProc));
- runConnectThread.Start();
- //if (bNotifyStateChange && OnConnectionStateChange != null)
- // this.OnConnectionStateChange.Invoke(this, new ConnectionChangedEventArgs(this._manager.ifsfManager.clientSocket.ConnectionState));
- //foreach (FUSIONPump pump in this.Pumps)
- //{
- // this._manager.ifsfManager.GetDeviceState(pump.Id, null, null);
- //}
- }
- private void ConnectThreadProc()
- {
- this.manager.Connect(connectionString);
- }
- public void Disconnect()
- {
- this.WritableConnectionState = DeviceConnectionState.Disconnecting;
- this.manager.Disconnect();
- }
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (disposing)
- {
- this.manager.Dispose();
- }
- }
- ~FUSIONForecourtControl()
- {
- this.Dispose(false);
- }
- internal void FireAlarmEvent(AlarmEventArgs args)
- {
- if (this.OnAlarm != null)
- {
- this.OnAlarm.BeginInvoke(this, args, null, null);
- }
- }
- internal void FireFuelPriceChangeEvent(FuelPriceChangeEventArgs args)
- {
- if (this.OnFuelPriceChange != null)
- {
- this.OnFuelPriceChange.BeginInvoke(this, args, null, null);
- }
- }
- public void ReserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- fuelPriceReserved = true;
- srChangeMode = new ServiceRequestChangeFuelMode();
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
- srChangeMode.RequestType = "ChangeFuelMode";
- else
- srChangeMode.RequestType = "ChangeFPFuelMode";
- foreach (IFuelPrice fuelprice in FuelPrices)
- {
- ((FUSIONFuelPrice)fuelprice).WritableReserved = true;
- }
- if (requestCompleted != null)
- requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
- }
- private void ReserveFuelPricesAsyncCompleted(object sender, AsyncCompletedEventArgs e)
- {
- /*TODO AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
- if (!(e.UserToken is ushort))
- {
- throw new Exception("ReserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
- }
- this.manager.ReadFuelPrices();
- foreach (NfsFuelPrice price in this.fuelPriceList)
- {
- price.WritableReserved = e.Success;
- }
- if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
- {
- operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
- }*/
- }
- public void SetSiteModeAsync(int siteMode, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- //AsyncOperation<ushort> operation = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, requestCompleted, userToken);
- //Function function = new Function(4, new Parameter[] { new PrimitiveParameter(0x66, PrimitiveType.UInt16, operation.Id), new PrimitiveParameter(0x69, PrimitiveType.Byte, siteMode) });
- //this.manager.Send(function);
- if (siteMode == 99)
- {
- //This is only for testing purpose
- TestMessages();
- return;
- }
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
- if (sValue != "")
- {
- Test();
- return;
- }
- }
- public void SetSiteOpenedAsync(bool opened, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
- if (sValue != "")
- {
- Test();
- return;
- }
- if (opened)
- {
- this.manager.ifsfManager.StartForecourt(requestCompleted, userToken, this);
- }
- else
- this.manager.ifsfManager.StopForecourt(requestCompleted, userToken, this);
- }
- public void Test()
- {
- int par1 = -1, par2 = -1;
- int id = -1;
- int trid = -1;
- int nozzleId = -1;
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Operation");
- string[] sElems;
- StreamReader sr = new StreamReader(ConfigurationParams.getSINPPath("ini\\") + sValue);
- while (sr.Peek() != -1)
- {
- sValue = sr.ReadLine();
- sElems = sValue.Split(',');
- try
- {
- if (sElems.GetLength(0) > 1)
- {
- try
- {
- par1 = Convert.ToInt32(sElems[1]);
- }
- catch (Exception ex)
- {
- }
- }
- if (sElems.GetLength(0) > 2)
- {
- try
- {
- par2 = Convert.ToInt32(sElems[2]);
- }
- catch (Exception ex)
- {
- }
- }
- sValue = sElems[0];
- id = par1;
- trid = par2;
- }
- catch (Exception ex)
- {
- }
- if (sValue == "StartFuelPointTest")
- {
- manager.ifsfManager.StartFuelPointTest(id, null, null, null);
- }
- else if (sValue == "EndFuelPointTest")
- {
- this.manager.ifsfManager.EndFuelPointTest(id, null, null, null);
- }
- else if (sValue == "CloseFuelPoint")
- {
- this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
- }
- else if (sValue == "OpenFuelPoint")
- {
- this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
- }
- else if (sValue == "AuthoriseFuelPoint")
- {
- AuthorizeParameters authParams = new AuthorizeParameters();
- authParams.PresetType = PresetType.Amount;
- authParams.PresetValue = 50;
- this.manager.ifsfManager.AuthoriseFuelPoint(id, trid, FuellingType.Unknown, 0, authParams, null, null, null);
- }
- else if (sValue == "SuspendFuelling")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.SuspendAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_SuspendResult), null);
- //this.manager.ifsfManager.SuspendFuelling(id, null, null);
- }
- else if (sValue == "ResumeFuelling")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.ResumeAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ResumeResult), null);
- //this.manager.ifsfManager.ResumeFuelling(id, null, null);
- }
- else if (sValue == "TerminateFuelling")
- {
- this.manager.ifsfManager.TerminateFuelling(id, null, null, null);
- }
- else if (sValue == "LogOff")
- {
- this.manager.ifsfManager.LogOff();
- }
- else if (sValue == "LogOn")
- {
- this.manager.ifsfManager.LogOn("", "");
- }
- else if (sValue == "GetFuelMode")
- {
- this.manager.ifsfManager.GetFuelMode(id, null, null, null);
- }
- else if (sValue == "GetModeTable")
- {
- this.manager.ifsfManager.GetModeTable(null, null, null);
- }
- else if (sValue == "ClearFuelSaleTrx")
- {
- this.manager.ifsfManager.ClearFuelSaleTrx(id, trid, 0, "", null, null, null);
- }
- else if (sValue == "LockFuelSaleTrx")
- {
- this.manager.ifsfManager.LockFuelSaleTrx(id, trid, 0, null, null, null);
- }
- else if (sValue == "UnlockFuelSaleTrx")
- {
- this.manager.ifsfManager.UnlockFuelSaleTrx(id, trid, 0, null, null, null);
- }
- else if (sValue == "getCountrySetting")
- {
- this.manager.ifsfManager.GetCountrySettings(null, null, null);
- }
- else if (sValue == "GetCurrentFuellingStatus")
- {
- this.manager.ifsfManager.GetCurrentFuellingStatus(id, null, null, null);
- }
- else if (sValue == "LockNozzle")
- {
- this.manager.ifsfManager.LockNozzle(id, nozzleId, null, null, null);
- }
- else if (sValue == "UnlockNozzle")
- {
- this.manager.ifsfManager.UnlockNozzle(id, nozzleId, null, null, null);
- }
- else if (sValue == "GetDeviceState")
- {
- this.manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser, id, null, null, null);
- }
- else if (sValue == "GetFuelPointTotals")
- {
- nozzleId = par2;
- this.manager.ifsfManager.GetFuelPointTotals(id, nozzleId, null, null, null);
- }
- else if (sValue == "CloseFuelPoint")
- {
- this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
- }
- else if (sValue == "OpenFuelPoint")
- {
- this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
- }
- else if (sValue == "ReserveFuelPoint")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.ReserveAsync(FuellingType.Unknown, 0, new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ReserveResult), null);
- //this.manager.ifsfManager.ReserveFuelPoint(id, null, null);
- }
- else if (sValue == "FreeFuelPoint")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.UnreserveAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_UnreserveResult), null);
- //this.manager.ifsfManager.FreeFuelPoint(id, null, null);
- }
- else if (sValue == "GetFuelSaleTrxDetails")
- {
- this.manager.ifsfManager.GetFuelSaleTrxDetails(id, trid, 0, null, null, null);
- }
- else if (sValue == "GetAvailableFuelSaleTrxs")
- {
- this.manager.ifsfManager.GetAvailableFuelSaleTrxs(id, null, null, null);
- }
- else if (sValue == "ChangeFuelMode")
- {
- int priceGroup = par2;
- this.manager.ifsfManager.ChangeFuelMode(id, priceGroup, null, null, null);
- }
- else if (sValue == "SendConfig")
- {
- this.manager.ifsfManager.SendConfig(sElems[1], null, null, null);
- }
- else
- {
- }
- }
- sr.Close();
- }
- static private void Test_SuspendResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
- {
- try
- {
- IPump pump = (IPump)completed.UserToken;
- if (pump != null)
- {
- Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
- }
- }
- static private void Test_ResumeResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
- {
- try
- {
- IPump pump = (IPump)completed.UserToken;
- if (pump != null)
- {
- Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
- }
- }
- static private void Test_ReserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
- {
- try
- {
- IPump pump = (IPump)completed.UserToken;
- if (pump != null)
- {
- Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
- }
- }
- static private void Test_UnreserveResult(Object src, Wayne.Lib.AsyncCompletedEventArgs completed)
- {
- try
- {
- IPump pump = (IPump)completed.UserToken;
- if (pump != null)
- {
- Trace.WriteLine(string.Format("pump={0}, result={1}", ((FUSIONPump)(pump)).realId, completed.Success));
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("EXCEPTION! Stack chiamate: {0} Messaggio: {1}", ex.StackTrace, ex.Message));
- }
- }
- private void TestMessages()
- {
- int par1 = -1, par2 = -1, par3 = -1;
- int id = -1;
- int trid = -1;
- int nozzleId = -1;
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Test", "Messages");
- string[] sElems;
- StreamReader sr = new StreamReader(ConfigurationParams.getSINPPath("ini\\") + sValue);
- while (sr.Peek() != -1)
- {
- sValue = sr.ReadLine();
- sElems = sValue.Split(',');
- try
- {
- if (sElems.GetLength(0) > 1)
- {
- try
- {
- par1 = Convert.ToInt32(sElems[1]);
- }
- catch (Exception ex)
- {
- }
- }
- if (sElems.GetLength(0) > 2)
- {
- try
- {
- par2 = Convert.ToInt32(sElems[2]);
- }
- catch (Exception ex)
- {
- }
- }
- if (sElems.GetLength(0) > 3)
- {
- try
- {
- par3 = Convert.ToInt32(sElems[3]);
- }
- catch (Exception ex)
- {
- }
- }
- sValue = sElems[0];
- id = par1;
- trid = par2;
- nozzleId = par3;
- }
- catch (Exception ex)
- {
- }
- if (sValue == "StartFuelPointTest")
- {
- manager.ifsfManager.StartFuelPointTest(id, null, null, null);
- }
- else if (sValue == "EndFuelPointTest")
- {
- this.manager.ifsfManager.EndFuelPointTest(id, null, null, null);
- }
- else if (sValue == "CloseFuelPoint")
- {
- this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
- }
- else if (sValue == "OpenFuelPoint")
- {
- this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
- }
- else if (sValue == "AuthoriseFuelPoint")
- {
- AuthorizeParameters authParams = new AuthorizeParameters();
- authParams.PresetType = PresetType.Amount;
- authParams.PresetValue = 50;
- this.manager.ifsfManager.AuthoriseFuelPoint(id, trid, FuellingType.OptCardPaid, 0, authParams, null, null, null);
- }
- else if (sValue == "SuspendFuelling")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.SuspendAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_SuspendResult), null);
- //this.manager.ifsfManager.SuspendFuelling(id, null, null);
- }
- else if (sValue == "ResumeFuelling")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.ResumeAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ResumeResult), null);
- //this.manager.ifsfManager.ResumeFuelling(id, null, null);
- }
- else if (sValue == "TerminateFuelling")
- {
- this.manager.ifsfManager.TerminateFuelling(id, null, null, null);
- }
- else if (sValue == "LogOff")
- {
- this.manager.ifsfManager.LogOff();
- }
- else if (sValue == "LogOn")
- {
- this.manager.ifsfManager.LogOn("", "");
- }
- else if (sValue == "GetFuelMode")
- {
- this.manager.ifsfManager.GetFuelMode(id, null, null, null);
- }
- else if (sValue == "GetModeTable")
- {
- this.manager.ifsfManager.GetModeTable(null, null, null);
- }
- else if (sValue == "ClearFuelSaleTrx")
- {
- this.manager.ifsfManager.ClearFuelSaleTrx(id, trid, 2, "",null, null, null);
- }
- else if (sValue == "LockFuelSaleTrx")
- {
- this.manager.ifsfManager.LockFuelSaleTrx(id, trid, 2, null, null, null);
- }
- else if (sValue == "UnlockFuelSaleTrx")
- {
- this.manager.ifsfManager.UnlockFuelSaleTrx(id, trid, 2, null, null, null);
- }
- else if (sValue == "GetCountrySettings")
- {
- this.manager.ifsfManager.GetCountrySettings(null, null, null);
- }
- else if (sValue == "GetCurrentFuellingStatus")
- {
- this.manager.ifsfManager.GetCurrentFuellingStatus(id, null, null, null);
- }
- else if (sValue == "LockNozzle")
- {
- this.manager.ifsfManager.LockNozzle(id, nozzleId, null, null, null);
- }
- else if (sValue == "UnlockNozzle")
- {
- this.manager.ifsfManager.UnlockNozzle(id, nozzleId, null, null, null);
- }
- else if (sValue == "GetDeviceState")
- {
- this.manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser, id, null, null, null);
- }
- else if (sValue == "GetFuelPointTotals")
- {
- nozzleId = par2;
- this.manager.ifsfManager.GetFuelPointTotals(id, nozzleId, null, null, null);
- }
- else if (sValue == "CloseFuelPoint")
- {
- this.manager.ifsfManager.CloseFuelPoint(id, null, null, null);
- }
- else if (sValue == "OpenFuelPoint")
- {
- this.manager.ifsfManager.OpenFuelPoint(id, null, null, null);
- }
- else if (sValue == "ReserveFuelPoint")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.ReserveAsync(FuellingType.Unknown, 0, new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_ReserveResult), null);
- //this.manager.ifsfManager.ReserveFuelPoint(id, null, null);
- }
- else if (sValue == "FreeFuelPoint")
- {
- FUSIONPump pump = this.manager.GetPumpById(id);
- if (pump != null)
- pump.UnreserveAsync(new EventHandler<Wayne.Lib.AsyncCompletedEventArgs>(Test_UnreserveResult), null);
- //this.manager.ifsfManager.FreeFuelPoint(id, null, null);
- }
- else if (sValue == "GetFuelSaleTrxDetails")
- {
- this.manager.ifsfManager.GetFuelSaleTrxDetails(id, trid, 2, null, null, null);
- }
- else if (sValue == "GetAvailableFuelSaleTrxs")
- {
- this.manager.ifsfManager.GetAvailableFuelSaleTrxs(id, null, null, null);
- }
- else if (sValue == "ChangeFuelMode")
- {
- int priceGroup = par2;
- this.manager.ifsfManager.ChangeFuelMode(id, priceGroup, null, null, null);
- }
- else if (sValue == "SendConfig")
- {
- this.manager.ifsfManager.SendConfig(sElems[1], null, null, null);
- }
- else if (sValue == "SetDeviceAlarm")
- {
- this.manager.ifsfManager.SetDeviceAlarm("1", id, 1, "test alarms", null, null, null);
- }
- else if (sValue == "ChangeDSPLimits")
- {
- this.manager.ifsfManager.ChangeDSPLimits(id, 1, 1, 9, 88, null, null, null);
- }
- else if (sValue == "ChangeFuelPrice")
- {
- this.manager.ifsfManager.ChangeFuelPrice(id, 3.39m, 1, null, null, null);
- }
- else if (sValue == "CloseDevice")
- {
- this.manager.ifsfManager.CloseDevice(id, null, null, null);
- }
- else if (sValue == "GetConfiguration")
- {
- this.manager.ifsfManager.GetConfiguration(null, null, null);
- }
- else if (sValue == "GetDSPLimits")
- {
- this.manager.ifsfManager.GetDSPLimits(id,null,null,null);
- }
- //else if (sValue == "GetFPState")
- //{
- // this.manager.ifsfManager.GetFPStateResp(id null);
- //}
- //else if (sValue == "GetFPState")
- //{
- // this.manager.ifsfManager.GetFPStateResp(id null);
- //}
- else
- {
- }
- }
- sr.Close();
- }
- public override string ToString()
- {
- return ("Forecourt Control ClientId=" + this.ClientId.ToString(CultureInfo.InvariantCulture));
- }
- public void UnreserveFuelPricesAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- //AsyncOperation<ushort> operation = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, requestCompleted, userToken);
- //AsyncOperation<ushort> operation2 = this.manager.AsyncManager.RegisterOperation<AsyncCompletedEventArgs>(this, new EventHandler<AsyncCompletedEventArgs>(this, (IntPtr)this.UnreserveFuelPricesAsyncCompleted), operation.Id);
- //Function function = new Function(6, new Parameter[] { new PrimitiveParameter(0x66, PrimitiveType.UInt16, operation2.Id) });
- //this.manager.Send(function);
- if (this.manager.forecourtControl.fuelPriceReserved)
- this.manager.ifsfManager.ChangeFuelModeSend(this.manager.forecourtControl.srChangeMode, requestCompleted, userToken, this);
- foreach (IFuelPrice fuelprice in FuelPrices)
- {
- ((FUSIONFuelPrice)fuelprice).WritableReserved = false;
- }
- if (requestCompleted != null && !this.manager.forecourtControl.fuelPriceReserved)
- requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
- srChangeMode = null;
- fuelPriceReserved = false;
- }
- private void UnreserveFuelPricesAsyncCompleted(object sender, AsyncCompletedEventArgs e)
- {
- //AsyncOperation<ushort, AsyncCompletedEventArgs> operation;
- //if (!(e.UserToken is ushort))
- //{
- // throw new Exception("UnreserveFuelPricesAsyncCompleted: Expected usertoken to be Uint16");
- //}
- //this.manager.ReadFuelPrices();
- //foreach (NfsFuelPrice price in this.fuelPriceList)
- //{
- // price.WritableReserved = false;
- //}
- //if (this.manager.AsyncManager.TryGetOperation<AsyncCompletedEventArgs>((ushort)e.UserToken, out operation))
- //{
- // operation.Complete(new AsyncCompletedEventArgs(e.Success, operation.UserToken));
- //}
- }
- internal void WriteSiteMode(bool newSiteOpen, int newSiteMode)
- {
- //if ((newSiteMode != this.siteMode) || (newSiteOpen != this.siteOpened))
- //{
- // this.siteOpened = newSiteOpen;
- // this.siteMode = newSiteMode;
- // if ((this.OnSiteModeChange != null) && (this.connectionState != DeviceConnectionState.Connecting))
- // {
- // this.OnSiteModeChange.Invoke(this, new SiteModeChangeEventArgs(this.siteMode, this.siteOpened));
- // }
- //}
- }
- #endregion
- #region Properties
- public int ClientId
- {
- get { return int.Parse(this.manager.ifsfManager.clientSocket.workstationID); }
- }
- public string ClientName
- {
- get
- {
- return this.clientName;
- }
- }
- public DeviceConnectionState ConnectionState
- {
- get
- {
- return this.connectionState;
- }
- }
- public string EntitySubType
- {
- get
- {
- return "";
- }
- }
- public string EntityType
- {
- get
- {
- return "FUSIONForecourtControl";
- }
- }
- /// <summary>
- /// This is used by the logger and should never be set by implementing classes
- /// </summary>
- public string FullEntityName { get; set; }
- public ReadOnlyCollection<IFuelPrice> FuelPrices
- {
- get
- {
- return this.fuelPriceList.AsReadOnly();
- }
- }
- public int Id
- {
- get { return this.id; }
- set { id = value; }
- }
- public IIdentifiableEntity ParentEntity
- {
- get { return null; }
- }
- public ReadOnlyCollection<IPricePole> PricePoles
- {
- get
- {
- return this.pricePoleList.AsReadOnly();
- }
- }
- public ReadOnlyCollection<IPump> Pumps
- {
- get
- {
- return this.pumpList.AsReadOnly();
- }
- }
- public int SiteMode
- {
- get
- {
- return this.siteMode;
- }
- }
- public bool SiteOpened
- {
- get
- {
- return this.siteOpened;
- }
- }
- public ReadOnlyCollection<ITankGroup> TankGroups
- {
- get
- {
- return this.tankGroupList.AsReadOnly();
- }
- }
- internal int WritableClientId
- {
- get
- {
- return this.id;
- }
- set
- {
- this.id = value;
- }
- }
- internal string WritableClientName
- {
- get
- {
- return this.clientName;
- }
- set
- {
- this.clientName = value;
- }
- }
- internal DeviceConnectionState WritableConnectionState
- {
- get
- {
- return this.connectionState;
- }
- set
- {
- Trace.WriteLine(string.Format("old connectionState={0}, new connectionState={1}", this.connectionState, value));
- if (this.connectionState != value)
- {
- this.connectionState = value;
- if (connectionState == DeviceConnectionState.Connected)
- {
- foreach (FUSIONPump pump in Pumps)
- {
- //foreach (FUSIONFuelling fuelling in pump.Fuellings)
- // fuelling.Dispose();
- pump.WritableFuellingList.Clear();
- //((FUSIONFuelling)pump.CurrentFuelling).Dispose();
- }
- // read current pump status
- //if (ConfigParam.IsEMSGVersion)
- //{
- manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, -1, null, null, null);
- //}
- //else
- //{
- // manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe, -1, null, null, null);
- //}
- // read current Vir status
- //if (FUSIONVirFactory.Virs.Count > 0)
- // manager.ifsfManager.GetDeviceState(Wayne.FDCPOSLibrary.DeviceType.DT_Vir, -1, null, null, null);
- // get the list of offline fuelling
- manager.ifsfManager.GetAvailableFuelSaleTrxs(-1, null, null, null);
- }
- if (this.OnConnectionStateChange != null)
- {
- this.OnConnectionStateChange.Invoke(this, new ConnectionChangedEventArgs(value));
- }
- }
- }
- }
- internal List<IFuelPrice> WritableFuelPriceList
- {
- get
- {
- return this.fuelPriceList;
- }
- }
- internal List<IPricePole> WritablePricePoleList
- {
- get
- {
- return this.pricePoleList;
- }
- }
- internal List<IPump> WritablePumpList
- {
- get
- {
- return this.pumpList;
- }
- }
- internal int WritableSiteMode
- {
- get
- {
- return this.siteMode;
- }
- set
- {
- this.siteMode = value;
- }
- }
- internal bool WritableSiteOpened
- {
- get
- {
- return this.siteOpened;
- }
- set
- {
- this.siteOpened = value;
- }
- }
- internal List<ITankGroup> WritableTankGroupList
- {
- get
- {
- return this.tankGroupList;
- }
- }
- public IFuelPrice getFuelPriceByProductId(int productId)
- {
- foreach (IFuelPrice fuelprice in FuelPrices)
- {
- if (productId == fuelprice.FuelGrade)
- return fuelprice;
- }
- return null;
- }
- #endregion
- #region IForecourtControl Members
- public void ReservePumpClusterAsync(int terminalDeviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- throw new NotImplementedException();
- }
- public void UnreservePumpClusterAsync(int terminalDeviceId, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
- {
- throw new NotImplementedException();
- }
- #endregion
- }
- }
|