using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WCS.BLL.Config { /// /// 本地文件 /// public class LocalFile { /// /// 程序运行名称(BaseUi.exe) /// public static readonly string AppName = AppDomain.CurrentDomain.FriendlyName; /// /// 程序运行目录 /// public static readonly string AppDir = AppDomain.CurrentDomain.BaseDirectory; /// /// 数据目录 /// public static readonly string DataDir = Path.Combine(AppDir, "data"); /// /// 日志目录 /// public static readonly string LogDir = Path.Combine(AppDir, "logs"); /// /// 运行主程序 /// public static readonly string AppPath = Path.Combine(AppDir, AppDomain.CurrentDomain.FriendlyName); /// /// 配置文件路径 /// public static readonly string ConfigPath = Path.Combine(DataDir, "jsconfig.json"); /// /// 货架模组编码正则表达式 /// public static readonly string ModuleCodePattern = "^[ABCD][0-9]{2}-R[0-9]{1,2}C[0-9]{1,2}$"; static object lockConfig = new object(); //static JsConfig config; ///// ///// 配置信息 ///// //public static JsConfig Config //{ // get // { // if (config != null) // return config; // else // { // try // { // if (File.Exists(ConfigPath)) // lock (lockConfig) // config = JsonConvert.DeserializeObject(File.ReadAllText(ConfigPath, Encoding.UTF8)); // else // config = null; // } // catch (Exception) // { // config = null; // } // } // return config ?? new JsConfig(); // } //} ///// ///// 刷新配置信息。将本地的配置信息重新加载到内存中 ///// //public static void UpdateConfig() //{ // if (File.Exists(ConfigPath)) // lock (lockConfig) // config = JsonConvert.DeserializeObject(File.ReadAllText(ConfigPath, Encoding.UTF8)); // else // config = null; //} ///// ///// 保存配置信息。将内存中的配置信息保存到本地 ///// //public static void SaveConfig() //{ // try // { // lock (lockConfig) // File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(Config, Formatting.Indented), Encoding.UTF8); // } // catch (Exception ex) // { // UpdateConfig(); // throw ex; // } //} } }