From c44c1b442fde596c1d20c0ad82e4d308f71ec806 Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期六, 01 八月 2020 13:55:46 +0800 Subject: [PATCH] 部分修改 --- src/Bro.Process/ProcessControl.cs | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs index afbc38d..8a4c27f 100644 --- a/src/Bro.Process/ProcessControl.cs +++ b/src/Bro.Process/ProcessControl.cs @@ -21,7 +21,7 @@ using System.Threading.Tasks; using static Bro.Common.Helper.EnumHelper; -namespace Bro.Process +namespace Bro.Process { [Process("", DeviceAttributeType.Device)] public partial class ProcessControl : IProcess @@ -348,10 +348,16 @@ { if (config == null) throw new ProcessException("淇濆瓨鐨勯厤缃俊鎭笉鑳戒负绌�"); - ProductionCode = newProductionCode; + + string newConfigPath = Path.Combine(Path.GetDirectoryName(_configPath), $"Config_{newProductionCode}.json"); + if (File.Exists(newConfigPath)) + { + throw new ProcessException($"{newProductionCode}閰嶇疆鏂囦欢宸茬粡瀛樺湪"); + } + //鐢熸垚config.json string newConfig = JsonConvert.SerializeObject(config, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); - using (StreamWriter writer = new StreamWriter(_configPath, false, System.Text.Encoding.UTF8)) + using (StreamWriter writer = new StreamWriter(newConfigPath, false, System.Text.Encoding.UTF8)) { writer.Write(newConfig); writer.Flush(); @@ -359,7 +365,7 @@ } //娣诲姞鍒癝etting.json - SettingHelper.AddNewProductionCode(ProductionCode); + SettingHelper.AddNewProductionCode(newProductionCode); } catch (Exception ex) { @@ -527,7 +533,7 @@ object res = null; int reTryTimes = config.ReTryTimes; IDevice device = DeviceCollection.FirstOrDefault(u => u.Id == deviceId); - LogAsync(DateTime.Now, $"{device.Name}璋冪敤{methodCode}寮�濮�", ""); + LogAsync(DateTime.Now, $"{device?.Name}璋冪敤{methodCode}寮�濮�", ""); Stopwatch sw = new Stopwatch(); sw.Start(); @@ -603,8 +609,8 @@ #endregion sw.Stop(); - LogAsync(DateTime.Now, $"{device.Name}璋冪敤{methodCode}瀹屾垚锛岃�楁椂{sw.ElapsedMilliseconds}ms", ""); - TimeRecordCSV(DateTime.Now, device.Name, $"{methodCode}璋冪敤瀹屾垚", (int)sw.ElapsedMilliseconds); + LogAsync(DateTime.Now, $"{device?.Name}璋冪敤{methodCode}瀹屾垚锛岃�楁椂{sw.ElapsedMilliseconds}ms", ""); + TimeRecordCSV(DateTime.Now, device?.Name, $"{methodCode}璋冪敤瀹屾垚", (int)sw.ElapsedMilliseconds); } /// <summary> -- Gitblit v1.8.0