diff --git a/Class/TcpServer.cs b/Class/TcpServer.cs index 72da845..7096b47 100644 --- a/Class/TcpServer.cs +++ b/Class/TcpServer.cs @@ -33,17 +33,17 @@ namespace SunlightAggregationTerminal.Class ServerTerminal = Terminal; - _= TcpClient(tcpClient, ServerIP); - + _ = TcpClient(tcpClient, ServerIP); + } public static async void TcpTransmit(string Dat) { var dat = new Person() - { - User = ServerName , - Password = ServerPassword, - IP = ServerIP, - Terminal = ServerTerminal, + { + User = ServerName, + Password = ServerPassword, + IP = ServerIP, + Terminal = ServerTerminal, Dat = Dat }; @@ -55,7 +55,7 @@ namespace SunlightAggregationTerminal.Class } catch (Exception) { - await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", "连接未启用", "是"); + await Application.Current!.Windows[0].Page!.DisplayAlertAsync("错误", "请求异常", "是"); } } @@ -69,33 +69,66 @@ namespace SunlightAggregationTerminal.Class #region Tcp客户端使用Received异步委托接收数据 tcpClient.Received = (client, e) => { - //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。 - var mes = e.Memory.Span.ToString(Encoding.UTF8); - var data = JsonSerializer.Deserialize>(mes); - if (data != null) + //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。 + var mes = e.Memory.Span.ToString(Encoding.UTF8); + + try { - //处理服务器发送信息 - if (data.TryGetValue("Enterprise", out var value_Enterprise)) - { - if (value_Enterprise != null) { App.GlobalData.Enterprise = value_Enterprise.ToString() ?? ""; } - } - if (data.TryGetValue("Department", out var value_Department)) - { - if (value_Department != null) { App.GlobalData.Department = value_Department.ToString() ?? ""; } - } - if (data.TryGetValue("Groups", out var value_Groups)) - { - if (value_Groups != null) { App.GlobalData.Groups = value_Groups.ToString() ?? ""; } - } - if (data.TryGetValue("UserId", out var value_UserId)) - { - if (value_Groups != null) { App.GlobalData.UserId = value_UserId.ToString() ?? ""; } - } - if (data.TryGetValue("UserName", out var value_UserName)) + var data = JsonSerializer.Deserialize>(mes); + + if (data != null) { - if (value_Groups != null) { App.GlobalData.Groups = value_UserName.ToString() ?? ""; } + //处理服务器发送信息 + if (data.TryGetValue("Enterprise", out var val) && val != null) App.GlobalData.Enterprise = val.ToString() ?? ""; + if (data.TryGetValue("Department", out val) && val != null) App.GlobalData.Department = val.ToString() ?? ""; + if (data.TryGetValue("Groups", out val) && val != null) App.GlobalData.Groups = val.ToString() ?? ""; + if (data.TryGetValue("UserId", out val) && val != null) App.GlobalData.UserId = val.ToString() ?? ""; + if (data.TryGetValue("UserName", out val) && val != null) App.GlobalData.UserName = val.ToString() ?? ""; + + if (data.TryGetValue("UserData", out var value_UserData)) + { + + } + if (data.TryGetValue("SysData", out var value_SysData)) + { + + } + + + if (data.TryGetValue("Notification", out val) && val != null)//信息接受 + { + var dataNotification = JsonSerializer.Deserialize>(val.ToString()!); + + string _Title = "", _Content = ""; + int _Type = 0; + + if (dataNotification!.TryGetValue("Title", out var value_Notification_Title)) + { + _Title = value_Notification_Title.ToString() ?? ""; + } + if (dataNotification!.TryGetValue("Content", out var value_Notification_Content)) + { + _Content = value_Notification_Content.ToString() ?? ""; + } + if (dataNotification!.TryGetValue("Type", out var value_Notification_Type)) + { + string temp = value_Notification_Type?.ToString() ?? ""; + // 转换 + _Type = temp switch + { + "System" => 2, + "Message" => 1, + _ => 0 + }; + } + + Models.AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type)VALUES('" + + _Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + _Type + "');"); + } } + } + catch (Exception) { } return EasyTask.CompletedTask; }; @@ -104,17 +137,7 @@ namespace SunlightAggregationTerminal.Class try { await tcpClient.SetupAsync(new TouchSocketConfig() - .SetRemoteIPHost(ip) - .ConfigurePlugins(a => - { - a.UseReconnection(options => - { - options.PollingInterval = TimeSpan.FromSeconds(5); - }); - }) - .ConfigureContainer(a => - { - })); + .SetRemoteIPHost(ip)); await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。 } catch (Exception) { diff --git a/Models/DataSource.cs b/Models/DataSource.cs index 57aa2b2..ec7f3b1 100644 --- a/Models/DataSource.cs +++ b/Models/DataSource.cs @@ -26,12 +26,13 @@ namespace SunlightAggregationTerminal.Models public static class DataService { - public static DataSet? data = AppModels.Select("select * from Notification Where Time > '" + DateTime.Now.AddDays(-30) + "'"); - // 直接返回 List public static List _NotificationData = new List(); public static List GetAllItems() { + DataSet? data = AppModels.Select("select * from Notification Where Time > '" + + DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss.fff") + "'"); + _NotificationData.Clear(); if (data != null) diff --git a/View/LogPage.xaml.cs b/View/LogPage.xaml.cs index 4f1fd15..d3013a2 100644 --- a/View/LogPage.xaml.cs +++ b/View/LogPage.xaml.cs @@ -117,7 +117,12 @@ public partial class LogPage : ContentPage await DisplayAlertAsync("未登录", "服务器不存在或拒绝访问", "是"); } LoadingIndicator.IsVisible = false; - } - + + + + + await Navigation.PopModalAsync(); + + } } \ No newline at end of file