Files
2024-10-02 16:14:15 +02:00

114 lines
2.9 KiB
C#

using EgwControlCenter.Core;
using Microsoft.AspNetCore.Components;
namespace EgwControlCenter.App.Components.Compo
{
public partial class CmpFooter : ComponentBase, IDisposable
{
#region Public Methods
public void Dispose()
{
if (aTimer != null)
{
aTimer.Elapsed -= ElapsedTimer;
aTimer.Stop();
aTimer.Dispose();
}
ACService.EA_ConfigUpdated -= ACService_EA_ConfigUpdated;
}
#endregion Public Methods
#region Protected Fields
protected DateTime adesso = DateTime.Now;
#endregion Protected Fields
[Inject]
protected NavigationManager NavMan { get; set; } = null!;
[Inject]
protected AppControlService ACService { get; set; } = null!;
#region Protected Methods
protected void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
{
adesso = DateTime.Now;
var pUpd = Task.Run(async () =>
{
adesso = DateTime.Now;
await InvokeAsync(StateHasChanged);
});
pUpd.Wait();
}
protected override void OnInitialized()
{
StartTimer();
CurrAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetName();
ACService.EA_ConfigUpdated += ACService_EA_ConfigUpdated;
}
private void ACService_EA_ConfigUpdated()
{
// fermo il timer e lo riavvio...
StartTimer();
}
protected int RefreshPeriod
{
get => ACService.RefreshPeriod;
set => ACService.RefreshPeriod = value;
}
protected void StartTimer()
{
if (aTimer != null)
{
aTimer.Stop();
aTimer.Dispose();
}
int tOutPeriod = RefreshPeriod < 1000 ? RefreshPeriod * 1000 : RefreshPeriod;
aTimer = new System.Timers.Timer(tOutPeriod);
aTimer.Elapsed += ElapsedTimer;
aTimer.Enabled = true;
aTimer.Start();
}
#endregion Protected Methods
#region Private Fields
private System.Timers.Timer aTimer = null!;
#endregion Private Fields
#region Private Properties
private Version AppVers
{
get
{
Version answ = new Version(0, 0, 0, 0);
if (CurrAssembly != null && CurrAssembly.Version != null)
{
answ = CurrAssembly.Version;
}
return answ;
}
}
private System.Reflection.AssemblyName CurrAssembly { get; set; } = null!;
private void NavAbout()
{
NavMan.NavigateTo("About");
}
#endregion Private Properties
}
}