SettingConfig.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. private static AppSettingConfig Instance;
  67. private string _FirmwareRoot, _Language, _MES , _MechineCode;
  68. private bool _IsDisableAuthRequired;
  69. private static string settingFileName = "config.ini";
  70. public AppSettingConfig()
  71. {
  72. if(!File.Exists(settingFileName))
  73. {
  74. LoadDefaultSetting();
  75. }
  76. else
  77. {
  78. LoadSettingFromDefaultFile();
  79. }
  80. }
  81. private void LoadSettingFromDefaultFile()
  82. {
  83. try
  84. {
  85. LoadDefaultSetting();
  86. var configStr = File.ReadAllText(settingFileName);
  87. var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Model.AppSettingConfig>(configStr);
  88. _FirmwareRoot = config.FirmwareRoot;
  89. _Language = config.Language;
  90. _MES = config.MES;
  91. _MechineCode = config.MechineCode;
  92. _IsDisableAuthRequired = config.IsDisableAuthRequired;
  93. }
  94. catch
  95. {
  96. }
  97. }
  98. private void LoadDefaultSetting()
  99. {
  100. _FirmwareRoot = "./Firmware";
  101. _Language = "zh-chs";
  102. _MES = "sajet2";
  103. _MechineCode = "testMechineCode";
  104. }
  105. }
  106. }