322 lines
8.9 KiB
C#
322 lines
8.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.Core.Conf;
|
|
using MP.Core.DTO;
|
|
|
|
namespace MP.MON.Client.Components
|
|
{
|
|
public partial class DetailMSE : ComponentBase
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public string cssOverlayOff { get; set; } = "";
|
|
|
|
[Parameter]
|
|
public MappaStatoExplDTO? CurrRecord { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public List<TagData>? currTagConf { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public Dictionary<string, string> currTagVal { get; set; } = new Dictionary<string, string>();
|
|
|
|
[Parameter]
|
|
public bool doAnimate { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public bool doBlink { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public int keepAliveMin { get; set; } = 5;
|
|
|
|
[Parameter]
|
|
public int maxChar4Scroll { get; set; } = 20;
|
|
|
|
[Parameter]
|
|
public string showArt { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
aTimer.Elapsed -= ElapsedTimer;
|
|
aTimer.Stop();
|
|
aTimer.Dispose();
|
|
}
|
|
|
|
public void ElapsedTimer(object? source, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
var pUpd = Task.Run(async () =>
|
|
{
|
|
await Task.Delay(1);
|
|
// verifica variazione x blink...
|
|
bool needUpdate = false;
|
|
if (CurrRecord == null)
|
|
{
|
|
needUpdate = true;
|
|
}
|
|
else
|
|
{
|
|
if (OldRecord == null)
|
|
{
|
|
needUpdate = true;
|
|
}
|
|
else
|
|
{
|
|
if (!CurrRecord.Semaforo.Equals(OldRecord.Semaforo) || CurrRecord.Semaforo != "sVe")
|
|
{
|
|
needUpdate = true;
|
|
}
|
|
}
|
|
}
|
|
if (needUpdate)
|
|
{
|
|
await InvokeAsync(() => StateHasChanged());
|
|
}
|
|
OldRecord = CurrRecord;
|
|
});
|
|
pUpd.Wait();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string baseCss = "sem";
|
|
|
|
protected int kaFactor = 60 / 2;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string codIOB
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (CurrRecord != null)
|
|
{
|
|
answ = CurrRecord.IdxMacchina;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
protected bool dataLoaded { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// CSS Class x overlay (effetto spento x macchina spenta/ sGr)
|
|
/// </summary>
|
|
protected string overlayCss
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
if (CurrRecord != null)
|
|
{
|
|
answ = CurrRecord.Semaforo == "sGr" ? cssOverlayOff : "";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// restituisce il valore data la tagLocation
|
|
/// </summary>
|
|
/// <param name="tagLocation"></param>
|
|
/// <returns></returns>
|
|
protected string currVal(string tagLocation)
|
|
{
|
|
string answ = "";
|
|
if (currTagVal.ContainsKey(tagLocation))
|
|
{
|
|
answ = currTagVal[tagLocation];
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se ci sia un override per la riga indicata
|
|
/// </summary>
|
|
/// <param name="numRow"></param>
|
|
/// <returns></returns>
|
|
protected bool hasRow(int numRow)
|
|
{
|
|
bool answ = false;
|
|
if (currTagConf != null)
|
|
{
|
|
if (currTagConf.Count > 0)
|
|
{
|
|
var currVals = rowValues(numRow);
|
|
answ = currVals.Count > 0;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
//StartTimer();
|
|
Random rnd = new Random();
|
|
await Task.Delay(rnd.Next(5));
|
|
setupConf();
|
|
dataLoaded = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce (se presenti) valori di override per la riga indicata
|
|
/// </summary>
|
|
/// <param name="numRow"></param>
|
|
/// <returns></returns>
|
|
protected List<TagData> rowValues(int numRow)
|
|
{
|
|
List<TagData>? rowVals = null;
|
|
if (currTagConf != null)
|
|
{
|
|
if (currTagConf.Count > 0)
|
|
{
|
|
//cerco solo la riga corrente...
|
|
rowVals = currTagConf.Where(x => x.RowNum == numRow).ToList();
|
|
}
|
|
}
|
|
if (rowVals == null)
|
|
{
|
|
rowVals = new List<TagData>();
|
|
}
|
|
return rowVals;
|
|
}
|
|
|
|
/// <summary>
|
|
/// CSS class x testo (se descr lunga scorre...)
|
|
/// </summary>
|
|
protected string textDescrCss(string currText, int maxChar)
|
|
{
|
|
string answ = "text-nowrap";
|
|
if (currText.Length > maxChar)
|
|
{
|
|
answ = " scroll-left";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
private static System.Timers.Timer aTimer { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Valore precedente x calcolo variazione
|
|
/// </summary>
|
|
private MappaStatoExplDTO? OldRecord { get; set; } = null;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
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;
|
|
}
|
|
|
|
private string cssStatus(string codSemaforo)
|
|
{
|
|
// se vuoto --> mostra nero!
|
|
if (string.IsNullOrEmpty(codSemaforo))
|
|
{
|
|
codSemaforo = "sNe";
|
|
}
|
|
string codColore = codSemaforo.Substring(1, 2);
|
|
string answ = $"{baseCss}{codColore}";
|
|
if (doAnimate && codColore != "Ve")
|
|
{
|
|
if (doBlink)
|
|
{
|
|
answ += "_b";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private decimal getDecimal(object? rawData)
|
|
{
|
|
decimal answ = 0;
|
|
if (rawData != null)
|
|
{
|
|
decimal.TryParse($"{rawData}", out answ);
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private string getMinSec(decimal? currTimeMin)
|
|
{
|
|
string answ = "nd";
|
|
TimeSpan tSpan = new TimeSpan(0);
|
|
try
|
|
{
|
|
double cTimeMin = currTimeMin != null ? (double)currTimeMin : 0;
|
|
tSpan = TimeSpan.FromMinutes(cTimeMin);
|
|
if (tSpan.TotalHours < 1)
|
|
{
|
|
answ = $"{tSpan:mm}:{tSpan:ss}";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tSpan.TotalHours:N0}h {tSpan:mm}:{tSpan:ss}";
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |