From ff7cab72419729ce2c5adc46350ef45d89a5d1e5 Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期六, 24 七月 2021 10:31:41 +0800 Subject: [PATCH] MES动作添加异常捕捉和重试机制 --- src/Bro.UI.Config/MenuForms/FrmOperation.cs | 119 ++++++++++++++++++++--------------------------------------- 1 files changed, 41 insertions(+), 78 deletions(-) diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.cs b/src/Bro.UI.Config/MenuForms/FrmOperation.cs index 9175789..43152d5 100644 --- a/src/Bro.UI.Config/MenuForms/FrmOperation.cs +++ b/src/Bro.UI.Config/MenuForms/FrmOperation.cs @@ -1,5 +1,6 @@ 锘縰sing Bro.Common.Factory; using Bro.Common.Helper; +using Bro.Common.PubSub; using Bro.UI.Model.Winform; using System; using System.Collections.Generic; @@ -9,6 +10,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; +using static Bro.Common.Helper.EnumHelper; namespace Bro.UI.Config.MenuForms { @@ -20,25 +22,22 @@ public FrmOperation() { InitializeComponent(); + PubSubCenter.GetInstance().RemoveSubscribers(PubSubCenterMessageType.UpdateProductionCodes.ToString()); + PubSubCenter.GetInstance().Subscribe(PubSubCenterMessageType.UpdateProductionCodes.ToString(), OnUpdateProductionCodes); LoadProcessCode(); LoadProductionCode(); - - Task.Run(() => - { - Thread.Sleep(1000); - - if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad) - { - LoadProcess(); - _isFirstLoad = false; - } - }); } #region Load Codes string _processCode = ""; string _productionCode = ""; + + private object OnUpdateProductionCodes(ISubscriber arg1, object arg2, object arg3) + { + LoadProductionCode(); + return null; + } private void LoadProcessCode() { @@ -56,7 +55,7 @@ pCodes = systemProcessCodes; } - if (pCodes.Count == 1 && pCodes[0] == "") + if (pCodes.Count == 1) { plProcess.Visible = false; _processCode = pCodes[0]; @@ -64,12 +63,21 @@ } else { - pCodes.Remove(""); + pCodes.RemoveAll(p => string.IsNullOrWhiteSpace(p)); } if (pCodes.Count > 1) { plProcess.Visible = true; + + //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProcess)) + //{ + // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProcess)) + // { + // pCodes.Remove(SettingHelper.SettingInfo.DefaultProcess); + // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProcess); + // } + //} cboProcessCode.SelectedIndexChanged -= cboProcessCode_SelectedIndexChanged; UIHelper.SetCombo(cboProcessCode, pCodes, "", ""); @@ -94,6 +102,16 @@ if (pCodes.Count > 1) { plProduct.Visible = true; + + //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProduction)) + //{ + // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProduction)) + // { + // pCodes.Remove(SettingHelper.SettingInfo.DefaultProduction); + // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProduction); + // } + //} + cboProductionCode.SelectedIndexChanged -= cboProductionCode_SelectedIndexChanged; UIHelper.SetCombo(cboProductionCode, pCodes, "", ""); cboProductionCode.SelectedIndexChanged += cboProductionCode_SelectedIndexChanged; @@ -127,10 +145,12 @@ LogAsync(DateTime.Now, "杞藉叆娴佺▼"); LoadProcess(); + + SettingHelper.SetDefault(_processCode, _productionCode); } bool isStart = true; - private void btnStart_Click(object sender, System.EventArgs e) + private async void btnStart_Click(object sender, System.EventArgs e) { if (Process == null) { @@ -140,18 +160,15 @@ btnStart.Enabled = false; - //Task.Run(() => - //{ try { - //if (Process.ProcessState != EnumHelper.DeviceState.DSOpen) if (isStart) { - ProcessOperation(true); + await ProcessOperation(true); } else { - ProcessOperation(false); + await ProcessOperation(false); } isStart = !isStart; @@ -162,9 +179,8 @@ } finally { - this.BeginInvoke(new Action(() => btnStart.Enabled = true)); + btnStart.Enabled = true; } - //}); } string _currentProcssCode = ""; @@ -182,7 +198,7 @@ return; } - //Process.OnProcessStateChanged += Process_OnProcessStateChanged; + Process.OnLog -= Process_OnLog; Process.OnLog += Process_OnLog; _currentProcssCode = _processCode; @@ -199,80 +215,27 @@ LogAsync(dt, prefix, msg); } - //private void Process_OnProcessStateChanged(EnumHelper.DeviceState state) - //{ - // try - // { - // if (InvokeRequired) - // { - // this.Invoke(new Action<EnumHelper.DeviceState>(Process_OnProcessStateChanged), state); - // } - // else - // { - // try - // { - // btnStart.Enabled = true; - - // switch (state) - // { - // case EnumHelper.DeviceState.DSOpen: - // btnStart.Text = " 鍋� 姝�"; - // btnStart.ImageIndex = 1; - // btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen); - - // btnLoad.Enabled = false; - // break; - // case EnumHelper.DeviceState.DSClose: - // btnStart.Text = " 鍚� 鍔�"; - // btnStart.ImageIndex = 0; - // btnStart.BackColor = SystemColors.Control; - - // btnLoad.Enabled = true; - // break; - // default: - // break; - // } - - // this.Refresh(); - // } - // catch (Exception ex) - // { - // } - // } - // } - // catch (Exception ex) - // { - // } - //} - - private void ProcessOperation(bool isStart) + private async Task ProcessOperation(bool isStart) { if (isStart) { - Process.Open(); + await Task.Run(() => Process.Open()); - //this.BeginInvoke(new Action(() => - //{ btnStart.Text = " 鍋� 姝�"; btnStart.ImageIndex = 1; btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen); btnLoad.Enabled = false; - //})); - } else { - Process.Close(); + await Task.Run(() => Process.Close()); - //this.BeginInvoke(new Action(() => - //{ btnStart.Text = " 鍚� 鍔�"; btnStart.ImageIndex = 0; btnStart.BackColor = SystemColors.Control; btnLoad.Enabled = true; - //})); } } } -- Gitblit v1.8.0