188 lines
5.8 KiB
C#
188 lines
5.8 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.Data.Services;
|
|
using NLog;
|
|
|
|
namespace MP_TAB3.Components
|
|
{
|
|
public partial class CmpFooter : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public Guid CurrDevGuid { get; set; }
|
|
|
|
[Parameter]
|
|
public int DtScadLogin { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public int MatrOper { get; set; } = -1;
|
|
|
|
[Parameter]
|
|
public int TypeScadLogin { get; set; } = -1;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (aTimer != null)
|
|
{
|
|
aTimer.Elapsed -= ElapsedTimer;
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService MsgServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected SharedMemService SMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataService TDataService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
adesso = DateTime.Now;
|
|
// solo se NON sono in login...
|
|
if (!IsLoginPage)
|
|
{
|
|
var diffOfTime = adesso.Subtract(MsgServ.dtLastAction);
|
|
CurrExpVal = MaxExpVal - diffOfTime.TotalMinutes;
|
|
if (TypeScadLogin == 1)
|
|
{
|
|
if (CurrExpVal < 0)
|
|
{
|
|
MsgServ.dtLastAction = adesso;
|
|
NavMan.NavigateTo("logout");
|
|
}
|
|
}
|
|
// in questo caso cerco SOLO se sia scaduto su redis
|
|
else if (TypeScadLogin == 2)
|
|
{
|
|
// mitigazione check: solo ogni 10 secondi...
|
|
if (adesso.Subtract(MsgServ.dtLastSave).TotalSeconds > 10)
|
|
{
|
|
MsgServ.dtLastSave = adesso;
|
|
// rileggo scadenza ultima...
|
|
TimeSpan tsScadenza = TDataService.OperatoreGetGuidTTL(MatrOper, CurrDevGuid);
|
|
// mostro scadenza SOLO se inferiore a 24h...
|
|
showProgrBar = tsScadenza.TotalHours < 24;
|
|
// se < 0 --> login
|
|
if (tsScadenza.TotalMinutes < 0)
|
|
{
|
|
NavMan.NavigateTo("logout");
|
|
}
|
|
else
|
|
{
|
|
MsgServ.dtLastAction = adesso.Subtract(TimeSpan.FromMinutes(MaxExpVal)).Add(tsScadenza);
|
|
}
|
|
// comunque controllo chiave redis
|
|
var userTkn = await TDataService.OperatoreGetRedis(MatrOper, CurrDevGuid);
|
|
if (string.IsNullOrEmpty(userTkn))
|
|
{
|
|
NavMan.NavigateTo("logout");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
var rawVers = typeof(Program).Assembly.GetName().Version;
|
|
version = rawVers != null ? rawVers : new Version("0.0.0.0");
|
|
DtScadLogin = SMServ.GetConfInt("TAB_dtTimerScadLogin");
|
|
showProgrBar = TypeScadLogin == 1;
|
|
MaxExpVal = DtScadLogin;
|
|
yLimit = MaxExpVal * 0.3;
|
|
rLimit = MaxExpVal * 0.1;
|
|
// rileggo scadenza ultima...
|
|
TimeSpan tsScadenza = TDataService.OperatoreGetGuidTTL(MatrOper, CurrDevGuid);
|
|
MsgServ.dtLastAction = adesso.Subtract(TimeSpan.FromMinutes(MaxExpVal)).Add(tsScadenza);
|
|
showProgrBar = tsScadenza.TotalHours < 24;
|
|
StartTimer();
|
|
}
|
|
|
|
protected void StartTimer()
|
|
{
|
|
if (aTimer != null)
|
|
{
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
int tOutPeriod = 1000;
|
|
aTimer = new System.Timers.Timer(tOutPeriod);
|
|
aTimer.Elapsed += ElapsedTimer;
|
|
aTimer.Enabled = true;
|
|
aTimer.Start();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private DateTime adesso = DateTime.Now;
|
|
private System.Timers.Timer aTimer = null!;
|
|
private bool showProgrBar = true;
|
|
private Version version = null!;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private double CurrExpVal { get; set; } = 50;
|
|
|
|
private bool IsLoginPage
|
|
{
|
|
get
|
|
{
|
|
string currPage = NavMan.Uri;
|
|
return currPage.Contains("logout") || currPage.Contains("reg-new-device");
|
|
}
|
|
}
|
|
|
|
private double MaxExpVal { get; set; } = 100;
|
|
|
|
private double rLimit { get; set; } = 10;
|
|
|
|
private string CurrUM
|
|
{
|
|
get
|
|
{
|
|
string answ = "m";
|
|
if (MaxExpVal > 60)
|
|
{
|
|
answ = "h";
|
|
}
|
|
else if (MaxExpVal > 1440)
|
|
{
|
|
answ = "gg";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private double yLimit { get; set; } = 30;
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |