Browse Source

错误日志输出

master
pry 2 years ago
parent
commit
b60e98e755
14 changed files with 160 additions and 57 deletions
  1. +2
    -2
      HBLConsole.Business/AbstractServer/Base.cs
  2. +2
    -2
      HBLConsole.Business/IotReport.cs
  3. +1
    -1
      HBLConsole.Communication/LebaiHelper.cs
  4. +4
    -4
      HBLConsole.Communication/ModbusTcpHelper.cs
  5. +2
    -2
      HBLConsole.Communication/MqttHelper.cs
  6. +1
    -1
      HBLConsole.MainConsole/Main.cs
  7. +28
    -0
      HBLConsole.Model/ViewModel/HardwareStatusData.cs
  8. +33
    -1
      HBLConsole.Service/MessageLog.cs
  9. +2
    -1
      HBLConsole.Service/SystemHelper.cs
  10. +1
    -1
      HBLConsole.Service/ThreadManage.cs
  11. +8
    -1
      HBLConsole/App.xaml.cs
  12. +62
    -0
      HBLConsole/ViewModel/HardwareStatusViewModel.cs
  13. +8
    -40
      HBLConsole/ViewModel/MainViewModel.cs
  14. +6
    -1
      HBLConsole/ViewModel/ViewModelBase.cs

+ 2
- 2
HBLConsole.Business/AbstractServer/Base.cs View File

@@ -99,7 +99,7 @@ namespace HBLConsole.Business.AbstractServer
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
}
}

@@ -144,7 +144,7 @@ namespace HBLConsole.Business.AbstractServer
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
}
var res = JsonConvert.DeserializeObject<OrderStatusRsp>(result);
return res == null ? false : res.isSuccess;


+ 2
- 2
HBLConsole.Business/IotReport.cs View File

@@ -86,7 +86,7 @@ namespace HBLConsole.Business
#region 赋值基本属性与状态
bool IsAllowRun = false;
bool TemperatureReached = false;
string kzsx = Tools.JsonConvertTools<DevSX>(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "",SXLX = "" } } });
iOTDevSXModel.KZSX = Tools.JsonConvertTools<DevSX>(new DevSX { data = new List<DevSXBase> { new DevSXBase { SXMC = "", SXLX = "" } } });
iOTDevSXModel.JBSX = Tools.JsonConvertTools<DevSX>(new DevSX
{
data = new List<DevSXBase>
@@ -149,7 +149,7 @@ namespace HBLConsole.Business
default:
break;
}
IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic,iOTDevSXModel.Tojson());
IOTDevServer.GetInstance().IOT_Publish(IOTDevServer.PubTopic, iOTDevSXModel.Tojson());
}
}
#endregion


+ 1
- 1
HBLConsole.Communication/LebaiHelper.cs View File

@@ -51,7 +51,7 @@ namespace HBLConsole.Communication
{
if (!ErrorFlag)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
ErrorFlag = true;
}
Thread.Sleep(3000);


+ 4
- 4
HBLConsole.Communication/ModbusTcpHelper.cs View File

@@ -67,8 +67,8 @@ namespace HBLConsole.Communication
{
if (!ErrorFlag)
{
MessageLog.GetInstance.Show($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
MessageLog.GetInstance.ShowEx(ex.ToString());
ErrorFlag = true;
}
Thread.Sleep(3000);
@@ -167,7 +167,7 @@ namespace HBLConsole.Communication
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
if (ex.InnerException is SocketException)
{
tcpClient = null;
@@ -233,7 +233,7 @@ namespace HBLConsole.Communication
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
if (ex.InnerException is SocketException)
{
tcpClient = null;


+ 2
- 2
HBLConsole.Communication/MqttHelper.cs View File

@@ -66,7 +66,7 @@ namespace HBLConsole.Communication
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.Message);
MessageLog.GetInstance.ShowEx(ex.Message);
MessageLog.GetInstance.Show("mqtt连接失败!重连执行中");
}

@@ -100,7 +100,7 @@ namespace HBLConsole.Communication
{
if (!ErrorFlag)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
ErrorFlag = true;
}
}


+ 1
- 1
HBLConsole.MainConsole/Main.cs View File

@@ -53,7 +53,7 @@ namespace HBLConsole.MainConsole
ThreadManage.GetInstance.Start(new Action(() =>
{
InternetInfo.ConfigInit();//从 consul 获取配置数据
//IotReport.GetInstance.Initialize();
IotReport.GetInstance.Initialize();
Topics.Clear();
Topics.Add(TOPIC.GetInstance.GetOrderPushTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));
Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.DeviceType, InternetInfo.ClientId));


+ 28
- 0
HBLConsole.Model/ViewModel/HardwareStatusData.cs View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Mvvm.ComponentModel;

namespace HBLConsole.Model
{
public class HardwareStatusData : ObservableObject
{
public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
private string _mName;

public string Describe { get { return _mDescribe; } set { _mDescribe = value; OnPropertyChanged(); } }
private string _mDescribe;


public string Address { get { return _mAddress; } set { _mAddress = value; OnPropertyChanged(); } }
private string _mAddress;


public string CurrentValue { get { return _mCurrentValue; } set { _mCurrentValue = value; OnPropertyChanged(); } }
private string _mCurrentValue;


}
}

+ 33
- 1
HBLConsole.Service/MessageLog.cs View File

@@ -13,6 +13,7 @@ namespace HBLConsole.Service
public static MessageLog GetInstance => _Instance ?? (_Instance = new MessageLog());
private MessageLog() { }

#region 普通消息日志
/// <summary>
/// 日志显示委托
/// </summary>
@@ -23,13 +24,44 @@ namespace HBLConsole.Service
/// </summary>
public string LogInfo { get; set; } = string.Empty;


/// <summary>
/// 普通日志输出
/// </summary>
/// <param name="info"></param>
public void Show(string info)
{
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
LogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {LogInfo}";
if (InfoNotify != null) InfoNotify(info);
}
#endregion

#region 异常消息日志
/// <summary>
/// 异常日志委托
/// </summary>
public Action<string> ExInfoNotify { get; set; }

/// <summary>
/// 异常日志信息
/// </summary>
public string ExLogInfo { get; set; } = string.Empty;

/// <summary>
/// 异常日志输出
/// </summary>
/// <param name="info"></param>
public void ShowEx(string info)
{
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
if (ExInfoNotify != null) ExInfoNotify(info);
}
#endregion





}
}

+ 2
- 1
HBLConsole.Service/SystemHelper.cs View File

@@ -60,8 +60,9 @@ namespace HBLConsole.Service
shortcut.Save(); //必须调用保存快捷才成创建成功
return true;
}
catch (Exception)
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx(ex.ToString());
return false;
}
}


+ 1
- 1
HBLConsole.Service/ThreadManage.cs View File

@@ -56,7 +56,7 @@ namespace HBLConsole.Service
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
MessageLog.GetInstance.ShowEx(ex.ToString());
if (IsRestart)
{
Thread.Sleep(2000);


+ 8
- 1
HBLConsole/App.xaml.cs View File

@@ -98,7 +98,14 @@ namespace HBLConsole
TextHelper.GetInstance.WriteTextInfo(ErroLog, "ErroLog");
SqlHelper.GetInstance.Save();
MainConsole.Main.GetInstance.DataSave();

IotReport.GetInstance.SendLogMessage(new BPA.Message.API请求.LogTable
{
ClientId = InternetInfo.ClientId.ToString(),
LogTime = DateTime.Now,
LogType = "1",
LogMessage = ErroLog,
LogVla = "正常",
});
// Process.Start($"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName}.exe");
}



+ 62
- 0
HBLConsole/ViewModel/HardwareStatusViewModel.cs View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using HBLConsole.Factory;
using System.Reflection;
using HBLConsole.Attributes;
using HBLConsole.Model;
using System.Threading;
using HBLConsole.Service;

namespace HBLConsole.ViewModel
{
public class HardwareStatusViewModel
{
public static void AddMonitorData()
{
if (SimpleFactory.GetInstance.HardwareStatus == null) return;
foreach (var item in SimpleFactory.GetInstance.HardwareStatus.GetType().GetProperties())
{
if (item.CustomAttributes.Count() > 0)
{
var attributeName = item.CustomAttributes.FirstOrDefault(p => p.AttributeType.Name == "HardwareStatusAttribute");
if (attributeName == null) return;
var Address = item.GetCustomAttribute<HardwareStatusAttribute>()?.Address;
var Describe = item.GetCustomAttribute<HardwareStatusAttribute>()?.Describe;
hardwareStatusDatas.Add(new HardwareStatusData()
{
Name = item.Name,
Address = Address,
Describe = Describe,
});
}
}
}

public static void UpdateValue()
{
if (SimpleFactory.GetInstance.HardwareStatus == null) return;
ThreadManage.GetInstance.StartLong(new Action(() =>
{
foreach (var item in SimpleFactory.GetInstance.HardwareStatus.GetType().GetProperties())
{

int index = Array.FindIndex(hardwareStatusDatas.ToArray(), p => p.Name == item.Name);
if (index >= 0 && index < hardwareStatusDatas.Count)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
hardwareStatusDatas.ElementAt(index).CurrentValue = item.GetValue(SimpleFactory.GetInstance.HardwareStatus)?.ToString();
}));
}
}
Thread.Sleep(1000);
}), "硬件状态监控");
}

public static ObservableCollection<HardwareStatusData> hardwareStatusDatas { get; set; } = new ObservableCollection<HardwareStatusData>();
}
}

+ 8
- 40
HBLConsole/ViewModel/MainViewModel.cs View File

@@ -17,6 +17,7 @@ using HBLConsole.Factory;
using HBLConsole.Attributes;
using BPA.Message.IOT;
using System.Collections.ObjectModel;
using HBLConsole.Interface;

namespace HBLConsole.ViewModel
{
@@ -34,7 +35,6 @@ namespace HBLConsole.ViewModel
OrderCount = orderStatusLists.Count;
Thread.Sleep(1000);
}), "界面状态监控");
//AlarmMonitoring();
Init();
}

@@ -43,55 +43,23 @@ namespace HBLConsole.ViewModel
ActionManage.GetInstance.Register(new Action(() =>
{
AlarmViewModel.AlarmMonitoring();

VariableMonitorViewModel.AddMonitorData();
VariableMonitorViewModel.UpdateValue();

HardwareStatusViewModel.AddMonitorData();
HardwareStatusViewModel.UpdateValue();

ThreadManage.GetInstance.StartLong(new Action(() =>
{
//节点状态上报
IotReport.GetInstance.iOTDevSXModel.NodeStatus=Tools.JsonConvertTools(new IOTNode<ObservableCollection<VariableMonitor>> { data = VariableMonitorViewModel.VariableMonitors });
//IotReport.GetInstance.iOTDevSXModel.HardwareStatus=?
IotReport.GetInstance.iOTDevSXModel.NodeStatus = Tools.JsonConvertTools(new IOTNode<ObservableCollection<VariableMonitor>> { data = VariableMonitorViewModel.VariableMonitors });
IotReport.GetInstance.iOTDevSXModel.HardwareStatus = Tools.JsonConvertTools(new IOTNode<ObservableCollection<HardwareStatusData>> { data = HardwareStatusViewModel.hardwareStatusDatas });
Thread.Sleep(1000);
}), "IOT数据上报");
}), "监控数据初始化");


}

//private void AlarmMonitoring()
//{
// ThreadManage.GetInstance.StartLong(new Action(() =>
// {
// if (SimpleFactory.GetInstance.Alarm != null)
// {
// foreach (var item in SimpleFactory.GetInstance.Alarm.GetType().GetProperties())
// {
// var res = item.GetValue(SimpleFactory.GetInstance.Alarm);
// if (res != null)
// {
// if (res is bool blen)
// {
// if (item.CustomAttributes.Count() > 0)
// {
// if (item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
// {
// var info = item.CustomAttributes.ElementAt(0)?.ConstructorArguments.ElementAt(0).Value;
// if (info != null)
// {
// App.Current.Dispatcher.Invoke(new Action(() =>
// {
// AlarmHelper.GetInstance.EdgeAlarm(blen, info.ToString());
// }));
// }
// }
// }
// }
// }
// }
// }
// Thread.Sleep(500);
// }), "报警检测监控");
//}

public RelayCommand<object> NavChangedCommand { get; set; }

private void DoNavChanged(object obj)


+ 6
- 1
HBLConsole/ViewModel/ViewModelBase.cs View File

@@ -28,8 +28,13 @@ namespace HBLConsole.ViewModel
{
MessageLog.GetInstance.InfoNotify = new Action<string>((s) =>
{
LogMessage = MessageLog.GetInstance.LogInfo;
LogMessage = $"{DateTime.Now.ToString("HH:mm:ss")}:{s} \n\r {LogMessage}";
//LogMessage = MessageLog.GetInstance.LogInfo;
});

MessageLog.GetInstance.ExInfoNotify = new Action<string>((s) =>
{
LogMessage = $"{DateTime.Now.ToString("HH:mm:ss")}:{s} \n\r {LogMessage}";
//IotReport.GetInstance.SendLogMessage(new BPA.Message.API请求.LogTable
//{
// ClientId = InternetInfo.ClientId.ToString(),


Loading…
Cancel
Save