Compare commits
No commits in common. "04e74cea455ddaec31261db67ef084459db308f3" and "a7fe049f15a5a4cbdca288e6b71c0abbdacd7534" have entirely different histories.
04e74cea45
...
a7fe049f15
|
@ -9,5 +9,7 @@
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg";
|
public const string CAMERA_FAILED_IMAGE_PATH = @"Images\CantConnectCamera.jpg";
|
||||||
|
|
||||||
|
public const int TIME_TO_GET_STATISTIC_INFO = 60;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,18 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
private readonly HttpClient client;
|
private readonly HttpClient client;
|
||||||
private readonly Thread thrStatistics;
|
private readonly Thread thrStatistics;
|
||||||
private readonly TimeSpan updateInterval;
|
|
||||||
private ParkInfo parkInfo;
|
|
||||||
|
|
||||||
private Label lblLoaiXe;
|
Label lblLoaiXe;
|
||||||
private Label lblXeMay;
|
Label lblXeMay;
|
||||||
private Label lblOto;
|
Label lblOto;
|
||||||
private Label lblSoLuong;
|
Label lblSoLuong;
|
||||||
private Label lblSoLuongXeMay;
|
Label lblSoLuongXeMay;
|
||||||
private Label lblSoLuongOto;
|
Label lblSoLuongOto;
|
||||||
|
|
||||||
public Statistic(string baseAddress, TimeSpan updateInterval)
|
public Statistic(string apiUrl)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.updateInterval = updateInterval;
|
client = new HttpClient { BaseAddress = new Uri(apiUrl), Timeout = TimeSpan.FromMilliseconds(5000) };
|
||||||
client = new HttpClient { BaseAddress = new Uri(baseAddress), Timeout = TimeSpan.FromMilliseconds(5000) };
|
|
||||||
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
thrStatistics = new Thread(new ThreadStart(GetStatistic)) { IsBackground = true };
|
||||||
thrStatistics.Start();
|
thrStatistics.Start();
|
||||||
}
|
}
|
||||||
|
@ -33,28 +30,35 @@ namespace AIParkingApplication
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
GetDataFromServer();
|
GETDataFromServer();
|
||||||
ShowInfo();
|
Thread.Sleep(AppConstant.TIME_TO_GET_STATISTIC_INFO * 1000);
|
||||||
Thread.Sleep(updateInterval);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void GetDataFromServer()
|
private async void GETDataFromServer()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = await client.GetAsync("/api/statistics");
|
HttpResponseMessage response = await client.GetAsync("/api/statistics");
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
parkInfo = await response.Content.ReadAsAsync<ParkInfo>();
|
var vehicle = await response.Content.ReadAsAsync<Vehicle>();
|
||||||
|
lblSoLuongXeMay?.Invoke(new Action(() =>
|
||||||
if (string.IsNullOrEmpty(parkInfo.TotalIn))
|
|
||||||
{
|
{
|
||||||
parkInfo.TotalIn = "0";
|
lblSoLuongXeMay.Text = vehicle.NumberOfMoto.ToString();
|
||||||
}
|
}));
|
||||||
if (string.IsNullOrEmpty(parkInfo.TotalOut))
|
lblSoLuongOto?.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
parkInfo.TotalOut = "0";
|
lblSoLuongOto.Text = vehicle.NumberOfCar.ToString();
|
||||||
}
|
}));
|
||||||
|
lblVehicleTotalIn?.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
lblVehicleTotalIn.Text = vehicle.TotalIn;
|
||||||
|
}));
|
||||||
|
lblVehicleTotalOut?.Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
lblVehicleTotalOut.Text = vehicle.TotelOut;
|
||||||
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -62,31 +66,6 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowInfo()
|
|
||||||
{
|
|
||||||
if (parkInfo == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lblSoLuongXeMay.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblSoLuongXeMay.Text = parkInfo.NumberOfMoto.ToString();
|
|
||||||
}));
|
|
||||||
lblSoLuongOto.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblSoLuongOto.Text = parkInfo.NumberOfCar.ToString();
|
|
||||||
}));
|
|
||||||
lblVehicleTotalIn.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblVehicleTotalIn.Text = parkInfo.TotalIn;
|
|
||||||
}));
|
|
||||||
lblVehicleTotalOut.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
lblVehicleTotalOut.Text = parkInfo.TotalOut;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void Statistic_Load(object sender, EventArgs e)
|
private void Statistic_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
tlpStatisticTable.BorderStyle = BorderStyle.FixedSingle;
|
tlpStatisticTable.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
@ -100,6 +79,7 @@ namespace AIParkingApplication
|
||||||
lblSoLuongXeMay = new Label() { Text = "0", Font = labelFont };
|
lblSoLuongXeMay = new Label() { Text = "0", Font = labelFont };
|
||||||
lblSoLuongOto = new Label() { Text = "0", Font = labelFont };
|
lblSoLuongOto = new Label() { Text = "0", Font = labelFont };
|
||||||
|
|
||||||
|
//Fill to StaticTable
|
||||||
tlpStatisticTable.Controls.Add(lblLoaiXe, 0, 0);
|
tlpStatisticTable.Controls.Add(lblLoaiXe, 0, 0);
|
||||||
tlpStatisticTable.Controls.Add(lblXeMay, 0, 1);
|
tlpStatisticTable.Controls.Add(lblXeMay, 0, 1);
|
||||||
tlpStatisticTable.Controls.Add(lblOto, 0, 2);
|
tlpStatisticTable.Controls.Add(lblOto, 0, 2);
|
||||||
|
@ -108,7 +88,7 @@ namespace AIParkingApplication
|
||||||
tlpStatisticTable.Controls.Add(lblSoLuongOto, 1, 2);
|
tlpStatisticTable.Controls.Add(lblSoLuongOto, 1, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
public class ParkInfo
|
public class Vehicle
|
||||||
{
|
{
|
||||||
[JsonProperty("oto")]
|
[JsonProperty("oto")]
|
||||||
public int NumberOfCar { get; set; }
|
public int NumberOfCar { get; set; }
|
||||||
|
@ -120,7 +100,7 @@ namespace AIParkingApplication
|
||||||
public string TotalIn { get; set; }
|
public string TotalIn { get; set; }
|
||||||
|
|
||||||
[JsonProperty("total_out")]
|
[JsonProperty("total_out")]
|
||||||
public string TotalOut { get; set; }
|
public string TotelOut { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user