Add project files.

This commit is contained in:
Admin
2024-09-02 10:03:23 +07:00
parent 42def0d4aa
commit 6219298497
361 changed files with 58423 additions and 0 deletions
@@ -0,0 +1,100 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.Json.Nodes;
using System.Text;
using System.Net.NetworkInformation;
using System.Linq;
using System;
using System.Windows.Documents;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
namespace SafeBagDE70.API
{
public static class APIModels
{
public static string URL = "https://203.171.20.94:9090/Safebag/";
public static async void SendHealthCheck(string? ID=null)
{
try
{
if (ID == null) ID = GetMACAddress();
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
// Pass the handler to httpclient(from you are calling api)
HttpClient httpClient = new HttpClient(clientHandler);
using HttpResponseMessage response = await httpClient.GetAsync(URL + "HealthCheck?Id=" + ID);
if (response.EnsureSuccessStatusCode().StatusCode == HttpStatusCode.OK)
{
var jsonResponse = await response.Content.ReadAsStringAsync();
}
}
catch(Exception ex)
{
}
}
public static async void SendCountingData(CountingData2Send data2Send)
{
try{
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
// Pass the handler to httpclient(from you are calling api)
HttpClient httpClient = new HttpClient(clientHandler);
string strJsonObj = JsonConvert.SerializeObject(data2Send);
var content = new StringContent(strJsonObj, Encoding.UTF8, "application/json");
using HttpResponseMessage response = await httpClient.PostAsync(URL + "UpdateCountingData", content);
if (response.EnsureSuccessStatusCode().StatusCode == HttpStatusCode.OK)
{
var jsonResponse = await response.Content.ReadAsStringAsync();
}
}
catch(Exception ex)
{
}
}
private static string GetMACAddress()
{
string? MACAdress = null;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
MACAdress = AddressBytesToString(nic.GetPhysicalAddress().GetAddressBytes());
break;
}
}
if (MACAdress == null) MACAdress = "N/A";
return MACAdress;
}
private static string? AddressBytesToString(byte[] addressBytes)
{
if (addressBytes != null)
{
var str = string.Join(":", (from b in addressBytes
select b.ToString("X2")).ToArray());
return str;
}
else
return null;
}
}
}