UriSetting.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Serialization;
  8. namespace Pms.WebHandle
  9. {
  10. public class UriData
  11. {
  12. public string Uri = "http://127.0.0.1:8804/taiguang";
  13. public string MESUri = "http://127.0.0.1:8804/taiguang";
  14. public string WMSUri = "http://127.0.0.1:8804/taiguang";
  15. }
  16. public class UriSetting
  17. {
  18. private static UriData g_DBSetting = new UriData();
  19. private static string m_ServiceUri = "";
  20. private static string m_MESUri = "";
  21. private static string m_WMSUri = "";
  22. public static string g_ServiceUri
  23. {
  24. get
  25. {
  26. if (m_ServiceUri == "")
  27. {
  28. InitDBSetting();
  29. try
  30. {
  31. XmlSerializer serializer1 = new XmlSerializer(UriSetting.g_DBSetting.GetType());
  32. string strPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\PMS\\Config";
  33. string strFileName = strPath + "\\UriSetting.xml";
  34. DirectoryInfo dir = new DirectoryInfo(strPath);
  35. if (!dir.Exists)
  36. {
  37. dir.Create();
  38. }
  39. using (TextWriter tw = new StreamWriter(strFileName))
  40. {
  41. serializer1.Serialize(tw, UriSetting.g_DBSetting);
  42. }
  43. }
  44. catch
  45. { }
  46. }
  47. return m_ServiceUri;
  48. }
  49. }
  50. public static string g_MESUri
  51. {
  52. get
  53. {
  54. if (m_MESUri == "")
  55. {
  56. InitDBSetting();
  57. try
  58. {
  59. XmlSerializer serializer1 = new XmlSerializer(UriSetting.g_DBSetting.GetType());
  60. string strPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\PMS\\Config";
  61. string strFileName = strPath + "\\UriSetting.xml";
  62. DirectoryInfo dir = new DirectoryInfo(strPath);
  63. if (!dir.Exists)
  64. {
  65. dir.Create();
  66. }
  67. using (TextWriter tw = new StreamWriter(strFileName))
  68. {
  69. serializer1.Serialize(tw, UriSetting.g_DBSetting);
  70. }
  71. }
  72. catch
  73. { }
  74. }
  75. return m_MESUri;
  76. }
  77. }
  78. public static string g_WMSUri
  79. {
  80. get
  81. {
  82. if (m_WMSUri == "")
  83. {
  84. InitDBSetting();
  85. try
  86. {
  87. XmlSerializer serializer1 = new XmlSerializer(UriSetting.g_DBSetting.GetType());
  88. string strPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\PMS\\Config";
  89. string strFileName = strPath + "\\UriSetting.xml";
  90. DirectoryInfo dir = new DirectoryInfo(strPath);
  91. if (!dir.Exists)
  92. {
  93. dir.Create();
  94. }
  95. using (TextWriter tw = new StreamWriter(strFileName))
  96. {
  97. serializer1.Serialize(tw, UriSetting.g_DBSetting);
  98. }
  99. }
  100. catch
  101. { }
  102. }
  103. return m_WMSUri;
  104. }
  105. }
  106. private static void InitDBSetting()
  107. {
  108. //反序列化
  109. XmlSerializer serializer = new XmlSerializer(UriSetting.g_DBSetting.GetType());
  110. try
  111. {
  112. string path = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\PMS\\Config\\UriSetting.xml";
  113. using (TextReader tr = new StreamReader(path))
  114. {
  115. UriSetting.g_DBSetting = (UriData)serializer.Deserialize(tr);
  116. }
  117. }
  118. catch (Exception)
  119. { }
  120. m_ServiceUri = g_DBSetting.Uri;
  121. m_MESUri = g_DBSetting.MESUri;
  122. m_WMSUri = g_DBSetting.WMSUri;
  123. }
  124. }
  125. }