Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightAggregationTerminal
This commit is contained in:
commit
e0c949bde9
4 files changed
+92
-46
No files matched your search
+38
-21
@@ -2,6 +2,7 @@
|
||||
using SunlightAggregationTerminal.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
@@ -116,33 +117,49 @@ namespace SunlightAggregationTerminal.Class
|
||||
}
|
||||
if (data.TryGetValue("Notification", out val) && val != null)//信息通知接受
|
||||
{
|
||||
var dataNotification = JsonSerializer.Deserialize<Dictionary<string, object>>(val.ToString()!);
|
||||
var dataNotification = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(val.ToString()!);
|
||||
|
||||
string _Title = "", _Content = "";
|
||||
int _Type = 0;
|
||||
int _Type = 0 ,_id = 0;
|
||||
|
||||
if (dataNotification!.TryGetValue("Title", out var value_Notification_Title))
|
||||
foreach (var dataNotificationrow in dataNotification!)
|
||||
{
|
||||
_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
|
||||
//解析信息
|
||||
if (dataNotificationrow!.TryGetValue("id", out var value_Notification_id))
|
||||
{
|
||||
"System" => 2,
|
||||
"Message" => 1,
|
||||
_ => 0
|
||||
};
|
||||
_id = (int)value_Notification_id;
|
||||
}
|
||||
if (dataNotificationrow!.TryGetValue("Title", out var value_Notification_Title))
|
||||
{
|
||||
_Title = value_Notification_Title.ToString() ?? "";
|
||||
}
|
||||
if (dataNotificationrow!.TryGetValue("Content", out var value_Notification_Content))
|
||||
{
|
||||
_Content = value_Notification_Content.ToString() ?? "";
|
||||
}
|
||||
if (dataNotificationrow!.TryGetValue("Type", out var value_Notification_Type))
|
||||
{
|
||||
string temp = value_Notification_Type?.ToString() ?? "";
|
||||
// 转换
|
||||
_Type = temp switch
|
||||
{
|
||||
"System" => 2,
|
||||
"Message" => 1,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
//记录信息到数据库
|
||||
DataSet? Notificationdata = AppModels.Select("select * from Notification where Id = " + _id);
|
||||
if (Notificationdata != null)
|
||||
{
|
||||
if (Notificationdata.Tables[0].Rows.Count == 0)
|
||||
{
|
||||
AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type,Id)VALUES('" +
|
||||
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") +
|
||||
"','" + _Type + "'," + _id + ");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Models.AppModels.INSERT("INSERT INTO Notification (Title,Content,Time,Type)VALUES('" +
|
||||
_Title + "','" + _Content + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + _Type + "');");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-21
@@ -40,6 +40,8 @@ namespace SunlightAggregationTerminal.Class
|
||||
else
|
||||
{
|
||||
await HttpClient(DataReceived.ServerIP);
|
||||
|
||||
HttpTransmit("{\"Command\":\"Log\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,30 +55,26 @@ namespace SunlightAggregationTerminal.Class
|
||||
#region Http客户端获取断线通知
|
||||
config.ConfigurePlugins(a =>
|
||||
{
|
||||
//处理连接断开
|
||||
a.AddTcpClosedPlugin(async (c, e) =>
|
||||
{
|
||||
// 专门处理超时或主动取消的情况
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
|
||||
});
|
||||
await e.InvokeNext();
|
||||
//MainThread.BeginInvokeOnMainThread(() =>
|
||||
// {
|
||||
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
|
||||
// });
|
||||
// await e.InvokeNext();
|
||||
});
|
||||
}); config.ConfigurePlugins(a =>
|
||||
{
|
||||
a.AddTcpConnectedPlugin(async (c, e) =>
|
||||
{
|
||||
HttpTransmit("{\"Command\":\"Log\"}");
|
||||
await e.InvokeNext();
|
||||
});
|
||||
});
|
||||
/*config.ConfigurePlugins(a =>
|
||||
{
|
||||
//自动重连
|
||||
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
|
||||
{
|
||||
options.PollingInterval = TimeSpan.FromSeconds(3);
|
||||
});
|
||||
});*/
|
||||
//处理连接
|
||||
a.AddTcpConnectedPlugin(async (c, e) =>
|
||||
{
|
||||
await e.InvokeNext();
|
||||
});
|
||||
});
|
||||
#endregion
|
||||
|
||||
if (httpclient.Online)//是否重置客户端
|
||||
@@ -93,6 +91,10 @@ namespace SunlightAggregationTerminal.Class
|
||||
/***发送信息处理***/
|
||||
public static async void HttpTransmit(string Dat)
|
||||
{
|
||||
if(!httpclient.Online) //检查连接
|
||||
{
|
||||
await httpclient.ConnectAsync();
|
||||
}
|
||||
var dat = new DataReceived.Person()
|
||||
{
|
||||
User = DataReceived.ServerName,
|
||||
@@ -119,6 +121,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
// GetBodyAsync 同样需要响应取消信号,如果这里超过剩余时间也会抛出异常
|
||||
var result = await response.GetBodyAsync();
|
||||
DataReceived.Received(result);
|
||||
//await httpclient.CloseAsync();//关闭客户端
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -126,8 +129,9 @@ namespace SunlightAggregationTerminal.Class
|
||||
// 专门处理超时或主动取消的情况
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络或服务器状态。", "是");
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是");
|
||||
});
|
||||
await httpclient.CloseAsync();//关闭客户端
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -136,9 +140,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -215,7 +215,13 @@ namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
string sql = "ALTER TABLE Notification ADD COLUMN Type INT;";
|
||||
SQLitedata.ExecuteNonQuery(sql, null);
|
||||
}
|
||||
}
|
||||
// 检查 id
|
||||
if (!existingColumns.Contains("Id"))
|
||||
{
|
||||
string sql = "ALTER TABLE Notification ADD COLUMN Id INTEGER PRIMARY KEY;";
|
||||
SQLitedata.ExecuteNonQuery(sql, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void CheckAndRepairTableSchemaSERVER()
|
||||
@@ -302,7 +308,7 @@ namespace SunlightAggregationTerminal.Class
|
||||
// 建表语句
|
||||
string createSql = @"
|
||||
CREATE TABLE Notification (
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
Id INTEGER PRIMARY KEY,
|
||||
Title TEXT,
|
||||
Content TEXT,
|
||||
Time TEXT,
|
||||
|
||||
Reference in new issue
Block a user