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.
121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
using Newtonsoft.Json.Converters;
|
|
using Newtonsoft.Json;
|
|
using Rs.MotionPlat.Entitys;
|
|
using Rs.MotionPlat.Flow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Rs.MotionPlat.Commom.SchedulingAlarms;
|
|
using static Rs.MotionPlat.Commom.SchedulingMessageBox;
|
|
using System.Threading;
|
|
|
|
namespace Rs.MotionPlat.Commom
|
|
{
|
|
/// <summary>
|
|
/// 报警弹框
|
|
/// </summary>
|
|
public class AlarmMessageBox
|
|
{
|
|
static Dictionary<int, ManualResetEvent> msgEventDic = new Dictionary<int, ManualResetEvent>();
|
|
static Dictionary<int, AlarmItem> closeInfoDic = new Dictionary<int, AlarmItem>();
|
|
static Dictionary<int, AlarmItem> msgBoxs = new Dictionary<int, AlarmItem>();
|
|
private static object lockObj = new object();
|
|
public static void Close(AlarmItem ai)
|
|
{
|
|
if (closeInfoDic.ContainsKey(ai.NO))
|
|
{
|
|
closeInfoDic.Remove(ai.NO);
|
|
}
|
|
closeInfoDic.Add(ai.NO, ai);
|
|
if (msgEventDic.ContainsKey(ai.NO))
|
|
{
|
|
msgEventDic[ai.NO].Set();
|
|
}
|
|
}
|
|
private static ETipButton Show(AlarmItem alarmInfo)
|
|
{
|
|
if (!msgEventDic.ContainsKey(alarmInfo.NO))
|
|
{
|
|
SchedulingAlarms alarms = new SchedulingAlarms();
|
|
alarms.Alarms.Add(alarmInfo);
|
|
alarms.GroupID = 0;
|
|
alarms.TurnoverID = 0;
|
|
alarms.Instruction = EInstruction.SetAlarms;
|
|
string content = JsonConvert.SerializeObject(alarms, new StringEnumConverter());
|
|
if (TestCenter.Instance.Send(content, Encoding.UTF8, true) > 0)
|
|
{
|
|
LightManger.Instance.SetStatus(ELightStatus.Red);
|
|
//在这里等待中控返回
|
|
if (!msgEventDic.ContainsKey(alarmInfo.NO))
|
|
{
|
|
msgEventDic.Add(alarmInfo.NO, new ManualResetEvent(false));
|
|
msgBoxs.Add(alarmInfo.NO, alarmInfo);
|
|
}
|
|
else
|
|
{
|
|
msgEventDic[alarmInfo.NO].Reset();
|
|
}
|
|
msgEventDic[alarmInfo.NO].WaitOne();
|
|
if (closeInfoDic.ContainsKey(alarmInfo.NO))
|
|
{
|
|
if(msgEventDic.ContainsKey(alarmInfo.NO))
|
|
{
|
|
msgEventDic.Remove(alarmInfo.NO);
|
|
msgBoxs.Remove(alarmInfo.NO);
|
|
}
|
|
ETipButton button = closeInfoDic[alarmInfo.NO].Button;
|
|
|
|
closeInfoDic.Remove(alarmInfo.NO);
|
|
return button;
|
|
}
|
|
}
|
|
}
|
|
return ETipButton.None;
|
|
|
|
}
|
|
public static ETipButton ShowDialog(bool pause,ETipButton button, Dictionary<ETipButton, string> buttonText,int msgID, params string[] parameters)
|
|
{
|
|
AlarmEntity ae = AlarmCollection.Get(msgID).Transform(parameters);
|
|
AlarmItem msg = new AlarmItem();
|
|
msg.Pause = pause;
|
|
msg.NO = msgID;
|
|
msg.ZH = ae.CN;
|
|
msg.EN = ae.EN;
|
|
msg.KO = ae.KO;
|
|
msg.Button = button;
|
|
msg.ButtonContexts = buttonText;
|
|
return Show(msg);
|
|
}
|
|
|
|
public static ETipButton ShowDialog(AlarmEntity alarmEntity,ETipButton button, Dictionary<ETipButton, string> buttonText,bool pause=true)
|
|
{
|
|
AlarmItem msg = new AlarmItem();
|
|
msg.Pause = pause;
|
|
msg.NO = alarmEntity.AlarmID;
|
|
msg.ZH = alarmEntity.CN;
|
|
msg.EN = alarmEntity.EN;
|
|
msg.KO = alarmEntity.KO;
|
|
msg.Button = button;
|
|
msg.ButtonContexts = buttonText;
|
|
return Show(msg);
|
|
}
|
|
|
|
public static int GetMsgID(ETipButton button)
|
|
{
|
|
if(msgBoxs!=null && msgBoxs.Count>0)
|
|
{
|
|
foreach (var item in msgBoxs)
|
|
{
|
|
if(item.Value.Button.HasFlag(button))
|
|
{
|
|
return item.Key;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
}
|