现场增加日志功能

This commit is contained in:
2026-05-14 10:41:23 +08:00
parent e954988fb5
commit 4cdda056b4

View File

@@ -39,9 +39,9 @@ namespace CapMachine.Wpf.ViewModels
IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
ComActionService actionService,
ConfigService configService, CanDriveService canDriveService,
IMapper mapper, MachineRtDataService machineRtDataService)
IMapper mapper, MachineRtDataService machineRtDataService, ILogService logService)
{
//LogService = logService;
LogService = logService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
RegionManager = regionManager;
@@ -52,7 +52,6 @@ namespace CapMachine.Wpf.ViewModels
Mapper = mapper;
this.MachineRtDataService = machineRtDataService;
//MachineDataService = machineDataService;
DialogService = dialogService;
WriteNameCbxItems = new ObservableCollection<CbxItems>()
@@ -89,6 +88,7 @@ namespace CapMachine.Wpf.ViewModels
public CanDriveService CanDriveService { get; }
public IMapper Mapper { get; }
private MachineRtDataService MachineRtDataService { get; }
public ILogService LogService { get; }
/// <summary>
/// 弹窗服务
@@ -104,55 +104,58 @@ namespace CapMachine.Wpf.ViewModels
/// </summary>
private void InitLoadCanConfigPro()
{
//CAN配置集合数据
canLinConfigPros = FreeSql.Select<CanLinConfigPro>().Where(a => a.CANLINInfo == CANLIN.CAN)
.Include(a => a.CANConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.ToList();
ListCanLinConfigPro = new ObservableCollection<CanLinConfigPro>(canLinConfigPros);
if (SelectCanLinConfigPro != null)
try
{
SelectCanLinConfigPro = canLinConfigPros.Where(a => a.Id == SelectCanLinConfigPro.Id).FirstOrDefault()!;
//无数据就返回
if (SelectCanLinConfigPro == null) return;
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
LogService.Info("开始加载CAN配置数据");
//CAN配置集合数据
canLinConfigPros = FreeSql.Select<CanLinConfigPro>().Where(a => a.CANLINInfo == CANLIN.CAN)
.Include(a => a.CANConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.ToList();
//配置信息
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
if (WirteData != null && WirteData.Count > 0)
ListCanLinConfigPro = new ObservableCollection<CanLinConfigPro>(canLinConfigPros);
if (SelectCanLinConfigPro != null)
{
ListWriteCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(WirteData));
SelectCanLinConfigPro = canLinConfigPros.Where(a => a.Id == SelectCanLinConfigPro.Id).FirstOrDefault()!;
//无数据就返回
if (SelectCanLinConfigPro == null) return;
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
//加载把当前的配置信息给指令
CanDriveService.CmdData.Clear();
foreach (var item in WirteData)
//配置信息
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
if (WirteData != null && WirteData.Count > 0)
{
CanDriveService.AddCmdData(new CanCmdData()
{
ConfigName = item.Name,
MsgName = item.MsgFrameName,
SignalName = item.SignalName,
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
});
//CanDriveService.CmdData.Add(new CanCmdData()
//{
// ConfigName = item.Name,
// MsgName = item.MsgFrameName,
// SignalName = item.SignalName,
// SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
//});
}
}
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(ReadData));
}
ListWriteCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(WirteData));
//匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListCanDbcModel
MatchSeletedAndCanDbcModel();
//加载把当前的配置信息给指令
CanDriveService.CmdData.Clear();
foreach (var item in WirteData)
{
CanDriveService.AddCmdData(new CanCmdData()
{
ConfigName = item.Name,
MsgName = item.MsgFrameName,
SignalName = item.SignalName,
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
});
}
}
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(ReadData));
}
//匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListCanDbcModel
MatchSeletedAndCanDbcModel();
}
LogService.Info("CAN配置数据加载成功");
}
catch (Exception ex)
{
LogService.Error($"加载CAN配置数据失败: {ex.Message}\r\n堆栈: {ex.StackTrace}");
System.Windows.MessageBox.Show($"加载CAN配置数据失败: {ex.Message}", "错误", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}
}
@@ -373,41 +376,54 @@ namespace CapMachine.Wpf.ViewModels
}
break;
case "Active":
//激活到取消的状态的判断
if (IsCanConfigProActive == true)
try
{
//控件的激活
IsCanConfigProActive = !IsCanConfigProActive;
//控件的激活配置信息
IsCANConfigDatagridActive = !IsCanConfigProActive;
return;
}
if ((CanDriveService.ToomossCanDrive.OpenState == true && CanDriveService.ToomossCanDrive.DbcParserState == true))
{
if (SelectCanLinConfigPro != null)
LogService.Info("开始执行CAN配置激活操作");
//激活到取消的状态的判断
if (IsCanConfigProActive == true)
{
//控件的激活
IsCanConfigProActive = !IsCanConfigProActive;
//控件的激活配置信息
IsCANConfigDatagridActive = !IsCanConfigProActive;
//当前使用的CAN 配置信息
CanDriveService.InitCanConfig(SelectCanLinConfigPro);
LogService.Info("CAN配置已取消激活");
return;
}
if ((CanDriveService.ToomossCanDrive.OpenState == true && CanDriveService.ToomossCanDrive.DbcParserState == true))
{
if (SelectCanLinConfigPro != null)
{
//控件的激活
IsCanConfigProActive = !IsCanConfigProActive;
//控件的激活配置信息
IsCANConfigDatagridActive = !IsCanConfigProActive;
//当前使用的CAN 配置信息
CanDriveService.InitCanConfig(SelectCanLinConfigPro);
InitLoadCanConfigPro();
LogService.Info($"CAN配置激活成功: {SelectCanLinConfigPro.ConfigName}");
}
else
{
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
InitLoadCanConfigPro();
}
else
{
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
System.Windows.MessageBox.Show("请确保CAN连接打开和Dbc解析成功后再激活", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
}
else
catch (Exception ex)
{
System.Windows.MessageBox.Show("请确保CAN连接打开和Dbc解析成功后再激活", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
LogService.Error($"CAN配置激活操作失败: {ex.Message}\r\n堆栈: {ex.StackTrace}");
System.Windows.MessageBox.Show($"CAN配置激活操作失败: {ex.Message}", "错误", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
//恢复状态
IsCanConfigProActive = false;
IsCANConfigDatagridActive = true;
}
break;
default: