Commit 1ce93e0a by liulongfei

系统日志

parent 1a51598c
...@@ -266,6 +266,14 @@ namespace VIZ.H2V.Module ...@@ -266,6 +266,14 @@ namespace VIZ.H2V.Module
try try
{ {
AlgorithmSender.Stop(manager, this.Support.ID); AlgorithmSender.Stop(manager, this.Support.ID);
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 发送算法停止消息
string system_log = string.Format(SystemLogStringFormats.ALGORITHM_SHUTDOWN_MESSAGE);
ApplicationDomainEx.CsvContext.AppendSystemLog(this.Support.ViewKey, this.Support.DisplayName, system_log);
//====================================================================
} }
catch catch
{ {
...@@ -297,6 +305,14 @@ namespace VIZ.H2V.Module ...@@ -297,6 +305,14 @@ namespace VIZ.H2V.Module
try try
{ {
this.Support.ProcessModel.MainProcess.Kill(); this.Support.ProcessModel.MainProcess.Kill();
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: Kill算法进程
string system_log = string.Format(SystemLogStringFormats.ALGORITHM_SHUTDOWN_KILL);
ApplicationDomainEx.CsvContext.AppendSystemLog(this.Support.ViewKey, this.Support.DisplayName, system_log);
//====================================================================
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -376,6 +392,14 @@ namespace VIZ.H2V.Module ...@@ -376,6 +392,14 @@ namespace VIZ.H2V.Module
log.Error($"算法'{this.Support.ViewConfig.StrategyType}'的启动路径:'{strategy.MainPath}'启动失败!"); log.Error($"算法'{this.Support.ViewConfig.StrategyType}'的启动路径:'{strategy.MainPath}'启动失败!");
MessageBoxEx.ShowDialog($"算法'{this.Support.ViewConfig.StrategyType}'的启动路径:'{strategy.MainPath}'启动失败!"); MessageBoxEx.ShowDialog($"算法'{this.Support.ViewConfig.StrategyType}'的启动路径:'{strategy.MainPath}'启动失败!");
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 算法启动失败
string system_log_error = string.Format(SystemLogStringFormats.ALGORITHM_SETUP_ERROR, this.Support.StrategyType.GetDescription());
ApplicationDomainEx.CsvContext.AppendSystemLog(this.Support.ViewKey, this.Support.DisplayName, system_log_error);
//====================================================================
return false; return false;
} }
...@@ -383,6 +407,14 @@ namespace VIZ.H2V.Module ...@@ -383,6 +407,14 @@ namespace VIZ.H2V.Module
this.Support.ProcessModel.ViewKey = this.Support.ViewKey; this.Support.ProcessModel.ViewKey = this.Support.ViewKey;
this.Support.ProcessModel.MainProcess = mainProcess; this.Support.ProcessModel.MainProcess = mainProcess;
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 算法启动
string system_log = string.Format(SystemLogStringFormats.ALGORITHM_SETUP, this.Support.StrategyType.GetDescription(), strategy.MainPath);
ApplicationDomainEx.CsvContext.AppendSystemLog(this.Support.ViewKey, this.Support.DisplayName, system_log);
//====================================================================
return true; return true;
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Common;
using VIZ.H2V.Domain;
namespace VIZ.H2V.Module
{
/// <summary>
/// NDI视图数据帧
/// </summary>
public class NDIViewDataFrame : IVideoControlSync
{
/// <summary>
/// 时间码
/// </summary>
public long TimeStamp { get; set; }
/// <summary>
/// 算法检测消息
/// </summary>
public AlgorithmMessage__detect AlgorithmMessage__detect { get; set; }
/// <summary>
/// 算法裁切消息
/// </summary>
public AlgorithmMessage__crop_roi AlgorithmMessage__crop_roi { get; set; }
}
}
...@@ -139,9 +139,9 @@ ...@@ -139,9 +139,9 @@
<RowDefinition Height="180"></RowDefinition> <RowDefinition Height="180"></RowDefinition>
<RowDefinition Height="60"></RowDefinition> <RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<CheckBox FontSize="16" Content="裁切策略:" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" <!--<CheckBox FontSize="16" Content="裁切策略:" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"
IsChecked="{Binding Path=IsUseClip,Mode=TwoWay}" IsChecked="{Binding Path=IsUseClip,Mode=TwoWay}"
Style="{StaticResource CheckBox_NdiView}"></CheckBox> Style="{StaticResource CheckBox_NdiView}"></CheckBox>-->
<Rectangle Grid.Row="1" Grid.RowSpan="10" Fill="#ff181d2b"></Rectangle> <Rectangle Grid.Row="1" Grid.RowSpan="10" Fill="#ff181d2b"></Rectangle>
<Border Grid.Row="1" IsEnabled="{Binding IsUseClip,Mode=OneWay}"> <Border Grid.Row="1" IsEnabled="{Binding IsUseClip,Mode=OneWay}">
<Grid> <Grid>
...@@ -150,18 +150,26 @@ ...@@ -150,18 +150,26 @@
<RowDefinition Height="60"></RowDefinition> <RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="60"></RowDefinition> <RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<RadioButton Content="{Binding Path=StrategyDisplayName,Mode=OneWay}" Grid.Row="0" FontSize="16" Foreground="White" <Border ToolTip="{Binding Path=StrategyDisplayName,Mode=OneWay}" Background="Transparent">
<RadioButton FontSize="16" Foreground="White"
Style="{StaticResource RadioButton_NdiView}" Style="{StaticResource RadioButton_NdiView}"
IsChecked="{Binding IsAutoModeChecked,Mode=TwoWay}"> IsChecked="{Binding IsAutoModeChecked,Mode=TwoWay}">
<TextBlock Text="{Binding Path=StrategyDisplayName,Mode=OneWay}" Margin="0,0,10,0" TextWrapping="NoWrap"
TextTrimming="CharacterEllipsis"></TextBlock>
</RadioButton> </RadioButton>
<RadioButton Content="居中" Grid.Row="1" FontSize="16" Foreground="White" </Border>
<Border ToolTip="居中" Grid.Row="1" Background="Transparent">
<RadioButton Content="居中" FontSize="16" Foreground="White"
Style="{StaticResource RadioButton_NdiView}" Style="{StaticResource RadioButton_NdiView}"
IsChecked="{Binding IsCenterModeChecked,Mode=TwoWay}"> IsChecked="{Binding IsCenterModeChecked,Mode=TwoWay}">
</RadioButton> </RadioButton>
<RadioButton Content="手动" Grid.Row="2" FontSize="16" Foreground="White" </Border>
<Border ToolTip="手动" Grid.Row="2" Background="Transparent">
<RadioButton Content="手动" FontSize="16" Foreground="White"
IsChecked="{Binding Path=IsManualModeChecked,Mode=TwoWay}" IsChecked="{Binding Path=IsManualModeChecked,Mode=TwoWay}"
Style="{StaticResource RadioButton_NdiView}"> Style="{StaticResource RadioButton_NdiView}">
</RadioButton> </RadioButton>
</Border>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>
......
...@@ -347,6 +347,14 @@ namespace VIZ.H2V.Module ...@@ -347,6 +347,14 @@ namespace VIZ.H2V.Module
if (value) if (value)
{ {
NDIViewModel.ActiveViewModel = this; NDIViewModel.ActiveViewModel = this;
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 视图激活
string system_log = string.Format(SystemLogStringFormats.VIEW_ACTIVE);
ApplicationDomainEx.CsvContext.AppendSystemLog(this.ViewKey, this.DisplayName, system_log);
//====================================================================
} }
} }
} }
......
...@@ -438,6 +438,14 @@ namespace VIZ.H2V.Module ...@@ -438,6 +438,14 @@ namespace VIZ.H2V.Module
ApplicationDomainEx.CsvContext.LogOperations.Enqueue(log); ApplicationDomainEx.CsvContext.LogOperations.Enqueue(log);
} }
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 算法切换模式
string system_log = string.Format(SystemLogStringFormats.ALGORITHM_CHANGE_MODE, this.StrategyType.GetDescription(), strategyMode.GetDescription());
ApplicationDomainEx.CsvContext.AppendSystemLog(this.ViewKey, this.DisplayName, system_log);
//====================================================================
} }
/// <summary> /// <summary>
......
...@@ -108,6 +108,15 @@ namespace VIZ.H2V.Module ...@@ -108,6 +108,15 @@ namespace VIZ.H2V.Module
return; return;
service.ViewStatus = NDIViewStatus.Stop; service.ViewStatus = NDIViewStatus.Stop;
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 算法进程消失
string system_log = string.Format(SystemLogStringFormats.ALGORITHM_PROCESS_LOST, service.StrategyType.GetDescription());
ApplicationDomainEx.CsvContext.AppendSystemLog(service.ViewKey, service.DisplayName, system_log);
//====================================================================
}); });
} }
} }
......
...@@ -48,7 +48,10 @@ namespace VIZ.H2V.Module ...@@ -48,7 +48,10 @@ namespace VIZ.H2V.Module
// 操作日志 // 操作日志
ApplicationDomainEx.CsvContext.OpenLogOperations(); ApplicationDomainEx.CsvContext.OpenLogOperations();
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCsv.WriteLogOperations", 60, this.WriteLogOperations); // 系统日志
ApplicationDomainEx.CsvContext.OpenSystemLog();
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCsv.WriteLog", 60, this.WriteLogOperations);
return true; return true;
} }
...@@ -59,6 +62,7 @@ namespace VIZ.H2V.Module ...@@ -59,6 +62,7 @@ namespace VIZ.H2V.Module
/// <param name="context">应用程序启动上下文</param> /// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context) public override void Shutdown(AppSetupContext context)
{ {
// 补全操作日志
lock (ApplicationDomainEx.CsvContext.LogOperations) lock (ApplicationDomainEx.CsvContext.LogOperations)
{ {
LogOperation last = ApplicationDomainEx.CsvContext.LogOperations.LastOrDefault(); LogOperation last = ApplicationDomainEx.CsvContext.LogOperations.LastOrDefault();
...@@ -69,7 +73,11 @@ namespace VIZ.H2V.Module ...@@ -69,7 +73,11 @@ namespace VIZ.H2V.Module
} }
} }
// 关闭操作日志
ApplicationDomainEx.CsvContext.CloseLogOperations(); ApplicationDomainEx.CsvContext.CloseLogOperations();
// 关闭系统日志
ApplicationDomainEx.CsvContext.CloseSystemLog();
} }
/// <summary> /// <summary>
...@@ -77,7 +85,10 @@ namespace VIZ.H2V.Module ...@@ -77,7 +85,10 @@ namespace VIZ.H2V.Module
/// </summary> /// </summary>
private void WriteLogOperations() private void WriteLogOperations()
{ {
// 输出操作日志
ApplicationDomainEx.CsvContext.FlushLogOperations(false); ApplicationDomainEx.CsvContext.FlushLogOperations(false);
// 输出系统日志
ApplicationDomainEx.CsvContext.FlushSystemLog();
} }
} }
} }
...@@ -49,6 +49,12 @@ namespace VIZ.H2V.Storage ...@@ -49,6 +49,12 @@ namespace VIZ.H2V.Storage
public Queue<LogOperation> LogOperations { get; private set; } public Queue<LogOperation> LogOperations { get; private set; }
/// <summary> /// <summary>
/// 系统日志
/// </summary>
[Csv(Scene = CsvScene.Write)]
public Queue<SystemLog> SystemLogs { get; private set; }
/// <summary>
/// 加载算法信息 /// 加载算法信息
/// </summary> /// </summary>
/// <param name="path">文件路径</param> /// <param name="path">文件路径</param>
...@@ -118,6 +124,11 @@ namespace VIZ.H2V.Storage ...@@ -118,6 +124,11 @@ namespace VIZ.H2V.Storage
private CsvWriter logOperationsWriter; private CsvWriter logOperationsWriter;
/// <summary> /// <summary>
/// 系统日志输出
/// </summary>
private CsvWriter systemLogWriter;
/// <summary>
/// 打开操作日志 /// 打开操作日志
/// </summary> /// </summary>
public void OpenLogOperations() public void OpenLogOperations()
...@@ -172,5 +183,78 @@ namespace VIZ.H2V.Storage ...@@ -172,5 +183,78 @@ namespace VIZ.H2V.Storage
this.logOperationsWriter?.Dispose(); this.logOperationsWriter?.Dispose();
this.logOperationsWriter = null; this.logOperationsWriter = null;
} }
/// <summary>
/// 打开系统日志
/// </summary>
public void OpenSystemLog()
{
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "system_log");
string fileName = Path.Combine(dir, $"{DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss")}.csv");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
CsvConfiguration config = new CsvConfiguration(System.Threading.Thread.CurrentThread.CurrentCulture);
CsvWriter writer = new CsvWriter(new StreamWriter(fileName, false, Encoding.Default), config);
writer.Context.RegisterClassMap(new SystemLogMap());
this.SystemLogs = new Queue<SystemLog>();
this.systemLogWriter = writer;
}
/// <summary>
/// 添加日志
/// </summary>
/// <param name="viewKey">视图键</param>
/// <param name="displayName">显示名称</param>
/// <param name="operation">操作内容</param>
public void AppendSystemLog(string viewKey, string displayName, string operation)
{
SystemLog log = new SystemLog();
log.ViewKey = viewKey;
log.DisplayName = displayName;
log.Operation = operation;
log.DateTime = DateTime.Now;
lock (SystemLogs)
{
SystemLogs.Enqueue(log);
}
}
/// <summary>
/// 输出系统日志
/// </summary>
public void FlushSystemLog()
{
if (this.systemLogWriter == null || this.SystemLogs == null || this.SystemLogs.Count == 0)
return;
List<SystemLog> list = new List<SystemLog>();
lock (this.SystemLogs)
{
while (this.SystemLogs.Count > 0)
{
SystemLog log = this.SystemLogs.Dequeue();
list.Add(log);
}
this.systemLogWriter.WriteRecords(list);
}
}
/// <summary>
/// 关闭系统日志
/// </summary>
public void CloseSystemLog()
{
this.FlushSystemLog();
this.systemLogWriter?.Flush();
this.systemLogWriter?.Dispose();
this.systemLogWriter = null;
}
} }
} }
using System; using CsvHelper.Configuration;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace VIZ.H2V.Storage.CSV.Log namespace VIZ.H2V.Storage
{ {
internal class SystemLog /// <summary>
/// 系统日志映射
/// </summary>
public class SystemLogMap : ClassMap<SystemLog>
{ {
public SystemLogMap()
{
this.Map(p => p.ID).Name("编号");
this.Map(p => p.ViewKey).Name("窗口");
this.Map(p => p.DisplayName).Name("窗口名称");
this.Map(p => p.Operation).Name("操作");
this.Map(p => p.DateTime).Name("时间");
}
}
/// <summary>
/// 系统日志
/// </summary>
public class SystemLog
{
/// <summary>
/// 统计ID
/// </summary>
private static int all_id = 1;
public SystemLog()
{
this.ID = all_id++;
}
/// <summary>
/// 编号
/// </summary>
public int ID { get; set; }
/// <summary>
/// 视图键
/// </summary>
public string ViewKey { get; set; }
/// <summary>
/// 显示名称
/// </summary>
public string DisplayName { get; set; }
/// <summary>
/// 操作类型
/// </summary>
public string Operation { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime DateTime { get; set; }
} }
} }
...@@ -20,5 +20,40 @@ namespace VIZ.H2V.Storage ...@@ -20,5 +20,40 @@ namespace VIZ.H2V.Storage
/// 系统关闭 /// 系统关闭
/// </summary> /// </summary>
public const string APPLICATION_SHUTDOWN = "系统关闭"; public const string APPLICATION_SHUTDOWN = "系统关闭";
/// <summary>
/// 视图激活
/// </summary>
public const string VIEW_ACTIVE = "视图激活";
/// <summary>
/// 发送算法停止消息
/// </summary>
public const string ALGORITHM_SHUTDOWN_MESSAGE = "发送算法停止消息";
/// <summary>
/// Kill算法进程
/// </summary>
public const string ALGORITHM_SHUTDOWN_KILL = "Kill算法进程";
/// <summary>
/// 算法启动
/// </summary>
public const string ALGORITHM_SETUP = "算法启动, [类型:{0}], 路径:{1}";
/// <summary>
/// 算法启动失败
/// </summary>
public const string ALGORITHM_SETUP_ERROR = "算法启动失败, [类型: {0}]";
/// <summary>
/// 算法进程消失
/// </summary>
public const string ALGORITHM_PROCESS_LOST = "算法进程消失, [类型:{0}]";
/// <summary>
/// 算法切换模式
/// </summary>
public const string ALGORITHM_CHANGE_MODE = "算法切换模式:[类型:{0}], <模式:{1}>";
} }
} }
...@@ -116,6 +116,8 @@ ...@@ -116,6 +116,8 @@
<Compile Include="CSV\Clip\ClipSystem.cs" /> <Compile Include="CSV\Clip\ClipSystem.cs" />
<Compile Include="CSV\CsvContext.cs" /> <Compile Include="CSV\CsvContext.cs" />
<Compile Include="CSV\Log\LogOperation.cs" /> <Compile Include="CSV\Log\LogOperation.cs" />
<Compile Include="CSV\Log\SystemLog.cs" />
<Compile Include="CSV\Log\SystemLogStringFormats.cs" />
<Compile Include="Init\Config\AlgorithmConfig.cs" /> <Compile Include="Init\Config\AlgorithmConfig.cs" />
<Compile Include="Init\Config\UdpConfig.cs" /> <Compile Include="Init\Config\UdpConfig.cs" />
<Compile Include="LiteDB\Algorithm\AlgorithmBase.cs" /> <Compile Include="LiteDB\Algorithm\AlgorithmBase.cs" />
......
using System; /*
* ===============================================================================
* CODE | Detail
* -------------------------------------------------------------------------------
* SYSTEM_LOG | 系統日志
* -------------------------------------------------------------------------------
* |
* ===============================================================================
*/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Data; using System.Data;
...@@ -9,7 +19,9 @@ using System.Windows; ...@@ -9,7 +19,9 @@ using System.Windows;
using VIZ.Framework.Core; using VIZ.Framework.Core;
using VIZ.Framework.Domain; using VIZ.Framework.Domain;
using VIZ.Framework.Module; using VIZ.Framework.Module;
using VIZ.H2V.Domain;
using VIZ.H2V.Module; using VIZ.H2V.Module;
using VIZ.H2V.Storage;
namespace VIZ.H2V namespace VIZ.H2V
{ {
...@@ -35,6 +47,8 @@ namespace VIZ.H2V ...@@ -35,6 +47,8 @@ namespace VIZ.H2V
// 初始化3D鼠标配置 // 初始化3D鼠标配置
AppSetup.AppendSetup(new AppSetup_Navigation3DConfig()); AppSetup.AppendSetup(new AppSetup_Navigation3DConfig());
// -----------------------------------------------------------------
// 初始化系统监控 // 初始化系统监控
AppSetup.AppendLoad(new AppSetup_Monitor()); AppSetup.AppendLoad(new AppSetup_Monitor());
// 初始化3D鼠标 // 初始化3D鼠标
...@@ -56,6 +70,13 @@ namespace VIZ.H2V ...@@ -56,6 +70,13 @@ namespace VIZ.H2V
{ {
Environment.Exit(-1); Environment.Exit(-1);
} }
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 系统启动
ApplicationDomainEx.CsvContext.AppendSystemLog(null, null, SystemLogStringFormats.APPLICATION_SETUP);
//====================================================================
} }
} }
} }
...@@ -13,6 +13,8 @@ using System.Windows.Media.Imaging; ...@@ -13,6 +13,8 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using VIZ.Framework.Core; using VIZ.Framework.Core;
using VIZ.Framework.Module; using VIZ.Framework.Module;
using VIZ.H2V.Domain;
using VIZ.H2V.Storage;
namespace VIZ.H2V namespace VIZ.H2V
{ {
...@@ -36,6 +38,13 @@ namespace VIZ.H2V ...@@ -36,6 +38,13 @@ namespace VIZ.H2V
// 执行卸载流程 // 执行卸载流程
AppSetup.UnLoad(); AppSetup.UnLoad();
//====================================================================
// CODE: SYSTEM_LOG | 记录日志
//====================================================================
// 记录日志: 系统关闭
ApplicationDomainEx.CsvContext.AppendSystemLog(null, null, SystemLogStringFormats.APPLICATION_SHUTDOWN);
//====================================================================
// 执行退出流程 // 执行退出流程
AppSetup.ShutDown(); AppSetup.ShutDown();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment