SettingConfig.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. namespace AwInitilizer
  8. {
  9. public class AppSettingConfig
  10. {
  11. public static string FirmwareRoot
  12. {
  13. get
  14. {
  15. if(Instance == null)
  16. {
  17. Instance = new AppSettingConfig();
  18. }
  19. return Instance._FirmwareRoot;
  20. }
  21. }
  22. public static string Language
  23. {
  24. get
  25. {
  26. if (Instance == null)
  27. {
  28. Instance = new AppSettingConfig();
  29. }
  30. return Instance._Language;
  31. }
  32. }
  33. public static string MES
  34. {
  35. get
  36. {
  37. if (Instance == null)
  38. {
  39. Instance = new AppSettingConfig();
  40. }
  41. return Instance._MES;
  42. }
  43. }
  44. public static string MechineCode
  45. {
  46. get
  47. {
  48. if (Instance == null)
  49. {
  50. Instance = new AppSettingConfig();
  51. }
  52. return Instance._MechineCode;
  53. }
  54. }
  55. public static bool IsDisableAuthRequired
  56. {
  57. get
  58. {
  59. if (Instance == null)
  60. {
  61. Instance = new AppSettingConfig();
  62. }
  63. return Instance._IsDisableAuthRequired;
  64. }
  65. }
  66. public static string JohnSenLedComPort
  67. {
  68. get
  69. {
  70. if (Instance == null)
  71. {
  72. Instance = new AppSettingConfig();
  73. }
  74. return Instance._JohnSenLedComPort;
  75. }
  76. }
  77. private static AppSettingConfig Instance;
  78. private string _FirmwareRoot, _Language, _MES , _MechineCode;
  79. private bool _IsDisableAuthRequired;
  80. private string _JohnSenLedComPort;
  81. private static string settingFileName = "config.ini";
  82. public AppSettingConfig()
  83. {
  84. if(!File.Exists(settingFileName))
  85. {
  86. LoadDefaultSetting();
  87. }
  88. else
  89. {
  90. LoadSettingFromDefaultFile();
  91. }
  92. }
  93. private void LoadSettingFromDefaultFile()
  94. {
  95. try
  96. {
  97. LoadDefaultSetting();
  98. var configStr = File.ReadAllText(settingFileName);
  99. var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Model.AppSettingConfig>(configStr);
  100. _FirmwareRoot = config.FirmwareRoot;
  101. _Language = config.Language;
  102. _MES = config.MES;
  103. _MechineCode = config.MechineCode;
  104. _IsDisableAuthRequired = config.IsDisableAuthRequired;
  105. _JohnSenLedComPort = config.JohnSenLedComPort;
  106. }
  107. catch
  108. {
  109. }
  110. }
  111. private void LoadDefaultSetting()
  112. {
  113. _FirmwareRoot = "./Firmware";
  114. _Language = "zh-chs";
  115. _MES = "sajet2";
  116. _MechineCode = "testMechineCode";
  117. }
  118. }
  119. }