You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
2 years ago
|
using Newtonsoft.Json;
|
||
|
|
||
|
namespace JiLinApp.Docking.Alarm;
|
||
|
|
||
|
public class AlarmCodeHelper
|
||
|
{
|
||
|
#region Fields
|
||
|
|
||
|
private static readonly Dictionary<string, AlarmCode> AlarmCodeDict;
|
||
|
private static readonly List<int> LevelList;
|
||
|
private static readonly List<string> TypeList;
|
||
|
|
||
|
#endregion fields
|
||
|
|
||
|
static AlarmCodeHelper()
|
||
|
{
|
||
|
using StreamReader r = new(Path.Combine("config", "alarmcode.json"));
|
||
|
string jsonStr = r.ReadToEnd();
|
||
|
List<AlarmCode> list = JsonConvert.DeserializeObject<List<AlarmCode>>(jsonStr) ?? new();
|
||
|
AlarmCodeDict = list.ToDictionary(item => item.Id, item => item);
|
||
|
LevelList = list.GroupBy(item => item.Level)
|
||
|
.Select(it => it.First().Level).ToList();
|
||
|
TypeList = list.GroupBy(item => item.Type)
|
||
|
.Select(it => it.First().Type).ToList();
|
||
|
}
|
||
|
|
||
|
public static void Init()
|
||
|
{ }
|
||
|
|
||
|
public static AlarmCode Get(string id)
|
||
|
{
|
||
|
return AlarmCodeDict[id];
|
||
|
}
|
||
|
|
||
|
public static bool TryGet(string id, out AlarmCode alarmCode)
|
||
|
{
|
||
|
bool flag = AlarmCodeDict.TryGetValue(id, out AlarmCode? temp);
|
||
|
alarmCode = temp ?? new();
|
||
|
return flag;
|
||
|
}
|
||
|
}
|