123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using System;
- //using System.Diagnostics;
- namespace Wayne.ForecourtControl.Fusion
- {
- public class ConfigurationParams
- {
- private static string _inifile = getSINPPath("ini\\") + @"ForecourtServer.ini";
- // TODO read path from registry
- //private static string _inifile = @".\ForecourtServer.ini";
- public static string inifile
- {
- get { return _inifile; }
- }
- // TODO read path from registry
- private static string _tracePath = getSINPPath("trace\\");
- public static string tracePath
- {
- get { return _tracePath; }
- }
- 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; }
- set { _sIPAddress = value; }
- }
- private string _sIPAddress2 = "";
- public string sIPAddress2
- {
- get { return _sIPAddress2; }
- set { _sIPAddress2 = value; }
- }
- private int _iIPPortA = 0;
- public int iIPPortA
- {
- get { return _iIPPortA; }
- set { _iIPPortA = value; }
- }
- private int _iIPPortB = 0;
- public int iIPPortB
- {
- get { return _iIPPortB; }
- set { _iIPPortB = value; }
- }
- private int _iIPPortC = 0;
- public int iIPPortC
- {
- get { return _iIPPortC; }
- set { _iIPPortC = value; }
- }
- private long _heartbeatInterval = 10000;
- public long heartbeatInterval
- {
- get { return _heartbeatInterval; }
- set { _heartbeatInterval = value; }
- }
- private long _heartbeatTimeout = 30000;
- public long heartbeatTimeout
- {
- get { return _heartbeatTimeout; }
- set { _heartbeatTimeout = value; }
- }
- private long _headerEncryption = 1;
- public long headerEncryption
- {
- get { return _headerEncryption; }
- set { _headerEncryption = value; }
- }
- public bool TraceXML { get; private set; }
- public bool IsEMSGVersion { get; private set; }
- private readonly int _readRunningFuelling;
- public int ReadRunningFuelling { get { return _readRunningFuelling; } }
- public static string getSINPPath(string subpath)
- {
- string path = "";
- //Microsoft.Win32.RegistryKey rk;
- //try
- //{
- // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Nuovo Pignone\\SINP"))
- // {
- // if (rk != null) path = (string) rk.GetValue("Directory", "");
- // }
- //}
- //catch (Exception ex)
- //{
- //}
- //if (path == "")
- //{
- // try
- // {
- // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Dresser Wayne\\FUSION"))
- // {
- // if (rk != null) path = (string) rk.GetValue("Directory", "");
- // }
- // }
- // catch (Exception ex)
- // {
- // }
- //}
- if (path == "")
- {
- if (path == "")
- {
- try
- {
- System.Reflection.Assembly assembly = System.Reflection.Assembly.GetCallingAssembly();
- path = System.IO.Path.GetDirectoryName(assembly.GetName().Name);
- }
- catch (Exception ex)
- {
- }
- }
- if (path == "")
- path = ".\\";
- return path;
- }
- return path += "\\" + subpath;
- }
- public ConfigurationParams()
- {
- string sValue = "";
- Trace.WriteLine(string.Format("inifile='{0}'", inifile));
- // read applicationSender config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "applicationSender");
- try
- {
- if (sValue.Length > 0)
- _applicationSender = sValue;
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading applicationSender: {0}", Ex.Message));
- }
- // read workstationID config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "workstationID");
- try
- {
- if (sValue.Length > 0)
- _workstationID = sValue;
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading workstationID: {0}", Ex.Message));
- }
- // read IPPortA config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host");
- Trace.WriteLine(string.Format("Host='{0}'", sValue));
- if (sValue.Length > 0) sIPAddress = sValue;
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host2");
- Trace.WriteLine(string.Format("Host2='{0}'", sValue));
- if (sValue.Length > 0) sIPAddress2 = sValue;
- // read IPPortA config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortA");
- try
- {
- if (sValue.Length > 0)
- iIPPortA = Convert.ToInt16(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading IPPortA: {0}", Ex.Message));
- }
- // read IPPortB config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortB");
- try
- {
- if (sValue.Length > 0)
- iIPPortB = Convert.ToInt16(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading IPPortB: {0}", Ex.Message));
- }
- // read IPPortC config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortC");
- try
- {
- if (sValue.Length > 0)
- iIPPortC = Convert.ToInt16(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading IPPortC: {0}", Ex.Message));
- }
- // read HeartbeatInterval config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatInterval");
- try
- {
- if (sValue.Length > 0)
- heartbeatInterval = Convert.ToInt32(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading HeartbeatInterval: {0}", Ex.Message));
- }
- // read HeartbeatTimeout config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatTimeout");
- try
- {
- if (sValue.Length > 0)
- heartbeatTimeout = Convert.ToInt32(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading heartbeatTimeout: {0}", Ex.Message));
- }
- // read headerEncryption config parameter
- sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "headerEncryption");
- try
- {
- if (sValue.Length > 0)
- headerEncryption = Convert.ToInt32(sValue);
- }
- catch (Exception Ex)
- {
- Trace.WriteLine(string.Format("Exception reading headerEncryption: {0}", Ex.Message));
- }
- sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Trace", "TraceXML");
- try
- {
- if (sValue.Length > 0)
- TraceXML = Convert.ToInt16(sValue) == 0 ? false : true;
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception reading traceXML: {0}", ex.Message + " - " + ex.StackTrace));
- }
- sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "EMSGFDCServer");
- int EMSGVersion;
- if (Int32.TryParse(sValue, out EMSGVersion))
- {
- IsEMSGVersion = EMSGVersion > 0;
- }
- sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "TimeoutType", "ReadRunningFuelling");
- try
- {
- if (!Int32.TryParse(sValue, out _readRunningFuelling))
- {
- _readRunningFuelling = 2000;
- }
- }
- catch (Exception ex)
- {
- Trace.WriteLine(string.Format("Exception reading ReadRunningFuelling: {0}", ex.Message + " - " + ex.StackTrace));
- }
- }
- }
- }
|