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)); } } } }