diff --git a/Class/DataReceived.cs b/Class/DataReceived.cs index b85a727..8dfc2fd 100644 --- a/Class/DataReceived.cs +++ b/Class/DataReceived.cs @@ -175,6 +175,7 @@ namespace SunlightAggregationTerminal.Class && value_Notification_id != null) { _id = (int)value_Notification_id; + App.GlobalData.NotificationID = _id.ToString(); } if (dataNotificationrow!.TryGetValue("Title", out var value_Notification_Title) && value_Notification_Title != null) @@ -213,6 +214,10 @@ namespace SunlightAggregationTerminal.Class } } } + + string sql = "UPDATE Users SET NotificationID = '" + App.GlobalData.NotificationID + + "'WHERE User='" + App.GlobalData.User + "';"; + AppModels.Updata(sql); } if (data.TryGetValue("SETUSER", out val) && val != null)//信息通知接受 { diff --git a/Class/HttpServer.cs b/Class/HttpServer.cs index 9ff3777..10b73df 100644 --- a/Class/HttpServer.cs +++ b/Class/HttpServer.cs @@ -105,7 +105,6 @@ namespace SunlightAggregationTerminal.Class { await httpclient.ConnectAsync(); } - Dispose(); var dat = new DataReceived.Person() { @@ -147,39 +146,12 @@ namespace SunlightAggregationTerminal.Class { MainThread.BeginInvokeOnMainThread(() => { - Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是"); + Application.Current!.Windows[0].Page!.DisplayAlertAsync("访问错误", ex.Message.ToString(), "是"); }); } finally { - //Start(); - } - } - - //倒计时5秒关闭http客户端 - private static Timer? _timer; - private static bool _isDisposed = false; - private static void Start() - { - // 延迟30秒后执行一次,不自动循环 - _timer = new Timer(Httpout, null, TimeSpan.FromSeconds(60), Timeout.InfiniteTimeSpan); - } - private static async void Dispose() - { - if (!_isDisposed) - { - _isDisposed = true; - _timer?.Dispose(); // 释放定时器资源 - _timer = null; - } - } - private static async void Httpout(object? state) - { - if (httpclient.Online) - { - await httpclient.CloseAsync(); } - Dispose(); } } diff --git a/Class/SQLiteConfig.cs b/Class/SQLiteConfig.cs index a02bf30..81976a5 100644 --- a/Class/SQLiteConfig.cs +++ b/Class/SQLiteConfig.cs @@ -160,6 +160,12 @@ namespace SunlightAggregationTerminal.Class string sql = "ALTER TABLE Users ADD COLUMN MessageNotificationMode BOOL DEFAULT (0);"; SQLitedata.ExecuteNonQuery(sql, null); } + // 检查 NotificationID + if (!existingColumns.Contains("NotificationID")) + { + string sql = "ALTER TABLE Users ADD COLUMN NotificationID TEXT;"; + SQLitedata.ExecuteNonQuery(sql, null); + } // 检查 GUID if (!existingColumns.Contains("GUID")) { @@ -290,6 +296,7 @@ namespace SunlightAggregationTerminal.Class LocalAreaNetworkMode BOOL DEFAULT (0), DarkMode BOOL DEFAULT (0), MessageNotificationMode BOOL DEFAULT (0), + NotificationID TEXT, GUID TEXT );"; diff --git a/Models/AppModels.cs b/Models/AppModels.cs index 60de25d..612e56f 100644 --- a/Models/AppModels.cs +++ b/Models/AppModels.cs @@ -13,7 +13,6 @@ namespace SunlightAggregationTerminal.Models public static SqliteHelper sqliteHelper = SQLiteConfig.Config(Path.Combine(FileSystem.AppDataDirectory, "MyAppData.db"))!; //数据库连接路径(获取各平台的应用数据目录) private Timer timer; - private static int TimerNotifications = -1440; public AppModels() { if(sqliteHelper != null) @@ -42,13 +41,14 @@ namespace SunlightAggregationTerminal.Models App.GlobalData.LocalAreaNetworkMode = Convert.ToBoolean(dat.Field("LocalAreaNetworkMode")); App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field("DarkMode")); App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field("MessageNotificationMode")); + App.GlobalData.NotificationID = dat.Field("NotificationID")?? "0"; } } } } //启动通知轮询延迟120s启动周期600s - timer = new Timer(TimerNotification, null, TimeSpan.FromSeconds(120), TimeSpan.FromSeconds(300)); + timer = new Timer(TimerNotification, null, TimeSpan.FromSeconds(120), TimeSpan.FromSeconds(10)); } //轮询通知的定时任务 @@ -58,10 +58,9 @@ namespace SunlightAggregationTerminal.Models { Dictionary NotificationDictionary = new Dictionary(); NotificationDictionary.Add("Command", "Notification"); - NotificationDictionary.Add("StartTime", DateTime.Now.AddMinutes(TimerNotifications).ToString("yyyy-MM-dd HH:mm:ss.fff")); + NotificationDictionary.Add("StartTime", App.GlobalData.NotificationID); NotificationDictionary.Add("EndTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); DataReceived.Transmit(NotificationDictionary.ToJsonString()); - TimerNotifications = -5; } } @@ -134,8 +133,6 @@ namespace SunlightAggregationTerminal.Models } } - - public static string GetAppUniqueId() { const string key = "sunlight_app_unique_id"; diff --git a/Models/DataModel.cs b/Models/DataModel.cs index feaad51..a011019 100644 --- a/Models/DataModel.cs +++ b/Models/DataModel.cs @@ -37,6 +37,8 @@ namespace SunlightAggregationTerminal.Models public partial bool DarkMode { get; set; } [ObservableProperty] public partial bool MessageNotificationMode { get; set; } + [ObservableProperty] + public partial string NotificationID { get; set; } public class RefreshUISignal { } diff --git a/View/LogPage.xaml.cs b/View/LogPage.xaml.cs index e4bf4e6..3838718 100644 --- a/View/LogPage.xaml.cs +++ b/View/LogPage.xaml.cs @@ -114,13 +114,13 @@ public partial class LogPage : ContentPage string sql = @"INSERT INTO Users (User,UserId ,UserName ,UserPassword , Enterprise ,Department ,ServerID ,ServerHTTP ,Groups , ProxyID ,LogNo ,LocalAreaNetworkMode ,DarkMode , - MessageNotificationMode ,GUID + MessageNotificationMode ,GUID ,NotificationID )VALUES('" + UsernameEntry.Text + "','"+ App.GlobalData.UserId + "','" + App.GlobalData.UserName + "','" + PasswordEntry.Text + "','"+ App.GlobalData.Enterprise + "','"+ App.GlobalData.Department + "','" + App.GlobalData.ServerID + "','" +App.GlobalData.ServerHTTP+ - "','"+ App.GlobalData.Groups + "'," + - " '',1,0,0,0,'" + Models.AppModels.GetAppUniqueId() + "');"; + "','"+ App.GlobalData.Groups + "'," + " '',1,0,0,0,'" + + Models.AppModels.GetAppUniqueId() + "','0');"; AppModels.INSERT(sql); }