添加服务状态表格

This commit is contained in:
Administrator committed 2026-05-24 01:12:37 +08:00
commit c379f00675
5 files changed
+197 -9

No files matched your search

+38 -9
View File
@@ -2,6 +2,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SunlightAggregationManager.UserClass;
using SunlightAggregationManager.View;
using System;
using System.Collections.Generic;
using System.Data;
@@ -10,6 +11,7 @@ using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Xml.Linq;
@@ -28,6 +30,10 @@ namespace SunlightAggregationManager.ViewModel
public static string TCP_E = "0";
public static string HTTP_E = "0";
public static string TLS_E = "0";
public static string SERVERIP = "";
public static string SERVERNAME = "";
public static string SERVERUSER = "";
public static string SERRVERPASWORD = "";
public static DataBase dataBase = new DataBase();
public static UserClass.SqliteHelper SQLiteHelpers = null!; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SunlightAggregationManager.db"; //数据库路径
@@ -38,6 +44,8 @@ namespace SunlightAggregationManager.ViewModel
public static DataTable _machines = new DataTable(); //设备表缓存
[ObservableProperty]
public static DataTable _userData = new DataTable();
[ObservableProperty]
public static DataTable _service = new DataTable();
public MainWindowViewModel()
{
@@ -46,12 +54,14 @@ namespace SunlightAggregationManager.ViewModel
SQMOD = Configini.IniReadvalue("SQL_SERVER", "SQL3");
SQLUSER = Configini.IniReadvalue("SQL_SERVER", "SQL4");
SQLPASWORD = Configini.IniReadvalue("SQL_SERVER", "SQL5");
MachineName = Configini.IniReadvalue("SYS", "Name");
TCP_E = Configini.IniReadvalue("NETWORK", "TCP");
HTTP_E = Configini.IniReadvalue("NETWORK", "HTTP");
TLS_E = Configini.IniReadvalue("NETWORK", "TLS");
SERVERIP = Configini.IniReadvalue("SERVER", "SERVERIP");
SERVERNAME = Configini.IniReadvalue("SERVER", "SERVERNAME");
SERVERUSER = Configini.IniReadvalue("SERVER", "SERVERUSER");
SERRVERPASWORD = Configini.IniReadvalue("SERVER", "SERRVERPASWORD");
//本地数据库(sqlite)
try
@@ -62,34 +72,41 @@ namespace SunlightAggregationManager.ViewModel
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines order by ID asc", null)?.Tables[0] ?? new DataTable();
ActionLog = (SQLiteHelpers.ExecuteDataSet("select * from ActionLog", null)?.Tables[0] ?? new DataTable()).Clone();
// SQLiteHelpers.Close();
DataRow[] dataRows = UserData.Select("State<90");
foreach (DataRow row in dataRows)
{
row["State"] = 0;
row["LinkID"] = 0;
}
Machines.RowChanged += Machines_Updata;
UserData.RowChanged += UserData_Updata;//注册userdata表更新事件
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
//运行数据库
dataBase.Config(SQLIP, SQLNAME, SQMOD, SQLUSER, SQLPASWORD);
//服务信息表
//DataTable Service = new DataTable();
Service.BeginInit();
Service.Columns.Add("ID", typeof(int));
Service.Columns.Add("Status", typeof(string));
Service.Columns.Add("Service", typeof(string));
//运行数据库
Service.Rows.Add(0, "RUN", "SQL_DataBase_Link");
dataBase.Config(SQLIP, SQLNAME, SQMOD, SQLUSER, SQLPASWORD);
Service.Rows.Add(1, "RUN", "Sunlight_Server_Link");
AsyncTcpClient.Configuration(SERVERIP, SERVERNAME, SERVERUSER, SERRVERPASWORD);//连接sunlight服务器
Console.WriteLine(GetLocalIP.GetLocalIPv4Address().ToString());
if (TCP_E == "1")//启动tcp(内网直连)
{
int P1, P2;
try
{
P1 =int.Parse( Configini.IniReadvalue("NETWORK", "TCP_PORT1"));
P1 = int.Parse(Configini.IniReadvalue("NETWORK", "TCP_PORT1"));
}
catch (Exception) { P1 = 7789; }
try
@@ -98,7 +115,12 @@ namespace SunlightAggregationManager.ViewModel
}
catch (Exception) { P2 = 7790; }
_ = AsyncTcpServer.TcpMain(P1,P2);
Service.Rows.Add(2, "RUN", "TCP");
_ = AsyncTcpServer.TcpMain(P1, P2);
}
else
{
Service.Rows.Add(2, "STOP", "TCP");
}
if (HTTP_E == "1")//启动tcp(内网直连)
{
@@ -108,8 +130,15 @@ namespace SunlightAggregationManager.ViewModel
P1 = int.Parse(Configini.IniReadvalue("NETWORK", "HTTP_PORT"));
}
catch (Exception) { P1 = 7791; }
Service.Rows.Add(3, "RUN", "HTTP");
_ = AsyncHttpServer.HttpMain(P1);
}
else
{
Service.Rows.Add(3, "STOP", "HTTP");
}
Service.EndInit();
}
private void Machines_Updata(object sender, DataRowChangeEventArgs e)