Administrator 1 month ago
committed by sc
parent
commit
a72383e422
  1. 5
      Class/DataReceived.cs
  2. 30
      Class/HttpServer.cs
  3. 7
      Class/SQLiteConfig.cs
  4. 9
      Models/AppModels.cs
  5. 2
      Models/DataModel.cs
  6. 6
      View/LogPage.xaml.cs

5
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)//信息通知接受
{

30
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();
}
}

7
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
);";

9
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<object>("LocalAreaNetworkMode"));
App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field<object>("DarkMode"));
App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field<object>("MessageNotificationMode"));
App.GlobalData.NotificationID = dat.Field<string>("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<string, object> NotificationDictionary = new Dictionary<string, object>();
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";

2
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 { }

6
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);
}

Loading…
Cancel
Save