From 5241a8f6377dfd1618610dd15fd05ed6f51c8ba2 Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期三, 16 十二月 2020 11:19:45 +0800 Subject: [PATCH] 1. 添加默认流程和默认产品功能 2. 修改批量建立检测项功能 --- src/Bro.Common.Model/Helper/SettingHelper.cs | 208 +++++++++++++++++++++++++++++----------------------- 1 files changed, 116 insertions(+), 92 deletions(-) diff --git a/src/Bro.Common.Model/Helper/SettingHelper.cs b/src/Bro.Common.Model/Helper/SettingHelper.cs index 99f93c2..f22e684 100644 --- a/src/Bro.Common.Model/Helper/SettingHelper.cs +++ b/src/Bro.Common.Model/Helper/SettingHelper.cs @@ -7,95 +7,145 @@ namespace Bro.Common.Helper { - public class SettingHelper + public static class SettingHelper { const string SETTINGFILE = "Setting.json"; - const string PROPERTY_PRODUCTIONCODES = "ProductionCodes"; - const string PROPERTY_CONFIGPATH = "ConfigPath"; - const string PROPERTY_PROCESSCODES = "ProcessCodes"; - const string PROPERTY_DESCRIPTION = "Description"; - const string PROPERTY_ICONPATH = "IconPath"; - static string ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE); - //static JObject data = null; - //static JObject Data - //{ - // get - // { - // if (File.Exists(ConfigPath)) - // { - // using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8)) - // { - // string dataStr = reader.ReadToEnd(); - // data = JsonConvert.DeserializeObject<JObject>(dataStr); - // } - // } - // return data; - // } - //} + public static SettingInfo SettingInfo = null; + static string SettingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE); - public static JObject GetSettingData() + static SettingHelper() { - JObject settingData = null; - if (File.Exists(ConfigPath)) + if (File.Exists(SettingPath)) { - using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8)) + using (StreamReader reader = new StreamReader(SettingPath, System.Text.Encoding.UTF8)) { string dataStr = reader.ReadToEnd(); - settingData = JsonConvert.DeserializeObject<JObject>(dataStr); + SettingInfo = JsonConvert.DeserializeObject<SettingInfo>(dataStr); } } - return settingData; } public static List<string> GetProductionCodes() { - List<string> codes = new List<string>(); - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES)) + if (SettingInfo.ProductionCodes.Count == 0) { - codes = Data.Value<JArray>(PROPERTY_PRODUCTIONCODES).ToList().ConvertAll(u => u.ToString()); + SettingInfo.ProductionCodes.Add("Default"); } - if (codes.Count == 0) + if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProduction)) { - codes.Add("Default"); + if (SettingInfo.ProductionCodes.Contains(SettingInfo.DefaultProduction)) + { + SettingInfo.ProductionCodes.Remove(SettingInfo.DefaultProduction); + SettingInfo.ProductionCodes.Insert(0, SettingInfo.DefaultProduction); + } } - return codes; + return SettingInfo.ProductionCodes; } public static List<string> GetProcessCodes() { - List<string> codes = new List<string>(); - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_PROCESSCODES)) + if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProcess)) { - codes = Data.Value<JArray>(PROPERTY_PROCESSCODES).ToList().ConvertAll(u => u.ToString()); + if (SettingInfo.ProcessCodes.Contains(SettingInfo.DefaultProcess)) + { + SettingInfo.ProcessCodes.Remove(SettingInfo.DefaultProcess); + SettingInfo.ProcessCodes.Insert(0, SettingInfo.DefaultProcess); + } } - return codes; + + return SettingInfo.ProcessCodes; } public static void AddNewProductionCode(string code) { - var dataTemp = GetSettingData(); - - if (!dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) + if (!SettingInfo.ProductionCodes.Contains(code)) { - dataTemp.Add(PROPERTY_PRODUCTIONCODES, new JArray()); + SettingInfo.ProductionCodes.Add(code); } - if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) - { - List<string> codes = GetProductionCodes(); - if (!codes.Contains(code)) - { - codes.Add(code); - } - dataTemp[PROPERTY_PRODUCTIONCODES] = new JArray(codes); + SaveSettingInfo(); + } - string newDataStr = JsonConvert.SerializeObject(dataTemp, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); - using (StreamWriter writer = new StreamWriter(ConfigPath, false, System.Text.Encoding.UTF8)) + public static string GetConfigFilePath() + { + return SettingInfo.ConfigPath; + } + + public static string GetProgramDescription() + { + if (string.IsNullOrWhiteSpace(SettingInfo.Description)) + { + SettingInfo.Description = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�"; + } + + return SettingInfo.Description; + } + + public static string GetProgramIcon() + { + string iconPath = SettingInfo.IconPath; + if (string.IsNullOrWhiteSpace(iconPath) || !File.Exists(iconPath)) + { + iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico"); + } + + if (!File.Exists(iconPath)) + { + iconPath = ""; + } + return iconPath; + } + + #region 淇濆瓨 + public static void SetDefaultProcess(string processCode) + { + if (SettingInfo.DefaultProcess != processCode) + { + SettingInfo.DefaultProcess = processCode; + SaveSettingInfo(); + } + } + + public static void SetDefaultProduction(string productionCode) + { + if (SettingInfo.DefaultProduction != productionCode) + { + SettingInfo.DefaultProduction = productionCode; + SaveSettingInfo(); + } + } + + public static void SetDefault(string processCode,string productionCode) + { + bool isChanged = false; + if (SettingInfo.DefaultProcess != processCode) + { + isChanged = true; + SettingInfo.DefaultProcess = processCode; + } + + if (SettingInfo.DefaultProduction != productionCode) + { + isChanged = true; + SettingInfo.DefaultProduction = productionCode; + } + + if (isChanged) + { + SaveSettingInfo(); + } + } + + static object saveLock = new object(); + private static void SaveSettingInfo() + { + string newDataStr = JsonConvert.SerializeObject(SettingInfo); + lock (saveLock) + { + using (StreamWriter writer = new StreamWriter(SettingPath, false, System.Text.Encoding.UTF8)) { writer.Write(newDataStr); writer.Flush(); @@ -103,46 +153,20 @@ } } } + #endregion + } - public static string GetConfigFilePath() - { - string path = ""; - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_CONFIGPATH)) - { - path = Data.Value<string>(PROPERTY_CONFIGPATH); - } + public class SettingInfo + { + public List<string> ProcessCodes { get; set; } = new List<string>(); + public List<string> ProductionCodes { get; set; } = new List<string>(); - return path; - } + public string DefaultProcess { get; set; } - public static string GetProgramDescription() - { - string desc = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�"; - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_DESCRIPTION)) - { - desc = Data.Value<string>(PROPERTY_DESCRIPTION); - } + public string DefaultProduction { get; set; } - return desc; - } - - public static string GetProgramIcon() - { - string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico"); - - if (!File.Exists(iconPath)) - { - iconPath = ""; - } - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_ICONPATH)) - { - iconPath = Data.Value<string>(PROPERTY_ICONPATH); - } - - return iconPath; - } + public string ConfigPath { get; set; } + public string Description { get; set; } + public string IconPath { get; set; } } } -- Gitblit v1.8.0