using Rs.MotionPlat.Flow; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; using static Rs.MotionPlat.Commom.SchedulingMessageBox; namespace Rs.MotionPlat.Commom { public class TestCenterMessageBox { static Dictionary msgList; static Dictionary msgSentEvent; static Dictionary resultMessageBox; static object msgLock = new object(); static TestCenterMessageBox() { msgSentEvent = new Dictionary(); resultMessageBox = new Dictionary(); msgList = new Dictionary(); } public static void Show(int id, string message, ETipButton button,bool bNeedStop=false) { lock(msgLock) { Show(id, message, button, null,bNeedStop); } } public static void Show(int id,string message,ETipButton button,Dictionary buttonTexts,bool bNeedStop=false) { lock (msgLock) { SchedulingMessageBox msgBox = new SchedulingMessageBox(); if (buttonTexts != null) msgBox.ButtonContexts = buttonTexts; msgBox.Message = message; msgBox.Button = button; msgBox.Instruction = EInstruction.ShowMessage; msgBox.ID = id; if(!msgList.ContainsKey(id)) { msgList.Add(id, msgBox); } TestCenter.Instance.ShowMsgBox(msgBox); if(!msgSentEvent.ContainsKey(id)) { msgSentEvent.Add(id, new ManualResetEvent(false)); } if(bNeedStop) { Ops.Stop(); } } } public static void RecivedMsg(SchedulingMessageBox result) { if (msgSentEvent.ContainsKey(result.ID)) { if (!resultMessageBox.ContainsKey(result.ID)) { resultMessageBox.Add(result.ID, result); } msgSentEvent[result.ID].Set(); } } public static SchedulingMessageBox WaitResult(int id) { SchedulingMessageBox box = new SchedulingMessageBox(); if (msgSentEvent.ContainsKey(id)) { msgSentEvent[id].WaitOne(); msgSentEvent.Remove(id); box = resultMessageBox[id]; resultMessageBox.Remove(id); msgList.Remove(id); } return box; } public static int GetMsgID() { if(msgSentEvent.Count==1) { return msgSentEvent.ElementAt(0).Key; } return -1; } /// /// 根据按钮的类型获取弹框的ID /// /// public static int GetMsgID(ETipButton btnType) { if(msgList!=null && msgList.Count>0) { foreach (var button in msgList.Values.ToList()) { if (button.Button.HasFlag(btnType)) return button.ID; } } return -1; } } }