新增设备状态存库

master
CaesarBao 3 months ago
parent 3b208a6d8a
commit 16bbeb4f6c

@ -33,7 +33,7 @@ namespace SlnMesnac.Config
}
public bool WriteAppSettings(string session,string key, string value)
{
string contentPath = System.IO.Directory.GetCurrentDirectory() + @"\"; ; //项目根目录
string contentPath = System.IO.Directory.GetCurrentDirectory() + @"\"; //项目根目录
var filePath = contentPath + "appsettings.json";
JObject jsonObject;
using (StreamReader file = new StreamReader(filePath))

@ -56,6 +56,7 @@ namespace SlnMesnac.Extensions
string IP = colonIndex != -1 ? item.Connectstr.Substring(0, colonIndex) : item.Connectstr;
string Port = colonIndex != -1 ? item.Connectstr.Substring(colonIndex + 1) : item.Connectstr;
RfidAbsractFactory _rfid = x.GetService<RflyFactory>();
_rfid.deviceid = item.Deviceid;
_rfid.ip = IP;
_rfid.port = int.Parse(Port);
_rfid.ConfigKey = sensor_Infos.Find(x => x.Deviceid == item.Deviceid).Combineid;

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Models
{
/// <summary>
///
///</summary>
[SugarTable("base_collect_state")]
public class Base_collect_state
{
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true,IsIdentity = true) ]
public int Id { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="collectId" ) ]
public string CollectId { get; set; } = null!;
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="collectState" ) ]
public int? CollectState { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="collectTime" ) ]
public DateTime? CollectTime { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="eidtTime" ) ]
public DateTime? EidtTime { get; set; }
}
}

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugar;
namespace Models
{
/// <summary>
///
///</summary>
[SugarTable("base_device_state")]
public class Base_device_state
{
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true,IsIdentity = true) ]
public int Id { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="deviceId" ) ]
public int DeviceId { get; set; }
/// <summary>
/// 备 注:设备连接状态 0为未连接 1为连接
/// 默认值:
///</summary>
[SugarColumn(ColumnName="deviceState" ) ]
public int? DeviceState { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
[SugarColumn(ColumnName="deviceTime" ) ]
public DateTime? DeviceTime { get; set; }
}
}

@ -6,12 +6,12 @@ namespace SlnMesnac.Model.domain
{
public class DeviceInfo
{
public string connectstr { get; set; }
public string IPAddress { get; set; }
public string combineid { get; set; }
public string EQUID { get; set; }
public string addr { get; set; }
public string position { get; set; }
public string port { get; set; }
public string ApiPort { get; set; }
}
}

@ -27,7 +27,7 @@ namespace SlnMesnac.Repository.service.Impl
List<DeviceInfo> taskInfos = null;
try
{
String sql = "select t1.connectstr, t2.combineid,t1.addr,t3.port from base_device_info t1 left join [dbo].[base_sensor_info] t2 on t1.deviceid = t2.deviceid left join [dbo].[base_collect_info] t3 on t1.collectid = t3.collectId where t1.deleteflag != 1 ";
String sql = "select t1.connectstr as IPAddress, t2.combineid as EQUID,t1.addr as position,t3.port as ApiPort from base_device_info t1 left join [dbo].[base_sensor_info] t2 on t1.deviceid = t2.deviceid left join [dbo].[base_collect_info] t3 on t1.collectid = t3.collectId where t1.deleteflag != 1 ";
taskInfos = base._rep.AsTenant().GetConnection("mes").Ado.SqlQuery<DeviceInfo>(sql);
}
catch (Exception ex)
@ -43,9 +43,9 @@ namespace SlnMesnac.Repository.service.Impl
try
{
List<DeviceInfo> device = new List<DeviceInfo>();
String sql = " SELECT [port] FROM [WLDB].[dbo].[base_collect_info] where deleteflag != 1 and collectId = "+ collectid;
String sql = " SELECT [port] as ApiPort FROM [WLDB].[dbo].[base_collect_info] where deleteflag != 1 and collectId = " + collectid;
device = base._rep.AsTenant().GetConnection("mes").Ado.SqlQuery<DeviceInfo>(sql);
return device[0].port;
return device[0].ApiPort;
}
catch (Exception ex)
{

@ -10,6 +10,7 @@ using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.@base;
using SlnMesnac.Rfid;
using SlnMesnac.Rfid.Factory;
using SlnMesnac.Serilog;
using SqlSugar;
using System;
using System.Collections.Generic;
@ -46,7 +47,7 @@ namespace SlnMesnac.TouchSocket
{
public class ApiServer: RpcServer
{
private ILogger<ApiServer> _logger;
private readonly SerilogHelper _logger;
private List<RfidAbsractFactory> rfidAbsractFactory;
private List<Base_sensor_info> base_Sensor_Infos;
public static Action<string> _RefreshLogMessageAction;
@ -54,7 +55,7 @@ namespace SlnMesnac.TouchSocket
private IReal_mesdataService _real_MesdataService;
private IReal_workdataService _real_WorkdataService;
public ApiServer(ILogger<ApiServer> logger, List<RfidAbsractFactory> rfidAbsractFactory, IReal_mesdataService real_MesdataService, IReal_workdataService real_WorkdataService)
public ApiServer(SerilogHelper logger, List<RfidAbsractFactory> rfidAbsractFactory, IReal_mesdataService real_MesdataService, IReal_workdataService real_WorkdataService)
{
_logger = logger;
this.rfidAbsractFactory = rfidAbsractFactory;
@ -124,7 +125,7 @@ namespace SlnMesnac.TouchSocket
// 设置标志位为 true表示方法正在执行
iFlag = true;
_RefreshLogMessageAction?.Invoke("接收MES主动读取指令" + JsonSerializer.Serialize(mesReadPara));
_logger.LogInformation("接收MES主动读取指令{0}", JsonSerializer.Serialize(mesReadPara));
_logger.Info("接收MES主动读取指令"+ JsonSerializer.Serialize(mesReadPara));
string FilterData = rfidAbsractFactory.Find(x => x.ConfigKey == mesReadPara.EQUID).FilterData;
List<TagInfo> rfid = await rfidAbsractFactory.Find(x => x.ConfigKey == mesReadPara.EQUID).GetRFIDAsync();
@ -177,7 +178,7 @@ namespace SlnMesnac.TouchSocket
Msg = Msg,
};
_RefreshLogMessageAction?.Invoke("发送MES主动读取指令" + JsonSerializer.Serialize(response));
_logger.LogInformation("发送MES主动读取指令{0}", JsonSerializer.Serialize(response));
_logger.Info("发送MES主动读取指令"+ JsonSerializer.Serialize(response));
Real_mesdata real_Mesdata = new Real_mesdata()
{
Combineid = mesReadPara.EQUID.ToString(),
@ -197,7 +198,7 @@ namespace SlnMesnac.TouchSocket
}
catch (Exception ex)
{
_logger.LogInformation("read接口异常" + ex.ToString());
_logger.Error("read接口异常" + ex.ToString());
return response;
}
finally
@ -226,7 +227,7 @@ namespace SlnMesnac.TouchSocket
ApiResponse<MesParaData> response = new ApiResponse<MesParaData>();
_RefreshLogMessageAction?.Invoke("接收MES控制报警灯指令" + JsonSerializer.Serialize(mesAlarmLightPara));
_logger.LogInformation("接收MES控制报警灯指令{0}", JsonSerializer.Serialize(mesAlarmLightPara));
_logger.Info("接收MES控制报警灯指令"+ JsonSerializer.Serialize(mesAlarmLightPara));
if (mesAlarmLightPara.Code == "0")
{
@ -251,7 +252,7 @@ namespace SlnMesnac.TouchSocket
Msg = "sucess",
};
_RefreshLogMessageAction?.Invoke("发送MES控制报警灯指令" + JsonSerializer.Serialize(response));
_logger.LogInformation("发送MES控制报警灯指令{0}", JsonSerializer.Serialize(response));
_logger.Info("发送MES控制报警灯指令"+ JsonSerializer.Serialize(response));
Real_mesdata real_Mesdata = new Real_mesdata()
{
Combineid = mesAlarmLightPara.EQUID.ToString(),

@ -7,6 +7,7 @@ using SlnMesnac.Model.dto;
using SlnMesnac.Repository.service;
using SlnMesnac.Rfid.Dto;
using SlnMesnac.Rfid.Enum;
using SlnMesnac.Serilog;
using SlnMesnac.TouchSocket;
using System;
using System.Collections;
@ -44,14 +45,14 @@ namespace SlnMesnac.Rfid.Factory
{
public class RflyFactory:RfidAbsractFactory
{
private ILogger<RflyFactory> _logger;
private SerilogHelper _logger;
private readonly TcpClient _tcpClient = new TcpClient();
private readonly StringChange _stringChange;
private string m_strIP;
private string m_deviceID;
private MeshttpClient _meshttpClient;
public RflyFactory(ILogger<RflyFactory> logger,StringChange stringChange, MeshttpClient meshttpClient)
public RflyFactory(SerilogHelper logger,StringChange stringChange, MeshttpClient meshttpClient)
{
_logger = logger;
_stringChange = stringChange;
@ -168,7 +169,7 @@ namespace SlnMesnac.Rfid.Factory
byte[] reciveBuffer = waitClient.SendThenReturn(pMessagePack.m_pData, timeout);
_logger.LogInformation($"接收原始报文:{_stringChange.bytesToHexStr(reciveBuffer,reciveBuffer.Length)}");
_logger.Info($"接收原始报文:{_stringChange.bytesToHexStr(reciveBuffer,reciveBuffer.Length)}");
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer,reciveBuffer.Length);
@ -233,10 +234,10 @@ namespace SlnMesnac.Rfid.Factory
});
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, timeout);
_logger.LogInformation($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData,pMessagePack.m_pData.Length)}");
_logger.Info($"{m_deviceID}发送读取指令{_stringChange.bytesToHexStr(pMessagePack.m_pData,pMessagePack.m_pData.Length)}");
byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
_logger.LogInformation($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer,resultBuffer.Length)}");
_logger.Info($"{m_deviceID}接收读取指令{_stringChange.bytesToHexStr(resultBuffer,resultBuffer.Length)}");
tagInfoList = Device_DealTagInfoList(resultBuffer);
@ -378,10 +379,10 @@ namespace SlnMesnac.Rfid.Factory
return false;
}
});
_logger.LogInformation($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
_logger.Info($"{m_deviceID}发送修改功率指令{_stringChange.bytesToHexStr(pMessagePack.m_pData, pMessagePack.m_pData.Length)}");
byte[] reciveBuffer = await waitClient.SendThenReturnAsync(pMessagePack.m_pData, 2000);
_logger.LogInformation($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
_logger.Info($"{m_deviceID}接收修改功率指令{_stringChange.bytesToHexStr(reciveBuffer, reciveBuffer.Length)}");
//byte[] resultBuffer = PareReceiveBufferData(reciveBuffer, reciveBuffer.Length);
if (reciveBuffer[3] == 0x42)
@ -781,7 +782,7 @@ namespace SlnMesnac.Rfid.Factory
iFirstPC = iFirstAnt + 1;
iFirstLeftBarcketPos = iFirstLeftBarcketPos + iBarcodeLength + 5;
_logger.LogInformation($"----{m_deviceID}函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]");
_logger.Info($"----{m_deviceID}函数调用:Device_DealTagInfoList 第[" + (iCommonSecondFlag + 1) + "]次数据解析为:" + tag.EPCstring + ",读取标签次数:[" + tempDataCount + "],标签信号强度:[" + tempDataRSSI + "],天线号:[" + tempDataANT + "]");
iCommonSecondFlag++;
if (iCommonSecondFlag == iBarcodeGroupCount)
{

@ -8,6 +8,7 @@ using Serilog.Events;
using SlnMesnac.Config;
using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Model.domain;
using SlnMesnac.Serilog;
using SQLitePCL;
using SqlSugar;
using System;
@ -26,10 +27,10 @@ namespace SlnMesnac.TouchSocket
public class MeshttpClient
{
private readonly AppConfig _appConfig;
private readonly ILogger<MeshttpClient> _logger;
private readonly SerilogHelper _logger;
public static Action<string, string> RefreshStateEvent;
public static Action<string> _RefreshLogMessageAction;
public MeshttpClient(AppConfig appConfig, ILogger<MeshttpClient> logger)
public MeshttpClient(AppConfig appConfig, SerilogHelper logger)
{
_appConfig = appConfig;
_logger = logger;
@ -42,14 +43,14 @@ namespace SlnMesnac.TouchSocket
MESHttpClient = new WebApiClient();
try
{
_logger.LogInformation("正在连接:" + IpHost);
_logger.Info("正在连接:" + IpHost);
MESHttpClient.Connect(IpHost);
_logger.LogInformation(IpHost + "连接成功");
_logger.Info(IpHost + "连接成功");
return MESHttpClient;
}
catch (Exception ex)
{
_logger.LogError("ERROR: " + ex.Message);
_logger.Info("MES API连接ERROR: " + ex.Message);
return null;
}
}
@ -93,14 +94,14 @@ namespace SlnMesnac.TouchSocket
JToken responseValue = MESHttpClient.InvokeT<JToken>("POST:/autoread", null, requestValue);
//JToken responseValue = MESHttpClient.InvokeT<JToken>("POST:/ApiServer/autoread", null, requestValue);
_RefreshLogMessageAction?.Invoke("发送MES自动读取指令"+JsonSerializer.Serialize(requestValue));
_logger.LogInformation("发送MES自动读取指令{0}", JsonSerializer.Serialize(requestValue));
_logger.Info("发送MES自动读取指令"+ JsonSerializer.Serialize(requestValue));
RefreshStateEvent?.Invoke(requestValue.EQUID,requestValue.EPCID);
return JTokenToEntity<ApiResponse<MesParaData>>(responseValue);
}
catch (Exception ex)
{
_logger.LogError("ERROR: " + ex.Message);
_logger.Info("autoread ERROR: " + ex.Message);
return new ApiResponse<MesParaData>();
}

@ -35,6 +35,7 @@ namespace SlnMesnac.Rfid
public string FilterData;
public string ip;
public int port;
public string deviceid;
public string ConfigKey { get; set; }
/// <summary>
/// 异步建立连接

@ -37,16 +37,15 @@ namespace SlnMesnac.TouchSocket
public static class TouchSocketSetup
{
public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app)
public static void UseTouchSocketExtensions(this IServiceProvider service)
{
//var _server = app.ApplicationServices.GetService<TcpServer>();
var _httpclient = app.ApplicationServices.GetService<MeshttpClient>();
var _apiServer = app.ApplicationServices.GetService<WebApiServer>();
var _httpclient = service.GetService<MeshttpClient>();
var _apiServer = service.GetService<WebApiServer>();
_apiServer.Init();
//_server.Init(6001);
_httpclient.CreateWebApiClient("172.16.0.106:9880");
//_httpclient.CreateWebApiClient("127.0.0.1:9880");
return app;
}
}
}

@ -103,7 +103,7 @@ namespace SlnMesnac.Serilog
}
// 确保各模块日志子目录存在
string[] subDirectories = { "Info", "Data", "Error", "Debug", "Audit" };
string[] subDirectories = { "Info", "Data", "Error"};
foreach (var subDir in subDirectories)
{
string dirPath = Path.Combine(baseLogPath, subDir);
@ -114,12 +114,12 @@ namespace SlnMesnac.Serilog
}
// 创建当前实例的启动日志文件
string startupLog = Path.Combine(baseLogPath, "Startup.log");
File.AppendAllText(startupLog,
$"=== Instance Startup ===\r\n" +
$"Time: {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}\r\n" +
$"Base Log Path: {baseLogPath}\r\n" +
$"=================================================================\r\n");
//string startupLog = Path.Combine(baseLogPath, "Startup.log");
//File.AppendAllText(startupLog,
// $"=== Instance Startup ===\r\n" +
// $"Time: {DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}\r\n" +
// $"Base Log Path: {baseLogPath}\r\n" +
// $"=================================================================\r\n");
}
catch (Exception ex)
{

@ -15,6 +15,8 @@ using System.Reflection;
using TouchSocket.Sockets;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.Rfid;
using SlnMesnac.TouchSocket;
using SlnMesnac.Quartz;
namespace SlnMesnac.WPF
{
@ -86,6 +88,7 @@ namespace SlnMesnac.WPF
// 配置Serilog和其他扩展
ServiceProvider.UseSerilogExtensions();
ServiceProvider.UseTouchSocketExtensions();
// 获取AppConfig并更新实例特定的配置
var appConfig = ServiceProvider.GetService<AppConfig>();
@ -114,8 +117,8 @@ namespace SlnMesnac.WPF
serilog.Info($"应用程序启动 - 实例ID: {_instanceId}, 进程ID: {Process.GetCurrentProcess().Id}");
serilog.Info($"日志目录: {appConfig?.logPath}");
serilog.Data($"数据目录: {_instanceDataPath}");
serilog.Error($"日志目录: {appConfig?.logPath}");
//serilog.Data($"数据目录: {_instanceDataPath}");
//serilog.Error($"日志目录: {appConfig?.logPath}");
}
catch (Exception exception)
{
@ -177,7 +180,7 @@ namespace SlnMesnac.WPF
//Directory.CreateDirectory(Path.Combine(_instanceDataPath, "Cache"));
//Directory.CreateDirectory(Path.Combine(_instanceDataPath, "Temp"));
SaveInstanceInfo();
//SaveInstanceInfo();
CleanupOldInstances();
}
@ -242,15 +245,15 @@ namespace SlnMesnac.WPF
WorkingDirectory = Environment.CurrentDirectory
};
string infoFile = Path.Combine(_instanceDataPath, "instance.info");
File.WriteAllText(infoFile,
$"Instance ID: {info.InstanceId}\r\n" +
$"Start Time: {info.StartTime}\r\n" +
$"Process ID: {info.ProcessId}\r\n" +
$"Process Name: {info.ProcessName}\r\n" +
$"Machine: {info.MachineName}\r\n" +
$"User: {info.UserName}\r\n" +
$"Working Dir: {info.WorkingDirectory}");
//string infoFile = Path.Combine(_instanceDataPath, "instance.info");
//File.WriteAllText(infoFile,
// $"Instance ID: {info.InstanceId}\r\n" +
// $"Start Time: {info.StartTime}\r\n" +
// $"Process ID: {info.ProcessId}\r\n" +
// $"Process Name: {info.ProcessName}\r\n" +
// $"Machine: {info.MachineName}\r\n" +
// $"User: {info.UserName}\r\n" +
// $"Working Dir: {info.WorkingDirectory}");
}
catch (Exception ex)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SlnMesnac.WPF"
mc:Ignorable="d"
Title="汇集软件" WindowStartupLocation="CenterScreen" WindowState="Normal" Height="1000" Width="1420" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing">
Title="汇集软件" WindowStartupLocation="CenterScreen" WindowState="Normal" Height="1000" Width="1420" Topmost="False" Loaded="Window_Loaded" Closing="Window_Closing" Icon="/Highway.ico">
<!--<Window.Background>
<ImageBrush ImageSource="/Templates/image/background.jpg" />
</Window.Background>-->

@ -1,5 +1,8 @@
using SlnMesnac.Model.AirportApiEntity;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Serilog;
using SlnMesnac.TouchSocket;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic;
@ -7,18 +10,16 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows;
using System.Windows.Forms;
using SlnMesnac.WPF.Attribute;
namespace SlnMesnac.WPF
{
@ -29,6 +30,7 @@ namespace SlnMesnac.WPF
[RegisterAsSingletonAttribute]
public partial class MainWindow : Window
{
private readonly SerilogHelper _logger;
//托盘
NotifyIcon trayIcon;
//注册AreaIcon属性用于托盘的图标
@ -45,6 +47,7 @@ namespace SlnMesnac.WPF
DependencyProperty.Register("AreaMenuItems", typeof(List<MenuItem>), typeof(MainWindow), new PropertyMetadata(new List<MenuItem>()));
public MainWindow()
{
_logger = App.ServiceProvider.GetRequiredService<SerilogHelper>();
InitializeComponent();
this.DataContext = new MainWindowViewModel();
@ -65,12 +68,12 @@ namespace SlnMesnac.WPF
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_logger.Info("系统启动!");
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
_logger.Info("系统关闭!");
}

@ -7,10 +7,14 @@
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<ApplicationIcon>Templates\icon\Highway.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="cloud.ico" />
<None Remove="Highway.ico" />
<None Remove="Icon.png" />
<None Remove="Templates\image\background.jpg" />
<None Remove="Templates\image\between.png" />
</ItemGroup>
@ -19,9 +23,13 @@
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Templates\icon\Highway.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="cloud.ico" />
<Resource Include="Highway.ico" />
<Resource Include="Icon.png" />
<Resource Include="Templates\image\between.png" />
</ItemGroup>

@ -83,7 +83,7 @@ namespace SlnMesnac.WPF
//启用Serilog中间件
//app.UseSerilogExtensions();
app.UseTouchSocketExtensions();
//app.UseTouchSocketExtensions();
//app.UseTouchSocketExtensions();
app.UseRouting();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -6,6 +6,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Models;
using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository;
using SlnMesnac.Rfid;
using SlnMesnac.TouchSocket;
@ -55,6 +56,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
LoadDeviceInfo();
LoadSenorInfo();
StartCheckStatus();
CollectState();
}
/// <summary>
/// 日志信息
@ -83,7 +85,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
LogMessages.Add($"{DateTime.Now}: {msg}");
while (LogMessages.Count > 10)
{
LogMessages.RemoveAt(0);
LogMessages.Clear();
}
var orderedList = LogMessages.OrderByDescending(x => x); // 排序后转为 List
LogMessages = new ObservableCollection<string>(orderedList);
@ -131,7 +133,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
private void LoadDeviceInfo()
{
List<Base_device_info> DeviceInfos = sqlSugarClient.Queryable<Base_device_info>().Where(expression: x =>x.Collectid == appConfig.StationCode).ToList();
List<Base_device_info> DeviceInfos = sqlSugarClient.Queryable<Base_device_info>().Where(expression: x =>x.Collectid == appConfig.StationCode && x.Deleteflag == 0).ToList();
App.Current.Dispatcher.Invoke(() =>
{
Deviceinfo.Clear();
@ -152,7 +154,7 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
}
private void LoadSenorInfo()
{
List<Base_sensor_info> SenorInfos = sqlSugarClient.Queryable<Base_sensor_info>().ToList();
List<Base_sensor_info> SenorInfos = sqlSugarClient.Queryable<Base_sensor_info>().Where(x=>x.Deleteflag == 0).ToList();
Senorinfo.Clear();
foreach (var item in Deviceinfo)
{
@ -205,27 +207,83 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
status = await device.ConnectAsync(device.ip, device.port,device.ConfigKey);
if (!status)
{
Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{device.ip}:{device.port}").IsOnline = "未连接";
Deviceinfo.FirstOrDefault(x => x.Deviceid == device.deviceid).IsOnline = "未连接";
}
else
{
Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{device.ip}:{device.port}").IsOnline = "已连接";
Deviceinfo.FirstOrDefault(x => x.Deviceid == device.deviceid).IsOnline = "已连接";
}
}
else
{
//更新界面状态
Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{device.ip}:{device.port}").IsOnline = "已连接";
Deviceinfo.FirstOrDefault(x => x.Deviceid == device.deviceid).IsOnline = "已连接";
}
//存库,如果没有则插入如果存在则更新
lock (string.Empty)
{
try
{
List<Base_device_state> Base_device_state = sqlSugarClient.Ado.Context.CopyNew().Queryable<Base_device_state>().Where(x => x.DeviceId == int.Parse(device.deviceid)).ToList();
if (Base_device_state != null && Base_device_state.Count > 0)
{
//只更新
Base_device_state[0].DeviceState = status ? 1 : 0;
Base_device_state[0].DeviceTime = DateTime.Now;
sqlSugarClient.Ado.Context.CopyNew().Updateable(Base_device_state).UpdateColumns(it => new { it.DeviceState,it.DeviceTime }).ExecuteCommand();
}
else
{
Base_device_state base_device_state = new Base_device_state()
{
DeviceId = int.Parse(device.deviceid),
DeviceState = status ? 1 : 0,
DeviceTime = DateTime.Now,
};
var a = sqlSugarClient.Ado.Context.CopyNew().Insertable<Base_device_state>(base_device_state).ExecuteCommand();
}
}
catch (Exception ex)
{
_logger.LogError($"更新RFID状态异常:{ex.Message}", ex);
}
}
}
catch (Exception ex)
{
_logger.LogError($"更新RFID状态异常:{ex.Message}", ex);
}
}
private void CollectState()
{
Task.Run(async () =>
{
while (true)
{
try
{
#region 汇集软件状态
Base_collect_state base_Collect_State = new Base_collect_state()
{
CollectId = appConfig.StationCode,
CollectState = 1,
CollectTime = DateTime.Now,
};
sqlSugarClient.Ado.Context.CopyNew().Insertable<Base_collect_state>(base_Collect_State).ExecuteCommand();
#endregion 汇集软件状态
}
catch (Exception ex)
{
_logger.LogError($"更新汇集软件状态异常:{ex.Message}");
}
await Task.Delay(1000 * 60 * 10);
}
});
}
private void StartCheckStatus()
{
Task.Run(async () =>
@ -253,36 +311,11 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
await Task.Delay(10);
}
}
//foreach (var rfid in rfidList)
//{
// if (rfid.ConfigKey == "C031040701")
// {
// }
// bool status = rfid.GetOnlineStatus();
// if (!status)
// {
// status = await rfid.ConnectAsync(rfid.ip, rfid.port);
// if (!status)
// {
// Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{rfid.ip}:{rfid.port}").IsOnline = "未连接";
// }
// else
// {
// Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{rfid.ip}:{rfid.port}").IsOnline = "已连接";
// }
// }
// else
// {
// //更新界面状态
// Deviceinfo.FirstOrDefault(x => x.Connectstr == $"{rfid.ip}:{rfid.port}").IsOnline = "已连接";
// }
//}
#endregion RFID状态
}
catch (Exception ex)
{
//_logger.Error($"监听设备状态异常:{ex.Message}");
_logger.LogError($"监听设备状态异常:{ex.Message}");
}
await Task.Delay(1000 * 30);
}

@ -8,6 +8,7 @@ using SlnMesnac.Config;
using SlnMesnac.Extensions;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using SlnMesnac.Serilog;
using SlnMesnac.TouchSocket;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.Page.Generate;
@ -20,11 +21,11 @@ namespace SlnMesnac.WPF.ViewModel
[RegisterAsSingletonAttribute]
public class MainWindowViewModel: ViewModelBase
{
private readonly ILogger<MainWindowViewModel> _logger;
private readonly ILogger<BaseTaskInfoBusiness> _BaseTaskInfoBusinesslogger;
private IAirportTaskService _Taskservice;
private IAGVStateService _AGVStateService;
private TcpServer _tcpServer;
private readonly SerilogHelper _logger;
//private readonly ILogger<BaseTaskInfoBusiness> _BaseTaskInfoBusinesslogger;
//private IAirportTaskService _Taskservice;
//private IAGVStateService _AGVStateService;
//private TcpServer _tcpServer;
//代码生成
//private readonly GenerateControl generateControl = new GenerateControl();
private MiddleWare indexContent = new MiddleWare();
@ -111,16 +112,16 @@ namespace SlnMesnac.WPF.ViewModel
public MainWindowViewModel()
{
_appConfig = App.ServiceProvider.GetService<AppConfig>();
_logger = App.ServiceProvider.GetService<ILogger<MainWindowViewModel>>();
_Taskservice = App.ServiceProvider.GetService<IAirportTaskService>();
_AGVStateService = App.ServiceProvider.GetService<IAGVStateService>();
_BaseTaskInfoBusinesslogger = App.ServiceProvider.GetService<ILogger<BaseTaskInfoBusiness>>();
_tcpServer = App.ServiceProvider.GetService<TcpServer>();
_logger = App.ServiceProvider.GetRequiredService<SerilogHelper>();
//_Taskservice = App.ServiceProvider.GetService<IAirportTaskService>();
//_AGVStateService = App.ServiceProvider.GetService<IAGVStateService>();
//_BaseTaskInfoBusinesslogger = App.ServiceProvider.GetService<ILogger<BaseTaskInfoBusiness>>();
//_tcpServer = App.ServiceProvider.GetService<TcpServer>();
_airPorthttpClient = App.ServiceProvider.GetService<MeshttpClient>();
BaseTaskInfoBusiness.GetInstance(_BaseTaskInfoBusinesslogger, _Taskservice, _AGVStateService, _tcpServer, _airPorthttpClient);
//BaseTaskInfoBusiness.GetInstance(_BaseTaskInfoBusinesslogger, _Taskservice, _AGVStateService, _tcpServer, _airPorthttpClient);
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(x => FormControl(x));
_tcpServer.RefreshStateAction+= (_clientIP, _state) =>
//_tcpServer.RefreshStateAction+= (_clientIP, _state) =>
{
//if (_clientIP == _appConfig.AMRIP)
//{
@ -128,6 +129,7 @@ namespace SlnMesnac.WPF.ViewModel
//}
};
UserContent = indexContent;
}
/// <summary>
@ -176,7 +178,7 @@ namespace SlnMesnac.WPF.ViewModel
}
catch (Exception ex)
{
_logger.LogError("窗体控制逻辑异常", ex);
_logger.Error("窗体控制逻辑异常", ex);
}
}
@ -201,7 +203,7 @@ namespace SlnMesnac.WPF.ViewModel
}
catch (Exception ex)
{
_logger.LogError("界面跳转逻辑异常", ex);
_logger.Error("界面跳转逻辑异常", ex);
}
}

@ -9,7 +9,7 @@
"AllowedHosts": "*",
"AppConfig": {
"logPath": "D:\\net6.0-windows\\log",
"InstanceDataPath": "D:\\net6.0-windows\\InstanceData",
"InstanceDataPath": "D:\\net6.0-windows\\log",
"SqlConfig": [
{
"configId": "mes",

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Loading…
Cancel
Save