From 1bcc0aaa89cce3888979391a4538cddf1fa1c4de Mon Sep 17 00:00:00 2001 From: wenjy Date: Tue, 26 Nov 2024 09:41:02 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E6=97=A5=E5=BF=97=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AppConfig.cs | 20 +++++++++ SlnMesnac.Quartz/Job/MyJob.cs | 8 ++-- SlnMesnac.Quartz/QuartzSetUp.cs | 6 +-- SlnMesnac.Quartz/SlnMesnac.Quartz.csproj | 4 ++ SlnMesnac.Serilog/SerilogExtensions.cs | 11 ++--- SlnMesnac.WPF/SlnMesnac.WPF.csproj | 1 + SlnMesnac.WPF/Startup.cs | 3 +- .../ViewModel/IndexControlViewModel.cs | 43 ++++++++++++------- SlnMesnac.WPF/appsettings.json | 4 ++ 9 files changed, 72 insertions(+), 28 deletions(-) diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 23d4665..17a4228 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -78,6 +78,26 @@ namespace SlnMesnac.Config /// public string redisConfig { get; set; } + /// + /// 相机网络地址 + /// + public string cameraIp { get; set; } + + /// + /// 相机端口 + /// + public int cameraPort { get; set; } + + /// + /// 相机用户名 + /// + public string cameraUserName { get; set; } + + /// + /// 相机密码 + /// + public string cameraPassword { get; set; } + public AppConfig Value => this; } } diff --git a/SlnMesnac.Quartz/Job/MyJob.cs b/SlnMesnac.Quartz/Job/MyJob.cs index 735f08c..ec7267e 100644 --- a/SlnMesnac.Quartz/Job/MyJob.cs +++ b/SlnMesnac.Quartz/Job/MyJob.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Quartz; +using SlnMesnac.Serilog; using System; using System.Collections.Generic; using System.Text; @@ -31,16 +32,17 @@ namespace SlnMesnac.Quartz.Job { public class MyJob : IJob { - private readonly ILogger _logger; - public MyJob(ILogger logger) + public readonly SerilogHelper _logger; + + public MyJob(SerilogHelper logger) { _logger = logger; } public Task Execute(IJobExecutionContext context) { - _logger.LogInformation($"执行MyJob:{DateTime.Now.ToString("HH:mm:ss")}"); + _logger.Info($"执行MyJob:{DateTime.Now.ToString("HH:mm:ss")}"); return Task.CompletedTask; } } diff --git a/SlnMesnac.Quartz/QuartzSetUp.cs b/SlnMesnac.Quartz/QuartzSetUp.cs index 1a6bb23..f18d6d8 100644 --- a/SlnMesnac.Quartz/QuartzSetUp.cs +++ b/SlnMesnac.Quartz/QuartzSetUp.cs @@ -40,9 +40,9 @@ namespace SlnMesnac.Quartz trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例:每3s执行一次 ); - q.ScheduleJob(trigger => - trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例:每5s执行一次 - ); + //q.ScheduleJob(trigger => + // trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例:每5s执行一次 + //); }); services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true); diff --git a/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj b/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj index 1040f6c..344e515 100644 --- a/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj +++ b/SlnMesnac.Quartz/SlnMesnac.Quartz.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/SlnMesnac.Serilog/SerilogExtensions.cs b/SlnMesnac.Serilog/SerilogExtensions.cs index 8f1e063..24eee11 100644 --- a/SlnMesnac.Serilog/SerilogExtensions.cs +++ b/SlnMesnac.Serilog/SerilogExtensions.cs @@ -42,7 +42,8 @@ namespace SlnMesnac.Serilog #region 通过配置文件读取日志存放位置 var appConfig = app.ApplicationServices.GetService(); - var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; + var logPath = $"{appConfig.logPath}/Logs/"; + #endregion //Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() @@ -55,16 +56,16 @@ namespace SlnMesnac.Serilog Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info")) - .WriteTo.File(Path.Combine(logPath, "Info.log"))) + .WriteTo.File(Path.Combine($"{logPath}/Info/", "Info.log"),rollingInterval:RollingInterval.Day)) .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc")) - .WriteTo.File(Path.Combine(logPath, "Plc.log"))) + .WriteTo.File(Path.Combine($"{logPath}/Plc/", "Plc.log"), rollingInterval: RollingInterval.Day)) .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Camera")) - .WriteTo.File(Path.Combine(logPath, "Camera.log"))) + .WriteTo.File(Path.Combine($"{logPath}/Camera/", "Camera.log"), rollingInterval: RollingInterval.Day)) .WriteTo.Logger(lc => lc .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error")) - .WriteTo.File(Path.Combine(logPath, "Error.log"))) + .WriteTo.File(Path.Combine($"{logPath}/Error/", "Error.log"), rollingInterval: RollingInterval.Day)) .CreateLogger(); app.UseSerilogRequestLogging(); diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index ec29df7..7e04033 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -6,6 +6,7 @@ enable true true + diff --git a/SlnMesnac.WPF/Startup.cs b/SlnMesnac.WPF/Startup.cs index ea916f6..ab2005e 100644 --- a/SlnMesnac.WPF/Startup.cs +++ b/SlnMesnac.WPF/Startup.cs @@ -9,7 +9,7 @@ using Autofac; using Microsoft.Extensions.Configuration; using SlnMesnac.Ioc; using SlnMesnac.Extensions; -using SlnMesnac.TouchSocket; +using SlnMesnac.Quartz; namespace SlnMesnac.WPF { @@ -41,6 +41,7 @@ namespace SlnMesnac.WPF //注册PLC工厂 services.AddPlcFactorySetup(); + //services.AddQuartzSetUp(); } /// diff --git a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs index 7b1ab07..c6bc6c5 100644 --- a/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexControlViewModel.cs @@ -55,22 +55,29 @@ namespace SlnMesnac.WPF.ViewModel public Int32 Scenery_RealHandle = -1; public Int32 Thermal_RealHandle = -1; - private const string DVRIPAddress = "192.168.1.64"; //设备IP地址或者域名 Device IP - private const Int16 DVRPortNumber = 8000; //设备服务端口号 Device Port - private const string DVRUserName = "admin"; //设备登录用户名 User name to login - private const string DVRPassword = "haiwei@2024"; //设备登录密码 Password to login + //private const string DVRIPAddress = "192.168.2.64"; //设备IP地址或者域名 Device IP + //private const Int16 DVRPortNumber = 8000; //设备服务端口号 Device Port + //private const string DVRUserName = "admin"; //设备登录用户名 User name to login + //private const string DVRPassword = "haiwei@2024"; //设备登录密码 Password to login public IndexControlViewModel() { - _log = App.ServiceProvider.GetService(); - _callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback); - _appConfig = App.ServiceProvider.GetService(); - autoModeBusiness = App.ServiceProvider.GetService(); - inspModeBusiness = App.ServiceProvider.GetService(); + try + { + _log = App.ServiceProvider.GetService(); + _callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback); + _appConfig = App.ServiceProvider.GetService(); + autoModeBusiness = App.ServiceProvider.GetService(); + inspModeBusiness = App.ServiceProvider.GetService(); - autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture; + autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture; - RefreshTrackMotorAddress(); + RefreshTrackMotorAddress(); + }catch (Exception ex) + { + _log.Error("巡检控制系统初始化失败",ex); + MessageBox.Show($"巡检控制系统初始化失败:{ex.Message}"); + } } #region 参数定义 @@ -115,7 +122,7 @@ namespace SlnMesnac.WPF.ViewModel } - m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo); + m_lUserID = CHCNetSDK.NET_DVR_Login_V30(_appConfig.cameraIp, _appConfig.cameraPort, _appConfig.cameraUserName, _appConfig.cameraPassword, ref DeviceInfo); if (m_lUserID < 0) { @@ -168,10 +175,14 @@ namespace SlnMesnac.WPF.ViewModel public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData) { var ret = Marshal.PtrToStructure(lpBuffer); - autoModeBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1); - autoModeBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature); - autoModeBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1); - autoModeBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1); + if (autoModeBusiness != null) + { + autoModeBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1); + autoModeBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature); + autoModeBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1); + autoModeBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1); + + } this.RealTemperature = new RealTemperatureInfo() { diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index 7d543f0..31f44b4 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -12,6 +12,10 @@ "visibleRangePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\可见光图像", "infraredImagePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\红外热成像", "videoFilePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\巡检录像", + "cameraIp": "192.168.2.64", + "cameraPort": 8000, + "cameraUserName": "admin", + "cameraPassword": "haiwei@2024", "checkCycle": 5, "SqlConfig": [ {