123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Threading;
- //using System.Diagnostics;
- using Wayne.Lib;
- #if _SINP
- using Wayne.ForecourtControl.Nfs;
- #endif
- using Wayne.ForecourtControl.OptBridge;
- using Wayne.ForecourtControl.OptBridge.Fusion;
- using Wayne.ForecourtControl.Vir.Fusion;
- using Wayne.FDCPOSLibrary;
- namespace Wayne.ForecourtControl.Fusion
- {
- internal class FUSIONAsyncMangager : Wayne.Lib.AsyncManager.AsyncManager<ushort>
- {
- // Fields
- private ushort nextSequenceNumber;
- private object nextSequenceNumberLock;
- // Methods
- public FUSIONAsyncMangager(int id, IIdentifiableEntity parentEntity)
- : base(id, parentEntity)
- {
- this.nextSequenceNumber = 1;
- this.nextSequenceNumberLock = new object();
- }
- protected override ushort CreateNextOperationId()
- {
- lock (this.nextSequenceNumberLock)
- {
- ushort num2;
- this.nextSequenceNumber = (ushort)((num2 = this.nextSequenceNumber) + 1);
- return num2;
- }
- }
- // Properties
- public override string EntitySubType
- {
- get
- {
- return "FUSIONForecourtControl";
- }
- }
- }
- public abstract class FUSIONAsyncOperation<TOperationId>
- {
- // Fields
- private DateTime creationDateTime;
- private object data;
- private TOperationId id;
- private object owner;
- private object userToken;
- // Events
- internal event EventHandler OnOperationCompleted;
- // Methods
- protected internal FUSIONAsyncOperation(object owner, TOperationId id, object userToken, object data)
- {
- this.creationDateTime = DateTime.Now;
- this.owner = owner;
- this.id = id;
- this.userToken = userToken;
- this.data = data;
- }
- public void Cancel()
- {
- this.Complete();
- }
- protected internal void Complete()
- {
- if (this.OnOperationCompleted != null)
- {
- this.OnOperationCompleted(this, EventArgs.Empty);
- }
- }
- // Properties
- internal DateTime CreationDateTime
- {
- get
- {
- return this.creationDateTime;
- }
- set
- {
- this.creationDateTime = value;
- }
- }
- public object Data
- {
- get
- {
- return this.data;
- }
- }
- public TOperationId Id
- {
- get
- {
- return this.id;
- }
- }
- public object Owner
- {
- get
- {
- return this.owner;
- }
- }
- public object UserToken
- {
- get
- {
- return this.userToken;
- }
- }
- }
- public class FUSIONAsyncOperation<TOperationId, TResultEventArgs> : FUSIONAsyncOperation<TOperationId> where TResultEventArgs : EventArgs
- {
- // Fields
- private EventHandler<TResultEventArgs> resultDelegate;
- // Methods
- internal FUSIONAsyncOperation(object owner, TOperationId id, object userToken, object data, EventHandler<TResultEventArgs> resultDelegate)
- : base(owner, id, userToken, data)
- {
- this.resultDelegate = resultDelegate;
- }
- public void Complete(TResultEventArgs resultEventArgs)
- {
- base.Complete();
- if (this.resultDelegate != null)
- {
- this.resultDelegate.Invoke(base.Owner, resultEventArgs);
- }
- }
- public override string ToString()
- {
- return this.ToString("", CultureInfo.InvariantCulture);
- }
- public virtual string ToString(IFormatProvider provider)
- {
- return this.ToString("", provider);
- }
- public virtual string ToString(string format)
- {
- return this.ToString(format, CultureInfo.InvariantCulture);
- }
- public virtual string ToString(string format, IFormatProvider provider)
- {
- string str;
- IIdentifiableEntity owner = base.Owner as IIdentifiableEntity;
- if (owner != null)
- {
- str = IdentifiableEntity.ToString(owner);
- }
- else
- {
- str = base.Owner.ToString();
- }
- return string.Format(CultureInfo.InvariantCulture, "FUSIONAsyncOperation<TOperatorId={0},TResultEventArgs={1}> Owner={2},Id={3},", new object[] { typeof(TOperationId).FullName, typeof(TResultEventArgs).FullName, str, base.Id });
- }
- }
- internal class FUSIONInitializationStatus
- {
- // Fields
- private bool clientPropertySet;
- private bool configurationDataRead;
- private BitArray pumpStatusRead;
- private bool readingConfigurationData;
- private bool siteModeRead;
- // Methods
- public FUSIONInitializationStatus()
- {
- this.PumpStatusRead = new BitArray(0x20, false);
- }
- public void Reset()
- {
- this.ReadingConfigurationData = false;
- //this.ConfigurationDataRead = false;
- this.ClientPropertySet = false;
- this.SiteModeRead = false;
- this.PumpStatusRead.SetAll(false);
- }
- // Properties
- public bool ClientPropertySet
- {
- get
- {
- return this.clientPropertySet;
- }
- set
- {
- this.clientPropertySet = value;
- }
- }
- public bool ConfigurationDataRead
- {
- get
- {
- return this.configurationDataRead;
- }
- set
- {
- this.configurationDataRead = value;
- }
- }
- public BitArray PumpStatusRead
- {
- get
- {
- return this.pumpStatusRead;
- }
- set
- {
- this.pumpStatusRead = value;
- }
- }
- public bool ReadingConfigurationData
- {
- get
- {
- return this.readingConfigurationData;
- }
- set
- {
- this.readingConfigurationData = value;
- }
- }
- public bool SiteModeRead
- {
- get
- {
- return this.siteModeRead;
- }
- set
- {
- this.siteModeRead = value;
- }
- }
- }
- public class FUSIONManager : IIdentifiableEntity, IDisposable
- {
- // Fields
- public IFSFManager ifsfManager;
- private ConfigurationReader configurationReader;
- //private Dictionary<string, string> connectionStringParamDict;
- //private DebugLogger debugLogger;
- private bool disposed;
- public FUSIONForecourtControl forecourtControl;
- private FUSIONInitializationStatus initializationStatus = new FUSIONInitializationStatus();
- //private DataSet latestPricesDataSet = new DataSet();
- //private ForecourtEntityTypes managedEntityTypes;
- private List<int> managedPumpIds;
- //private ParameterFormatInfo parserFormatInfo = new ParameterFormatInfo();
- //private NfsManagerState state;
- public AutoResetEvent versionInfoWakeUpEvent;
- public string version;
- public string release;
- public string hotfix;
- public string getFwRelease()
- {
- return version + "." + release + "." + hotfix;
- }
- public int IdShift = 0;
- public int IdPumpShift = 0;
- public int IdNozzleShift = 0;
- public int IdTankShift = 0;
- private bool shouldSetConnected = false; // a flag to indicate if need to set connection state to be connected
- // Methods
- public FUSIONManager(FUSIONForecourtControl forecourtControl, ForecourtEntityTypes managedEntityTypes, int[] managedPumpIds)
- {
- try
- {
- //Logger.SetConfigFile(@".\LogConfig.xml");
- //Logger.RefreshConfig();
- Trace.Add(this);
- }
- catch (Exception ex)
- {
- Trace.WriteLine("FusionManager Exception - " + ex.Message);
- }
- this.configurationReader = new ConfigurationReader(this);
- //this.state = NfsManagerState.Uninitialized;
- this.forecourtControl = forecourtControl;
- Trace.WriteLine("starting ...Id = " + this.Id);
- //this.managedEntityTypes = managedEntityTypes;
- //this.asyncManager = new FUSIONAsyncMangager(this.Id, this);
- //this.debugLogger = new DebugLogger(this, true);
- this.ifsfManager = new IFSFManager(forecourtControl.Id, forecourtControl.ConfigParam);
- //this.clientSocket.ParserDomain = ParserDomain.FillingServer;
- //this.clientSocket.OnRpcRead += new EventHandler<RpcEventArgs>(this, (IntPtr)this.clientSocket_OnRpcRead);
- this.ifsfManager.clientSocket.OnConnectionStateChange += new EventHandler<ConnectionChangedEventArgs>(clientSocket_OnConnectionStateChange); //new EventHandler<ConnectionChangedEventArgs>(this, (IntPtr)this.clientSocket_OnConnectionStateChange);
- this.ifsfManager.OnDeviceStateChange += new EventHandler<DeviceStateChangedEventArgs>(manager_OnDeviceStateChange);
- this.ifsfManager.OnVirStateChange += new EventHandler<VIRStateChangedEventArgs>(manager_OnVirStateChange);
- this.ifsfManager.OnFuelModeChange += new EventHandler<FuelModeChangedEventArgs>(manager_OnFuelModeChange);
- this.ifsfManager.OnCurrentFuellingStatus += new EventHandler<CurrentFuellingStatusEventArgs>(manager_OnCurrentFuellingStatus);
- this.ifsfManager.OnFuelPointTotals += new EventHandler<FuelPointTotalsEventArgs>(manager_OnFuelPointTotals);
- this.ifsfManager.OnFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnFuelSaleTrx);
- this.ifsfManager.OnDeviceAlarm += new EventHandler<DeviceAlarmEventArgs>(manager_OnDeviceAlarm);
- this.ifsfManager.OnVersionInfo += new EventHandler<VersionInfoEventArgs>(manager_OnVersionInfo);
- this.ifsfManager.OnChangeFuelPrice += new EventHandler<ChangeFuelPriceEventArgs>(manager_OnChangeFuelPrice);
- this.ifsfManager.OnLockFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnLockFuelSaleTrx);
- this.ifsfManager.OnUnlockFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnUnlockFuelSaleTrx);
- this.ifsfManager.OnClearFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnClearFuelSaleTrx);
- this.ifsfManager.OnGetAvailableFuelSaleTrx += new EventHandler<FuelSaleTrxEventArgs>(manager_OnGetAvailableFuelSaleTrx);
- this.ifsfManager.OnGetFuelSaleTrxDetails += new EventHandler<FuelSaleTrxEventArgs>(manager_OnGetFuelSaleTrxDetails);
- this.ifsfManager.OnGetConfiguration += new EventHandler<GetConfigurationEventArgs>(manager_OnGetConfiguration);
- this.ifsfManager.OnConfigurationChange += new EventHandler<EventArgs>(manager_OnConfigurationChange);
- this.ifsfManager.OnGetProductTable += new EventHandler<GetProductTableEventArgs>(manager_OnGetProductTable);
- this.ifsfManager.OnTankData += new EventHandler<TankDataEventArgs>(manager_OnTankData);
- this.ifsfManager.OnTwinMasterReady += new EventHandler<EventArgs>(manager_OnTwinMasterReady);
- this.ifsfManager.OnOptRead += new EventHandler<OptReadEventArgs>(manager_OnOptRead);
- this.versionInfoWakeUpEvent = new AutoResetEvent(false);
- }
- private int convertDeviceType(string deviceType)
- {
- if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser)
- return (int)(ForecourtEntityTypes.Pump); //3; // is that Wayne.ForecourtControl.Nfs.ForecourtEntityTypes.Pump ?
- else if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_PricePole || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_PricePolePoint)
- return (int)(ForecourtEntityTypes.PricePole);
- else if (deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge || deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe)
- return (int)(ForecourtEntityTypes.Tank);
- return 0;
- }
- private int getAlarmCategory(int alarmId)
- {
- switch (alarmId)
- {
- case 1003:
- return 0; // Information
- //case xxx:
- // return 1; // warning
- default:
- return 1; // Error
- }
- }
- private int convertAlarmCode(int error)
- {
- return error;
- //int AlarmId = 0;
- //if (error == 6) // volume or amount decreased
- //{
- // AlarmId = 219;
- //}
- //else if (error == 7 || error == 8) // pulser error
- //{
- // AlarmId = 220;
- //}
- //else if (error == 9) // zero fuelling - antispandimento
- //{
- // AlarmId = 212;
- //}
- //else if (error == 11) // price error
- //{
- // AlarmId = 211;
- //}
- //else if (error == 12) // volume or amount garbage
- //{
- // AlarmId = 219;
- //}
- //else if (error == 13) // display error
- //{
- // AlarmId = 215;
- //}
- //else if (error == 14) // checksum error
- //{
- // AlarmId = 219;
- //}
- //return AlarmId;
- }
- private void clientSocket_OnConnectionStateChange(object sender, ConnectionChangedEventArgs e)
- {
- Trace.WriteLine("manager clientSocket_OnConnectionStateChange ConnectionState=" + e.ConnectionState);
- try
- {
- if (e.ConnectionState == DeviceConnectionState.Connected)
- {
- this.initializationStatus.Reset();
- shouldSetConnected = true;
- // when socket connection is active, start getting configuration
- this.InitializeOrhcestrator();
- // JDL, AUG-10-10, site is open when FDC connection established.
- this.forecourtControl.WritableSiteOpened = true;
- }
- else if (e.ConnectionState != DeviceConnectionState.Connected)
- {
- if (e.ConnectionState == DeviceConnectionState.Disconnected)
- {
- //WJU - do not make reconnection read ConfigurationData again. It should read only first time connection
- initializationStatus.ReadingConfigurationData = false;
- // JDL, AUG-10-10, set site to closed
- this.forecourtControl.WritableSiteOpened = false;
- //this.DestroyObjects();
- ifsfManager.Disconnect();
- if (FUSIONOptFactory.getOptBridge() != null)
- {
- foreach (IOpt opt in ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).Opts)
- {
- if (((FUSIONOpt)opt).managedBy == OPTManagedBy.SINP)
- ((FUSIONOpt)opt).optTCP.Disconnect();
- }
- }
- foreach (FUSIONPump pump in this.forecourtControl.Pumps)
- {
- pump.WritableState = PumpState.Inoperative;
- }
- }
- this.forecourtControl.WritableConnectionState = e.ConnectionState;
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- }
- private void manager_OnDeviceStateChange(object sender, DeviceStateChangedEventArgs e)
- {
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- if (pump != null)
- {
- PumpState state = pump.convertPumpState(e.state);
- Trace.WriteLine(string.Format("pump={0}, State={1}, pump.State={2}, nozzleUp={3}", pump.realId, state, pump.State, e.nozzleUp));
- if (pump.State != state)
- pump.WritableState = state;
- try
- {
- pump.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : -1;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
- }
- foreach (FUSIONNozzle nozzle in pump.Nozzles)
- {
- Trace.WriteLine(string.Format("pump={0}, nozzle={1}, nozzle.State={2}", pump.realId, nozzle.Id, nozzle.State));
- if (nozzle.State == NozzleState.Out && e.nozzleUp != nozzle.Id)
- nozzle.State = NozzleState.In;
- else if (nozzle.State == NozzleState.In && e.nozzleUp == nozzle.Id)
- nozzle.State = NozzleState.Out;
- }
- }
- }
- else if (e.deviceType == DeviceType.DT_OutdoorPaymentTerminal)
- {
- if (FUSIONOptFactory.getOptBridge() == null)
- return;
- FUSIONOpt opt = ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).GetOptFromId(e.deviceId);
- if (opt != null)
- {
- DeviceConnectionState state;
- if (e.state == LogicalDeviceState.FDC_READY) state = DeviceConnectionState.Connected;
- else state = DeviceConnectionState.Disconnected;
- Trace.WriteLine(string.Format("opt={0}, State={1}", opt.Id, state));
- if (opt.ConnectionState != state)
- opt.WritableConnectionState = state;
- }
- }
- else if (e.deviceType == DeviceType.DT_TankProbe)
- {
- FUSIONTank tank = this.getTankByIndex(e.deviceId);
- if (e.state == LogicalDeviceState.FDC_READY)
- tank.WritableConnectionState = DeviceConnectionState.Connected;
- else
- tank.WritableConnectionState = DeviceConnectionState.Disconnected;
- }
- }
- private void manager_OnVirStateChange(object sender, VIRStateChangedEventArgs e)
- {
- FUSIONVir vir = (FUSIONVir)(FUSIONVirFactory.getVir(e.deviceId));
- if (vir != null)
- {
- if (e.state == DeviceConnectionState.Connected)
- vir.Connected(e.virId);
- else if (e.state == DeviceConnectionState.Disconnected)
- vir.Disconnected(e.virId);
- else
- Trace.WriteLine(string.Format("manager_OnVirStateChange>: vir={0} State={1} NOT managed !", vir.Id, e.state));
- }
- else
- Trace.WriteLine(string.Format("manager_OnVirStateChange: vir={0} NOT FOUND !", e.deviceId));
- }
- private void manager_OnFuelModeChange(object sender, FuelModeChangedEventArgs e)
- {
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- if (pump != null)
- {
- int mode = e.mode;
- Trace.WriteLine(string.Format("pump={0}, mode={1}", pump.realId, mode));
- pump.FireFuelModeChange(mode);
- }
- }
- }
- private void manager_OnCurrentFuellingStatus(object sender, CurrentFuellingStatusEventArgs e)
- {
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- try
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- if (pump != null && pump.CurrentFuelling != null)
- {
- if (e.volume > 0 && e.volume != pump.CurrentFuelling.Quantity && pump.RunningFuellingUpdates)
- {
- // TODO setting pump current fuelling attributes
- FUSIONFuelling currentFuelling = null;
- currentFuelling = (FUSIONFuelling)(pump.CurrentFuelling);
- currentFuelling.WritablePrice = e.price;
- currentFuelling.WritableAmount = e.amount;
- currentFuelling.WritableQuantity = e.volume;
- if (pump.Nozzles.Count > e.nozzleId - 1 && e.nozzleId > 0)
- {
- currentFuelling.WritableNozzle = pump.Nozzles[e.nozzleId - 1];
- currentFuelling.WritableFuelGrade = pump.Nozzles[e.nozzleId - 1].FuelGrade;
- }
- else
- Trace.WriteLine(String.Format("INVALID Nozzle: '{0}'", e.nozzleId));
- pump.FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
- }
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- }
- }
- private void manager_OnFuelPointTotals(object sender, FuelPointTotalsEventArgs e)
- {
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- try
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- FUSIONNozzle nozzle = (FUSIONNozzle)(pump.Nozzles[e.nozzleId - 1]);
- if (pump != null && nozzle != null)
- {
- PumpAccumulatorReading pumpAccumulatorReading = new PumpAccumulatorReading(pump, nozzle, 0, PumpAccumulatorReadingType.RequestedReading,
- e.volume, e.amount);
- this.ifsfManager.clientSocket.ifsfMessages.asyncResponseManager.SendResponse(e.requestId, e.overallResult, pumpAccumulatorReading);
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- }
- }
- private void manager_OnFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
- {
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- try
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- if (pump != null && pump.CurrentFuelling != null)
- {
- lock (pump.CurrentFuelling)
- {
- //if (e.volume != pump.CurrentFuelling.Quantity)
- Trace.WriteLine(string.Format("pump={0}, pump.Nozzles.Count={1}, e.nozzleId={2}", pump.realId, pump.Nozzles.Count, e.nozzleId));
- Trace.WriteLine(String.Format("Transaction state={0}", ((Wayne.FDCPOSLibrary.FuellingState)(e.transactionStatus)).ToString()));
- FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId, e.releaseToken));
- FUSIONFuelling currentFuelling = (FUSIONFuelling)(pump.CurrentFuelling);
- FuellingState fuellingState = FuellingState.Unknown;
- if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Locked)
- fuellingState = FuellingState.Locked;
- else if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Payable)
- fuellingState = FuellingState.PayableTransaction;
- #if !_USE_OLD_FCONTROL_
- else if (e.transactionStatus == Wayne.FDCPOSLibrary.FuellingState.Paid)
- fuellingState = FuellingState.Paid;
- #endif
- if (fuelling == null)
- {
- if (pump.Nozzles.Count > e.nozzleId - 1)//&& e.nozzleId > 0)
- {
- // TODO possible transaction status to be defined
- currentFuelling.WritableCompletionReason = currentFuelling.convertStatus(e.completionReason);
- // overwrite the value set when authorising fuelling
- currentFuelling.WritableFuellingSequenceNumber = e.transactionId;
- currentFuelling.WritableCompletionDateTime = e.trxEndDateTime;
- // TODO is fuel mode useful ?
- //e.fuelMode
- currentFuelling.WritableFuelGrade = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1].FuelGrade : 0;
- currentFuelling.WritableState = fuellingState;
- currentFuelling.WritablePrice = e.price;
- currentFuelling.WritableAmount = e.amount;
- if (pump.CurrentFuelling.PresetValue == 0)
- {
- currentFuelling.WritablePresetType = PresetType.Amount;
- currentFuelling.WritablePresetValue = e.amount;
- }
- currentFuelling.WritableQuantity = e.volume;
- currentFuelling.WritableNozzle = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1] : null;
- try
- {
- currentFuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
- }
- try
- {
- currentFuelling.WritableAuthorizedBy = (e.authAS != null && e.authAS != "") ? Convert.ToInt32(e.authAS) : 0;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception! cannot convert e.authAS='{0}' to Int32", e.authAS));
- }
- //currentFuelling.WritableSignedReceiptLines = (e.DSPFields == null) ? "" : e.DSPFields;
- currentFuelling.WritableSignedReceiptLines = (e.MIDLinesNarrow == null) ? "" : e.MIDLinesNarrow;
- Trace.WriteLine(string.Format("SignedReceiptLines='{0}'", currentFuelling.SignedReceiptLines));
- currentFuelling.WritableSignedReceiptLinesWide = (e.MIDLinesWide == null) ? "" : e.MIDLinesWide;
- Trace.WriteLine(string.Format("SignedReceiptLinesWide='{0}'", currentFuelling.SignedReceiptLinesWide));
- currentFuelling.WritableAuthorizationId = e.releaseToken;
- currentFuelling.WritableReservingDeviceId = e.reservingDeviceId;
- currentFuelling.WritableType = e.fuellingType;
- // add a fuelling to the pump fuellings list
- fuelling = new FUSIONFuelling(this, pump);
- pump.WritableFuellingList.Add(fuelling);
- fuelling.WritableFuellingSequenceNumber = currentFuelling.WritableFuellingSequenceNumber;
- fuelling.WritableCompletionReason = currentFuelling.convertStatus(e.completionReason);
- fuelling.WritableCompletionDateTime = e.trxEndDateTime;
- // TODO is fuel mode useful ?
- //e.fuelMode
- fuelling.WritablePresetType = currentFuelling.PresetType;
- fuelling.WritablePresetValue = currentFuelling.PresetValue;
- fuelling.WritableFuelGrade = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1].FuelGrade : 0;
- fuelling.WritableState = fuellingState;
- fuelling.WritablePrice = e.price;
- fuelling.WritableAmount = e.amount;
- fuelling.WritableQuantity = e.volume;
- fuelling.WritableNozzle = (e.nozzleId > 0) ? pump.Nozzles[e.nozzleId - 1] : null;
- fuelling.WritableCRC = 0;
- fuelling.WritableReservedBy = currentFuelling.WritableReservedBy;
- fuelling.WritableAuthorizedBy = currentFuelling.WritableAuthorizedBy;
- fuelling.WritableSignedReceiptLines = currentFuelling.WritableSignedReceiptLines;
- fuelling.WritableSignedReceiptLinesWide = currentFuelling.WritableSignedReceiptLinesWide;
- fuelling.WritableAuthorizationId = e.releaseToken;
- fuelling.WritableReservingDeviceId = e.reservingDeviceId;
- fuelling.WritableType = currentFuelling.WritableType;
- #if !_USE_OLD_FCONTROL_
- Trace.WriteLine(String.Format("Firing FuellingStateChange: CurrentFuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, authAS={5}, lockAS={6}, reservingDeviceId={7}",
- pump.CurrentFuelling.FuellingSequenceNumber, pump.realId, ((Wayne.FDCPOSLibrary.FuellingState)(pump.CurrentFuelling.State)).ToString(), pump.CurrentFuelling.Quantity, pump.CurrentFuelling.Amount, pump.CurrentFuelling.AuthorizedBy, pump.CurrentFuelling.ReservedBy,
- pump.CurrentFuelling.ReservingDeviceId));
- #else
- Trace.WriteLine(String.Format("Firing FuellingStateChange: CurrentFuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, lockAS={5}",
- pump.CurrentFuelling.FuellingSequenceNumber, pump.realId, ((Wayne.FDCPOSLibrary.FuellingState)(pump.CurrentFuelling.State)).ToString(), pump.CurrentFuelling.Quantity, pump.CurrentFuelling.Amount, pump.CurrentFuelling.ReservedBy));
- #endif
- pump.FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
- pump.FireFuellingStateChange(fuelling, fuellingState);
- }
- else
- Trace.WriteLine(String.Format("INVALID Nozzle: '{0}'", e.nozzleId));
- }
- else
- {
- // if fuelling exist the only item that can change is the status
- //if (fuellingState != fuelling.State)
- {
- fuelling.WritableState = fuellingState;
- try
- {
- fuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
- }
- if (e.transactionId == currentFuelling.FuellingSequenceNumber)
- {
- currentFuelling.WritableState = fuellingState;
- try
- {
- currentFuelling.WritableReservedBy = (e.lockingAS != null && e.lockingAS != "") ? Convert.ToInt32(e.lockingAS) : 0;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception! cannot convert e.lockingAS='{0}' to Int32", e.lockingAS));
- }
- }
- Trace.WriteLine(String.Format("Firing FuellingStateChange: fuellingID={0}, pump={1}, state={2}, quantity={3}, amount={4}, authAS={5}, lockAS={6}",
- fuelling.FuellingSequenceNumber, ((FUSIONPump)(fuelling.Pump)).realId, ((Wayne.FDCPOSLibrary.FuellingState)(fuelling.State)).ToString(), fuelling.Quantity, fuelling.Amount, fuelling.AuthorizedBy, fuelling.ReservedBy));
- pump.FireFuellingStateChange(fuelling, fuellingState);
- #if !_USE_OLD_FCONTROL_
- if (fuellingState == FuellingState.Paid)
- {
- pump.WritableFuellingList.Remove(fuelling);
- currentFuelling.WritableType = FuellingType.Unknown;
- }
- #endif
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- }
- }
- private void manager_OnDeviceAlarm(object sender, DeviceAlarmEventArgs e)
- {
- //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- //{
- // FUSIONPump pump = this.GetPumpById(e.deviceId);
- // if (pump != null && pump.CurrentFuelling != null)
- // {
- // pump...FireFuellingDataChange(pump.CurrentFuelling, pump.CurrentFuelling.Amount, pump.CurrentFuelling.Quantity);
- // }
- //}
- int alarmCategory = getAlarmCategory(e.alarmId);
- int deviceType = convertDeviceType(e.deviceType);
- int deviceId = e.deviceId;
- int alarmCode = convertAlarmCode(e.alarmId);
- string debugText = e.alarmDescr;
- AlarmEventArgs args = new AlarmEventArgs(deviceId, deviceType, alarmCode, alarmCategory, debugText);
- // low level alarm code: 4
- const int LOWLEVELALARMCODE = 0x1F; //15;
- const int NOALARMCODE = 0;
- if ((e.deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint || e.deviceType == Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser) &&
- (alarmCode == 0 || alarmCode == LOWLEVELALARMCODE))
- {
- FUSIONPump pump = this.GetPumpById(deviceId);
- Trace.WriteLine(string.Format("pump={0}, deviceType={1}, alarmCode={2}, TankLevelSwitchStatus={3}", deviceId, deviceType, alarmCode, (pump != null) ? pump.TankLevelSwitchStatus.ToString() : "invalid"));
- if (pump != null)
- {
- if (alarmCode == LOWLEVELALARMCODE && pump.TankLevelSwitchStatus != TankLevelSwitchStatus.Low)
- {
- pump.WritableTankLevelSwitchStatus = TankLevelSwitchStatus.Low;
- //this.forecourtControl.FireAlarmEvent(args);
- }
- else if (alarmCode == NOALARMCODE && pump.TankLevelSwitchStatus == TankLevelSwitchStatus.Low)
- {
- pump.WritableTankLevelSwitchStatus = TankLevelSwitchStatus.Ok;
- this.forecourtControl.FireAlarmEvent(args);
- }
- }
- }
- else
- this.forecourtControl.FireAlarmEvent(args);
- }
- private void manager_OnVersionInfo(object sender, VersionInfoEventArgs e)
- {
- this.release = e.release;
- this.version = e.version;
- this.hotfix = e.hotfix;
- versionInfoWakeUpEvent.Set();
- }
- private void manager_OnChangeFuelPrice(object sender, ChangeFuelPriceEventArgs e)
- {
- FUSIONFuelPrice fuelPrice = (FUSIONFuelPrice)this.forecourtControl.getFuelPriceByProductId(e.productId);
- if (fuelPrice == null)
- return;
- try
- {
- FUSIONFuelPriceAddPricePerPriceGroup pgd = null;
- if (fuelPrice != null)
- pgd = (FUSIONFuelPriceAddPricePerPriceGroup)(fuelPrice.PriceGroupDelta);
- if (pgd != null)
- {
- Monitor.Enter(fuelPrice.locker);
- pgd.setChanged(e.mode, false);
- bool resetchange = true;
- //for (int mode = pgd.PriceGroupNumbersMin; mode <= pgd.PriceGroupNumbersMax; mode++)
- for (int mode = FUSIONFuelPrice.PriceGroupNumbersMin; mode <= FUSIONFuelPrice.PriceGroupNumbersMax; mode++)
- {
- if (pgd.getChanged(mode))
- {
- resetchange = false;
- break;
- }
- }
- if (resetchange)
- fuelPrice.Changed = false;
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine("Exception! " + ex.Message + " - " + ex.StackTrace);
- }
- finally
- {
- Monitor.Exit(fuelPrice.locker);
- }
- }
- private void manager_OnLockFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
- {
- //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- //{
- // FUSIONPump pump = this.GetPumpById(e.deviceId);
- // if (pump != null)
- // {
- // FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId));
- // if (fuelling != null)
- // {
- // fuelling.WritableReservedBy = this.Id;
- // }
- // }
- //}
- }
- private void manager_OnUnlockFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
- {
- //if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- //{
- // FUSIONPump pump = this.GetPumpById(e.deviceId);
- // if (pump != null)
- // {
- // FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId));
- // if (fuelling != null)
- // {
- // // TODO what value shoul be set ? at the moment set to '0'
- // fuelling.WritableReservedBy = 0;
- // }
- // }
- //}
- }
- private void manager_OnClearFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
- {
- // when the transaction is paid it is removed from the pump transaction list
- if (e.deviceType == DeviceType.DT_FuelDispenser || e.deviceType == DeviceType.DT_FuellingPoint)
- {
- FUSIONPump pump = this.GetPumpById(e.deviceId);
- if (pump != null)
- {
- FUSIONFuelling fuelling = (FUSIONFuelling)(pump.getFuellingByTransactionId(e.transactionId, e.releaseToken));
- if (fuelling != null)
- {
- fuelling.Dispose();
- }
- }
- }
- }
- private void manager_OnGetAvailableFuelSaleTrx(object sender, FuelSaleTrxEventArgs e)
- {
- this.forecourtControl.manager.ifsfManager.GetFuelSaleTrxDetails(e.deviceId, e.transactionId, e.releaseToken, null, null, null);
- }
- private void manager_OnGetFuelSaleTrxDetails(object sender, FuelSaleTrxEventArgs e)
- {
- // do nothing because GetFuelSaleTrxDetails response is managed by OnFuelSaleTrx event
- }
- private void manager_OnGetProductTable(object sender, GetProductTableEventArgs e)
- {
- Trace.WriteLine("init");
- ConfigurationReader.GetProductTableParam param = new ConfigurationReader.GetProductTableParam(e.sr, this);
- configurationReader.ReadProductTable(param);
- Trace.WriteLine("end");
- }
- private void manager_OnTankData(object sender, TankDataEventArgs e)
- {
- Trace.WriteLine("init");
- Trace.WriteLine("end");
- }
- private void manager_OnGetConfiguration(object sender, GetConfigurationEventArgs e)
- {
- Trace.WriteLine("manager_OnGetConfiguration init");
- ConfigurationReader.GetConfigurationParam param = new ConfigurationReader.GetConfigurationParam(e.sr, this);
- if (configurationReader.ReadConfiguration(param))
- this.ifsfManager.isConfigRead = true;
- Trace.WriteLine("manager_OnGetConfiguration End");
- }
- private void manager_OnConfigurationChange(object sender, EventArgs e)
- {
- Trace.WriteLine("manager_OnConfigurationChange - init");
- //this.Disconnect();
- this.DestroyObjects(false);
- this.forecourtControl.WritableConnectionState = DeviceConnectionState.Connecting;
- this.initializationStatus.ConfigurationDataRead = false;
- this.initializationStatus.ReadingConfigurationData = false;
- try
- {
- if (FUSIONConfigFactory.getConfigurator() != null)
- FUSIONConfigFactory.getConfigurator().FireOnConfigurationChanged();
- }
- catch (Exception ex)
- {
- }
- shouldSetConnected = false;
- this.InitializeOrhcestrator();
- Trace.WriteLine("End manager_OnConfigurationChange");
- }
- private void manager_OnTwinMasterReady(object sender, EventArgs e)
- {
- Trace.WriteLine("init manager_OnTwinMasterReady");
- try
- {
- if (FUSIONTwinFactory.getTwin() != null)
- ((FUSIONTwin)(FUSIONTwinFactory.getTwin())).FireOnTwinMasterReady();
- else
- Trace.WriteLine("manager_OnTwinMasterReady - twin NOT created");
- }
- catch (Exception ex)
- {
- }
- Trace.WriteLine("End manager_OnTwinMasterReady");
- }
- private void manager_OnOptRead(object sender, OptReadEventArgs e)
- {
- Trace.WriteLine("init");
- OptReadEventArgs args = new OptReadEventArgs(e.deviceType, e.deviceId, e.message);
- if (FUSIONOptFactory.getOptBridge() != null)
- ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).FireOnDataRead(e.deviceId, e.message);
- Trace.WriteLine("End");
- }
- protected bool CheckConfiguration(ServiceResponseGetConfiguration sr)
- {
- Trace.WriteLine("init CheckConfiguration");
- bool bResult = true;
- foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
- {
- switch (deviceClass.Type)
- {
- case Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser:
- {
- //look for FuellingPoint in actual configuration
- if (true && forecourtControl.ConfigParam.IsEMSGVersion)
- break;
- if (!ConfigPump(deviceClass.DeviceClass[0]))
- bResult = false;
- }
- break;
- case Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint:
- {
- //look for FuellingPoint in actual configuration
- if (!ConfigPump(deviceClass))
- bResult = false;
- }
- break;
- case Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge:
- case Wayne.FDCPOSLibrary.DeviceType.DT_TankProbe:
- case Wayne.FDCPOSLibrary.DeviceType.DT_PricePole:
- break;
- }
- }
- //look for actual pump in new configuration
- bool bPumpFound = false;
- foreach (FUSIONPump pump in forecourtControl.WritablePumpList)
- {
- bPumpFound = false;
- foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
- {
- if (deviceClass.Type != Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint && deviceClass.Type != Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser)
- continue;
- if (Convert.ToInt32(deviceClass.FPPumpNo) == pump.realId)
- {
- bPumpFound = true;
- break;
- }
- }
- if (!bPumpFound)
- {
- Trace.WriteLine(string.Format("pump {0} not found in new configuration", pump.realId));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} not found in new configuration", pump.Id));
- this.manager_OnDeviceAlarm(this, arg);
- bResult = false;
- }
- }
- Trace.WriteLine("end CheckConfiguration");
- return bResult;
- }
- internal bool ConfigPump(ServiceDeviceClassConfiguration deviceClass)
- {
- bool bResult = true;
- bool bFPFound = false;
- foreach (FUSIONPump pump in this.forecourtControl.WritablePumpList)
- {
- if (pump.realId == Convert.ToInt32(deviceClass.FPPumpNo))
- {
- bFPFound = true;
- bool bNozzleFound = false;
- foreach (ServiceNozzleFPDeviceClassConfiguration FPNozzle in deviceClass.FPNozzle)
- {
- string productNo = (FPNozzle.FPProductId[0].PIFPProductNo != null) ? FPNozzle.FPProductId[0].PIFPProductNo : FPNozzle.FPProductId[0].PIFPProductNo1;
- bNozzleFound = false;
- foreach (FUSIONNozzle nozzle in pump.Nozzles)
- {
- if (nozzle.realId == Convert.ToInt32(FPNozzle.FPNozzleNo))
- {
- bNozzleFound = true;
- if (nozzle.FuelGrade != Convert.ToInt32(productNo))
- {
- Trace.WriteLine(string.Format("pump {0}, nozzle {1}, new product {2}, old product = {3} ", pump.realId, FPNozzle.FPNozzleNo, FPNozzle.FPProductId, nozzle.FuelGrade));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: nozzle {1} new productNo {2} configured productNo {3}", pump.Id, FPNozzle.FPNozzleNo, productNo, nozzle.FuelGrade));
- this.manager_OnDeviceAlarm(this, arg);
- bResult = false;
- }
- break;
- }
- }
- if (!bNozzleFound)
- {
- Trace.WriteLine(string.Format("pump {0}, nozzle {1}, product {2} not found in actual configuration", pump.realId, FPNozzle.FPNozzleNo, FPNozzle.FPProductId));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: new nozzle {1} productNo {2} not configured", pump.Id, FPNozzle.FPNozzleNo, productNo));
- this.manager_OnDeviceAlarm(this, arg);
- bResult = false;
- }
- }
- foreach (FUSIONNozzle nozzle in pump.Nozzles)
- {
- bNozzleFound = false;
- foreach (ServiceNozzleFPDeviceClassConfiguration FPNozzle in deviceClass.FPNozzle)
- {
- if (nozzle.realId == Convert.ToInt32(FPNozzle.FPNozzleNo))
- {
- bNozzleFound = true;
- break;
- }
- }
- if (!bNozzleFound)
- {
- Trace.WriteLine(string.Format("pump {0}, nozzle {1}, product {2} not found in new configuration", pump.realId, nozzle.Id, nozzle.FuelGrade));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0}: nozzle {1} productNo {2} not found in new configuration", pump.Id, nozzle.Id, nozzle.FuelGrade));
- this.manager_OnDeviceAlarm(this, arg);
- bResult = false;
- break;
- }
- }
- break;
- }
- }
- if (!bFPFound)
- {
- bResult = false;
- Trace.WriteLine(string.Format("pump {0} not found in old configuration", deviceClass.FPPumpNo));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, Convert.ToInt32(deviceClass.FPPumpNo), (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} not found in previous configuration", deviceClass.FPPumpNo));
- this.manager_OnDeviceAlarm(this, arg);
- }
- Trace.WriteLine("end - true");
- return bResult;
- }
- internal bool Connect(string connectionString)
- {
- //if (this.debugLogger.IsActive())
- //{
- // this.debugLogger.Add("Connect, connectionString=" + connectionString);
- //}
- //this.connectionStringParamDict = Strings.ParseConnectionString(connectionString);
- return this.ifsfManager.clientSocket.Connect(connectionString);
- //this.forecourtControl.WritableClientId = this.clientSocket.ClientId;
- //this.forecourtControl.WritableClientName = this.clientSocket.ClientName;
- }
- private void DestroyObjects(bool bDisconnect)
- {
- foreach (FUSIONPump pump in this.forecourtControl.WritablePumpList)
- {
- pump.Dispose();
- }
- this.forecourtControl.WritablePumpList.Clear();
- this.forecourtControl.WritableTankGroupList.Clear();
- this.forecourtControl.WritablePricePoleList.Clear();
- this.forecourtControl.WritableFuelPriceList.Clear();
- if (bDisconnect)
- ifsfManager.Disconnect();
- }
- internal void Disconnect()
- {
- if (FUSIONOptFactory.getOptBridge() != null)
- {
- foreach (IOpt opt in ((FUSIONOptBridge)(FUSIONOptFactory.getOptBridge())).Opts)
- {
- if (((FUSIONOpt)opt).managedBy == OPTManagedBy.SINP)
- ((FUSIONOpt)opt).optTCP.Disconnect();
- else
- this.ifsfManager.OptRemove(opt.Id, null, null, null);
- }
- }
- this.ifsfManager.LogOff();
- //this.DestroyObjects();
- }
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (!this.disposed)
- {
- this.disposed = true;
- if (disposing)
- {
- if (this.configurationReader != null)
- this.configurationReader.Dispose();
- if (Trace.debugLogger != null)
- Trace.debugLogger.Dispose();
- }
- }
- }
- ~FUSIONManager()
- {
- this.Dispose(false);
- }
- public FUSIONPump GetPumpById(int pumpNumber)
- {
- foreach (FUSIONPump pump in this.forecourtControl.Pumps)
- {
- if (pump.realId == pumpNumber)
- {
- return pump;
- }
- }
- return null;
- }
- public FUSIONTankGroup getTankGroupByIndex(int iTankGroupId)
- {
- foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
- {
- if (tankgroup.Id == iTankGroupId)
- {
- return tankgroup;
- }
- }
- return null;
- }
- public FUSIONTank getTankByIndex(int iTankGroupId, int iTankId)
- {
- foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
- {
- if (tankgroup.Id == iTankGroupId)
- {
- foreach (FUSIONTank tank in tankgroup.Tanks)
- {
- if (tank.Id /*oppure tank.realId ?*/ == iTankId)
- return tank;
- }
- }
- }
- return null;
- }
- public FUSIONTank getTankByIndex(int iTankId)
- {
- foreach (FUSIONTankGroup tankgroup in this.forecourtControl.TankGroups)
- {
- foreach (FUSIONTank tank in tankgroup.Tanks)
- {
- if (tank.Id /*oppure tank.realId ?*/ == iTankId)
- return tank;
- }
- }
- return null;
- }
- private void InitializeOrhcestrator()
- {
- Trace.WriteLine("InitializeOrhcestrator init");
- if (!this.disposed) //&& (this.clientSocket.ConnectionState == DeviceConnectionState.Connected))
- {
- if (!this.initializationStatus.ConfigurationDataRead)
- {
- if (!this.initializationStatus.ReadingConfigurationData)
- {
- Trace.WriteLine("calling ReadConfigurationDataAsync");
- shouldSetConnected = false;
- this.initializationStatus.ReadingConfigurationData = true;
- ifsfManager.isConfigRead = false;
- this.configurationReader.ForceStart = true;
- this.configurationReader.ReadConfigurationDataAsync();
- }
- else
- Trace.WriteLine("ReadingConfigurationData");
- }
- }
- if (shouldSetConnected)
- {
- Trace.WriteLine("ConfigurationDataRead");
- this.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
- }
- }
- internal void RequestFillingData(int pumpNumber, bool onlyCurrentFuelling)
- {
- this.ifsfManager.GetCurrentFuellingStatus(pumpNumber, null, null, null);
- }
- // Properties
- public string EntitySubType
- {
- get
- {
- return "";
- }
- }
- public string EntityType
- {
- get
- {
- return "FUSIONManager";
- }
- }
- /// <summary>
- /// This is used by the logger and should never be set by implementing classes
- /// </summary>
- public string FullEntityName { get; set; }
- public int Id
- {
- get
- {
- return this.forecourtControl.Id;
- }
- }
- public IIdentifiableEntity ParentEntity
- {
- get
- {
- return null;
- }
- }
- // Nested Types
- private class ConfigurationReader : IDisposable
- {
- // Fields
- private bool cancelled;
- private FUSIONManager nfsManager;
- private AutoResetEvent readingDoneEvent = new AutoResetEvent(false);
- private bool running;
- // Methods
- public ConfigurationReader(FUSIONManager nfsManager)
- {
- this.nfsManager = nfsManager;
- }
- public void Cancel()
- {
- if (this.running)
- {
- this.cancelled = true;
- }
- }
- public void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected void Dispose(bool disposing)
- {
- this.Cancel();
- if (disposing)
- {
- this.readingDoneEvent.Close();
- this.readingDoneEvent = null;
- }
- }
- public bool Running
- {
- get { return running; }
- }
- public bool ForceStart { get; set; }
- ~ConfigurationReader()
- {
- this.Dispose(false);
- }
- private void ReadConfigurationData(object o)
- {
- Trace.WriteLine("ReadConfigurationData - init");
- try
- {
- FUSIONManager parentEntity = o as FUSIONManager;
- //TLG parentEntity.ifsfManager.GetConfiguration(null, null, null);
- parentEntity.ifsfManager.GetProductTable(null, null, null);
- }
- finally
- {
- }
- Trace.WriteLine("ReadConfigurationData - end");
- }
- public void ReadConfigurationDataAsync()
- {
- Trace.WriteLine(string.Format("ReadConfigurationDataAsync - Running={0}, ForceStart={1}", running, ForceStart));
- if (ForceStart || (!this.running))
- {
- Trace.WriteLine("ReadConfigurationDataAsync - Start ReadConfigurationData");
- ForceStart = false;
- this.cancelled = false;
- this.readingDoneEvent.Reset();
- this.running = true;
- Trace.WriteLine("ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReadConfigurationData), this.nfsManager);");
- ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReadConfigurationData), this.nfsManager);
- }
- else
- {
- Trace.WriteLine("ReadConfigurationDataAsync() was called already!");
- }
- }
- public void ReadProductTable(object o)
- {
- if (o == null)
- return;
- GetProductTableParam param = (GetProductTableParam)o;
- ServiceResponseGetProductTable sr = param.sr;
- FUSIONManager parentEntity = param.nfsManager;
- if (sr == null || (sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString() && sr.OverallResult != "") ||
- sr.FDCdata == null || sr.FDCdata.Length == 0 ||
- sr.FDCdata[0].FuelProducts == null || sr.FDCdata[0].FuelProducts.Length == 0 ||
- sr.FDCdata[0].FuelProducts[0].Product == null || sr.FDCdata[0].FuelProducts[0].Product.Length == 0)
- {
- Trace.WriteLine(string.Format("errore in ServiceResponseGetProductTable"));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, "Error in GetProductTable");
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
- this.running = false;
- this.readingDoneEvent.Set();
- return;
- }
- try
- {
- try
- {
- if (parentEntity.forecourtControl.WritableFuelPriceList.Count > 0)
- {
- bool bAlarm = false;
- Trace.WriteLine(string.Format("forecourtControl.WritableFuelPriceList.Count = {0}, verify prices", parentEntity.forecourtControl.WritableFuelPriceList.Count));
- //verify product numberl
- if (parentEntity.forecourtControl.WritableFuelPriceList.Count != sr.FDCdata[0].FuelProducts[0].Product.Length)
- {
- Trace.WriteLine(string.Format("forecourtControl.WritableFuelPriceList.Count = {0}, sr.FDCData[0].FuelProducts.Lenght = {1}", parentEntity.forecourtControl.WritableFuelPriceList.Count, sr.FDCdata[0].FuelProducts.Length));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product number received ({0}) differs from product number cofigured ({1})", sr.FDCdata[0].FuelProducts[0].Product.Length, parentEntity.forecourtControl.WritableFuelPriceList.Count));
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- bAlarm = true;
- }
- foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
- {
- bool bFound = false;
- foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
- {
- if (Convert.ToInt32(product.ProductNo) == fuelprice.FuelGrade)
- {
- bFound = true;
- break;
- }
- }
- if (!bFound)
- {
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product {0} not present in new configuration", fuelprice.FuelGrade));
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- bAlarm = true;
- break;
- }
- }
- foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
- {
- bool bFound = false;
- foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
- {
- if (Convert.ToInt32(product.ProductNo) == fuelprice.FuelGrade)
- {
- bFound = true;
- break;
- }
- }
- if (!bFound)
- {
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("GetProductTable: product {0} not present in previous configuration", product.ProductNo));
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- bAlarm = true;
- break;
- }
- }
- return;
- }
- foreach (ServiceResponseProductGetProductTable product in sr.FDCdata[0].FuelProducts[0].Product)
- {
- FUSIONFuelPrice fuelprice = new FUSIONFuelPrice(Convert.ToInt32(product.ProductNo));
- parentEntity.forecourtControl.WritableFuelPriceList.Add(fuelprice);
- }
- }
- catch (Exception exception)
- {
- //managed in readConfiguration
- //initializationStatus.ReadingConfigurationData = false;
- }
- }
- finally
- {
- }
- //if (!nfsManager.forecourtControl.ConfigParam.IsEMSGVersion)
- {
- parentEntity.ifsfManager.GetDSPConfiguration(null, null, null);
- }
- //else
- //{
- // parentEntity.ifsfManager.GetConfiguration(null, null, null);
- //}
- Trace.WriteLine("end");
- }
- public bool ReadConfiguration(object o)
- {
- Trace.WriteLine("init ReadConfiguration");
- if (o == null)
- return false;
- GetConfigurationParam param = (GetConfigurationParam)o;
- ServiceResponseGetConfiguration sr = param.sr;
- FUSIONManager parentEntity = param.nfsManager;
- bool end = true;
- try
- {
- if (sr == null || ((sr.RequestType == "GetDSPConfiguration" || sr.RequestType == "GetConfiguration") && sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString()) ||
- (sr.RequestType == "GetTLGConfiguration" && sr.OverallResult != FDCPOSLibrary.OverallResult.Success.ToString() && sr.OverallResult != FDCPOSLibrary.OverallResult.NoData.ToString() && sr.OverallResult != FDCPOSLibrary.OverallResult.WrongConfiguration.ToString()) ||
- sr.FDCdata == null || sr.FDCdata.Length == 0 ||
- ((sr.RequestType == "GetDSPConfiguration" || sr.RequestType == "GetConfiguration") && (sr.FDCdata[0].DeviceClass == null || sr.FDCdata[0].DeviceClass.Length == 0)))
- {
- Trace.WriteLine(string.Format("end ReadConfiguration - errore in ServiceResponseGetConfiguration"));
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, 0, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("error in Getconfiguration"));
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
- return false;
- }
- try
- {
- if (parentEntity.forecourtControl.WritablePumpList.Count > 0 && (sr.RequestType == "GetConfiguration" || sr.RequestType == "GetDSPConfiguration"))
- {
- Trace.WriteLine(string.Format("end ReadConfiguration - forecourtControl.WritablePumpList.Count = {0}, call CheckConfiguration", parentEntity.forecourtControl.WritablePumpList.Count));
- if (!parentEntity.CheckConfiguration(sr))
- {
- Trace.WriteLine(string.Format("Configurazione Fusion != Configurazione interna, send Alarm"));
- //TODO SendAlarm
- }
- return false;
- }
- else if (parentEntity.forecourtControl.WritableTankGroupList.Count > 0 && sr.RequestType == "GetTLGConfiguration")
- {
- Trace.WriteLine(string.Format("forecourtControl.WritablePumpList.Count = {0}, call CheckConfiguration", parentEntity.forecourtControl.WritablePumpList.Count));
- if (!parentEntity.CheckConfiguration(sr))
- {
- Trace.WriteLine(string.Format("Configurazione Fusion != Configurazione interna, send Alarm"));
- //TODO SendAlarm
- return false;
- }
- }
- if (sr.FDCdata[0].DeviceClass != null)
- {
- foreach (ServiceDeviceClassConfiguration deviceClass in sr.FDCdata[0].DeviceClass)
- {
- switch (deviceClass.Type)
- {
- case Wayne.FDCPOSLibrary.DeviceType.DT_FuelDispenser:
- {
- //if (nfsManager.forecourtControl.ConfigParam.IsEMSGVersion)
- //{
- // break;
- //}
- ReadPumpConfiguration(parentEntity, deviceClass.DeviceClass[0]);
- }
- break;
- case Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint:
- {
- ReadPumpConfiguration(parentEntity, deviceClass);
- }
- break;
- case Wayne.FDCPOSLibrary.DeviceType.DT_TankLevelGauge: //DT_TankProbe:
- {
- Trace.WriteLine(string.Format("DT_TankLevelGauge.Add id={0}", deviceClass.DeviceID));
- foreach (ServiceDeviceClassConfiguration nestedDevice in deviceClass.DeviceClass)
- {
- // only 1 tankgroup per product will be created
- FUSIONTankGroup tankgroup = parentEntity.getTankGroupByIndex(Convert.ToInt32(nestedDevice.TPProductNo));
- if (tankgroup == null)
- {
- tankgroup = new FUSIONTankGroup(parentEntity, Convert.ToInt32(nestedDevice.TPProductNo), Convert.ToInt32(nestedDevice.TPProductNo));
- parentEntity.forecourtControl.WritableTankGroupList.Add(tankgroup);
- }
- FUSIONTank tank = new FUSIONTank(parentEntity, Convert.ToInt32(nestedDevice.TPTankNo), tankgroup);
- tankgroup.WritableTankList.Add(tank);
- Trace.WriteLine(string.Format("WritableTankList.Add tank={0}", tank.realId));
- // TODO assign tank properties
- // ...
- }
- }
- break;
- }
- }
- }
- if (this.cancelled)
- {
- Trace.WriteLine("end ReadConfiguration - this.cancelled");
- return false;
- }
- if (sr.RequestType == "GetDSPConfiguration")
- {
- //parentEntity.ifsfManager.GetTLGConfiguration(null, null, null);
- end = false;
- //return false;
- }
- //parentEntity.initializationStatus.ConfigurationDataRead = true;
- }
- catch (Exception exception)
- {
- parentEntity.initializationStatus.ReadingConfigurationData = false;
- Trace.WriteLine(string.Format("Exception! : {0}", exception.Message));
- //Logger.AddEntry(new ExceptionLogEntry(parentEntity, ErrorLogSeverity.RecoverableDataLoss, "Exception in ReadConfigurationData ", exception));
- }
- finally
- {
- if (end)
- {
- Trace.WriteLine("ReadConfiguration finally");
- this.running = false;
- this.readingDoneEvent.Set();
- }
- }
- //FG, MAR-15-2011, bug fix #28041; trigger to GetConfiguration again if there's no pump on FM.
- if (parentEntity.forecourtControl.WritablePumpList.Count == 0)
- {
- return false;
- }
- parentEntity.shouldSetConnected = false;
- parentEntity.InitializeOrhcestrator();
- // TODO codice temporaneo if (this.OnConnectionStateChange != null)
- parentEntity.initializationStatus.ConfigurationDataRead = true;
- Trace.WriteLine("WritableConnectionState = DeviceConnectionState.Connected");
- parentEntity.forecourtControl.WritableConnectionState = DeviceConnectionState.Connected;
- }
- finally
- {
- if (end)
- {
- Trace.WriteLine("ReadConfiguration finally");
- this.running = false;
- this.readingDoneEvent.Set();
- }
- }
- Trace.WriteLine("ReadConfiguration - end");
- return true;
- }
- internal void ReadPumpConfiguration(FUSIONManager parentEntity, ServiceDeviceClassConfiguration deviceClass)
- {
- FUSIONPump pump = new FUSIONPump(parentEntity);
- pump.WritableParentDevice = parentEntity.forecourtControl;
- pump.WritableCapFuelGradeSelected = false;
- pump.WritableCapNozzleDetection = false;
- pump.WritableCapSetLight = false;
- pump.WritableCapSuspendFuelling = false;
- pump.WritablePumpId = Convert.ToInt32(deviceClass.FPPumpNo);
- pump.WritableDeviceName = "Pump " + deviceClass.FPPumpNo;
- foreach (ServiceNozzleFPDeviceClassConfiguration FPnozzle in deviceClass.FPNozzle)
- {
- string productNo = (FPnozzle.FPProductId[0].PIFPProductNo != null) ? FPnozzle.FPProductId[0].PIFPProductNo : FPnozzle.FPProductId[0].PIFPProductNo1;
- FUSIONNozzle nozzle = new FUSIONNozzle(Convert.ToInt32(FPnozzle.FPNozzleNo), pump);
- nozzle.FuelGrade = Convert.ToInt32(productNo);
- bool bFound = false;
- foreach (FUSIONFuelPrice fuelprice in parentEntity.forecourtControl.WritableFuelPriceList)
- {
- if (fuelprice.FuelGrade == Convert.ToInt32(productNo))
- {
- bFound = true;
- break;
- }
- }
- if (!bFound)
- {
- DeviceAlarmEventArgs arg = new DeviceAlarmEventArgs(Wayne.FDCPOSLibrary.DeviceType.DT_FuellingPoint, pump.realId, (int)Wayne.FDCPOSLibrary.ErrorCode.ERRCD_BADCONF, string.Format("Pump {0} nozzle {1}: product {2} is not a valid productNo", pump.Id, nozzle.Id, FPnozzle.FPProductId[0].PIFPProductNo));
- parentEntity.manager_OnDeviceAlarm(parentEntity, arg);
- }
- pump.WritableNozzleList.Add(nozzle);
- }
- parentEntity.forecourtControl.WritablePumpList.Add(pump);
- Trace.WriteLine(string.Format("WritablePumpList.Add pump={0}", pump.realId));
- }
- public class GetProductTableParam
- {
- public FUSIONManager nfsManager;
- public ServiceResponseGetProductTable sr;
- public GetProductTableParam(ServiceResponseGetProductTable _sr, FUSIONManager _nfsManager)
- {
- sr = _sr;
- nfsManager = _nfsManager;
- }
- }
- public class GetConfigurationParam
- {
- public FUSIONManager nfsManager;
- public ServiceResponseGetConfiguration sr;
- public GetConfigurationParam(ServiceResponseGetConfiguration _sr, FUSIONManager _nfsManager)
- {
- sr = _sr;
- nfsManager = _nfsManager;
- }
- }
- }
- }
- }
|