瀏覽代碼

冲突解决

样式分支
pry 2 年之前
父節點
當前提交
d17af52133
共有 14 個檔案被更改,包括 718 行新增67 行删除
  1. +6
    -1
      BPASmartClient.CustomResource/Themes/MyStyle.xaml
  2. +26
    -25
      BPASmartClient.Device/BaseDevice.cs
  3. +2
    -2
      BPASmartClient.Device/IDevice.cs
  4. +1
    -0
      BPASmartClient.Helper/BPASmartClient.Helper.csproj
  5. +423
    -0
      BPASmartClient.Helper/logHelper.cs
  6. +53
    -13
      BPASmartClient.IoT/DataVClient.cs
  7. +2
    -1
      BPASmartClient.IoT/Model/DataVReport.cs
  8. +42
    -1
      BPASmartClient.Message/MessageLog.cs
  9. +49
    -7
      BPASmartClient.ViewModel/LogViewModel.cs
  10. +95
    -0
      BPASmartClient.ViewModel/MainViewModel.cs
  11. +11
    -10
      BPASmartClient/App.config
  12. +3
    -3
      BPASmartClient/Control/LogView.xaml
  13. +3
    -4
      BPASmartClient/MainWindow.xaml
  14. +2
    -0
      BPASmartClient/MainWindow.xaml.cs

+ 6
- 1
BPASmartClient.CustomResource/Themes/MyStyle.xaml 查看文件

@@ -77,7 +77,7 @@
HorizontalAlignment="Center"
FontSize="8"
Foreground="#FF00E6F7"
Text="{Binding ListNum}" />
Text="{Binding ListNum, Mode=TwoWay}" />
<!-- -->
</Border>
<Image
@@ -93,6 +93,11 @@
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="image1" Property="Source" Value="/BPASmartClient.CustomResource;component/Image/告警/严重告警.png" />
<Setter TargetName="bd1" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="image1" Property="Source" Value="/BPASmartClient.CustomResource;component/Image/告警/无告警.png" />
<Setter TargetName="bd1" Property="Visibility" Value="Collapsed" />
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>


+ 26
- 25
BPASmartClient.Device/BaseDevice.cs 查看文件

@@ -99,8 +99,8 @@ namespace BPASmartClient.Device
/// </summary>
private List<IPeripheral> peripherals;

public Action<object> AddErrorAction { get; set; }
public Action<object> DeleteErrorAction { get; set; }
public Action<int,object> AddErrorAction { get; set; }
public Action<int, object> DeleteErrorAction { get; set; }

#endregion

@@ -153,36 +153,37 @@ namespace BPASmartClient.Device
Status.Update($"{TypeName}.{key}", peripheral.GetAllStatus()[key]);
}
}

}

foreach (var item in Status.GetStatusT())
if (AddErrorAction != null && DeleteErrorAction != null)
{
if (item.Name == "Warning" || item.Name == "Fault")
foreach (var item in Status.GetStatusT())
{
if (item.Status != "无故障" && item.Status != "无警告" && item.Status != "未发生故障")
if (item.Name == "Warning" || item.Name == "Fault")
{
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == item.Ms);
if (res == null)
if (item.Status != "无故障" && item.Status != "无警告" && item.Status != "未发生故障")
{
object obj = new
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString() == item.Ms);
if (res == null)
{
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
Type = item.Name == "Warning" ? "警告" : "故障",
Text = item.Ms
};
Error.Add(obj);
AddErrorAction?.Invoke(obj);
object obj = new
{
Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
Type = item.Name == "Warning" ? "警告" : "故障",
Text = item.Ms
};
Error.Add(obj);
AddErrorAction?.Invoke(DeviceId,obj);
}
}
}
else
{
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString().Contains(item.id));
if (res != null)
else
{
Error.Remove(res);
DeleteErrorAction?.Invoke(res);
var res = Error?.FirstOrDefault(p => p.GetType().GetProperty("Text").GetValue(p).ToString().Contains(item.id));
if (res != null)
{
Error.Remove(res);
DeleteErrorAction?.Invoke(DeviceId,res);
}
}
}
}
@@ -233,7 +234,7 @@ namespace BPASmartClient.Device
Text = res.Info
};
Error.Add(obj);
AddErrorAction?.Invoke(obj);
AddErrorAction?.Invoke(DeviceId, obj);
}
});
alarmHelper.RemoveAction = new Action<string>((s) =>
@@ -242,7 +243,7 @@ namespace BPASmartClient.Device
if (res != null && Error.Contains(res))
{
Error.Remove(res);
DeleteErrorAction?.Invoke(res);
DeleteErrorAction?.Invoke(DeviceId, res);
}
});
ThreadManage.GetInstance().StartLong(new Action(() =>


+ 2
- 2
BPASmartClient.Device/IDevice.cs 查看文件

@@ -82,7 +82,7 @@ namespace BPASmartClient.Device
/// <param name="field"></param>
object GetPropertyValue(object info, string field);

Action<object> AddErrorAction { get; set; }
Action<object> DeleteErrorAction { get; set; }
Action<int, object> AddErrorAction { get; set; }
Action<int, object> DeleteErrorAction { get; set; }
}
}

+ 1
- 0
BPASmartClient.Helper/BPASmartClient.Helper.csproj 查看文件

@@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.14" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>


+ 423
- 0
BPASmartClient.Helper/logHelper.cs 查看文件

@@ -0,0 +1,423 @@
using log4net;
using log4net.Repository;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Helper
{
/// <summary>
/// 创建人:奉友福
/// 时间:2021/11/12
/// </summary>
public class logHelper
{
#region 单例模式
static private logHelper m_logHelperInstance = null;
public static logHelper GetLogConfigInstance()
{
if (null == m_logHelperInstance)
{
m_logHelperInstance = new logHelper();

}
return m_logHelperInstance;
}
#endregion
/// <summary>
/// 日志显示委托
/// </summary>
public Action<string> InfoNotify { get; set; }
private ILog directLogger = null;
private log4net.Appender.RollingFileAppender directRollfileAppender = null;
ILoggerRepository logRepos = null;
private static bool m_isInitDirectLog = false; //是否初始化了直接写入日志文件
private static Int32 directFileSize = 50;
private static string directLogDir = string.Empty;
private static string directLogFileName = string.Empty;
//static private UAFLogHelper uafLogInstance = null;
private LogLevel logLevel = LogLevel.ALL;

/// <summary>
/// 初始化日志
/// </summary>
/// <param name="path"></param>
public static void Fun_InitLog(string path)
{
try
{
/// 设置需要的日志信息
GetLogConfigInstance().SetConfigEnableThreadId(true);
GetLogConfigInstance().SetConfigEnableAppDomain(true);

/// 使用直接日志接口写入日志信息
GetLogConfigInstance().SetLogLevel(LogLevel.ERROR);
GetLogConfigInstance().SetDirectFileLogInfo(5, string.Empty);
GetLogConfigInstance().SetDirectFileLogName("HBL.LogDir");
if (!(GetLogConfigInstance().initDirectLogger(path)))
{

}
}
catch (Exception ex)
{
}
}
public void SetDirectFileLogInfo(Int32 fileSize, string logDirectory)
{
directFileSize = fileSize;
directLogDir = logDirectory;
}

public void SetDirectFileLogName(string logFileName)
{
directLogFileName = logFileName;
}

//初始化日志实例
public bool initDirectLogger(string loggerName)
{
try
{
logRepos = log4net.LogManager.CreateRepository(loggerName);
//初始化记录日志到文件的 appender
InitDirectRollFileAppender(loggerName);

m_isInitDirectLog = true;

return true;
}
catch (Exception e)
{
throw e;
}
}

private void InitDirectRollFileAppender(string loggerName)
{
try
{
directLogger = LogManager.GetLogger(logRepos.Name, loggerName);
//初始化记录日志到文件的 appender
directRollfileAppender = new log4net.Appender.RollingFileAppender();

// pattern layout
log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
//UAFCustomDataDB.UAFCustomLayout layout = new UAFCustomDataDB.UAFCustomLayout();
//layout.ConversionPattern = "%log_time %log_threadname %log_ip %-5level %log_domain %log_location %log_msg %log_details%n"; // pattern

layout.ConversionPattern = string.Empty;
if (LogConfig.GetLogConfigInstance().EnableDate)
{
layout.ConversionPattern += "%date{yyyy-MM-dd HH:mm:ss} ";
}

//级别
layout.ConversionPattern += "%-5level ";

if (LogConfig.GetLogConfigInstance().EnableAppDomain)
{
layout.ConversionPattern += "%a ";
}

if (LogConfig.GetLogConfigInstance().EnableThreadId)
{
layout.ConversionPattern += "[%t] ";
}

layout.ConversionPattern += "%m%n";

layout.ActivateOptions(); // activate

//directRollfileAppender.CloseFlag = false; //添加打开标志
directRollfileAppender.Layout = layout; // layout pattern
//directRollfileAppender.Name = "DirectLogRollFileAppender";
directRollfileAppender.Name = loggerName;

directRollfileAppender.File = string.Empty;

//设置日志文件路径
if (string.Empty == directLogDir)
{
directRollfileAppender.File = "LogDir\\";
}

else
{
if (directLogDir.EndsWith("\\"))
{
directRollfileAppender.File = directLogDir;
}
else
{
directRollfileAppender.File = directLogDir + "\\";
}
}
//设置日志文件名字
if (string.Empty == directLogFileName)
{
//获取进程Id,构造日志文件名字
string loggerFileName = Process.GetCurrentProcess().ProcessName
+ Process.GetCurrentProcess().Id.ToString() + "_"
+ DateTime.Now.Year.ToString()
+ DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString()
+ DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString()
+ DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + "_";//"UAFMsgName";
directRollfileAppender.File += loggerFileName;
}
else
{
directRollfileAppender.File += directLogFileName;
}

directRollfileAppender.AppendToFile = true; // overwrite any existin g file with the same name
if (directFileSize <= 0)
{
directRollfileAppender.MaxFileSize = (50 * 1024 * 1024); // max file size - 50*1024*1024 = 50MB
}
else
{
directRollfileAppender.MaxFileSize = (directFileSize * 1024 * 1024);
}

directRollfileAppender.MaxSizeRollBackups = 50; // keep 50 files
directRollfileAppender.ImmediateFlush = true; // flush after every append
directRollfileAppender.Threshold = log4net.Core.Level.All;
directRollfileAppender.DatePattern = "yyyy_M_d'.log'";
directRollfileAppender.StaticLogFileName = false;

directRollfileAppender.ActivateOptions(); // activate



// add appenders
//log4net.Config.BasicConfigurator.Configure(directRollfileAppender);
log4net.Config.BasicConfigurator.Configure(logRepos, directRollfileAppender);
}
catch (Exception e)
{
throw e;
}
}

//重新设置日志保存路径和文件名
public void ReconfigLogDirAndName()
{
directRollfileAppender.File = string.Empty;

//设置日志文件路径
if (string.Empty == directLogDir)
{
directRollfileAppender.File = "LogDir\\";
}

else
{
if (directLogDir.EndsWith("\\"))
{
directRollfileAppender.File = directLogDir;
}
else
{
directRollfileAppender.File = directLogDir + "\\";
}
}
//设置日志文件名字
if (string.Empty == directLogFileName)
{
//获取进程Id,构造日志文件名字
string loggerFileName = Process.GetCurrentProcess().ProcessName
+ Process.GetCurrentProcess().Id.ToString() + "_"
+ DateTime.Now.Year.ToString()
+ DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString()
+ DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString()
+ DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + "_";//"UAFMsgName";
directRollfileAppender.File += loggerFileName;
}
else
{
directRollfileAppender.File += directLogFileName;
}

if (directFileSize <= 0)
{
directRollfileAppender.MaxFileSize = (50 * 1024 * 1024); // max file size - 50*1024*1024 = 50MB
}
else
{
directRollfileAppender.MaxFileSize = (directFileSize * 1024 * 1024);
}

directRollfileAppender.ActivateOptions(); // activate
}

public void SetLogLevel(LogLevel level)
{
logLevel = level;

}

public bool WriteLog(LogLevel level, string logMsg)
{
try
{
if (null == directLogger)
{
return false;
}

//if ((LogLevel.OFF == logLevel) || ((Int32)level > (Int32)logLevel /*&& LogObjectLib.LogLevel.ALL != logLevel*/))
//{
// return true;
//}

//调用日志接口直接写日志信息
switch (level)
{
case LogLevel.FATAL:
if (directLogger.IsFatalEnabled)
{
directLogger.Fatal(logMsg);
}
break;
case LogLevel.ERROR:
if (directLogger.IsErrorEnabled)
{
directLogger.Error(logMsg);
}
break;
case LogLevel.WARN:
if (directLogger.IsWarnEnabled)
{
directLogger.Warn(logMsg);
}
break;
case LogLevel.INFO:
if (directLogger.IsInfoEnabled)
{
directLogger.Info(logMsg);
}
break;
case LogLevel.DEBUG:
if (directLogger.IsDebugEnabled)
{
directLogger.Debug(logMsg);
}
break;
default:
break;
}
if (InfoNotify != null)
{
logMsg = $"{DateTime.Now.ToString("HH:mm:ss")}:{level} {logMsg} \n\r";
InfoNotify(logMsg);
}
return true;
}
catch (Exception e)
{
throw e;
}


}

//设置日志配置--app域名
public void SetConfigEnableAppDomain(bool value)
{
LogConfig.GetLogConfigInstance().EnableAppDomain = value;
}

//设置日志配置--线程id
public void SetConfigEnableThreadId(bool value)
{
LogConfig.GetLogConfigInstance().EnableThreadId = value;
}

public bool GetConfigEnableAppDomain()
{
return LogConfig.GetLogConfigInstance().EnableAppDomain;
}

public bool GetConfigEnableThreadId()
{
return LogConfig.GetLogConfigInstance().EnableThreadId;
}


}

/// <summary>
/// 创建人:奉友福
/// </summary>
public class LogConfig
{
private bool m_enableDate = true;
private bool m_enableAppDomain = false;
private bool m_enableThreadId = false;
#region 单例模式
static private LogConfig m_logConfigInstance = null;
public static LogConfig GetLogConfigInstance()
{
if (null == m_logConfigInstance)
{
m_logConfigInstance = new LogConfig();

}
return m_logConfigInstance;
}
#endregion
private LogConfig()
{

}
public bool EnableDate
{
set
{
m_enableDate = value;
}
get { return m_enableDate; }
}
public bool EnableAppDomain
{
set
{
m_enableAppDomain = value;
}
get { return m_enableAppDomain; }
}
public bool EnableThreadId
{
set
{
m_enableThreadId = value;
}
get { return m_enableThreadId; }
}
}

/// <summary>
/// 创建人:奉友福
/// 时间:2021/11/12
/// </summary>
public enum LogLevel
{
OFF = 0,
FATAL,
ERROR,
WARN,
INFO,
DEBUG,
ALL
}
}

+ 53
- 13
BPASmartClient.IoT/DataVClient.cs 查看文件

@@ -19,17 +19,34 @@ namespace BPASmartClient.IoT
public class DataVClient
{
#region 单例模式
private volatile static DataVClient _Instance;
public static DataVClient GetInstance() => _Instance ?? (_Instance = new DataVClient());
public static DataVClient init = null;
public static DataVClient GetInstance()
{
if (init == null)
{
init = new DataVClient();
}
return init;
}
/// <summary>
/// 显示定义构造函数为私有,表示只允许自己实例化自己
/// </summary>
public DataVClient()
{
DataVApiAddress = System.Configuration.ConfigurationManager.AppSettings["DataVServiceUri"].ToString();
ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
Initialize();
DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"].ToString();
ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"].ToString();
DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"].ToString();
StartupMode = System.Configuration.ConfigurationManager.AppSettings["StartupMode"].ToString();
}
#endregion

#region 公有变量
public string StartupMode { set; get; }
public string DeviceName { set; get; }
public string ProductKey { set; get; }
public string DeviceSecret { set; get; }
/// <summary>
/// DataV 服务地址
/// </summary>
@@ -49,7 +66,9 @@ namespace BPASmartClient.IoT
/// <summary>
/// 广播
/// </summary>
public string PubTopic = "/broadcast/" + "grgpECHSL7q" + "/" + "Transit_SetDevice";
//public string PubTopic = "/broadcast/" + "grgpECHSL7q" + "/" + "Transit_SetDevice";
public string PubTopic = "/broadcast/" + "grgpECHSL7q" + "/" + "Transit_Test_SetDevice";

/// <summary>
/// key值
/// </summary>
@@ -66,7 +85,7 @@ namespace BPASmartClient.IoT
{
try
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
alarmTable.ClientId = ClientId;
alarmTable.devicename = DeviceDataV.deviceTable.devicename;
@@ -90,7 +109,7 @@ namespace BPASmartClient.IoT
string id = string.Empty;
try
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable!=null)
{
logTable.ClientId = ClientId;
logTable.devicename = DeviceDataV.deviceTable.devicename;
@@ -120,14 +139,29 @@ namespace BPASmartClient.IoT
public void Initialize()
{
string message = string.Empty;
if (DeviceDataV.Initialize(DataVApiAddress, ClientId, "", ref message))
if (StartupMode == "API")
{
DeviceDataV.DataVMessageAction += DevIOTActionHandler;
MessageLog.GetInstance.Show($"客户端:【{ClientId}】,设备名称{DeviceDataV.deviceTable.devicename}阿里云连接成功");
if (DeviceDataV.Initialize(DataVApiAddress, ClientId, "", ref message))
{
ProductKey = DeviceDataV.deviceTable.productkey;
DeviceName = DeviceDataV.deviceTable.devicename;
DeviceSecret = DeviceDataV.deviceTable.devicesecret;
DeviceDataV.DataVMessageAction += DevIOTActionHandler;
MessageLog.GetInstance.Show($"客户端:【{ClientId}】,设备名称{DeviceName}阿里云连接成功");
}
else
{
MessageLog.GetInstance.ShowEx(message);
}
}
else
{
MessageLog.GetInstance.ShowEx(message);
if (DeviceDataV.InitializeNo(ProductKey, DeviceName, DeviceSecret, ref message))
{
MessageLog.GetInstance.Show($"客户端:【{ClientId}】,设备名称{DeviceName}阿里云连接成功");
}
else
MessageLog.GetInstance.ShowEx(message);
}
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
{
@@ -143,7 +177,7 @@ namespace BPASmartClient.IoT
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (DeviceDataV != null && DeviceDataV.GetIsConnected())
if (DeviceDataV != null && DeviceDataV.GetIsConnected() && DeviceDataV.deviceTable != null)
{
List<object> dataVNode = new List<object>();
Plugin.GetInstance()?.GetPlugin<DeviceMgr>()?.GetDevices()?.ForEach(device =>
@@ -182,7 +216,7 @@ namespace BPASmartClient.IoT
/// 增加告警
/// </summary>
/// <param name="obj"></param>
private void AddErrorAction(object obj)
private void AddErrorAction(int Devid, object obj)
{
string id = Guid.NewGuid().ToString();
HttpAddAlarm(new AlarmTable
@@ -191,16 +225,19 @@ namespace BPASmartClient.IoT
AlarmType = GetPropertyValue(obj, "Type").ToString(),
AlarmMessage = GetPropertyValue(obj, "Text").ToString(),
AlarmVla = "告警",
DeviceId = Devid.ToString(),
KeyID = id,
});
keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] =id ;
MessageLog.GetInstance.AddDeviceAlarmLogShow(GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(),id);

}

/// <summary>
/// 删除告警
/// </summary>
/// <param name="obj"></param>
private void DeleteErrorAction(object obj)
private void DeleteErrorAction(int Devid, object obj)
{
string message = GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString();
if (keyValues.ContainsKey(message))
@@ -211,9 +248,12 @@ namespace BPASmartClient.IoT
AlarmType = GetPropertyValue(obj, "Type").ToString(),
AlarmMessage = GetPropertyValue(obj, "Text").ToString(),
AlarmVla = "告警",
DeviceId= Devid.ToString(),
KeyID = keyValues[message],
State="n"
});
MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]);

}
}



+ 2
- 1
BPASmartClient.IoT/Model/DataVReport.cs 查看文件

@@ -43,6 +43,7 @@ namespace BPASmartDatavDeviceClient.IoT
{
try
{
if (deviceTable == null) deviceTable = new DeviceTable();
deviceTable.devicename = _devicename;
SetValue(_productkey, _devicename, _devicesecret);
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
@@ -161,7 +162,7 @@ namespace BPASmartDatavDeviceClient.IoT
{
string json = string.Empty;
if (string.IsNullOrEmpty(deviceId))
json = HttpRequestHelper.HttpGetRequest($"{url}/api/Device/Query?clientId={clientId}");
json = HttpRequestHelper.HttpGetRequest($"{url}/api/Device/Query?clientId={clientId}",1000);
else
json = HttpRequestHelper.HttpGetRequest($"{url}/api/Device/Query?clientId={clientId}&deviceId={deviceId}");
JsonMsg<List<DeviceTable>> jsonMsg = Tools.JsonToObjectTools<JsonMsg<List<DeviceTable>>>(json);


+ 42
- 1
BPASmartClient.Message/MessageLog.cs 查看文件

@@ -66,7 +66,7 @@ namespace BPASmartClient.Message
/// <summary>
/// 设备过程日志委托
/// </summary>
public Action<string> DeviceProcessLogNotify { get; set; }
public Action<string, string> DeviceProcessLogNotify { get; set; }

/// <summary>
/// 设备日志信息字典
@@ -81,6 +81,47 @@ namespace BPASmartClient.Message
{
if (!DPLogInfo.ContainsKey(id))
DPLogInfo.TryAdd(id, info);
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
//ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id,info);
}
}
#endregion

#region 设备告警日志
/// <summary>
/// 设备告警日志委托
/// </summary>
public Action<string, string> DeviceAlarmLogNotify { get; set; }
public Action AlarmLogNotify { get; set; }
/// <summary>
/// 设备告警日志委托字典
/// </summary>
public ConcurrentDictionary<string, string> DPAlarmInfo = new ConcurrentDictionary<string, string>();
/// <summary>
/// 设备告警日志输出
/// </summary>
/// <param name="info"></param>
public void AddDeviceAlarmLogShow(string id, string info)
{
DPAlarmInfo[info] = id;
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
if (DeviceAlarmLogNotify != null) DeviceAlarmLogNotify(id, info);
if (AlarmLogNotify != null) AlarmLogNotify();
}
/// <summary>
/// 设备告警日志输出
/// </summary>
/// <param name="info"></param>
public void DeleteDeviceAlarmLogShow(string id, string info)
{
if (DPAlarmInfo.ContainsKey(id))
{
string mes=string.Empty;
DPAlarmInfo.Remove(id, out mes);
if (AlarmLogNotify != null) AlarmLogNotify();
}
}
else
DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}";
Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");


+ 49
- 7
BPASmartClient.ViewModel/LogViewModel.cs 查看文件

@@ -1,4 +1,5 @@
using BPASmartClient.IoT;
using BPASmartClient.Helper;
using BPASmartClient.IoT;
using BPASmartClient.Message;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
@@ -22,8 +23,8 @@ namespace BPASmartClient.ViewModel
/// </summary>
public class LogViewModel : ObservableObject
{
//public DispatcherTimer dispatcherTimer;
public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
public DispatcherTimer dispatcherTimer;
public string ClientId= System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString();
private ObservableCollection<LogModel> _LogModels;
public ObservableCollection<LogModel> LogDataGrid
{
@@ -43,20 +44,46 @@ namespace BPASmartClient.ViewModel
public static LogViewModel GetInstance() => _Instance ?? (_Instance = new LogViewModel());
private LogViewModel()
{
if (LogDataGrid == null)
LogDataGrid = new ObservableCollection<LogModel>();
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory);
if (LogDataGrid==null) LogDataGrid = new ObservableCollection<LogModel>();

//一般日志
MessageLog.GetInstance.InfoNotify = new Action<string>((s) =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = s, type = "Base" });//基础消息
LogDataGrid.Insert(0,new LogModel { message = s,type = "Info" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s);
}));
});

//设备日志
MessageLog.GetInstance.DeviceProcessLogNotify = new Action<string,string>((id,s) =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s);
}));
});

//设备告警日志
MessageLog.GetInstance.DeviceAlarmLogNotify = new Action<string, string>((id, s) =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id);
}));
});

//错误日志
MessageLog.GetInstance.ExInfoNotify = new Action<string>((s) =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
LogDataGrid.Insert(0, new LogModel { message = s, type = "Error" });//错误消息
LogDataGrid.Insert(0,new LogModel { message = s,type = "Error" });
logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s);
DataVClient.GetInstance().HttpAddLog(new LogTable
{
ClientId = ClientId,
@@ -78,6 +105,21 @@ namespace BPASmartClient.ViewModel
{
ExcellOrder();
});

dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += delegate
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
if (LogDataGrid.Count > 100)
{
LogDataGrid.RemoveAt(LogDataGrid.Count-1);
}
}));
};
dispatcherTimer.Interval = TimeSpan.FromSeconds(10);
dispatcherTimer.Start();
}

/// <summary>


+ 95
- 0
BPASmartClient.ViewModel/MainViewModel.cs 查看文件

@@ -1,4 +1,6 @@
using BPASmartClient.Business;
using BPASmartClient.Helper;
using BPASmartClient.Message;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
@@ -9,6 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;

namespace BPASmartClient.ViewModel
{
@@ -17,9 +20,101 @@ namespace BPASmartClient.ViewModel
/// </summary>
public class MainViewModel : ObservableObject
{
/// <summary>
/// 网络连接状态
/// </summary>
private bool _NetworkConnectState = true;
public bool NetworkConnectState
{
get
{
return _NetworkConnectState;
}
set
{
if (_NetworkConnectState == value)
return;
_NetworkConnectState = value;
OnPropertyChanged("NetworkConnectState");
}
}
/// <summary>
/// 是否告警
/// </summary>
public AlarmModel IsAlarm { get; set; }

public DispatcherTimer dispatcherTimer;


public MainViewModel()
{
IsAlarm =new AlarmModel();
OrderStatusViewModel.Init();
//设备告警日志
MessageLog.GetInstance.AlarmLogNotify = new Action(() =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0;
IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count;
}));
});

dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += delegate
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState();
}));
};
dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
dispatcherTimer.Start();
}
}

public class AlarmModel : ObservableObject
{
/// <summary>
/// 是否告警
/// </summary>
private bool _IsCheck = false;
public bool IsCheck
{
get
{
return _IsCheck;
}
set
{
if (_IsCheck == value)
return;
_IsCheck = value;
OnPropertyChanged("IsCheck");
}
}
/// <summary>
/// 告警数量
/// </summary>
private int _ListNum = 0;
public int ListNum
{
get
{
return _ListNum;
}
set
{
if (_ListNum == value)
return;
_ListNum = value;
OnPropertyChanged("ListNum");
}
}

public AlarmModel()
{
}
}
}

+ 11
- 10
BPASmartClient/App.config 查看文件

@@ -2,14 +2,6 @@
<configuration>
<appSettings>
<!--通用配置-->

<!--测试服务 Consul 地址-->
<!--<add key="ConsulAddress" value="http://111.9.47.105:9011/" />-->

<!--正式服务 Consul 地址-->
<!--<add key="ConsulAddress" value="http://162.14.105.138:9005" />-->

<!--客户端ID-->
<!--1:且时且多冰淇淋咖啡机,2:且时且多煮面机,3:海科煮面机测试店铺-->
<add key="ClientId" value="111"/>
<!--<add key="ApolloUri" value="http://10.2.1.21:28080"/>
@@ -17,6 +9,7 @@
<add key="StockServiceUri" value="http://10.2.1.26:21527/stock/"/>-->

<!--<add key="ApolloUri" value="https://bpa.black-pa.com:28080"/>-->
<add key="ClientId" value="2"/>

<!--开发环境-->
<add key="ApolloUri" value="http://10.2.1.21:28080"/>
@@ -32,8 +25,16 @@
<add key="StockServiceUri" value="https://witt.black-pa.com/stock/"/>
<add key="DataVServiceUri" value="https://bpa.black-pa.com:21527/datav"/>-->


<add key="COM_Coffee" value="COM3"/>
<!--阿里云上报启动方式:API 或者 LOCAL-->
<!--API :通过客户端ID,调用接口查询“设备连接信息”-->
<!--LOCAL:直接使用下方本地“设备连接信息”-->
<add key="StartupMode" value="API"/>
<add key="ProductKey" value="grgpECHSL7q"/>
<add key="DeviceName" value="qsqd"/>
<add key="DeviceSecret" value="3c0f2390943bff4fece523af22655196"/>
<!--外设配置-->
<add key="COM_Coffee" value="COM3"/>
<add key="BAUD_Coffee" value="115200"/>
<add key="COM_IceCream" value="COM12"/>
<add key="BAUD_IceCream" value="9600"/>


+ 3
- 3
BPASmartClient/Control/LogView.xaml 查看文件

@@ -25,9 +25,9 @@

<!--查询按钮栏-->
<StackPanel Orientation="Horizontal" Margin="10,0,10,0">
<CheckBox Margin="10,0,0,0" IsChecked="{Binding RealTimeModel, UpdateSourceTrigger=PropertyChanged}" >实时模式</CheckBox>
<CheckBox Margin="10,0,0,0" IsChecked="{Binding TimedClear, UpdateSourceTrigger=PropertyChanged}">定时清除</CheckBox>
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding ExcelCommand}">导出</Button>
<!--<CheckBox Margin="10,0,0,0" IsChecked="{Binding RealTimeModel, UpdateSourceTrigger=PropertyChanged}" >实时模式</CheckBox>
<CheckBox Margin="10,0,0,0" IsChecked="{Binding TimedClear, UpdateSourceTrigger=PropertyChanged}">定时清除</CheckBox>-->
<Button Margin="10,0,0,0" Cursor="Hand" Command="{Binding ExcelCommand}">导出日志</Button>
</StackPanel>

<!--表格栏-->


+ 3
- 4
BPASmartClient/MainWindow.xaml 查看文件

@@ -177,16 +177,15 @@
HorizontalAlignment="Center"
VerticalAlignment="Center"
Cursor="Hand"
DataContext="{Binding GaoJingMessage}"
IsChecked="True"
IsChecked="{Binding NetworkConnectState}"
Style="{DynamicResource StatusBtnStyle网络连接状态}"
ToolTip="网络连接状态" />
<Border Style="{DynamicResource border竖线}" />
<ToggleButton
HorizontalAlignment="Center"
VerticalAlignment="Center"
Cursor="Hand"
DataContext="{Binding GaoJingMessage}"
Cursor="Hand"
DataContext="{Binding IsAlarm}"
Style="{DynamicResource StatusBtnStyle告警}"
ToolTip="告警消息" />
<Border Style="{DynamicResource border竖线}" />


+ 2
- 0
BPASmartClient/MainWindow.xaml.cs 查看文件

@@ -63,6 +63,8 @@ namespace BPASmartClient
{
new MainConsole().Start();
}), "启动主控制台", false);

DataVClient.GetInstance().Initialize();
DataVClient.GetInstance().Start();
}
#endregion


Loading…
取消
儲存