753cac48bbd425c8627e4c30385c996cb3b17792.svn-base 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 
  2. using System.Configuration;
  3. using System;
  4. namespace Core.Mes.ServerFrameWork
  5. {
  6. public delegate void InvokeCallback(string msg);
  7. [Serializable]
  8. public class ServerConfigure
  9. {
  10. public Core.Mes.ServerFrameWork.ExtSrvDaemon.ShowExtSrvEvent ssc_event = null;
  11. private int _magicID = 0xFACE;
  12. public int MAGIC_ID
  13. {
  14. get { return _magicID; }
  15. }
  16. public int PreserveSystemMemory = 500;
  17. public string MainServerIP = "";
  18. public string MainServerPort = "";
  19. public string ExtServers = "";
  20. public string Debug = "false";
  21. public int CompressThreshold = 100;
  22. public int MethodTime = 30;
  23. public int MemoryMaxSize = 1000;
  24. public string ConfigFilePath = "";
  25. public string MESDB = "";
  26. public string ServerPort = "";
  27. public string UserTableSpace = "";
  28. public int CheckPassword = 0;
  29. public int CheckIpRule = 0;
  30. public double PriorityFactor = 1;
  31. public InvokeCallback OnMasterServerChanged = null;
  32. private string _masterServer = "";
  33. public string MasterServer
  34. {
  35. get { return _masterServer; }
  36. set
  37. {
  38. if (_masterServer == value) return;
  39. _masterServer = value;
  40. if (OnMasterServerChanged != null)
  41. {
  42. OnMasterServerChanged.Invoke(_masterServer);
  43. }
  44. }
  45. }
  46. public ServerConfigure()
  47. {
  48. MainServerIP = ReadConfigure("ServerIP");
  49. MainServerPort = ReadConfigure("ServerPort");
  50. ExtServers = ReadConfigure("RemoteServerUrl");
  51. Debug = ReadConfigure("Debug").ToLower();
  52. MESDB = ReadConfigure("MESDB");
  53. ServerPort = ReadConfigure("ServerPort");
  54. UserTableSpace = ReadConfigure("UserTableSpace");
  55. ConfigFilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
  56. //进行序列化压缩传送的数据阀值;(定义数据集所有表行数之和>CompressThreshold 时,进行压缩传输),数据阀值不能太小,最小100;
  57. _magicID = (new Random()).Next();
  58. CompressThreshold = ReadConfigure("CompressThreshold", 100);
  59. PriorityFactor = ReadConfigure("PriorityFactor", 1.0);
  60. MethodTime = ReadConfigure("MethodTime", 30);
  61. MemoryMaxSize = ReadConfigure("MemoryMaxSize", 1000);
  62. PreserveSystemMemory = ReadConfigure("PreserveSysMem", 500);
  63. CheckPassword = ReadConfigure("CheckPassword", 0);
  64. CheckIpRule = ReadConfigure("CheckIpRule", 0);
  65. }
  66. private string ReadConfigure(string ItemName)
  67. {
  68. try
  69. {
  70. return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings[ItemName].Value.ToString().Trim();
  71. }
  72. catch { }
  73. return "";
  74. }
  75. private int ReadConfigure(string ItemName, int default_value)
  76. {
  77. int _out = default_value;
  78. try
  79. {
  80. string _str_tmp = ReadConfigure(ItemName);
  81. if (!string.IsNullOrEmpty(_str_tmp) && int.TryParse(_str_tmp, out _out))
  82. {
  83. _out = (_out < default_value ? default_value : _out);
  84. }
  85. return _out;
  86. }
  87. catch { }
  88. return _out;
  89. }
  90. private double ReadConfigure(string ItemName, double default_value)
  91. {
  92. double _out = default_value;
  93. try
  94. {
  95. string _str_tmp = ReadConfigure(ItemName);
  96. if (!string.IsNullOrEmpty(_str_tmp) && double.TryParse(_str_tmp, out _out))
  97. {
  98. _out = (_out < default_value ? default_value : _out);
  99. }
  100. return _out;
  101. }
  102. catch { }
  103. return _out;
  104. }
  105. }
  106. }