ConfigurationParams.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using Wayne.Lib.Log;
  3. namespace Wayne.ForecourtControl.Fusion
  4. {
  5. 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 static string getSINPPath(string subpath)
  79. {
  80. string path = "";
  81. //Microsoft.Win32.RegistryKey rk;
  82. //try
  83. //{
  84. // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Nuovo Pignone\\SINP"))
  85. // {
  86. // if (rk != null) path = (string)rk.GetValue("Directory", "");
  87. // }
  88. //}
  89. //catch (Exception ex)
  90. //{
  91. //}
  92. //if (path == "")
  93. //{
  94. // try
  95. // {
  96. // using (rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Dresser Wayne\\FUSION"))
  97. // {
  98. // if (rk != null) path = (string)rk.GetValue("Directory", "");
  99. // }
  100. // }
  101. // catch (Exception ex)
  102. // {
  103. // }
  104. //}
  105. if (path == "")
  106. {
  107. if (path == "")
  108. {
  109. try
  110. {
  111. System.Reflection.Assembly assembly = System.Reflection.Assembly.GetCallingAssembly();
  112. path = System.IO.Path.GetDirectoryName(assembly.GetName().Name);
  113. }
  114. catch (Exception ex)
  115. {
  116. }
  117. }
  118. if (path == "")
  119. path = ".\\";
  120. return path;
  121. }
  122. return path += "\\" + subpath;
  123. }
  124. public ConfigurationParams(DebugLogger debugLogger)
  125. {
  126. string sValue = "";
  127. if (debugLogger.IsActive())
  128. debugLogger.Add(string.Format("inifile='{0}'", inifile));
  129. // read applicationSender config parameter
  130. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "applicationSender");
  131. try
  132. {
  133. if (sValue.Length > 0)
  134. _applicationSender = sValue;
  135. }
  136. catch (Exception ex)
  137. {
  138. if (debugLogger.IsActive())
  139. debugLogger.Add(string.Format("Exception reading applicationSender: {0}", ex.ToString()));
  140. }
  141. // read workstationID config parameter
  142. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "workstationID");
  143. try
  144. {
  145. if (sValue.Length > 0)
  146. _workstationID = sValue;
  147. }
  148. catch (Exception ex)
  149. {
  150. if (debugLogger.IsActive())
  151. debugLogger.Add(string.Format("Exception reading workstationID: {0}", ex.ToString()));
  152. }
  153. // read IPPortA config parameter
  154. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host");
  155. if (sValue.Length > 0) sIPAddress = sValue;
  156. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "Host2");
  157. if (sValue.Length > 0) sIPAddress2 = sValue;
  158. if (debugLogger.IsActive())
  159. debugLogger.Add(string.Format("Host='{0}', Host2='{1}'", sIPAddress, sIPAddress2));
  160. // read IPPortA config parameter
  161. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortA");
  162. try
  163. {
  164. if (sValue.Length > 0)
  165. iIPPortA = Convert.ToInt16(sValue);
  166. }
  167. catch (Exception ex)
  168. {
  169. if (debugLogger.IsActive())
  170. debugLogger.Add(string.Format("Exception reading IPPortA: {0}", ex.ToString()));
  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. if (debugLogger.IsActive())
  182. debugLogger.Add(string.Format("Exception reading IPPortB: {0}", ex.ToString()));
  183. }
  184. // read IPPortC config parameter
  185. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "IPPortC");
  186. try
  187. {
  188. if (sValue.Length > 0)
  189. iIPPortC = Convert.ToInt16(sValue);
  190. }
  191. catch (Exception ex)
  192. {
  193. if (debugLogger.IsActive())
  194. debugLogger.Add(string.Format("Exception reading IPPortC: {0}", ex.ToString()));
  195. }
  196. // read HeartbeatInterval config parameter
  197. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatInterval");
  198. try
  199. {
  200. if (sValue.Length > 0)
  201. heartbeatInterval = Convert.ToInt64(sValue);
  202. }
  203. catch (Exception ex)
  204. {
  205. if (debugLogger.IsActive())
  206. debugLogger.Add(string.Format("Exception reading HeartbeatInterval: {0}", ex.ToString()));
  207. }
  208. // read HeartbeatTimeout config parameter
  209. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "HeartbeatTimeout");
  210. try
  211. {
  212. if (sValue.Length > 0)
  213. heartbeatTimeout = Convert.ToInt64(sValue);
  214. }
  215. catch (Exception ex)
  216. {
  217. if (debugLogger.IsActive())
  218. debugLogger.Add(string.Format("Exception reading heartbeatTimeout: {0}", ex.ToString()));
  219. }
  220. // read headerEncryption config parameter
  221. sValue = IniFile.IniReadValue(inifile, "FUSION-Connection", "headerEncryption");
  222. try
  223. {
  224. if (sValue.Length > 0)
  225. headerEncryption = Convert.ToInt32(sValue);
  226. }
  227. catch (Exception ex)
  228. {
  229. if (debugLogger.IsActive())
  230. debugLogger.Add(string.Format("Exception reading headerEncryption: {0}", ex.ToString()));
  231. }
  232. }
  233. }
  234. }