503 lines
18 KiB
C#
503 lines
18 KiB
C#
using LiMan.DB;
|
|
using LiMan.DB.DBModels;
|
|
using LiMan.DB.DTO;
|
|
using LiMan.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using static Core.Enum;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class InstallInfoStats : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
LMDService.EnrollMessPipe.EA_NewMessage -= async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e);
|
|
LMDService.TaskMessPipe.EA_NewMessage -= async (sender, e) => await TaskMessPipe_EA_NewMessage(sender, e);
|
|
LMDService.UpdActMessPipe.EA_NewMessage -= async (sender, e) => await UpdActMessPipe_EA_NewMessage(sender, e);
|
|
MServ.EA_SelCodApp -= async () => await MServ_EA_SelCodApp();
|
|
MServ.EA_SelCodImp -= async () => await MServ_EA_SelCodImp();
|
|
MServ.EA_SelCodInst -= async () => await MServ_EA_SelCodInst();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Codice installazione selezionata
|
|
/// </summary>
|
|
protected string CodInstSel
|
|
{
|
|
get => codInstSel;
|
|
set
|
|
{
|
|
if (codInstSel != value)
|
|
{
|
|
codInstSel = value;
|
|
isLoading = true;
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await ReloadData();
|
|
MServ.UsrParamSet("CodInst", value);
|
|
MServ.ReportSelCodInst();
|
|
});
|
|
pUpd.Wait();
|
|
isLoading = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tipo app selezionato
|
|
/// </summary>
|
|
protected string CodTipoApp
|
|
{
|
|
get => codTipoApp;
|
|
set
|
|
{
|
|
if (codTipoApp != value)
|
|
{
|
|
codTipoApp = value;
|
|
isLoading = true;
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await ReloadData();
|
|
// resetto eventuale App
|
|
MServ.UsrParamSet("CodApp", "");
|
|
MServ.ReportSelCodApp();
|
|
});
|
|
pUpd.Wait();
|
|
isLoading = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected LiManDataService LMDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
LMDService.EnrollMessPipe.EA_NewMessage += async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e);
|
|
LMDService.TaskMessPipe.EA_NewMessage += async (sender, e) => await TaskMessPipe_EA_NewMessage(sender, e);
|
|
LMDService.UpdActMessPipe.EA_NewMessage += async (sender, e) => await UpdActMessPipe_EA_NewMessage(sender, e);
|
|
MServ.EA_SelCodApp += async () => await MServ_EA_SelCodApp();
|
|
MServ.EA_SelCodImp += async () => await MServ_EA_SelCodImp();
|
|
MServ.EA_SelCodInst += async () => await MServ_EA_SelCodInst();
|
|
await ReloadLicData();
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string CodDeviceSel = "";
|
|
private string codInstSel = "";
|
|
|
|
/// <summary>
|
|
/// Secondi di debounce x evitare reload continui
|
|
/// </summary>
|
|
private int debounceSec = 5;
|
|
|
|
private Dictionary<string, string> DetailFilt = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Ebilitazione editing parametri configurazione x impiango selezionata
|
|
/// </summary>
|
|
private bool DoEditConfig = false;
|
|
|
|
private bool HasFiltClienti = false;
|
|
private bool HasFiltImpiego = false;
|
|
|
|
/// <summary>
|
|
/// DataOra ultimo reload
|
|
/// </summary>
|
|
private DateTime lastReload = DateTime.Now;
|
|
|
|
private List<InstallazioneModel> ListInstall;
|
|
|
|
/// <summary>
|
|
/// Lista Task in stato DONE
|
|
/// </summary>
|
|
private Dictionary<string, string> TaskDone = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Lista Task in stato REQUESTED
|
|
/// </summary>
|
|
private Dictionary<string, string> TaskReq = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Lista Task in stato RUNNING
|
|
/// </summary>
|
|
private Dictionary<string, string> TaskRun = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// Versione raw serializzata della conf impianto (immutabile x modifica)
|
|
/// </summary>
|
|
private string TgtListRaw = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
/// <summary>
|
|
/// App selezionata
|
|
/// </summary>
|
|
private string CodAppSel { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Impianto selezionato
|
|
/// </summary>
|
|
private string CodImpSel { get; set; } = "";
|
|
|
|
private string codTipoApp { get; set; } = "";
|
|
|
|
private string cssBtnCli
|
|
{
|
|
get => HasFiltClienti ? "btn-info" : "btn-primary";
|
|
}
|
|
|
|
private string DevName { get; set; } = "";
|
|
private DateTime DtFine { get; set; } = DateTime.Today.AddHours(DateTime.Now.Hour + 1);
|
|
private DateTime DtInizio { get; set; } = DateTime.Today.AddMonths(-1);
|
|
private InstallStatusDTO InfoStats { get; set; } = new InstallStatusDTO();
|
|
private bool isLoading { get; set; } = false;
|
|
private Dictionary<string, DeviceDTO> ListDevices { get; set; } = new Dictionary<string, DeviceDTO>();
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private string BtnState(int numRec)
|
|
{
|
|
return numRec > 0 ? "text-bg-dark" : "text-bg-secondary";
|
|
}
|
|
|
|
private async Task CloseDetail()
|
|
{
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
HasFiltImpiego = false;
|
|
CodImpSel = "";
|
|
DetailFilt.Clear();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricezione configurazione serializzata da inviare al device
|
|
/// </summary>
|
|
/// <param name="reqSent"></param>
|
|
private void ConfigUpdated(string newData)
|
|
{
|
|
if (!string.IsNullOrEmpty(newData))
|
|
{
|
|
// invio task update configurazione
|
|
LMDService.TaskReqAdd(CodImpSel, EgwAccTask.TargetListUpsert, newData);
|
|
}
|
|
DoEditConfig = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Evento refresh legato a ricezione evento da MessagePipe di Enroll
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async Task EnrollMessPipe_EA_NewMessage(object sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// qualsiasi messaggio fa scattare reload data
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
await ReloadLicData();
|
|
await ReloadData();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezionato CodApp (Singola app, molti PC)
|
|
/// </summary>
|
|
private async Task MServ_EA_SelCodApp()
|
|
{
|
|
isLoading = true;
|
|
// se trovo salvate in preferenze utente le info necessarie...
|
|
CodAppSel = MServ.UsrParamGet("CodApp");
|
|
HasFiltImpiego = !string.IsNullOrEmpty(CodAppSel);
|
|
DetailFilt.Clear();
|
|
DetailFilt.Add("App", CodAppSel);
|
|
DetailFilt.Add("# Copie", MServ.UsrParamGet("NumApp"));
|
|
DetailFilt.Add("# Lic.", MServ.UsrParamGet("NumLic"));
|
|
DetailFilt.Add("vers.", MServ.UsrParamGet("LastVers"));
|
|
DetailFilt.Add("score", MServ.UsrParamGet("Score"));
|
|
ReloadTaskStatus();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezionato CodImp (PC)
|
|
/// </summary>
|
|
private async Task MServ_EA_SelCodImp()
|
|
{
|
|
isLoading = true;
|
|
// se trovo salvate in preferenze utente le info necessarie...
|
|
CodImpSel = MServ.UsrParamGet("CodImp");
|
|
HasFiltImpiego = !string.IsNullOrEmpty(CodImpSel);
|
|
DetailFilt.Clear();
|
|
DetailFilt.Add("Cliente", MServ.UsrParamGet("Cliente"));
|
|
DevName = MServ.UsrParamGet("PcInst");
|
|
DetailFilt.Add("PC", DevName);
|
|
DetailFilt.Add("SW ver.", MServ.UsrParamGet("Version"));
|
|
DetailFilt.Add("IP", MServ.UsrParamGet("PcIP"));
|
|
DetailFilt.Add("Started", MServ.UsrParamGet("PcRestart"));
|
|
ReloadTaskStatus();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezionato CodInstall (Cliente)
|
|
/// </summary>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private async Task MServ_EA_SelCodInst()
|
|
{
|
|
isLoading = true;
|
|
CodInstSel = MServ.UsrParamGet("CodInst");
|
|
HasFiltClienti = !string.IsNullOrEmpty(CodInstSel);
|
|
ReloadDevices();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
InfoStats = await LMDService.InstallStatusGetInfo(DtInizio, DtFine, CodInstSel, CodTipoApp);
|
|
ReloadDevices();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void ReloadDevices()
|
|
{
|
|
ListDevices = new Dictionary<string, DeviceDTO>();
|
|
if (InfoStats != null)
|
|
{
|
|
// se necessario filtro...
|
|
if (HasFiltClienti)
|
|
{
|
|
ListDevices = InfoStats
|
|
.InstDevices
|
|
.Where(x => x.Value.CodInst == CodInstSel)
|
|
.OrderBy(x => x.Value.DevName)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
else
|
|
{
|
|
ListDevices = InfoStats
|
|
.InstDevices
|
|
.OrderBy(x => x.Value.DevName)
|
|
.ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task ReloadLicData()
|
|
{
|
|
ListInstall = await LMDService.InstallazioniNextGetAll();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue update stato task
|
|
/// </summary>
|
|
private void ReloadTaskStatus()
|
|
{
|
|
TaskReq = new Dictionary<string, string>();
|
|
TaskRun = new Dictionary<string, string>();
|
|
TaskDone = new Dictionary<string, string>();
|
|
TgtListRaw = "";
|
|
if (!string.IsNullOrEmpty(CodImpSel))
|
|
{
|
|
TaskReq = LMDService.TaskReqGet(CodImpSel);
|
|
TaskRun = LMDService.TaskRunGet(CodImpSel);
|
|
TaskDone = LMDService.TaskDoneGet(CodImpSel);
|
|
// è uno dei task done l'elenco target...
|
|
if (TaskDone.ContainsKey("TargetList"))
|
|
{
|
|
TgtListRaw = TaskDone["TargetList"];
|
|
}
|
|
}
|
|
else if (!string.IsNullOrEmpty(CodAppSel))
|
|
{
|
|
TaskReq = LMDService.TaskListReqGet();
|
|
TaskRun = LMDService.TaskListRunGet();
|
|
TaskDone = LMDService.TaskListDoneGet();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resetta le richeiste di task x impiango corrente
|
|
/// </summary>
|
|
private async Task ResetTaskReq()
|
|
{
|
|
if (!string.IsNullOrEmpty(CodImpSel))
|
|
{
|
|
// registro la richiesta
|
|
LMDService.TaskReqReset(CodImpSel);
|
|
await Task.Delay(5);
|
|
}
|
|
else if (!string.IsNullOrEmpty(CodAppSel))
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler resettare richieste aperte per i devices con l'applicazione selezionata?"))
|
|
return;
|
|
|
|
// ciclo x tutti i codImp derivati dall'app...
|
|
var listRecSel = InfoStats
|
|
.InstallRelList
|
|
.Where(x => x.CodApp == CodAppSel)
|
|
.ToList();
|
|
foreach (var item in listRecSel)
|
|
{
|
|
// registro la richiesta
|
|
LMDService.TaskReqReset(item.CodImp);
|
|
await Task.Delay(5);
|
|
}
|
|
}
|
|
// mando notifica con messageservice...
|
|
MServ.ReportTaskChange();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Force reboot applicazione EgwACC
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task SendReboot()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler forzare il riavvio di EgwAppControlCenter sul Device? In caso di update disponibile questo sarà applicato in modo automatico senza conferma utente."))
|
|
return;
|
|
|
|
await SendTask(Core.Enum.EgwAccTask.ForceUpdate);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invia una richiesta esecuzione task
|
|
/// </summary>
|
|
/// <param name="reqTask"></param>
|
|
/// <param name="optPar">Parametri opzionali x svolgiimento</param>
|
|
private async Task SendTask(EgwAccTask reqTask, string optPar = "")
|
|
{
|
|
// se parametro vuoto metto dataora...
|
|
optPar = string.IsNullOrEmpty(optPar) ? $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}" : optPar;
|
|
if (!string.IsNullOrEmpty(CodImpSel))
|
|
{
|
|
// registro la richiesta
|
|
LMDService.TaskReqAdd(CodImpSel, reqTask, optPar);
|
|
// aggiorno stato...
|
|
ReloadTaskStatus();
|
|
// mando notifica con messageservice...
|
|
MServ.ReportTaskChange();
|
|
}
|
|
else if (!string.IsNullOrEmpty(CodAppSel))
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler inviare il comando a tutti i devices con l'applicazione selezionata? La richiesta sarà inserita in coda di esecuzione e verrà eseguita in modo asyncrono dai vari devices appena possibile."))
|
|
return;
|
|
|
|
// ciclo x tutti i codImp derivati dall'app...
|
|
var listRecSel = InfoStats
|
|
.InstallRelList
|
|
.Where(x => x.CodApp == CodAppSel)
|
|
.ToList();
|
|
foreach (var item in listRecSel)
|
|
{
|
|
// registro la richiesta
|
|
LMDService.TaskReqAdd(item.CodImp, reqTask, optPar);
|
|
}
|
|
}
|
|
ReloadTaskStatus();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Evento refresh legato a ricezione evento da MessagePipe TASK
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async Task TaskMessPipe_EA_NewMessage(object sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// qualsiasi messaggio TASK fa scattare...
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
isLoading = true;
|
|
ReloadTaskStatus();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private void TglFiltCli()
|
|
{
|
|
HasFiltClienti = !HasFiltClienti;
|
|
if (!HasFiltClienti)
|
|
{
|
|
CodInstSel = "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Toggle modalità editing parametri confguraziione app
|
|
/// </summary>
|
|
private void ToggleParamConfig()
|
|
{
|
|
if (!string.IsNullOrEmpty(CodImpSel))
|
|
{
|
|
DoEditConfig = !DoEditConfig;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Evento refresh legato a ricezione evento da MessagePipe Update
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async Task UpdActMessPipe_EA_NewMessage(object sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
DateTime adesso = DateTime.Now;
|
|
// qualsiasi messaggio (dopo debounceSec sec dal precedente) fa scattare reload data
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage) && adesso.Subtract(lastReload).TotalSeconds > debounceSec)
|
|
{
|
|
lastReload = adesso;
|
|
isLoading = true;
|
|
#if false
|
|
InfoStats = null;
|
|
#endif
|
|
await ReloadLicData();
|
|
await ReloadData();
|
|
isLoading = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |