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; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user