e7dcefb069
- Rivisitazione completa gestione riconnessione blazor 8 - fic logico e grafico
139 lines
3.4 KiB
C#
139 lines
3.4 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
|
|
namespace MP.MON.Client.Components
|
|
{
|
|
public partial class CmpFooter : ComponentBase, IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public int slowRefreshSec { get; set; } = 300;
|
|
|
|
[Parameter]
|
|
public Version version { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (aTimer != null)
|
|
{
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
}
|
|
|
|
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
// dispongo i vari timers...
|
|
disposeTimers();
|
|
Console.WriteLine("Elapsed Slow Timer --> full page reload");
|
|
// reload pagina intera
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
|
|
public void StartTimer()
|
|
{
|
|
// timer lento
|
|
aTimer = new System.Timers.Timer(slowRefreshMs);
|
|
aTimer.Elapsed += ElapsedTimer;
|
|
aTimer.Enabled = true;
|
|
aTimer.Start();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Public Classes
|
|
|
|
public class WindowDimension
|
|
{
|
|
#region Public Properties
|
|
|
|
public int Height { get; set; }
|
|
public int Width { get; set; }
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
#endregion Public Classes
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
protected int slowRefreshMs
|
|
{
|
|
get
|
|
{
|
|
// tempo variabile tra +/- 10% del target
|
|
int answ = rnd.Next(900, 1100) * slowRefreshSec;
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task getWDim()
|
|
{
|
|
var dimension = await JSRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
|
|
Height = dimension.Height;
|
|
Width = dimension.Width;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await getWDim();
|
|
StateHasChanged();
|
|
StartTimer();
|
|
Console.WriteLine($"Footer | Dimensioni schermo: {Width}x{Height} | slowRefreshSec: {slowRefreshSec}");
|
|
}
|
|
Console.WriteLine($"Footer | OnAfterRenderAsync completato");
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
rnd = new Random();
|
|
Console.WriteLine($"Footer | OnInitialized completato");
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static System.Timers.Timer aTimer = null!;
|
|
private Random rnd;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int Height { get; set; } = 0;
|
|
|
|
private int Width { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void disposeTimers()
|
|
{
|
|
aTimer.Elapsed -= ElapsedTimer;
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |