This commit is contained in:
Nguyen Dinh Thuan
2024-09-17 08:26:12 +07:00
parent c1268760b2
commit b3ad51909d
3 changed files with 52 additions and 39 deletions
+2
View File
@@ -47,10 +47,12 @@ namespace SafeBagDE70.API
TaskSendHealthCheck(deviceStatus).ContinueWith(t => { TaskSendHealthCheck(deviceStatus).ContinueWith(t => {
if (t.IsCompletedSuccessfully) if (t.IsCompletedSuccessfully)
{ {
AppData.IsInternetOk = true;
Log.Information("Send HealthCheck Success"); Log.Information("Send HealthCheck Success");
} }
else else
{ {
AppData.IsInternetOk = false;
Log.Information("Send HealthCheck Fail"); Log.Information("Send HealthCheck Fail");
} }
}); });
+1
View File
@@ -36,6 +36,7 @@ namespace SafeBagDE70
public static int MaxNotes = 300; public static int MaxNotes = 300;
public static string BaseURL = ""; public static string BaseURL = "";
public static int TenantId = 0; public static int TenantId = 0;
public static bool IsInternetOk = false;
public static DeviceStatus? _DeviceStatus = null; public static DeviceStatus? _DeviceStatus = null;
public static DeviceStatus? DeviceStatus public static DeviceStatus? DeviceStatus
{ {
+24 -14
View File
@@ -392,11 +392,30 @@ namespace SafeBagDE70
AppData.DeviceStatus.DeviceTime = DateTime.Now; AppData.DeviceStatus.DeviceTime = DateTime.Now;
APIModels.SendHealthCheck(AppData.DeviceStatus); APIModels.SendHealthCheck(AppData.DeviceStatus);
} }
if (countSensorTimer % 1800 == 0) if (countSensorTimer % 300 == 0)
{ {
if (!AppData.IsInTransaction) ResenData();
}
countSensorTimer++;
sensorTimer.IsEnabled = false;
GetSensorValue();
sensorTimer.IsEnabled = true;
}
catch (Exception ex)
{ {
Task.Run(async () => Log.Fatal(ex, "Sensor_Timer");
}
sensorTimer.IsEnabled = true;
}
static Task? resendTask=null;
private static void ResenData()
{
if (!AppData.IsInTransaction && AppData.IsInternetOk)
{
if(resendTask==null || resendTask.IsCompleted)
{
resendTask = Task.Run(async () =>
{ {
try try
{ {
@@ -429,21 +448,12 @@ namespace SafeBagDE70
{ {
Log.Fatal(ex, "Resend failed"); Log.Fatal(ex, "Resend failed");
} }
}); });
} }
} }
countSensorTimer++;
sensorTimer.IsEnabled = false;
GetSensorValue();
sensorTimer.IsEnabled = true;
}
catch (Exception ex)
{
Log.Fatal(ex, "Sensor_Timer");
}
sensorTimer.IsEnabled = true;
} }
Stopwatch watch = new Stopwatch(); Stopwatch watch = new Stopwatch();
private void GetSensorValue() private void GetSensorValue()
{ {