123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace ST_CUBE_MES.Service
- {
- public class AppSettingService
- {
- private static AppSettingService _Instance;
- public static AppSettingService Instance
- {
- get
- {
- if (_Instance == null)
- {
- _Instance = new AppSettingService();
- }
- return _Instance;
- }
- }
- private AppSettingService()
- {
- }
- public string MES => appSetting?.MES;
- public string MechineCode => appSetting?.MechineCode;
- public bool LOCK => appSetting == null ? false : appSetting.LOCK;
- public string STCubeCliPath => appSetting?.STCubeCliPath;
- public string BinPath => appSetting?.BinPath;
- public string Port => appSetting?.Port;
- public string CustomDefaultOptions => appSetting?.CustomDefaultOptions;
- private const string settingFileName = "Settings.ini";
- private AppSetting appSetting;
- public void Load()
- {
- if (!File.Exists(settingFileName))
- {
- appSetting = new AppSetting()
- {
- MES = "phv",
- };
- return;
- }
- try
- {
- appSetting = JsonConvert.DeserializeObject<AppSetting>(File.ReadAllText(settingFileName));
- }
- catch
- {
- MessageBox.Show($"{settingFileName} format ERROR");
- }
- }
- public void Save(AppSetting setting)
- {
- if (File.Exists(settingFileName))
- {
- File.Delete(settingFileName);
- }
- File.WriteAllText(settingFileName, JsonConvert.SerializeObject(setting));
- Load();
- }
- }
- public class AppSetting
- {
- public string MES { get; set; }
- public string MechineCode { get; set; }
- public bool LOCK { get; set; }
- public string STCubeCliPath { get; set; }
- public string BinPath { get; set; }
- public string Port { get; set; }
- public string CustomDefaultOptions { get; set; }
- }
- }
|