| | |
| | | namespace HMI.Core.Api |
| | | using HMI.Core.Entity; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace HMI.Core.Api |
| | | { |
| | | public class AlarmShowHelper |
| | | { |
| | | private static List<IAlarmHandler> handlers; |
| | | |
| | | private static IAlarmShow shower; |
| | | |
| | | public static void Register(IAlarmShow shower) |
| | |
| | | } |
| | | } |
| | | |
| | | public static bool ShowAlarm(string message) |
| | | public static void UnRegister(IAlarmShow shower) |
| | | { |
| | | if (AlarmShowHelper.shower == shower) |
| | | { |
| | | AlarmShowHelper.shower = null; |
| | | } |
| | | } |
| | | |
| | | public static void AddHandler(IAlarmHandler handler) |
| | | { |
| | | if (handlers == null) |
| | | { |
| | | handlers = new List<IAlarmHandler>(); |
| | | } |
| | | if (!handlers.Contains(handler)) |
| | | { |
| | | handlers.Add(handler); |
| | | } |
| | | } |
| | | |
| | | public static bool ShowAlarm(AlarmText alarm) |
| | | { |
| | | if (handlers != null) |
| | | { |
| | | foreach (var handler in handlers) |
| | | { |
| | | try |
| | | { |
| | | handler.HandleAlarm(alarm); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (shower != null) |
| | | { |
| | | return shower.ShowAlarm(message); |
| | | return shower.ShowAlarm(alarm); |
| | | } |
| | | return false; |
| | | } |