695b46bb49
- Gestione fermate RT - fix lettura h2IOB
159 lines
4.8 KiB
C#
159 lines
4.8 KiB
C#
using global::Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.Data.Services;
|
|
using NLog;
|
|
using System.Diagnostics;
|
|
|
|
namespace MP_TAB_SERV.Shared
|
|
{
|
|
public partial class MainLayout : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
NavMan.LocationChanged -= HandleLocationChanged;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string ResetClass = "btn-primary";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Livello corrente del menu
|
|
/// </summary>
|
|
protected string CurrLevel { get; set; } = "";
|
|
|
|
/// <summary>
|
|
/// Elenco items da menù per pagina corrente...
|
|
/// </summary>
|
|
protected List<LinkMenu> CurrMenuItems { get; set; } = new List<LinkMenu>();
|
|
|
|
[Inject]
|
|
protected ListSelectDataSrv MDataService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected SharedMemService MStor { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataService TDataService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task ForceReload()
|
|
{
|
|
Stopwatch sw = new Stopwatch();
|
|
sw.Start();
|
|
Log.Info("Start ForceReload");
|
|
ResetClass = "btn-warning";
|
|
await InvokeAsync(StateHasChanged);
|
|
// reset cache varie
|
|
await MServ.ClearLocalStor();
|
|
await MServ.ClearSessionStor();
|
|
await MDataService.FlushCache();
|
|
// reload MStor
|
|
await ReloadMemStor();
|
|
// calcolo tempo esecuzione
|
|
sw.Stop();
|
|
int delta = 500 - (int)sw.ElapsedMilliseconds;
|
|
delta = delta > 0 ? delta : 50;
|
|
await Task.Delay(delta);
|
|
ResetClass = "btn-primary";
|
|
// await InvokeAsync(StateHasChanged);
|
|
Log.Info($"ForceReload completed in {sw.ElapsedMilliseconds}ms");
|
|
// ricarica pagina!
|
|
NavMan.NavigateTo("/", true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Init struttura dati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
NavMan.LocationChanged += HandleLocationChanged;
|
|
// verifica preliminare setup mdati
|
|
if (!MStor.MenuOk)
|
|
{
|
|
await ReloadMemStor();
|
|
}
|
|
|
|
CurrLevel = MStor.PageLevel(NavMan.Uri);
|
|
// recupero menù
|
|
if (MStor.DictMenu.ContainsKey(CurrLevel))
|
|
{
|
|
CurrMenuItems = MStor.DictMenu[CurrLevel];
|
|
}
|
|
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected async Task ReloadMemStor()
|
|
{
|
|
// in primis svuoto...
|
|
MStor.ClearCache();
|
|
// rileggo link
|
|
var allData = await MDataService.ListLinkAll();
|
|
MStor.SetupMenu(allData);
|
|
// fix config...
|
|
var allConf = await MDataService.ConfigGetAll();
|
|
MStor.SetConfig(allConf);
|
|
// fix MSFD...
|
|
var allMSFD = await TDataService.VMSFDGetAll();
|
|
MStor.SetMsfd(allMSFD);
|
|
// fix elenco eventi
|
|
var allEvents = await TDataService.AnagEventiGetAll();
|
|
MStor.SetEventi(allEvents);
|
|
// fix elenco stati
|
|
var allStati = await TDataService.AnaStatiGetAll();
|
|
MStor.SetStati(allStati);
|
|
// non da farsi globalmente // fix macchine var allMach = await
|
|
// MDataService.MacchineByMatrOper(0); MStor.DictMacchine = allMach.ToDictionary(x =>
|
|
// x.IdxMacchina, x => $"{x.IdxMacchina} | {x.Nome}");
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
// Logger.LogInformation("URL of new location: {Location}", e.Location);
|
|
CurrLevel = MStor.PageLevel(NavMan.Uri);
|
|
// recupero menù
|
|
if (MStor.DictMenu.ContainsKey(CurrLevel))
|
|
{
|
|
CurrMenuItems = MStor.DictMenu[CurrLevel];
|
|
InvokeAsync(StateHasChanged).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
private void OnYes()
|
|
{
|
|
Console.WriteLine($"{DateTime.Now} | 'Yes' button selected.");
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |