float 转换 decimal 有时报错,捕获异常并记录日志

old
xiaoguo 1 year ago
parent 1b47cf889c
commit f15354b72a

@ -0,0 +1,23 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\serverRep\\GuideScreen\\guidescreen\\GuideScreen\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 1,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedHeight": 200,
"SelectedChildIndex": -1,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
}
]
}
]
}
]
}

@ -1,12 +1,14 @@
using GuideScreen.Common.Common;
using GuideScreen.Common.Services;
using GuideScreen.Common.Services.Models;
using Masuit.Tools;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity.Infrastructure.Design;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -43,9 +45,13 @@ namespace GuideScreen.Common
/// 写入Error级别日志
/// </summary>
/// <param name="ex">异常对象</param>
public static void WriteErrorLog(this Exception ex)
public static void WriteErrorLog(this Exception ex,string title="")
{
var error = new StringBuilder();
if (!title.IsNullOrEmpty())
{
error.AppendLine(title);
}
while (ex != null)
{
error.AppendLine($"{ex.Message}:{Environment.NewLine}");
@ -59,9 +65,13 @@ namespace GuideScreen.Common
/// 写入Fatal级别日志
/// </summary>
/// <param name="ex">异常对象</param>
public static void WriteFatalLog(this Exception ex)
public static void WriteFatalLog(this Exception ex, string title = "")
{
var error = new StringBuilder();
if (!title.IsNullOrEmpty())
{
error.AppendLine(title);
}
while (ex != null)
{
error.AppendLine($"{ex.Message}:{Environment.NewLine}");

@ -19,7 +19,7 @@ namespace GuideScreen.Common.Services
/// <summary>
/// PLC 点位改变触发
/// </summary>
event EventHandler<PLCPoint> PointChnage;
event EventHandler<PLCPoint> PointChange;
/// <summary>
/// 获取错误相信

@ -148,10 +148,27 @@ namespace GuideScreen.Common.Services.Impl
{
detail = entity;
}
detail.RecordValue = Convert.ToDecimal(value);
detail.RecordValue = ConvetToDecimal(value, $"{name}:{note}");
this.deviceRecordRepository.UpdatePLCDeviceRecordDay(detail);
}
/// <summary>
/// todo:数据格式转换有时报错,记录日志信息
/// </summary>
/// <returns></returns>
private static decimal ConvetToDecimal(float value, string title)
{
try
{
return Convert.ToDecimal(value);
}
catch (Exception ex)
{
ex.WriteErrorLog(title);
}
return 0;
}
/// <summary>
/// 根据日期获取能耗信息
/// </summary>

@ -35,7 +35,7 @@ namespace GuideScreen.Common.Services.Impl
/// <summary>
/// PLC 点位改变触发
/// </summary>
public event EventHandler<PLCPoint> PointChnage;
public event EventHandler<PLCPoint> PointChange;
/// <summary>
/// 获取错误相信
@ -254,7 +254,7 @@ namespace GuideScreen.Common.Services.Impl
if (point.ObjectValue==null || !point.ObjectValue.Equals(result.Content))
{
point.ObjectValue = result.Content;
PointChnage?.Invoke(this, point);
PointChange?.Invoke(this, point);
}
}
else

@ -43,7 +43,7 @@ namespace GuideScreen.Common.Services.Impl
this.plcPointService = plcPointService;
this.plcMonitorService = plcMonitorService;
this.deviceRecordService = deviceRecordService;
this.plcMonitorService.PointChnage += (object sender, PLCPoint e) =>
this.plcMonitorService.PointChange += (object sender, PLCPoint e) =>
{
AdddeviceRecord(e);

Loading…
Cancel
Save