138 lines
4.1 KiB
C#
138 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using System.Net.Http;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Components.Web.Virtualization;
|
|
using Microsoft.JSInterop;
|
|
using MP.Mon;
|
|
using MP.Mon.Shared;
|
|
using MP.Mon.Components;
|
|
using MP.Data.DatabaseModels;
|
|
|
|
namespace MP.Mon.Components
|
|
{
|
|
public partial class DetailMSE
|
|
{
|
|
|
|
protected string baseCss = "sem";
|
|
protected bool dataLoaded { get; set; } = false;
|
|
protected int kaFactor = 60 / 2;
|
|
|
|
[Parameter]
|
|
public bool doAnimate { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public string showArt { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public int keepAliveMin { get; set; } = 5;
|
|
[Parameter]
|
|
public MappaStatoExpl? CurrRecord { get; set; } = null;
|
|
|
|
private string cssStatus(string codSemaforo)
|
|
{
|
|
string answ= $"{baseCss}{codSemaforo.Substring(1, 2)}";
|
|
if (doAnimate)
|
|
{
|
|
// blink se secondo pari...
|
|
DateTime adesso = DateTime.Now;
|
|
int resto = 0;
|
|
Math.DivRem(adesso.Second, 2, out resto);
|
|
if (resto == 0)
|
|
{
|
|
answ += "_b";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string cssComStatus(string semaforo, DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
string answ = cssStatus(semaforo);
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
answ = $"{baseCss}Ro";
|
|
// blink se secondo pari...
|
|
DateTime adesso = DateTime.Now;
|
|
int resto = 0;
|
|
Math.DivRem(adesso.Second, 2, out resto);
|
|
if (resto == 0)
|
|
{
|
|
answ += "_b";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
StartTimer();
|
|
Random rnd = new Random();
|
|
//await Task.Delay(rnd.Next(500));
|
|
dataLoaded = true;
|
|
setupConf();
|
|
}
|
|
private void setupConf()
|
|
{
|
|
//baseCss = doAnimate ? "semBlink" : "sem";
|
|
}
|
|
private bool showComErr(DateTime? lastUpdateN)
|
|
{
|
|
DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1);
|
|
bool answ = false;
|
|
if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor))
|
|
{
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string getMinSec(decimal? currTimeMin)
|
|
{
|
|
string answ = "nd";
|
|
TimeSpan tSpan = new TimeSpan(0);
|
|
try
|
|
{
|
|
tSpan = TimeSpan.FromMinutes((double)currTimeMin);
|
|
answ = $"{tSpan:mm}:{tSpan:ss}";
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
|
|
private static System.Timers.Timer aTimer = new System.Timers.Timer(60 * 1000);
|
|
|
|
public void StartTimer()
|
|
{
|
|
int tOutPeriod = 1000;
|
|
//int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod);
|
|
aTimer = new System.Timers.Timer(tOutPeriod);
|
|
aTimer.Elapsed += ElapsedTimer;
|
|
aTimer.Enabled = true;
|
|
aTimer.Start();
|
|
}
|
|
|
|
public void ElapsedTimer(Object source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
} |