ConfigurationParams.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. //using System.Diagnostics;
  3. namespace Wayne.ForecourtControl.Fusion
  4. {
  5. public class ConfigurationParams
  6. {
  7. private static string _inifile = getSINPPath("ini\\") + @"ForecourtServer.ini";
  8. // TODO read path from registry
  9. //private static string _inifile = @".\ForecourtServer.ini";
  10. public static string inifile
  11. {
  12. get { return _inifile; }
  13. }
  14. // TODO read path from registry
  15. private static string _tracePath = getSINPPath("trace\\");
  16. public static string tracePath
  17. {
  18. get { return _tracePath; }
  19. }
  20. private string _applicationSender = "";
  21. public string applicationSender
  22. {
  23. get { return _applicationSender; }
  24. }
  25. private string _workstationID = "";
  26. public string workstationID
  27. {
  28. get { return _workstationID; }
  29. }
  30. private string _sIPAddress = "";
  31. public string sIPAddress
  32. {
  33. get { return _sIPAddress; }
  34. set { _sIPAddress = value; }
  35. }
  36. private string _sIPAddress2 = "";
  37. public string sIPAddress2
  38. {
  39. get { return _sIPAddress2; }
  40. set { _sIPAddress2 = value; }
  41. }
  42. private int _iIPPortA = 0;
  43. public int iIPPortA
  44. {
  45. get { return _iIPPortA; }
  46. set { _iIPPortA = value; }
  47. }
  48. private int _iIPPortB = 0;
  49. public int iIPPortB
  50. {
  51. get { return _iIPPortB; }
  52. set { _iIPPortB = value; }
  53. }
  54. private int _iIPPortC = 0;
  55. public int iIPPortC
  56. {
  57. get { return _iIPPortC; }
  58. set { _iIPPortC = value; }
  59. }
  60. private long _heartbeatInterval = 10000;
  61. public long heartbeatInterval
  62. {
  63. get { return _heartbeatInterval; }
  64. set { _heartbeatInterval = value; }
  65. }
  66. private long _heartbeatTimeout = 30000;
  67. public long heartbeatTimeout
  68. {
  69. get { return _heartbeatTimeout; }
  70. set { _heartbeatTimeout = value; }
  71. }
  72. private long _headerEncryption = 1;
  73. public long headerEncryption
  74. {
  75. get { return _headerEncryption; }
  76. set { _headerEncryption = value; }
  77. }
  78. public bool TraceXML { get; private set; }
  79. public bool IsEMSGVersion { get; private set; }
  80. private readonly int _readRunningFuelling;
  81. public int ReadRunningFuelling { get { return _readRunningFuelling; } }
  82. public static string getSINPPath(string subpath)
  83. {
  84. string path = "";
  85. //Microsoft.Win32.RegistryKey rk;
  86. //try
  87. //{
  88. // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Nuovo Pignone\\SINP"))
  89. // {
  90. // if (rk != null) path = (string) rk.GetValue("Directory", "");
  91. // }
  92. //}
  93. //catch (Exception ex)
  94. //{
  95. //}
  96. //if (path == "")
  97. //{
  98. // try
  99. // {
  100. // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Dresser Wayne\\FUSION"))
  101. // {
  102. // if (rk != null) path = (string) rk.GetValue("Directory", "");
  103. // }
  104. // }
  105. // catch (Exception ex)
  106. // {
  107. // }
  108. //}
  109. if (path == "")
  110. {
  111. if (path == "")
  112. {
  113. try
  114. {
  115. System.Reflection.Assembly assembly = System.Reflection.Assembly.GetCallingAssembly();
  116. path = System.IO.Path.GetDirectoryName(assembly.GetName().Name);
  117. }
  118. catch (Exception ex)
  119. {
  120. }
  121. }
  122. if (path == "")
  123. path = ".\\";
  124. return path;
  125. }
  126. return path += "\\" + subpath;
  127. }
  128. public ConfigurationParams()
  129. {
  130. string sValue = "";
  131. Trace.WriteLine(string.Format("inifile='{0}'", inifile));
  132. // read applicationSender config parameter
  133. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "applicationSender");
  134. try
  135. {
  136. if (sValue.Length > 0)
  137. _applicationSender = sValue;
  138. }
  139. catch (Exception Ex)
  140. {
  141. Trace.WriteLine(string.Format("Exception reading applicationSender: {0}", Ex.Message));
  142. }
  143. // read workstationID config parameter
  144. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "workstationID");
  145. try
  146. {
  147. if (sValue.Length > 0)
  148. _workstationID = sValue;
  149. }
  150. catch (Exception Ex)
  151. {
  152. Trace.WriteLine(string.Format("Exception reading workstationID: {0}", Ex.Message));
  153. }
  154. // read IPPortA config parameter
  155. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host");
  156. Trace.WriteLine(string.Format("Host='{0}'", sValue));
  157. if (sValue.Length > 0) sIPAddress = sValue;
  158. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host2");
  159. Trace.WriteLine(string.Format("Host2='{0}'", sValue));
  160. if (sValue.Length > 0) sIPAddress2 = sValue;
  161. // read IPPortA config parameter
  162. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortA");
  163. try
  164. {
  165. if (sValue.Length > 0)
  166. iIPPortA = Convert.ToInt16(sValue);
  167. }
  168. catch (Exception Ex)
  169. {
  170. Trace.WriteLine(string.Format("Exception reading IPPortA: {0}", Ex.Message));
  171. }
  172. // read IPPortB config parameter
  173. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortB");
  174. try
  175. {
  176. if (sValue.Length > 0)
  177. iIPPortB = Convert.ToInt16(sValue);
  178. }
  179. catch (Exception Ex)
  180. {
  181. Trace.WriteLine(string.Format("Exception reading IPPortB: {0}", Ex.Message));
  182. }
  183. // read IPPortC config parameter
  184. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortC");
  185. try
  186. {
  187. if (sValue.Length > 0)
  188. iIPPortC = Convert.ToInt16(sValue);
  189. }
  190. catch (Exception Ex)
  191. {
  192. Trace.WriteLine(string.Format("Exception reading IPPortC: {0}", Ex.Message));
  193. }
  194. // read HeartbeatInterval config parameter
  195. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatInterval");
  196. try
  197. {
  198. if (sValue.Length > 0)
  199. heartbeatInterval = Convert.ToInt32(sValue);
  200. }
  201. catch (Exception Ex)
  202. {
  203. Trace.WriteLine(string.Format("Exception reading HeartbeatInterval: {0}", Ex.Message));
  204. }
  205. // read HeartbeatTimeout config parameter
  206. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatTimeout");
  207. try
  208. {
  209. if (sValue.Length > 0)
  210. heartbeatTimeout = Convert.ToInt32(sValue);
  211. }
  212. catch (Exception Ex)
  213. {
  214. Trace.WriteLine(string.Format("Exception reading heartbeatTimeout: {0}", Ex.Message));
  215. }
  216. // read headerEncryption config parameter
  217. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "headerEncryption");
  218. try
  219. {
  220. if (sValue.Length > 0)
  221. headerEncryption = Convert.ToInt32(sValue);
  222. }
  223. catch (Exception Ex)
  224. {
  225. Trace.WriteLine(string.Format("Exception reading headerEncryption: {0}", Ex.Message));
  226. }
  227. sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "Trace", "TraceXML");
  228. try
  229. {
  230. if (sValue.Length > 0)
  231. TraceXML = Convert.ToInt16(sValue) == 0 ? false : true;
  232. }
  233. catch (Exception ex)
  234. {
  235. Trace.WriteLine(string.Format("Exception reading traceXML: {0}", ex.Message + " - " + ex.StackTrace));
  236. }
  237. sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "FUSION-Connection", "EMSGFDCServer");
  238. int EMSGVersion;
  239. if (Int32.TryParse(sValue, out EMSGVersion))
  240. {
  241. IsEMSGVersion = EMSGVersion > 0;
  242. }
  243. sValue = IniFile.IniReadValue(ConfigurationParams.inifile, "TimeoutType", "ReadRunningFuelling");
  244. try
  245. {
  246. if (!Int32.TryParse(sValue, out _readRunningFuelling))
  247. {
  248. _readRunningFuelling = 2000;
  249. }
  250. }
  251. catch (Exception ex)
  252. {
  253. Trace.WriteLine(string.Format("Exception reading ReadRunningFuelling: {0}", ex.Message + " - " + ex.StackTrace));
  254. }
  255. }
  256. }
  257. }