You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.6 KiB
C#

11 months ago
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<int, SchedulingMessageBox> msgList;
static Dictionary<int,ManualResetEvent> msgSentEvent;
static Dictionary<int, SchedulingMessageBox> resultMessageBox;
static object msgLock = new object();
static TestCenterMessageBox()
{
msgSentEvent = new Dictionary<int,ManualResetEvent>();
resultMessageBox = new Dictionary<int, SchedulingMessageBox>();
msgList = new Dictionary<int, SchedulingMessageBox>();
}
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<ETipButton,string> 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;
}
/// <summary>
/// 根据按钮的类型获取弹框的ID
/// </summary>
/// <returns></returns>
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;
}
}
}