From f16828098a7aeecdd009d9df72cd88a499a871b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com>
Date: Tue, 24 May 2022 13:37:12 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=AD=A6=E7=9B=91=E6=8E=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BPASmartClient.Device/Alarm.cs | 113 +++++++++---------
BPASmartClient.Device/AlarmHelper.cs | 32 ++---
.../BPASmartClient.Device.csproj | 1 +
BPASmartClient.Device/BaseDevice.cs | 25 ++--
BPASmartClient.Device/IDevice.cs | 16 +++
BPASmartClient.Helper/Sqlite.cs | 2 +-
BPASmartClient.IoT/DataVClient.cs | 24 ++--
BPASmartClient.Message/MessageLog.cs | 5 +-
BPASmartClient.MorkS/Alarm.cs | 66 +++++++++-
BPASmartClient.MorkS/Control_Morks.cs | 38 ++++--
BPASmartClient.ViewModel/AlarmViewModel.cs | 101 +++++-----------
BPASmartClient/App.xaml.cs | 2 +
BPASmartClient/Control/AlarmView.xaml | 2 +
BPASmartClient/DeviceInfo.xml | 5 +-
BPASmartClient/MainWindow.xaml | 6 +
15 files changed, 247 insertions(+), 191 deletions(-)
diff --git a/BPASmartClient.Device/Alarm.cs b/BPASmartClient.Device/Alarm.cs
index fecb1b9d..82588982 100644
--- a/BPASmartClient.Device/Alarm.cs
+++ b/BPASmartClient.Device/Alarm.cs
@@ -1,56 +1,57 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BPASmartClient.Device
-{
- public class Alarm
- {
- ///
- /// ID
- ///
- [Key]
- public int Id { get { return _mId; } set { _mId = value; } }
- private int _mId;
-
- ///
- /// 编号ID
- ///
- public int NumId { get { return _mNumId; } set { _mNumId = value; } }
- private int _mNumId;
-
-
- ///
- /// 日期
- ///
- public string Date { get { return _mDate; } set { _mDate = value; } }
- private string _mDate;
-
- ///
- /// 时间
- ///
- public string Time { get { return _mTime; } set { _mTime = value; } }
- private string _mTime;
-
- ///
- /// 报警信息
- ///
- public string Info { get { return _mInfo; } set { _mInfo = value; } }
- private string _mInfo;
-
- ///
- /// 报警值
- ///
- public string Value { get { return _mValue; } set { _mValue = value; } }
- private string _mValue;
-
- ///
- /// 报警等级
- ///
- public string Grade { get { return _mGrade; } set { _mGrade = value; } }
- private string _mGrade;
- }
-}
+//using System;
+//using System.Collections.Generic;
+//using System.ComponentModel.DataAnnotations;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
+
+
+//namespace BPASmartClient.Device
+//{
+// public class Alarm
+// {
+// ///
+// /// ID
+// ///
+// [Key]
+// public int Id { get { return _mId; } set { _mId = value; } }
+// private int _mId;
+
+// ///
+// /// 编号ID
+// ///
+// public int NumId { get { return _mNumId; } set { _mNumId = value; } }
+// private int _mNumId;
+
+
+// ///
+// /// 日期
+// ///
+// public string Date { get { return _mDate; } set { _mDate = value; } }
+// private string _mDate;
+
+// ///
+// /// 时间
+// ///
+// public string Time { get { return _mTime; } set { _mTime = value; } }
+// private string _mTime;
+
+// ///
+// /// 报警信息
+// ///
+// public string Info { get { return _mInfo; } set { _mInfo = value; } }
+// private string _mInfo;
+
+// ///
+// /// 报警值
+// ///
+// public string Value { get { return _mValue; } set { _mValue = value; } }
+// private string _mValue;
+
+// ///
+// /// 报警等级
+// ///
+// public string Grade { get { return _mGrade; } set { _mGrade = value; } }
+// private string _mGrade;
+// }
+//}
diff --git a/BPASmartClient.Device/AlarmHelper.cs b/BPASmartClient.Device/AlarmHelper.cs
index 7a0fd494..297ea918 100644
--- a/BPASmartClient.Device/AlarmHelper.cs
+++ b/BPASmartClient.Device/AlarmHelper.cs
@@ -1,4 +1,7 @@
-using System;
+using BPASmartClient.Helper;
+using BPASmartClient.Message;
+using BPASmartClient.Model;
+using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
@@ -48,7 +51,7 @@ namespace BPASmartClient.Device
{
Alarm tempAlarm = new Alarm()
{
- NumId = Alarms.Count,
+ NumId = Alarms.Count + 1,
Date = DateTime.Now.ToString("yyyy/MM/dd"),
Grade = alarmLevel.ToString(),
Info = AlarmInfo,
@@ -56,22 +59,15 @@ namespace BPASmartClient.Device
Time = DateTime.Now.ToString("HH:mm:ss"),
};
- //tempAlarm.Id = IotReport.GetInstance.HttpAddAlarm(new BPA.Message.API请求.AlarmTable
- //{
- // AlarmTime=DateTime.Now,
- // AlarmType= tempAlarm.Grade,
- // AlarmMessage= tempAlarm.Info,
- // AlarmVla= tempAlarm.Value,
- // ClientId= InternetInfo.ClientId.ToString()
- //});
-
- //Sqlite.GetInstance.Base.Add(tempAlarm);
+ Sqlite.GetInstance.Base.Add(tempAlarm);
if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null)
{
- Alarms.Add(tempAlarm);
- if (AddAction != null) AddAction(AlarmInfo);//添加报警通知
- if (ChangeAction != null) ChangeAction();//更改报警通知
+ Alarms.Insert(0, tempAlarm);
+ for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; }
+ AddAction?.Invoke(AlarmInfo);//添加报警通知
+ ChangeAction?.Invoke();//更改报警通知
+ MessageLog.GetInstance.AddDeviceAlarmLogShow(tempAlarm.Info, Guid.NewGuid().ToString());
}
}
@@ -85,11 +81,7 @@ namespace BPASmartClient.Device
if (result != null)
{
Alarms.Remove(result);
- //IotReport.GetInstance.HttpDeleteAlarm(result.Id);
- for (int i = 0; i < Alarms.Count; i++)
- {
- Alarms.ElementAt(i).NumId = i + 1;
- }
+ for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; }
if (RemoveAction != null) RemoveAction(AlarmInfo);
if (ChangeAction != null) ChangeAction();
}
diff --git a/BPASmartClient.Device/BPASmartClient.Device.csproj b/BPASmartClient.Device/BPASmartClient.Device.csproj
index 3f4f0b9f..ce865d26 100644
--- a/BPASmartClient.Device/BPASmartClient.Device.csproj
+++ b/BPASmartClient.Device/BPASmartClient.Device.csproj
@@ -12,6 +12,7 @@
+
diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs
index 44356031..035dd5c2 100644
--- a/BPASmartClient.Device/BaseDevice.cs
+++ b/BPASmartClient.Device/BaseDevice.cs
@@ -2,6 +2,7 @@
using BPA.Message.Enum;
using BPASmartClient.Helper;
using BPASmartClient.Message;
+using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using System;
using System.Collections.Concurrent;
@@ -101,6 +102,9 @@ namespace BPASmartClient.Device
public Action AddErrorAction { get; set; }
public Action DeleteErrorAction { get; set; }
+ public List alarms { get; set; } = new List();
+ public IAlarm InterfaceAlarm { get; set; }
+ public AlarmHelper alarmHelper { get; set; } = new AlarmHelper();
#endregion
@@ -217,9 +221,10 @@ namespace BPASmartClient.Device
}
else if (faces.Name == "IAlarm")
{
- IAlarm alarm = item.GetValue(this) as IAlarm;
- AlarmHelper alarmHelper = new AlarmHelper();
- alarmHelper.AddAction = new Action((s) =>
+ InterfaceAlarm = item.GetValue(this) as IAlarm;
+ //IAlarm alarm = item.GetValue(this) as IAlarm;
+ //AlarmHelper alarmHelper = new AlarmHelper();
+ alarmHelper.AddAction += new Action((s) =>
{
var res = alarmHelper.Alarms.FirstOrDefault(p => p.Info == s);
if (res != null)
@@ -234,7 +239,7 @@ namespace BPASmartClient.Device
AddErrorAction?.Invoke(DeviceId, obj);
}
});
- alarmHelper.RemoveAction = new Action((s) =>
+ alarmHelper.RemoveAction += new Action((s) =>
{
var res = Error.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == s);
if (res != null && Error.Contains(res))
@@ -245,7 +250,7 @@ namespace BPASmartClient.Device
});
ThreadManage.GetInstance().StartLong(new Action(() =>
{
- AlarmMonitoring(alarm, alarmHelper);
+ AlarmMonitoring();
Thread.Sleep(500);
}), $"报警检测监控:{DeviceId}");
}
@@ -261,17 +266,17 @@ namespace BPASmartClient.Device
///
///
///
- private void AlarmMonitoring(IAlarm alarm, AlarmHelper alarmHelper)
+ private void AlarmMonitoring()
{
- if (alarm == null) return;
- foreach (var item in alarm.GetType().GetProperties())
+ if (InterfaceAlarm == null) return;
+ foreach (var item in InterfaceAlarm.GetType().GetProperties())
{
- var res = item.GetValue(alarm);
+ var res = item.GetValue(InterfaceAlarm);
if (res != null && res is bool blen)
{
if (item.CustomAttributes.Count() > 0 && item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
{
- var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value;
+ var info = item.GetCustomAttribute().AlarmInfo;
if (info != null) alarmHelper.EdgeAlarm(blen, info.ToString());
}
}
diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs
index 582215a8..cf5205bb 100644
--- a/BPASmartClient.Device/IDevice.cs
+++ b/BPASmartClient.Device/IDevice.cs
@@ -1,4 +1,5 @@
using BPA.Message.Enum;
+using BPASmartClient.Model;
using BPASmartClient.Peripheral;
using System;
using System.Collections.Concurrent;
@@ -43,6 +44,21 @@ namespace BPASmartClient.Device
///
List variableMonitors { get; set; }
+ ///
+ /// 设备报警信息集合
+ ///
+ List alarms { get; set; }
+
+ ///
+ /// 接口报警对象
+ ///
+ IAlarm InterfaceAlarm { get; set; }
+
+ ///
+ /// 报警实体
+ ///
+ AlarmHelper alarmHelper { get; set; }
+
///
/// 是否忙碌
///
diff --git a/BPASmartClient.Helper/Sqlite.cs b/BPASmartClient.Helper/Sqlite.cs
index 4deff21b..ab396a46 100644
--- a/BPASmartClient.Helper/Sqlite.cs
+++ b/BPASmartClient.Helper/Sqlite.cs
@@ -39,7 +39,7 @@ namespace BPASmartClient.Helper
SaveChanges();
}
- public object GetData()
+ public List GetData()
{
Database.EnsureCreated();
return Base.ToList();
diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs
index d08a6a24..d9dd7ea5 100644
--- a/BPASmartClient.IoT/DataVClient.cs
+++ b/BPASmartClient.IoT/DataVClient.cs
@@ -39,7 +39,7 @@ namespace BPASmartClient.IoT
ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString();
DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString();
StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString();
- BroadcastPubTopic= System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
+ BroadcastPubTopic = System.Configuration.ConfigurationManager.AppSettings["BroadcastPubTopic"].ToString();
}
#endregion
@@ -68,7 +68,7 @@ namespace BPASmartClient.IoT
///
/// key值
///
- public Dictionary keyValues = new Dictionary();
+ public Dictionary keyValues = new Dictionary();
#endregion
#region API调用
@@ -105,7 +105,7 @@ namespace BPASmartClient.IoT
string id = string.Empty;
try
{
- if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable!=null)
+ if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
logTable.ClientId = ClientId;
logTable.devicename = DeviceDataV.deviceTable.devicename;
@@ -147,7 +147,7 @@ namespace BPASmartClient.IoT
}
else
{
- MessageLog.GetInstance.ShowEx(message);
+ MessageLog.GetInstance.ShowEx(message);
}
}
else
@@ -161,7 +161,7 @@ namespace BPASmartClient.IoT
}
Plugin.GetInstance()?.GetPlugin()?.GetDevices()?.ForEach(device =>
{
- device.AddErrorAction+= AddErrorAction;
+ device.AddErrorAction += AddErrorAction;
device.DeleteErrorAction += DeleteErrorAction;
});
}
@@ -173,7 +173,7 @@ namespace BPASmartClient.IoT
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
- if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
+ if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
List