remote update
This commit is contained in:
+66
-2
@@ -256,6 +256,70 @@ namespace SafeBagDE70.API
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static async Task<DeviceCommand[]?> GetCommands()
|
||||
{
|
||||
try
|
||||
{
|
||||
string deviceID = Environment.MachineName;
|
||||
int tenantId = AppData.TenantId;
|
||||
string url = AppData.BaseURL + $"GetListCommand?Device={deviceID}&TenantId={tenantId}";
|
||||
HttpClientHandler clientHandler = new HttpClientHandler();
|
||||
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
|
||||
|
||||
using (HttpClient client = new HttpClient(clientHandler))
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(url);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string json = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DeviceCommand[]>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("GetCommands: StatusCode=" + response.StatusCode);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "GetCommands");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static async Task<bool> UpdateDeviceCommand(int commandId, int executed)
|
||||
{
|
||||
bool bSuccess = false;
|
||||
try
|
||||
{
|
||||
HttpClientHandler clientHandler = new HttpClientHandler();
|
||||
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
|
||||
HttpClient httpClient = new HttpClient(clientHandler);
|
||||
var data = new
|
||||
{
|
||||
id = commandId,
|
||||
executed = executed
|
||||
};
|
||||
|
||||
|
||||
string strJsonObj = JsonConvert.SerializeObject(data);
|
||||
var content = new StringContent(strJsonObj, Encoding.UTF8, "application/json");
|
||||
|
||||
using HttpResponseMessage response = await httpClient.PostAsync(AppData.BaseURL + $"PostUpdateCommand", content);
|
||||
|
||||
if (response.EnsureSuccessStatusCode().StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
bSuccess = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return bSuccess;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static string GetMACAddress()
|
||||
@@ -273,6 +337,7 @@ namespace SafeBagDE70.API
|
||||
return MACAdress;
|
||||
}
|
||||
|
||||
|
||||
private static string? AddressBytesToString(byte[] addressBytes)
|
||||
{
|
||||
if (addressBytes != null)
|
||||
@@ -285,6 +350,7 @@ namespace SafeBagDE70.API
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public class AeonMallCustomer
|
||||
{
|
||||
@@ -306,6 +372,4 @@ namespace SafeBagDE70.API
|
||||
public string? Type { get; set; }
|
||||
public string? TimeTag { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -30,40 +30,15 @@ namespace SafeBagDE70.Admin
|
||||
|
||||
private void btnResetCounter_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AppData.cCmdRsp != null)
|
||||
Log.Information("[ADMIN] reset cdm counter");
|
||||
bool bResetCDMCounter = AppData.ResetCDMCounter();
|
||||
if(!bResetCDMCounter)
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter");
|
||||
CCmdRsp cCmdRsp = AppData.cCmdRsp;
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_UNLOCK);
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
//Event fix
|
||||
var recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] == recvData.dat[16])
|
||||
{
|
||||
cCmdRsp.SendLock();
|
||||
bResetCDMCounter = AppData.ResetCDMCounter();
|
||||
}
|
||||
else
|
||||
if (bResetCDMCounter)
|
||||
{
|
||||
cCmdRsp.SendEventFix(recvData.dat[16]);
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
|
||||
var currentMode = cCmdRsp.GetLockParam().mode;
|
||||
cCmdRsp.GetLockParam().mode = Mode.MODE_COLLECTION;
|
||||
cCmdRsp.SendLock();
|
||||
Thread.Sleep(10000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] != recvData.dat[16])
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter success");
|
||||
Log.Information("[ADMIN] reset counter successfully");
|
||||
lblCounterStatus.Text = "TRẠNG THÁI: KHỞI TẠO BỘ ĐẾM THÀNH CÔNG";
|
||||
((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen();
|
||||
Task.Run(() =>
|
||||
@@ -74,13 +49,12 @@ namespace SafeBagDE70.Admin
|
||||
lblCounterStatus.Text = "";
|
||||
});
|
||||
});
|
||||
AppData.GetCassetteData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter fail");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnOpenEscrow_Click(object sender, RoutedEventArgs e)
|
||||
@@ -101,36 +75,10 @@ namespace SafeBagDE70.Admin
|
||||
{
|
||||
try
|
||||
{
|
||||
var cCmdRsp = AppData.cCmdRsp;
|
||||
bool bSuccess = true;
|
||||
if (cCmdRsp != null)
|
||||
{
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE);
|
||||
|
||||
var recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] == recvData.dat[16])
|
||||
{
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
cCmdRsp.SendEventFix(recvData.dat[16]);
|
||||
}
|
||||
//if (cCmdRsp.recv_dat.dat[0] != 0x40)
|
||||
//{
|
||||
// bSuccess = false;
|
||||
//}
|
||||
//if (bSuccess)
|
||||
//{
|
||||
|
||||
//}
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_RESET);
|
||||
Thread.Sleep(2000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE);
|
||||
if (cCmdRsp.recv_dat.dat[1] == 0x04 && cCmdRsp.recv_dat.dat[2] == 0x41)
|
||||
Log.Information("[ADMIN] Reset CDM Error");
|
||||
if (AppData.ResetCDMError())
|
||||
{
|
||||
Log.Information("[ADMIN] Reset CDM Error successfully");
|
||||
lblCounterStatus.Text = "Reset lỗi thành công";
|
||||
((MainWindow)Application.Current.MainWindow).ShowWelcomeScreen();
|
||||
Task.Run(() =>
|
||||
@@ -143,7 +91,6 @@ namespace SafeBagDE70.Admin
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Log.Fatal(ex, "SoftReset");
|
||||
}
|
||||
|
||||
+128
@@ -39,6 +39,7 @@ namespace SafeBagDE70
|
||||
public static int TenantId = 0;
|
||||
public static bool IsInternetOk = false;
|
||||
static Task? resendTask = null;
|
||||
static Task? commandTask = null;
|
||||
public static DeviceStatus? _DeviceStatus = null;
|
||||
public static DeviceStatus? DeviceStatus
|
||||
{
|
||||
@@ -315,6 +316,133 @@ namespace SafeBagDE70
|
||||
Log.Error($"Resend could not start IsInTransaction: {AppData.IsInTransaction} IsInternetOk: {AppData.IsInternetOk}");
|
||||
}
|
||||
}
|
||||
public static void GetandExecuteCommands()
|
||||
{
|
||||
if (IsInternetOk && (commandTask == null || commandTask.IsCompleted))
|
||||
{
|
||||
commandTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var commands= await APIModels.GetCommands();
|
||||
if(commands != null && commands.Count()>0)
|
||||
{
|
||||
foreach (var command in commands)
|
||||
{
|
||||
bool bResult = false;
|
||||
switch(command.CommandCode)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Log.Information("Remote Reset CDM Error");
|
||||
//Restart CDM
|
||||
bResult=ResetCDMError();
|
||||
break;
|
||||
case 2:
|
||||
Log.Information("Remote Reset CDM Counter");
|
||||
bResult = ResetCDMCounter();
|
||||
if (!bResult)
|
||||
{
|
||||
bResult = ResetCDMCounter();
|
||||
}
|
||||
break;
|
||||
}
|
||||
//
|
||||
await APIModels.UpdateDeviceCommand(command.Id, bResult?1:-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "GetandExecuteCommands failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var str = "";
|
||||
if (commandTask != null && !commandTask.IsCompleted)
|
||||
str += "Previous command state are running; ";
|
||||
if (!IsInternetOk)
|
||||
str += "No Internet Connection";
|
||||
Log.Error("GetandExecuteCommands error: "+str);
|
||||
}
|
||||
}
|
||||
public static bool ResetCDMCounter()
|
||||
{
|
||||
bool bResetOk = false;
|
||||
if (AppData.cCmdRsp != null)
|
||||
{
|
||||
Log.Information("[ADMIN] reset counter");
|
||||
CCmdRsp cCmdRsp = AppData.cCmdRsp;
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_UNLOCK);
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
//Event fix
|
||||
var recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] == recvData.dat[16])
|
||||
{
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
cCmdRsp.SendEventFix(recvData.dat[16]);
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
|
||||
var currentMode = cCmdRsp.GetLockParam().mode;
|
||||
cCmdRsp.GetLockParam().mode = Mode.MODE_COLLECTION;
|
||||
cCmdRsp.SendLock();
|
||||
Thread.Sleep(10000);
|
||||
cCmdRsp.SendDeSense();
|
||||
Thread.Sleep(1000);
|
||||
recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] != recvData.dat[16])
|
||||
{
|
||||
AppData.GetCassetteData();
|
||||
bResetOk = true;
|
||||
}
|
||||
}
|
||||
return bResetOk;
|
||||
}
|
||||
public static bool ResetCDMError()
|
||||
{
|
||||
var cCmdRsp = AppData.cCmdRsp;
|
||||
bool bSuccess = false;
|
||||
if(cCmdRsp!=null && cCmdRsp.recv_dat!=null)
|
||||
{
|
||||
if(cCmdRsp.recv_dat.dat[1] == 0x1C && cCmdRsp.recv_dat.dat[2] == 0x4A)
|
||||
{
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE);
|
||||
|
||||
var recvData = cCmdRsp.recv_dat;
|
||||
|
||||
if (recvData.dat[14] == recvData.dat[16])
|
||||
{
|
||||
cCmdRsp.SendLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
cCmdRsp.SendEventFix(recvData.dat[16]);
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_RESET);
|
||||
Thread.Sleep(2000);
|
||||
cCmdRsp.SendXXCmd((byte)Command.CMD_DE_SENSE);
|
||||
if (cCmdRsp.recv_dat.dat[1] == 0x04 && cCmdRsp.recv_dat.dat[2] == 0x41)
|
||||
{
|
||||
bSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
}
|
||||
public class CustomerAccount
|
||||
|
||||
@@ -42,6 +42,8 @@ using UserControl = System.Windows.Controls.UserControl;
|
||||
using Application = System.Windows.Application;
|
||||
using Control = System.Windows.Controls.Control;
|
||||
using static Azure.Core.HttpHeader;
|
||||
using System.Net.Http;
|
||||
using Azure;
|
||||
|
||||
|
||||
namespace SafeBagDE70
|
||||
@@ -72,13 +74,11 @@ namespace SafeBagDE70
|
||||
//DispatcherTimer?
|
||||
private volatile bool bIsCounted = false;
|
||||
|
||||
int countTimer = 0;
|
||||
CCmdRsp cCmdRsp = null;
|
||||
bool bInitialized = false;
|
||||
bool bOpenPort = true;
|
||||
bool bIsMaintain = false;
|
||||
MainWindow mainWindow = null;
|
||||
Thread thread = null;
|
||||
Task taskCounting = null;
|
||||
public DepositSMUCv2()
|
||||
{
|
||||
@@ -396,6 +396,7 @@ namespace SafeBagDE70
|
||||
{
|
||||
GetPrinterStatus();
|
||||
GetCDMStatus();
|
||||
AppData.GetandExecuteCommands();
|
||||
|
||||
AppData.DeviceStatus.Description = AppData.CDMSTATE.CDMStatus;
|
||||
AppData.DeviceStatus.DeviceTime = DateTime.Now;
|
||||
@@ -484,6 +485,7 @@ namespace SafeBagDE70
|
||||
}
|
||||
if (AppData.DeviceStatus.PrinterStatus != prevPrinterStatus)
|
||||
{
|
||||
Log.Information(strPrinterMessage);
|
||||
AppData.DeviceStatus.Description = strPrinterMessage;
|
||||
APIModels.SendEvent(AppData.DeviceStatus);
|
||||
prevPrinterStatus = AppData.DeviceStatus.PrinterStatus;
|
||||
@@ -1288,6 +1290,7 @@ namespace SafeBagDE70
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public History Save2DB(CountingData2Send data2Send)
|
||||
{
|
||||
var data = JsonConvert.SerializeObject(data2Send);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SafeBagDE70.Model
|
||||
{
|
||||
public class DeviceCommand
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int TenantId { get; set; }
|
||||
public string Device { get; set; }
|
||||
public string CreationTime { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
public int CommandCode { get; set; }
|
||||
public int Executed { get; set; }
|
||||
public string LastUpdate { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user