Files
gpw_next/GPW.CORE.SMART/Components/DtCard.razor.cs
T
Samuele Locatelli f5c764eafb SMART:
- Update link reload (da testare)
- update colore in reload
2023-01-14 10:07:25 +01:00

160 lines
4.1 KiB
C#

using Microsoft.AspNetCore.Components;
namespace GPW.CORE.Smart.Components
{
public partial class DtCard : IDisposable
{
#region Public Properties
[Parameter]
public string LastAction { get; set; } = "Ultima operazione...";
[Parameter]
public bool NextIsExtrata { get; set; } = true;
[Parameter]
public bool IsLoading { get; set; } = true;
[Parameter]
public bool ShowAction
{
get => showAction;
set
{
showAction = value;
if (value)
{
StartTimerTimb();
}
}
}
#endregion Public Properties
#region Public Methods
public void Dispose()
{
try
{
if (uiTimer != null)
{
uiTimer.Elapsed -= ElapsedTimerUi;
uiTimer.Stop();
uiTimer.Dispose();
}
}
catch
{ }
try
{
if (timbTimer != null)
{
timbTimer.Elapsed -= ElapsedTimerTimb;
timbTimer.Stop();
timbTimer.Dispose();
}
}
catch
{ }
}
public void ElapsedTimerTimb(object? source, System.Timers.ElapsedEventArgs e)
{
timbTimer.Enabled = false;
var pUpd = Task.Run(async () =>
{
// nasconde
showAction = false;
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
});
pUpd.Wait();
}
public void ElapsedTimerUi(object? source, System.Timers.ElapsedEventArgs e)
{
var pUpd = Task.Run(async () =>
{
dtCurr = DateTime.Now;
cssSec = (dtCurr.Second % 2 == 0) ? "text-light" : "text-light opacity-50";
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
});
pUpd.Wait();
}
public void StartTimerTimb()
{
// timer che scatta dopo 3sec
timbTimer = new System.Timers.Timer(3000);
timbTimer.Elapsed += ElapsedTimerTimb;
timbTimer.Enabled = true;
timbTimer.Start();
}
public void StartTimerUI()
{
// timer che scatta dopo 3sec
uiTimer = new System.Timers.Timer(1000);
uiTimer.Elapsed += ElapsedTimerUi;
uiTimer.Enabled = true;
uiTimer.AutoReset = true;
uiTimer.Start();
}
#endregion Public Methods
#region Protected Properties
protected string cssSec { get; set; } = "text-light";
#endregion Protected Properties
#region Protected Methods
protected override void OnInitialized()
{
base.OnInitialized();
StartTimerUI();
}
#endregion Protected Methods
#region Private Fields
private DateTime dtCurr = DateTime.Now;
private System.Timers.Timer timbTimer = null!;
private System.Timers.Timer uiTimer = null!;
#endregion Private Fields
#region Private Properties
/// <summary>
/// Card da collegare al tipo di stato/colore
/// </summary>
private string cardCss
{
get
{
string answ = "defaultCard";
if (!IsLoading)
{
answ = NextIsExtrata ? "cardEntrata" : "cardUscita";
// se showAction --> aggiungo pulse
if (showAction)
{
answ = NextIsExtrata ? "cardUscita pulse-warning" : "cardEntrata pulse-warning";
}
}
return answ;
}
}
private bool showAction { get; set; } = false;
#endregion Private Properties
}
}