227 lines
8.0 KiB
C#
227 lines
8.0 KiB
C#
|
using Support.Controllers;
|
|||
|
using Support.Crypto;
|
|||
|
using Support.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace Support.Controls
|
|||
|
{
|
|||
|
public partial class Dashboard : UserControl
|
|||
|
{
|
|||
|
private Main _MainForm = null;
|
|||
|
private bool IsRunning = false;
|
|||
|
private Thread Updater = null;
|
|||
|
private Appsettings Appsettings = null;
|
|||
|
private Controllers.DashboardController DashboardController = null;
|
|||
|
private delegate void UpdateOnMainThreadDelegate(DashboardViewModel dashboard);
|
|||
|
private delegate void UpdateServiceInsideStatusOnMainThreadDelegate(Models.Version serviceInside);
|
|||
|
private delegate void UpdateServiceOutsideStatusOnMainThreadDelegate(Models.Version serviceOutside);
|
|||
|
|
|||
|
public Dashboard(Appsettings appsettings, Main mainForm)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
this._MainForm = mainForm;
|
|||
|
this.Appsettings = appsettings;
|
|||
|
string connString = appsettings.DatabaseConnectionString;
|
|||
|
|
|||
|
string decryptedConnectioString = AES.Decrypt(connString);
|
|||
|
|
|||
|
if(!string.IsNullOrEmpty(decryptedConnectioString))
|
|||
|
{
|
|||
|
connString = decryptedConnectioString;
|
|||
|
}
|
|||
|
|
|||
|
this.DashboardController = new Controllers.DashboardController(new Database(connString));
|
|||
|
|
|||
|
this.Start();
|
|||
|
}
|
|||
|
|
|||
|
public void Start()
|
|||
|
{
|
|||
|
if(this.Updater != null)
|
|||
|
{
|
|||
|
this.Updater.Abort();
|
|||
|
this.Updater = null;
|
|||
|
}
|
|||
|
|
|||
|
this.Updater = new Thread(this.Update);
|
|||
|
this.Updater.Start();
|
|||
|
}
|
|||
|
|
|||
|
public void Stop()
|
|||
|
{
|
|||
|
this.IsRunning = false;
|
|||
|
|
|||
|
if(this.Updater != null)
|
|||
|
{
|
|||
|
this.Updater.Abort();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateServiceInsideStatus()
|
|||
|
{
|
|||
|
new Thread(() => {
|
|||
|
Models.Version serviceInside = Https.GetVersion(this.Appsettings.ServiceInsideURL);
|
|||
|
this.UpdateServiceInsideStatusOnMainThread(serviceInside);
|
|||
|
}).Start();
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateServiceOutsideStatus()
|
|||
|
{
|
|||
|
new Thread(() => {
|
|||
|
Models.Version serviceOutside = Https.GetVersion(this.Appsettings.ServiceOutsideURL);
|
|||
|
this.UpdateServiceOutsideStatusOnMainThread(serviceOutside);
|
|||
|
}).Start();
|
|||
|
}
|
|||
|
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
this.IsRunning = true;
|
|||
|
|
|||
|
while(this.IsRunning)
|
|||
|
{
|
|||
|
this.UpdateServiceInsideStatus();
|
|||
|
this.UpdateServiceOutsideStatus();
|
|||
|
|
|||
|
DashboardViewModel dashboard = this.DashboardController.GetModel(this.Appsettings);
|
|||
|
this.UpdateOnMainThread(dashboard);
|
|||
|
|
|||
|
Thread.Sleep(60 * 5000);
|
|||
|
}
|
|||
|
}
|
|||
|
catch(ThreadAbortException ex)
|
|||
|
{
|
|||
|
Console.WriteLine(ex.Message);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Refresh()
|
|||
|
{
|
|||
|
this._MainForm.ShowLoading();
|
|||
|
|
|||
|
new Thread(() =>
|
|||
|
{
|
|||
|
this.UpdateServiceInsideStatus();
|
|||
|
this.UpdateServiceOutsideStatus();
|
|||
|
|
|||
|
DashboardViewModel dashboard = this.DashboardController.GetModel(this.Appsettings);
|
|||
|
this.UpdateOnMainThread(dashboard);
|
|||
|
|
|||
|
}).Start();
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateOnMainThread(DashboardViewModel dashboard)
|
|||
|
{
|
|||
|
if(this.lblTodayRegistred.InvokeRequired)
|
|||
|
{
|
|||
|
this.lblTodayRegistred.Invoke(new UpdateOnMainThreadDelegate(UpdateOnMainThread), dashboard);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.lblTodayRegistred.Text = (dashboard != null ? dashboard.DevicesToday : 0).ToString();
|
|||
|
this.lblDevices.Text = (dashboard != null ? dashboard.Devices : 0).ToString();
|
|||
|
this.lblResults.Text = (dashboard != null ? dashboard.Results : 0).ToString();
|
|||
|
this.lblReadyToDownloads.Text = (dashboard != null ? dashboard.ResultsAvailable : 0).ToString();
|
|||
|
this.lblNotifications.Text = (dashboard != null ? dashboard.ResultsNotified : 0).ToString();
|
|||
|
this.lblDownloads.Text = (dashboard != null ? dashboard.ResultsPickedUp : 0).ToString();
|
|||
|
|
|||
|
if(dashboard != null && dashboard.Maintenance == 1)
|
|||
|
{
|
|||
|
this.lblMaintenanceWork.Text = "Aktiv";
|
|||
|
this.lblMaintenanceWork.ForeColor = Color.Red;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.lblMaintenanceWork.Text = "Inaktiv";
|
|||
|
this.lblMaintenanceWork.ForeColor = Color.Black;
|
|||
|
}
|
|||
|
|
|||
|
this.lblHL7.Text = (dashboard != null ? dashboard.ResultsFiles : 0).ToString();
|
|||
|
this.lblEncryptedFiles.Text = (dashboard != null ? dashboard.EncryptedResultsFiles : 0).ToString();
|
|||
|
this.lblAckFiles.Text = (dashboard != null ? dashboard.PendingAcks : 0).ToString();
|
|||
|
this.lblAckCompleted.Text = (dashboard != null ? dashboard.DoneAcks : 0).ToString();
|
|||
|
|
|||
|
dtLastResults.DataSource = null;
|
|||
|
|
|||
|
if(dashboard != null && dashboard.LastResults != null)
|
|||
|
{
|
|||
|
dtLastResults.AutoGenerateColumns = false;
|
|||
|
dtLastResults.DataSource = dashboard.LastResults;
|
|||
|
}
|
|||
|
|
|||
|
if (dashboard != null && dashboard.Maintenance == 1)
|
|||
|
{
|
|||
|
lblMaintenanceWork.Text = "Aktiv";
|
|||
|
lblMaintenanceWork.ForeColor = Color.Red;
|
|||
|
lblMaintenanceWorkTitle.BackColor = Color.Red;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
lblMaintenanceWork.Text = "Inaktiv";
|
|||
|
lblMaintenanceWork.ForeColor = Color.FromArgb(100, 153, 19, 85);
|
|||
|
lblMaintenanceWorkTitle.BackColor = Color.FromArgb(100, 238, 238, 238);
|
|||
|
}
|
|||
|
|
|||
|
this._MainForm.HideLoading();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateServiceInsideStatusOnMainThread(Models.Version serviceInside)
|
|||
|
{
|
|||
|
if (this.lblServiceInsideStatus.InvokeRequired)
|
|||
|
{
|
|||
|
this.lblServiceInsideStatus.Invoke(new UpdateServiceInsideStatusOnMainThreadDelegate(UpdateServiceInsideStatusOnMainThread), serviceInside);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (serviceInside != null && !string.IsNullOrEmpty(serviceInside.version))
|
|||
|
{
|
|||
|
lblServiceInside.Text = serviceInside.version;
|
|||
|
lblServiceInsideStatus.BackColor = Color.Green;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
lblServiceInside.Text = "Offline";
|
|||
|
lblServiceInsideStatus.BackColor = Color.Red;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UpdateServiceOutsideStatusOnMainThread(Models.Version serviceOutside)
|
|||
|
{
|
|||
|
if (this.lblServiceOutsideStatus.InvokeRequired)
|
|||
|
{
|
|||
|
this.lblServiceOutsideStatus.Invoke(new UpdateServiceOutsideStatusOnMainThreadDelegate(UpdateServiceOutsideStatusOnMainThread), serviceOutside);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (serviceOutside != null && !string.IsNullOrEmpty(serviceOutside.version))
|
|||
|
{
|
|||
|
lblServiceOutside.Text = serviceOutside.version;
|
|||
|
lblServiceOutsideStatus.BackColor = Color.Green;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
lblServiceOutside.Text = "Offline";
|
|||
|
lblServiceOutsideStatus.BackColor = Color.Red;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|