123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Xml.Linq;
- using System.Xml.Serialization;
- using Wayne.FDCPOSLibrary;
- using Wayne.FDCPOSLibrary.Configuration;
- using Wayne.Lib;
- using Wayne.Lib.Log;
- namespace Wayne.ForecourtControl.Fusion
- {
- public class TCPListenerThread : DisposableBase
- {
- public bool bRunning = false;
- private bool bTerminate = false;
- TcpListener tcpListener = null;
- IFSFManager ifsfManager = null;
- string name = "";
- private readonly DebugLogger debugLogger;
- public TCPListenerThread(TcpListener _listener, IFSFManager _ifsfManager, string _name)
- {
- tcpListener = _listener;
- ifsfManager = _ifsfManager;
- name = _name;
- debugLogger = ifsfManager.DebugLogger;
- }
- private void DebugLog(string s)
- {
- if (debugLogger.IsActive())
- debugLogger.Add(s);
- }
- public void TCPListenerThreadProc()
- {
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: init", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID));
- TcpClient tcpclient = null;
- bRunning = true;
- try
- {
- if (tcpListener != null)
- {
- DebugLog("tcpListener starting");
- tcpListener.Start();
- DebugLog("tcpListener started");
- }
- }
- catch (Exception ex)
- {
- DebugLog("TCPListenerThreadProc: Exception tcpListener.Start! " + ex.ToString());
- bRunning = false;
- return;
- }
- bTerminate = false;
- string sbuffer = "";
- while (!bTerminate)
- {
- try
- {
- if (tcpclient == null && tcpListener != null)
- {
- DebugLog("TCPListenerThreadProc: TcpClient Accepting");
- tcpclient = tcpListener.AcceptTcpClient();
- DebugLog("TcpClient Accepted");
- }
- else
- {
- NetworkStream networkStream;
- if (tcpListener != null)
- networkStream = tcpclient.GetStream();
- else
- networkStream = ifsfManager.clientSocket.socketReqChannelA.GetStream();
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: {2} got stream ...", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID, this.name));
- StringBuilder sb = new StringBuilder();
- // read header
- int headerLength, encrStart;
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
- {
- headerLength = Define.HeaderLength + Define.MD5EncriptionLength;
- encrStart = Define.HeaderLength;
- }
- else if (this.ifsfManager.clientSocket.headerEncryption != 0)
- {
- headerLength = Define.HeaderLength + Define.EncriptionTypeLength + Define.MD5EncriptionLength;
- encrStart = Define.HeaderLength + Define.EncriptionTypeLength;
- }
- else
- {
- headerLength = Define.HeaderLength + Define.EncriptionTypeLength;
- encrStart = Define.HeaderLength + Define.EncriptionTypeLength;
- }
- var header = new byte[headerLength];
- DebugLog(string.Format("TCPListenerThreadProc: header length={0}", header.GetLength(0)));
- int nread, nreadtot = 0;
- do
- {
- DebugLog("TCPListenerThreadProc: reading ...");
- nread = networkStream.Read(header, nreadtot, (headerLength) - nreadtot);
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: read '{2}' bytes", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID, nread));
- nreadtot += nread;
- if (nread == 0)
- Thread.Sleep(500);
- }
- while (nreadtot < headerLength);
- int msglength = getMsgLength(header);
- // read message
- var buffer = new byte[msglength];
- DebugLog(string.Format("TCPListenerThreadProc: buffer msg length={0}", buffer.GetLength(0)));
- nreadtot = 0;
- do
- {
- DebugLog("TCPListenerThreadProc: reading ...");
- nread = networkStream.Read(buffer, nreadtot, msglength - nreadtot);
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: read '{2}' bytes", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID, nread));
- nreadtot += nread;
- if (nread == 0)
- Thread.Sleep(500);
- }
- while (nreadtot < msglength);
- sb.Remove(0, sb.Length);
- sb.Append(Encoding.UTF8.GetString(buffer, 0, nreadtot));
- string myString = Encoding.ASCII.GetString(buffer, 0, msglength);
- string logString;
- try
- {
- logString = XElement.Parse(myString).ToString();
- }
- catch
- {
- logString = myString;
- }
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: read '{2}' bytes:\r\n{3}", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID, msglength, logString));
- sbuffer += sb.ToString();
- bool bEnd = false;
- do
- {
- var indexEndMsgSR = sbuffer.IndexOf("</ServiceResponse>");
- var indexEndFDCMsg = sbuffer.IndexOf("</FDCMessage>");
- string sEndmsg;
- int indexEnd;
- if (indexEndMsgSR >= 0 && indexEndFDCMsg >= 0)
- {
- indexEnd = System.Math.Min(indexEndMsgSR, indexEndFDCMsg);
- if (indexEndMsgSR < indexEndFDCMsg)
- {
- sEndmsg = "</ServiceResponse>";
- }
- else
- {
- sEndmsg = "</FDCMessage>";
- }
- }
- else if (indexEndMsgSR >= 0 && indexEndFDCMsg < 0)
- {
- indexEnd = indexEndMsgSR;
- sEndmsg = "</ServiceResponse>";
- }
- else if (indexEndFDCMsg > 0)
- {
- indexEnd = indexEndFDCMsg;
- sEndmsg = "</FDCMessage>";
- }
- else
- {
- indexEnd = sbuffer.IndexOf("/>");
- sEndmsg = "/>";
- }
- if (indexEnd >= 0)
- {
- var smsg = sbuffer.Substring(0, indexEnd + sEndmsg.Length);
- sbuffer = sbuffer.Substring(indexEnd + sEndmsg.Length);
- var result = OverallResult.Success;
- if (this.ifsfManager.clientSocket.headerEncryption != 0)
- {
- bool error = checkHash(smsg, encrStart, header);
- if (error)
- {
- DebugLog(error ? "ValidationError" : "check OK");
- int i = 0;
- while (i < sbuffer.Length && (sbuffer[i] == '\n' || sbuffer[i] == ' ' || sb[i] == '\t'))
- i++;
- if (i > 0)
- {
- DebugLog(string.Format("try to verify msg with '\\n' or ' ' ending chars ('{0}' found)", i));
- smsg += sbuffer.Substring(0, i);
- sbuffer = sbuffer.Substring(0, sbuffer.Length - i);
- error = checkHash(smsg, encrStart, header);
- DebugLog(error ? "ValidationError" : "check OK");
- if (error)
- result = OverallResult.ValidationError;
- }
- else
- result = OverallResult.ValidationError;
- }
- }
- if (smsg.Length > 0)
- {
- int i = 0;
- while (i < sbuffer.Length && (sbuffer[i] == '\n' || sbuffer[i] == ' ' || sb[i] == '\t'))
- i++;
- if (i > 0)
- {
- DebugLog(string.Format("try to verify msg with '\\n' or ' ' ending chars ('{0}' found)", i));
- smsg += sbuffer.Substring(0, i);
- sbuffer = sbuffer.Substring(0, sbuffer.Length - i);
- DebugLog(string.Format("smsg={0}", smsg));
- DebugLog(string.Format("sbuffer={0}", sbuffer));
- }
- if (smsg.IndexOf("<ServiceResponse") >= 0)
- ifsfManager.ReadResponse(smsg, msglength, ref result);
- else
- ifsfManager.ReadMessage(smsg, msglength, ref result);
- }
- }
- else bEnd = true;
- } while (!bEnd);
- }
- }
- catch (SocketException sex)
- {
- DebugLog("Exception TCPListenerThreadProc: " + sex.ToString());
- tcpclient = null;
- if (sex.ErrorCode == 10049)
- ifsfManager.Disconnect();
- Thread.Sleep(1000);
- }
- catch (Exception ex)
- {
- DebugLog("Exception TCPListenerThreadProc! " + ex.ToString());
- tcpclient = null;
- ifsfManager.Disconnect();
- Thread.Sleep(1000);
- }
- }
- if (tcpListener != null)
- tcpListener.Stop();
- bRunning = false;
- DebugLog(string.Format("TCPListenerThreadProc Id={0}, WId={1}: end", this.ifsfManager.clientSocket.Id, this.ifsfManager.clientSocket.workstationID));
- }
- private bool checkHash(string smsg, int encrStart, byte[] header)
- {
- MD5Crypter crypter = new MD5Crypter();
- byte[] datahash = crypter.ComputeHash(System.Text.Encoding.UTF8.GetBytes(smsg + MD5Crypter.passphrase));
- var inputhash = new byte[Define.MD5EncriptionLength];
- for (int i = encrStart; i < Define.MD5EncriptionLength + encrStart; i++)
- inputhash[i - encrStart] = header[i];
- bool error = false;
- for (int i = 0; i < Define.MD5EncriptionLength; i++)
- if (inputhash[i] != datahash[i])
- {
- DebugLog(string.Format("ValidationError: inputhash={0}, datahash={1}", System.Text.Encoding.UTF8.GetString(inputhash, 0, inputhash.GetLength(0)), System.Text.Encoding.UTF8.GetString(datahash, 0, datahash.GetLength(0))));
- DebugLog(string.Format("ValidationError: inputhash[{0}]={1} != datahash[{2}]={3}", i, inputhash[i], i, datahash[i]));
- error = true;
- break;
- }
- return error;
- }
- private int getMsgLength(byte[] header)
- {
- int length = 0;
- for (int pos = 1; pos <= Define.HeaderLength; pos++)
- {
- length |= header[pos - 1] << (Define.HeaderLength - pos) * 8;
- }
- return length;
- }
- protected override void DoDispose()
- {
- bTerminate = true;
- }
- }
- public class IFSFSockets : IIdentifiableEntity, IDisposable//, IConnectable
- {
- private TcpClient _socketReqChannelA;
- public TcpClient socketReqChannelA
- {
- get { return _socketReqChannelA; }
- }
- private TcpListener _socketRespChannelB;
- public TcpListener socketRespChannelB
- {
- get { return _socketRespChannelB; }
- }
- private TcpListener _socketUnsolicitedChannelC;
- public TcpListener socketUnsolicitedChannelC
- {
- get { return _socketUnsolicitedChannelC; }
- }
- private TcpClient _socketReqChannelConfig;
- public TcpClient socketReqChannelConfig
- {
- get { return _socketReqChannelConfig; }
- }
- public TCPListenerThread respChannelBThreadObj;
- public Thread respChannelBThread;
- public TCPListenerThread unsolicitedChannelCThreadObj;
- public Thread unsolicitedChannelCThread;
- public TCPListenerThread respChannelConfigThreadObj;
- public Thread respChannelConfigThread;
- IFSFManager ifsfManager;
- IFSFMessages _ifsfMessages;
- public IFSFMessages ifsfMessages
- {
- get { return _ifsfMessages; }
- }
- private string _applicationSender;
- public string applicationSender
- {
- get { return _applicationSender; }
- }
- private string _workstationID;
- public string workstationID
- {
- get { return _workstationID; }
- }
- private string _sIPAddress;
- public string sIPAddress
- {
- get { return _sIPAddress; }
- }
- private string _sIPAddress2;
- public string sIPAddress2
- {
- get { return _sIPAddress2; }
- }
- private int _iIPPortA;
- public int iIPPortA
- {
- get { return _iIPPortA; }
- }
- private int _iIPPortB;
- public int iIPPortB
- {
- get { return _iIPPortB; }
- }
- private int _iIPPortC;
- public int iIPPortC
- {
- get { return _iIPPortC; }
- }
- private long _heartbeatInterval;
- public long heartbeatInterval
- {
- get { return _heartbeatInterval; }
- }
- private long _heartbeatTimeout;
- public long heartbeatTimeout
- {
- get { return _heartbeatTimeout; }
- }
- private long _runningFuellingTimeout = 2000;
- public long runningFuellingTimeout
- {
- get { return _runningFuellingTimeout; }
- }
- private long _headerEncryption;
- public long headerEncryption
- {
- get { return _headerEncryption; }
- set { _headerEncryption = value; }
- }
- public bool logOnSendCalled = false;
- private byte[][] _validationInfo;
- public byte[][] validationInfo
- {
- get { return _validationInfo; }
- set { _validationInfo = value; }
- }
- private string _posInfo = "";
- public string posInfo
- {
- get { return _posInfo; }
- set { _posInfo = value; }
- }
- private bool disposed;
- private int id;
- private IIdentifiableEntity parentEntity;
- private DeviceConnectionState _mainConnectionState = DeviceConnectionState.Disconnected;
- public DeviceConnectionState mainConnectionState
- {
- get { return _mainConnectionState; }
- set
- {
- if (_mainConnectionState != value)
- {
- _mainConnectionState = value;
- if (OnConnectionStateChange != null)
- {
- OnConnectionStateChange.Invoke(this, new ConnectionChangedEventArgs(mainConnectionState));
- }
- }
- }
- }
- public event EventHandler<ConnectionChangedEventArgs> OnConnectionStateChange;
- public event EventHandler OnResponseTimeout;
- private readonly DebugLogger debugLogger;
- public IFSFSockets(int id, IFSFManager _ifsfManager)
- {
- this.id = id;
- this.parentEntity = (IIdentifiableEntity)ifsfManager;
- ifsfManager = _ifsfManager;
- debugLogger = ifsfManager.DebugLogger;
- ConfigurationParams configParam = new ConfigurationParams(debugLogger);
- this._applicationSender = configParam.applicationSender;
- this._workstationID = configParam.workstationID;
- this._sIPAddress = configParam.sIPAddress;
- this._sIPAddress2 = configParam.sIPAddress2;
- this._iIPPortA = configParam.iIPPortA;
- this._iIPPortB = configParam.iIPPortB;
- this._iIPPortC = configParam.iIPPortC;
- this._heartbeatTimeout = configParam.heartbeatTimeout;
- this._heartbeatInterval = configParam.heartbeatInterval;
- this._headerEncryption = configParam.headerEncryption;
- _ifsfMessages = new IFSFMessages(this, debugLogger);
- _ifsfMessages.OnIFSFSMessageEnqueued += new EventHandler(ifsfmessages_OnMessageEnqueued);
- _ifsfMessages.OnResponseTimeout += new EventHandler(ifsfmessages_OnResponseTimeout);
- }
- private void DebugLog(string s)
- {
- if (debugLogger.IsActive())
- debugLogger.Add(s);
- }
- private bool getConnectionParams(string connectionString)
- {
- Dictionary<string, string> connectionStringParamDict;
- connectionStringParamDict = Strings.ParseConnectionString(connectionString);
- string key = "";
- key = "IdShift";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[this.Id])).manager.IdShift = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IdShift: {0}", ex.ToString()));
- }
- }
- key = "IdPumpShift";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[this.Id])).manager.IdPumpShift = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IdPumpShift: {0}", ex.ToString()));
- }
- }
- key = "IdNozzleShift";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[this.Id])).manager.IdNozzleShift = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IdNozzleShift: {0}", ex.ToString()));
- }
- }
- key = "IdTankShift";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[this.Id])).manager.IdTankShift = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IdTankShift: {0}", ex.ToString()));
- }
- }
- key = "FuelGradeShift";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- ((FUSIONForecourtControl)(FUSIONFactory.fusionForecourtControlList[this.Id])).manager.FuelGradeShift = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading FuelGradeShift: {0}", ex.ToString()));
- }
- }
- key = "Host";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- this._sIPAddress = connectionStringParamDict[key];
- key = "Host2";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- this._sIPAddress2 = connectionStringParamDict[key];
- key = "Port";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._iIPPortA = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IPPortA: {0}", ex.ToString()));
- }
- }
- key = "PortB";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._iIPPortB = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IPPortB: {0}", ex.ToString()));
- }
- }
- key = "PortC";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._iIPPortC = Convert.ToInt32(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading IPPortC: {0}", ex.ToString()));
- }
- }
- //key = "workstationID";
- //if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- // this._applicationSender = connectionStringParamDict[key];
- //else
- //{
- // key = "ClientName";
- // if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- // this._applicationSender = connectionStringParamDict[key];
- //}
- //key = "applicationSender";
- //if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- // this._workstationID = connectionStringParamDict[key];
- //else
- //{
- // key = "ClientId";
- // if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- // this._workstationID = connectionStringParamDict[key];
- //}
- key = "ClientId";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- this._workstationID = connectionStringParamDict[key];
- this._applicationSender = connectionStringParamDict[key];
- }
- else
- {
- key = "applicationSender";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- this._workstationID = connectionStringParamDict[key];
- this._applicationSender = connectionStringParamDict[key];
- }
- }
- key = "heartbeatInterval";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._heartbeatInterval = Convert.ToInt64(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading heartbeatInterval: {0}", ex.ToString()));
- }
- }
- key = "heartbeatTimeout";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._heartbeatTimeout = Convert.ToInt64(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading _heartbeatTimeout: {0}", ex.ToString()));
- }
- }
- key = "runningFuellingTimeout";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._runningFuellingTimeout = Convert.ToInt64(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading _runningFuellingTimeout: {0}", ex.ToString()));
- }
- }
- key = "headerEncryption";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- try
- {
- this._headerEncryption = Convert.ToInt16(connectionStringParamDict[key]);
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading _headerEncryption: {0}", ex.ToString()));
- }
- }
- key = "posInfo";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- this._posInfo = connectionStringParamDict[key];
- key = "validationInfo";
- if (connectionStringParamDict.ContainsKey(key) && connectionStringParamDict[key] != null && connectionStringParamDict[key] != "")
- {
- string[] validationInfoArray;
- try
- {
- //validationInfoArray = connectionStringParamDict[key].Split('@');
- //this._validationInfo = new byte[validationInfoArray.Length][];
- //int i = 0;
- //foreach(string s in validationInfoArray)
- //{
- string s = connectionStringParamDict[key];
- string elem;
- while (s.Length > 0)
- {
- if (s.IndexOf("@@@") >= 0)
- {
- elem = s.Substring(0, s.IndexOf("@@@"));
- s = s.Substring(s.IndexOf("@@@") + 3);
- }
- else
- {
- elem = s;
- s = "";
- }
- //DESCrypter descrypter = new DESCrypter();
- //byte[] dataencrypted = descrypter.Encrypt(elem);
- byte[] b = System.Text.Encoding.Unicode.GetBytes(elem);
- this.ifsfManager.LogOnAddValidationInfo(b);
- //IFSFManager.ArrayResize<byte[]>(ref _validationInfo, (_validationInfo != null) ? _validationInfo.Length + 1 : 1);
- //this._validationInfo[_validationInfo.Length-1] = new byte[dataencrypted.Length];
- //this._validationInfo[_validationInfo.Length-1] = dataencrypted;
- }
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Exception reading _validationInfo: {0}", ex.ToString()));
- }
- }
- return true;
- }
- public void SendConfig(string commandFileName)
- {
- if (this.mainConnectionState == DeviceConnectionState.Connected)
- {
- int iIPPortConfig = Convert.ToInt32(IniFile.IniReadValue(ConfigurationParams.getSINPPath("ini\\") + @"ForecourtServer.ini", "FUSION-Connection", "IPPortConfig"));
- try
- {
- IPAddress serverIPAddress = null;
- IPEndPoint endPoint = null;
- if (iIPPortConfig != this._iIPPortA)
- {
- int socketTimeout = 3000;
- bool noDelay = true;
- try
- {
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "SocketTimeout");
- if (sValue.Length > 0)
- socketTimeout = Convert.ToInt32(sValue);
- sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "NoDelay");
- if (sValue.Length > 0 && sValue == "0")
- noDelay = false;
- }
- catch (Exception ex)
- {
- DebugLog("EXCEPTION! " + ex.ToString());
- }
- DebugLog(string.Format("socketTimeout={0}", socketTimeout));
- _socketReqChannelConfig = new TcpClient();
- _socketReqChannelConfig.SendTimeout = socketTimeout;
- _socketReqChannelConfig.NoDelay = noDelay;
- int retrycount = 0;
- bool bConnected = false;
- string ipAddress = this._sIPAddress;
- string error = "";
- while (!bConnected)
- {
- if (retrycount == 5)
- {
- if (this._sIPAddress2 != "") ipAddress = this._sIPAddress2;
- DebugLog(error);
- }
- else if (retrycount == 10)
- {
- retrycount = 0;
- ipAddress = this._sIPAddress;
- DebugLog(error);
- Thread.Sleep(5000);
- }
- retrycount++;
- try
- {
- socketReqChannelConfig.Connect(ipAddress, iIPPortConfig);
- bConnected = true;
- }
- catch (SocketException sex)
- {
- error = sex.ToString();
- Thread.Sleep(1000);
- }
- }
- respChannelConfigThreadObj = new TCPListenerThread(null, ifsfManager, "ChannelConfig");
- respChannelConfigThread = new Thread(new ThreadStart(respChannelConfigThreadObj.TCPListenerThreadProc));
- respChannelConfigThread.Start();
- }
- else
- _socketReqChannelConfig = this._socketReqChannelA;
- Thread.Sleep(2000);
- // start reading file with config messages
- string line, xmlconfigfile = ConfigurationParams.getSINPPath("ini\\") + commandFileName;
- StringBuilder sb = new StringBuilder(); ;
- StreamReader sr = new StreamReader(xmlconfigfile);
- while (sr.Peek() != -1)
- {
- line = sr.ReadLine();
- sb.Append(line);
- }
- sr.Close();
- string allconfig = sb.ToString();
- //string allconfig = sr.ReadToEnd();
- string[] messages;
- string msg2;
- messages = allconfig.Split('#');
- foreach (string msg in messages)
- {
- msg2 = msg;
- //msg2 = msg.Replace("\r", "");
- //msg2 = msg2.Replace("\n", "");
- //msg2 = msg2.Replace("\t", "");
- this.SendConfigMessage(msg2);
- }
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("SendConfig end: EXCEPTION! {0}", ex.ToString()));
- }
- if (iIPPortConfig != this._iIPPortA)
- {
- if (_socketReqChannelConfig != null)
- this._socketReqChannelConfig.Close();
- this._socketReqChannelConfig = null;
- }
- }
- else
- DebugLog("SendConfig ERROR: NOT Connected!");
- }
- public bool Connect(string connectionString)
- {
- DebugLog(string.Format("Connect init: status='{0}'", this.mainConnectionState));
- if (this.mainConnectionState == DeviceConnectionState.Disconnected
- || this.mainConnectionState == DeviceConnectionState.Disconnecting)
- {
- //this.mainConnectionState = DeviceConnectionState.Connecting;
- try
- {
- getConnectionParams(connectionString);
- FDCGlobal.ProtocolVersion = FDCGlobal.VersionFromString(IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "FDCPOSInterfaceVersion"));
- FDCGlobal.ConfigVersion = FDCGlobal.ConfigVersionFromString(IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "FDCPOSConfigVersion"));
- DebugLog(string.Format("id={0}, -connectionString:'{1}', version:'{2}', configVersion:'{3}'", this.id, connectionString, FDCGlobal.ProtocolVersion, FDCGlobal.ConfigVersion));
- this.ifsfManager.heartbeat.Stop();
- this.ifsfManager.heartbeat.heartbeatInterval = this.heartbeatInterval;
- this.ifsfManager.heartbeat.heartbeatTimeout = this.heartbeatTimeout;
- int socketTimeout = 3000;
- bool noDelay = true;
- try
- {
- string sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "SocketTimeout");
- if (sValue.Length > 0)
- socketTimeout = Convert.ToInt32(sValue);
- sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "NoDelay");
- if (sValue.Length > 0 && sValue == "0")
- noDelay = false;
- }
- catch (Exception ex)
- {
- DebugLog("EXCEPTION! " + ex.ToString());
- }
- DebugLog(string.Format("socketTimeout={0}", socketTimeout));
- IPAddress serverIPAddress = null;
- IPEndPoint endPoint = null;
- _socketReqChannelA = new TcpClient();
- _socketReqChannelA.SendTimeout = socketTimeout;
- _socketReqChannelA.NoDelay = noDelay;
- int retrycount = 0;
- bool bConnected = false;
- string ipAddress = this._sIPAddress;
- string error = "";
- while (!bConnected)
- {
- if (retrycount == 5)
- {
- if (this._sIPAddress2 != "") ipAddress = this._sIPAddress2;
- DebugLog(error);
- }
- else if (retrycount == 10)
- {
- retrycount = 0;
- ipAddress = this._sIPAddress;
- DebugLog(error);
- Thread.Sleep(5000);
- }
- retrycount++;
- try
- {
- DebugLog(string.Format("connecting to ip={0}, port={1}", ipAddress, this.iIPPortA));
- this.socketReqChannelA.Connect(ipAddress, this.iIPPortA);
- bConnected = true;
- }
- catch (SocketException sex)
- {
- error = sex.ToString();
- Thread.Sleep(1000);
- }
- }
- if (iIPPortB != iIPPortA /*&& _socketRespChannelB == null*/)
- _socketRespChannelB = new TcpListener(iIPPortB);
- else
- _socketRespChannelB = null;
- if (iIPPortC != iIPPortA /*&& _socketUnsolicitedChannelC == null*/)
- _socketUnsolicitedChannelC = new TcpListener(iIPPortC);
- else
- _socketUnsolicitedChannelC = null;
- DebugLog(string.Format("Channel A Connected: Id={0}, WId={1}, AId={2}", this.id, this.workstationID, this.applicationSender));
- ifsfManager.authentificationErrorRetry = true;
- if (this.validationInfo != null)
- ifsfManager.LogOn(validationInfo, posInfo, "");
- else
- ifsfManager.LogOnSend(posInfo);
- ifsfManager.heartbeat.ResetDisconnectionTimeout();
- if (iIPPortB != iIPPortA /*&& respChannelBThreadObj == null*/)
- {
- respChannelBThreadObj = new TCPListenerThread(socketRespChannelB, ifsfManager, "ChannelB");
- respChannelBThread = new Thread(new ThreadStart(respChannelBThreadObj.TCPListenerThreadProc));
- respChannelBThread.Start();
- }
- else /*if (respChannelBThreadObj == null)*/
- {
- respChannelBThreadObj = new TCPListenerThread(null, ifsfManager, "ChannelA");
- respChannelBThread = new Thread(new ThreadStart(respChannelBThreadObj.TCPListenerThreadProc));
- respChannelBThread.Start();
- }
- if (iIPPortC != iIPPortA /*&& unsolicitedChannelCThreadObj == null*/)
- {
- unsolicitedChannelCThreadObj = new TCPListenerThread(socketUnsolicitedChannelC, ifsfManager, "ChannelC");
- unsolicitedChannelCThread = new Thread(new ThreadStart(unsolicitedChannelCThreadObj.TCPListenerThreadProc));
- unsolicitedChannelCThread.Start();
- }
- }
- catch (Exception ex)
- {
- DebugLog(string.Format("Connect end: EXCEPTION! {0}", ex.ToString()));
- return false;
- }
- }
- DebugLog("Connect end: ok");
- return true;
- }
- public void Disconnect()
- {
- DebugLog("terminating respThreadObjs");
- if (respChannelBThreadObj != null)
- respChannelBThreadObj.Dispose();
- DebugLog("terminating respChannelCThreadObj");
- if (unsolicitedChannelCThreadObj != null)
- unsolicitedChannelCThreadObj.Dispose();
- if (respChannelConfigThreadObj != null)
- respChannelConfigThreadObj.Dispose();
- if (_socketReqChannelA != null)
- this._socketReqChannelA.Close();
- this._socketReqChannelA = null;
- if (_socketReqChannelConfig != null)
- this._socketReqChannelConfig.Close();
- this._socketReqChannelConfig = null;
- if (this._socketRespChannelB != null)
- this._socketRespChannelB.Stop();
- _socketRespChannelB = null;
- if (this._socketUnsolicitedChannelC != null)
- this._socketUnsolicitedChannelC.Stop();
- _socketUnsolicitedChannelC = null;
- }
- public virtual void Dispose()
- {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (!this.disposed)
- {
- this.disposed = true;
- if (disposing)
- {
- }
- }
- }
- public DeviceConnectionState ConnectionState
- {
- get
- {
- return this.mainConnectionState;
- }
- }
- public string EntitySubType
- {
- get
- {
- return "RPC";
- }
- }
- public string EntityType
- {
- get
- {
- return "ClientSocket";
- }
- }
- /// <summary>
- /// This is used by the logger and should never be set by inheriting classes
- /// </summary>
- public string FullEntityName { get; set; }
- public int Id
- {
- get
- {
- return this.id;
- }
- }
- public IIdentifiableEntity ParentEntity
- {
- get
- {
- return this.parentEntity;
- }
- }
- public void Serialize<T>(T sr)
- {
- NetworkStream netstream = socketReqChannelA.GetStream();
- byte[] payload;
- using (var memstream = new MemoryStream())
- {
- XmlSerializer serializer = ifsfMessages.GetXmlSerializer(typeof(T));
- serializer.Serialize(memstream, (T)sr);
- payload = memstream.ToArray();
- }
- // writes header and encription string
- // writes message length
- using (var memstream = new MemoryStream())
- {
- using (var writer = new BinaryWriter(memstream))
- {
- writer.Write(new[]
- {
- (byte)(payload.Length >> 24),
- (byte)(payload.Length >> 16),
- (byte)(payload.Length >> 8),
- (byte)(payload.Length)
- });
- // if V01 then writes algorithm type (0: no encription, 1: MD5 encryption
- if (FDCGlobal.ProtocolVersion >= FDCVersion.V0100)
- {
- writer.Write(new[]
- {
- (byte)(0),
- this.ifsfManager.clientSocket.headerEncryption != 0 ? (byte)(1) : (byte)(0)
- });
- }
- // writes encryption
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007 ||
- (FDCGlobal.ProtocolVersion >= FDCVersion.V0100 && this.ifsfManager.clientSocket.headerEncryption != 0))
- {
- byte[] bytes;
- if (this.ifsfManager.clientSocket.headerEncryption != 0)
- {
- var crypter = new MD5Crypter();
- var passPhrase = crypter.getPassphrase();
- var hashingbytes = new byte[payload.Length + passPhrase.Length];
- Array.Copy(payload, hashingbytes, payload.Length);
- Array.Copy(passPhrase, 0, hashingbytes, payload.Length, passPhrase.Length);
- bytes = crypter.ComputeHash(hashingbytes);
- }
- else
- {
- bytes = new byte[Define.MD5EncriptionLength];
- for (int i = 0; i < Define.MD5EncriptionLength; i++)
- bytes[i] = 0;
- }
- writer.Write(bytes);
- }
- writer.Write(payload);
- memstream.WriteTo(netstream);
- DebugLog(string.Format("Serialize: memstream={0}", Encoding.UTF8.GetString(payload)));
- }
- }
- }
- public void SendConfigMessage(string configmessage)
- {
- NetworkStream netstream = socketReqChannelConfig.GetStream();
- byte[] payload = Encoding.UTF8.GetBytes(configmessage);
- // writes header and encription string
- using (MemoryStream memstream = new MemoryStream())
- {
- using (BinaryWriter writer = new BinaryWriter(memstream))
- {
- writer.Write(new[]
- {
- (byte)(payload.Length >> 24),
- (byte)(payload.Length >> 16),
- (byte)(payload.Length >> 8),
- (byte)(payload.Length)
- });
- // if V01 then writes algorithm type (0: no encription, 1: MD5 encryption
- if (FDCGlobal.ProtocolVersion >= FDCVersion.V0100)
- {
- writer.Write(new[]
- {
- (byte)(0),
- this.ifsfManager.clientSocket.headerEncryption != 0 ? (byte)(1) : (byte)(0)
- });
- }
- // writes encryption
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007 ||
- (FDCGlobal.ProtocolVersion >= FDCVersion.V0100 && this.ifsfManager.clientSocket.headerEncryption != 0))
- {
- byte[] bytes;
- if (this.ifsfManager.clientSocket.headerEncryption != 0)
- {
- var crypter = new MD5Crypter();
- var passPhrase = crypter.getPassphrase();
- var hashingbytes = new byte[payload.Length + passPhrase.Length];
- Array.Copy(payload, hashingbytes, payload.Length);
- Array.Copy(passPhrase, 0, hashingbytes, payload.Length, passPhrase.Length);
- bytes = crypter.ComputeHash(hashingbytes);
- }
- else
- {
- bytes = new byte[Define.MD5EncriptionLength];
- for (int i = 0; i < Define.MD5EncriptionLength; i++)
- bytes[i] = 0;
- }
- writer.Write(bytes);
- }
- writer.Write(payload);
- memstream.WriteTo(netstream);
- DebugLog(string.Format("SendConfigMessage: memstream={0}", configmessage));
- }
- }
- }
- private void ifsfmessages_OnResponseTimeout(object sender, EventArgs e)
- {
- if (OnResponseTimeout != null)
- OnResponseTimeout.Invoke(this, null);
- }
- private void ifsfmessages_OnMessageEnqueued(object sender, EventArgs e)
- {
- DebugLog("ifsfmessages_OnMessageEnqueued init:");
- string requestType = "";
- int requestId = 0;
- try
- {
- while (ifsfMessages.serviceRequestChannelA.Count > 0)
- {
- BasePOSRequest sr = ifsfMessages.serviceRequestChannelA.Dequeue();
- //DebugLog(string.Format("sr.GetType: {0}", sr.GetType().FullName));
- if (sr.GetType() == typeof(POSMessagePOSReady))
- {
- requestType = ((FDCMessage)sr).MessageType;
- requestId = Convert.ToInt32(((FDCMessage)sr).MessageID);
- }
- else
- {
- requestType = ((ServiceRequest)sr).RequestType;
- requestId = Convert.ToInt32(((ServiceRequest)sr).RequestID);
- }
- DebugLog(string.Format("SendRequest RequestType: {0}, requestId={1}", requestType, requestId));
- if (requestType == "POSHeartBeat")
- {
- Serialize<ServiceRequestHeartbeat>((ServiceRequestHeartbeat)sr);
- }
- else if (requestType == "POS_Ready")
- {
- //Serialize<ServiceRequestPOSReady>((ServiceRequestPOSReady)sr);
- Serialize<POSMessagePOSReady>((POSMessagePOSReady)sr);
- }
- else if (requestType == "LogOn")
- {
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
- Serialize<ServiceRequestLogOnV07>((ServiceRequestLogOnV07)sr);
- else
- Serialize<ServiceRequestLogOn>((ServiceRequestLogOn)sr);
- }
- else if (requestType == "LogOff")
- {
- Serialize<ServiceRequestLogOff>((ServiceRequestLogOff)sr);
- }
- else if (requestType == "VersionInfo")
- {
- Serialize<ServiceRequestVersionInfo>((ServiceRequestVersionInfo)sr);
- }
- else if (requestType == "StartForecourt")
- {
- Serialize<ServiceRequestStartForecourt>((ServiceRequestStartForecourt)sr);
- }
- else if (requestType == "TwinOpenMaster")
- {
- Serialize<ServiceRequestTwinOpenMaster>((ServiceRequestTwinOpenMaster)sr);
- }
- else if (requestType == "StopForecourt")
- {
- Serialize<ServiceRequestStopForecourt>((ServiceRequestStopForecourt)sr);
- }
- else if (requestType == "GetCurrentFuellingStatus")
- {
- Serialize<ServiceRequestGetCurrentFuellingStatus>((ServiceRequestGetCurrentFuellingStatus)sr);
- }
- else if (requestType == "GetTotals")
- {
- Serialize<ServiceRequestGetFuelPointTotals>((ServiceRequestGetFuelPointTotals)sr);
- }
- else if (requestType == "GetDeviceState")
- {
- Serialize<ServiceRequestGetDeviceState>((ServiceRequestGetDeviceState)sr);
- }
- else if (requestType == "GetFPState")
- {
- Serialize<ServiceRequestGetFPState>((ServiceRequestGetFPState)sr);
- }
- else if (requestType == "GetTPState")
- {
- Serialize<ServiceRequestGetTPState>((ServiceRequestGetTPState)sr);
- }
- else if (requestType == "GetPPState")
- {
- Serialize<ServiceRequestGetPPState>((ServiceRequestGetPPState)sr);
- }
- else if (requestType == "GetVIRState")
- {
- Serialize<ServiceRequestGetVIRState>((ServiceRequestGetVIRState)sr);
- }
- else if (requestType == "TerminateFuelling")
- {
- Serialize<ServiceRequestTerminateFuelling>((ServiceRequestTerminateFuelling)sr);
- }
- else if (requestType == "AuthoriseFuelPoint")
- {
- Serialize<ServiceRequestAuthoriseFuelPoint>((ServiceRequestAuthoriseFuelPoint)sr);
- }
- else if (requestType == "ChangeFuelMode")
- {
- Serialize<ServiceRequestChangeFuelMode>((ServiceRequestChangeFuelMode)sr);
- }
- else if (requestType == "ChangeFPFuelMode")
- {
- Serialize<ServiceRequestChangeFuelMode>((ServiceRequestChangeFuelMode)sr);
- }
- else if (requestType == "ChangeFuelPrice")
- {
- Serialize<ServiceRequestChangeFuelPrice>((ServiceRequestChangeFuelPrice)sr);
- }
- else if (requestType == "LockFuelSaleTrx")
- {
- Serialize<ServiceRequestLockFuelSaleTrx>((ServiceRequestLockFuelSaleTrx)sr);
- }
- else if (requestType == "UnlockFuelSaleTrx")
- {
- Serialize<ServiceRequestUnlockFuelSaleTrx>((ServiceRequestUnlockFuelSaleTrx)sr);
- }
- else if (requestType == "ClearFuelSaleTrx")
- {
- Serialize<ServiceRequestClearFuelSaleTrx>((ServiceRequestClearFuelSaleTrx)sr);
- }
- else if (requestType == "GetAvailableFuelSaleTrxs")
- {
- Serialize<ServiceRequestGetAvailableFuelSaleTrxs>((ServiceRequestGetAvailableFuelSaleTrxs)sr);
- }
- else if (requestType == "GetFuelSaleTrxDetails")
- {
- Serialize<ServiceRequestGetFuelSaleTrxDetails>((ServiceRequestGetFuelSaleTrxDetails)sr);
- }
- else if (requestType == "GetProductTable")
- {
- Serialize<ServiceRequestGetProductTable>((ServiceRequestGetProductTable)sr);
- }
- else if (requestType == "GetModeTable")
- {
- Serialize<ServiceRequestGetModeTable>((ServiceRequestGetModeTable)sr);
- }
- else if (requestType == "GetFuelMode")
- {
- Serialize<ServiceRequestGetFuelMode>((ServiceRequestGetFuelMode)sr);
- }
- else if (requestType == "GetFPFuelMode")
- {
- Serialize<ServiceRequestGetFPFuelMode>((ServiceRequestGetFPFuelMode)sr);
- }
- else if (requestType == "GetConfiguration")
- {
- Serialize<ServiceRequestGetConfiguration>((ServiceRequestGetConfiguration)sr);
- }
- else if (requestType == "GetDSPConfiguration")
- {
- Serialize<ServiceRequestGetDSPConfiguration>((ServiceRequestGetDSPConfiguration)sr);
- }
- else if (requestType == "GetTLGConfiguration")
- {
- Serialize<ServiceRequestGetTLGConfiguration>((ServiceRequestGetTLGConfiguration)sr);
- }
- else if (requestType == "GetPPConfiguration")
- {
- Serialize<ServiceRequestGetPPConfiguration>((ServiceRequestGetPPConfiguration)sr);
- }
- else if (requestType == "SetConfiguration")
- {
- Serialize<ServiceRequestSetConfiguration>((ServiceRequestSetConfiguration)sr);
- }
- else if (requestType == "LockNozzle")
- {
- Serialize<ServiceRequestLockNozzle>((ServiceRequestLockNozzle)sr);
- }
- else if (requestType == "UnlockNozzle")
- {
- Serialize<ServiceRequestUnlockNozzle>((ServiceRequestUnlockNozzle)sr);
- }
- else if (requestType == "OpenDevice")
- {
- Serialize<ServiceRequestOpenDevice>((ServiceRequestOpenDevice)sr);
- }
- else if (requestType == "CloseDevice")
- {
- Serialize<ServiceRequestCloseDevice>((ServiceRequestCloseDevice)sr);
- }
- else if (requestType == "GetCountrySettings")
- {
- Serialize<ServiceRequestGetCountrySettings>((ServiceRequestGetCountrySettings)sr);
- }
- else if (requestType == "GetDSPLimits")
- {
- Serialize<ServiceRequestGetDSPLimits>((ServiceRequestGetDSPLimits)sr);
- }
- else if (requestType == "ChangeDSPLimits")
- {
- Serialize<ServiceRequestChangeDSPLimits>((ServiceRequestChangeDSPLimits)sr);
- }
- else if (requestType == "SuspendFuelling")
- {
- Serialize<ServiceRequestSuspendFuelling>((ServiceRequestSuspendFuelling)sr);
- }
- else if (requestType == "ResumeFuelling")
- {
- Serialize<ServiceRequestResumeFuelling>((ServiceRequestResumeFuelling)sr);
- }
- else if (requestType == "LockTank")
- {
- Serialize<ServiceRequestLockTank>((ServiceRequestLockTank)sr);
- }
- else if (requestType == "UnlockTank")
- {
- Serialize<ServiceRequestUnlockTank>((ServiceRequestUnlockTank)sr);
- }
- else if (requestType == "GetTankData")
- {
- Serialize<ServiceRequestGetTankData>((ServiceRequestGetTankData)sr);
- }
- else if (requestType == "ReserveFuelPoint")
- {
- Serialize<ServiceRequestReserveFuelPoint>((ServiceRequestReserveFuelPoint)sr);
- }
- else if (requestType == "FreeFuelPoint")
- {
- Serialize<ServiceRequestFreeFuelPoint>((ServiceRequestFreeFuelPoint)sr);
- }
- else if (requestType == "StartFuelPointTest")
- {
- Serialize<ServiceRequestStartFuelPointTest>((ServiceRequestStartFuelPointTest)sr);
- }
- else if (requestType == "EndFuelPointTest")
- {
- Serialize<ServiceRequestEndFuelPointTest>((ServiceRequestEndFuelPointTest)sr);
- }
- else if (requestType == "OpenFuelPoint")
- {
- Serialize<ServiceRequestOpenFuelPoint>((ServiceRequestOpenFuelPoint)sr);
- }
- else if (requestType == "CloseFuelPoint")
- {
- Serialize<ServiceRequestCloseFuelPoint>((ServiceRequestCloseFuelPoint)sr);
- }
- else if (requestType == "SetDeviceAlarm")
- {
- Serialize<ServiceRequestSetDeviceAlarm>((ServiceRequestSetDeviceAlarm)sr);
- }
- else if (requestType == "OPTAdd")
- {
- Serialize<ServiceRequestOPTAdd>((ServiceRequestOPTAdd)sr);
- }
- else if (requestType == "OPTRemove")
- {
- Serialize<ServiceRequestOPTRemove>((ServiceRequestOPTRemove)sr);
- }
- else if (requestType == "OPTWrite")
- {
- if (FDCGlobal.ProtocolVersion <= FDCVersion.V0007)
- Serialize<ServiceRequestOPTWriteV07>((ServiceRequestOPTWriteV07)sr);
- else
- Serialize<ServiceRequestOPTWrite>((ServiceRequestOPTWrite)sr);
- }
- else if (requestType == "ConfigStart")
- {
- Serialize<ServiceRequestConfigStart>((ServiceRequestConfigStart)sr);
- }
- else if (requestType == "ConfigEnd")
- {
- Serialize<ServiceRequestConfigEnd>((ServiceRequestConfigEnd)sr);
- }
- else if (requestType == "DefProducts")
- {
- Serialize<ServiceRequestDefProducts>((ServiceRequestDefProducts)sr);
- }
- else if (requestType == "DefGrades" || requestType == "DefGrade")
- {
- Serialize<ServiceRequestDefGrades>((ServiceRequestDefGrades)sr);
- }
- else if (requestType == "AssignGradePars")
- {
- Serialize<ServiceRequestAssignGradePars>((ServiceRequestAssignGradePars)sr);
- }
- else if (requestType == "DefTanks")
- {
- Serialize<ServiceRequestDefTanks>((ServiceRequestDefTanks)sr);
- }
- else if (requestType == "DefTankSuctions")
- {
- Serialize<ServiceRequestDefTankSuctions>((ServiceRequestDefTankSuctions)sr);
- }
- else if (requestType == "DefFuelMode" || requestType == "DefFPFuelModes")
- {
- Serialize<ServiceRequestDefFuelMode>((ServiceRequestDefFuelMode)sr);
- }
- else if (requestType == "DefFuellingMode" || requestType == "DefFCFuelMode")
- {
- Serialize<ServiceRequestDefFuellingMode>((ServiceRequestDefFuellingMode)sr);
- }
- else if (requestType == "DefFuelPoint")
- {
- Serialize<ServiceRequestDefFuelPoint>((ServiceRequestDefFuelPoint)sr);
- }
- else if (requestType == "DefFuelPoints")
- {
- Serialize<ServiceRequestDefFuelPoints>((ServiceRequestDefFuelPoints)sr);
- }
- else if (requestType == "AssignGrades")
- {
- Serialize<ServiceRequestAssignGrades>((ServiceRequestAssignGrades)sr);
- }
- else if (requestType == "AssignMeters")
- {
- Serialize<ServiceRequestAssignMeters>((ServiceRequestAssignMeters)sr);
- }
- else if (requestType == "AssignTanks")
- {
- Serialize<ServiceRequestAssignTanks>((ServiceRequestAssignTanks)sr);
- }
- else if (requestType == "DefPricePole" | requestType == "DefPricePoles")
- {
- Serialize<ServiceRequestDefPricePole>((ServiceRequestDefPricePole)sr);
- }
- else if (requestType == "LoadPriceset")
- {
- Serialize<ServiceRequestLoadPriceset>((ServiceRequestLoadPriceset)sr);
- }
- else if (requestType == "DefTankMonitor" || requestType == "DefTankMonitors")
- {
- Serialize<ServiceRequestDefTankMonitor>((ServiceRequestDefTankMonitor)sr);
- }
- else if (requestType == "GetFuelPrice")
- {
- Serialize<ServiceRequestGetFuelPrices>((ServiceRequestGetFuelPrices)sr);
- }
- else if (requestType == "DefFPOperationModes")
- {
- Serialize<ServiceRequestDefFPOperationModes>((ServiceRequestDefFPOperationModes)sr);
- }
- else if (requestType == "CloseReconciliationPeriod")
- {
- Serialize<ServiceRequestCloseReconciliationPeriod>((ServiceRequestCloseReconciliationPeriod)sr);
- }
- else if (requestType == "GetTankReconciliation")
- {
- Serialize<ServiceRequestGetTankReconciliation>((ServiceRequestGetTankReconciliation)sr);
- }
- else if (requestType == "GetTankDelivery")
- {
- Serialize<ServiceRequestGetTankDelivery>((ServiceRequestGetTankDelivery)sr);
- }
- else if (requestType == "StartFuelPoint")
- {
- Serialize((ServiceRequestStartFuelPoint)sr);
- }
- else if (requestType == "StopFuelPoint")
- {
- Serialize((ServiceRequestStopFuelPoint)sr);
- }
- else
- {
- DebugLog(string.Format("!!!!! Unhandled SendRequest RequestType: {0}, requestId={1}", requestType, requestId));
- }
- }
- }
- catch (Exception ex)
- {
- DebugLog("ifsfmessages_OnMessageEnqueued RequestType:" + requestType + " RequestId:" + requestId + " Exception! " + ex.ToString());
- if (mainConnectionState != DeviceConnectionState.Disconnected)
- {
- this.ifsfManager.Disconnect();
- mainConnectionState = DeviceConnectionState.Disconnected;
- }
- }
- DebugLog(string.Format("ifsfmessages_OnMessageEnqueued end RequestType: {0}", requestType));
- }
- }
- }
|