添加服务状态表格
This commit is contained in:
commit
c379f00675
5 files changed
+197
-9
No files matched your search
@@ -68,6 +68,7 @@ namespace SunlightAggregationManager
|
||||
{
|
||||
state.Visibility = Visibility.Collapsed;
|
||||
Picture.Visibility = Visibility.Visible;
|
||||
Picture.Content = new View.ServicePage();
|
||||
}
|
||||
private void ListViewItem_MouseLeftButtonUp_log(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class AsyncTcpClient
|
||||
{
|
||||
public static TouchSocket.Sockets.TcpClient tcpClient = new TouchSocket.Sockets.TcpClient();
|
||||
public static async void Configuration(string ip, string Name, string user, string Password)
|
||||
{
|
||||
await TcpClient(tcpClient, "tcp://"+ip);
|
||||
}
|
||||
public static async Task TcpClient(TouchSocket.Sockets.TcpClient tcpClient, string ip)
|
||||
{
|
||||
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
|
||||
tcpClient.Connected = (client, e) =>
|
||||
{
|
||||
|
||||
return EasyTask.CompletedTask;
|
||||
};//成功连接到服务器
|
||||
tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
|
||||
tcpClient.Closed = (client, e) => { return EasyTask.CompletedTask; };//从服务器断开连接,当连接不成功时不会触发。
|
||||
#region Tcp客户端使用Received异步委托接收数据
|
||||
tcpClient.Received = (client, e) =>
|
||||
{
|
||||
//从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
|
||||
var mes = e.Memory.Span.ToString(Encoding.UTF8);
|
||||
|
||||
//DataReceived.Received(mes);
|
||||
|
||||
return EasyTask.CompletedTask;
|
||||
};
|
||||
#endregion
|
||||
|
||||
try
|
||||
{
|
||||
await tcpClient.SetupAsync(new TouchSocketConfig()
|
||||
.SetSingleStreamDataHandlingAdapter(() => new PeriodPackageAdapter())//以超时周期和包
|
||||
.SetRemoteIPHost(ip)
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
a.UseReconnection<TouchSocket.Sockets.TcpClient>(options =>
|
||||
{
|
||||
options.PollingInterval = TimeSpan.FromSeconds(5);
|
||||
});
|
||||
}));
|
||||
|
||||
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<UserControl x:Class="SunlightAggregationManager.View.ServicePage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.View"
|
||||
xmlns:viewmodel="clr-namespace:SunlightAggregationManager.ViewModel"
|
||||
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="720" d:DesignWidth="1080">
|
||||
<Grid>
|
||||
<DataGrid x:Name="DataGridmachinesdata"
|
||||
ItemsSource="{Binding Service.DefaultView}"
|
||||
SelectionMode="Single"
|
||||
AlternationCount="2"
|
||||
IsReadOnly="True"
|
||||
FontSize="26"
|
||||
Margin="5,5,5,5"
|
||||
AutoGenerateColumns="False"
|
||||
MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9"
|
||||
VerticalGridLinesBrush="#FFC9C9C9"
|
||||
GridLinesVisibility="All"
|
||||
BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1"
|
||||
ColumnHeaderHeight="40"
|
||||
HorizontalContentAlignment="Right"
|
||||
CanUserReorderColumns="False"
|
||||
VerticalContentAlignment="Center">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
<Setter Property="Height" Value="40" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
<Setter Property="Height" Value="40" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="ID" Width="100" FontSize="26"
|
||||
Binding="{Binding ID}" MaxWidth="100" MinWidth="100" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="Status" Width="200" FontSize="26"
|
||||
Binding="{Binding Status}" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="Service" Width="*" FontSize="26"
|
||||
Binding="{Binding Service}" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,27 @@
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace SunlightAggregationManager.View
|
||||
{
|
||||
/// <summary>
|
||||
/// ServicePage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ServicePage : UserControl
|
||||
{
|
||||
public ServicePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user