259 lines
7.2 KiB
C#
259 lines
7.2 KiB
C#
using global::Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data;
|
|
using MP.Data.Conf;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.Data.Services;
|
|
using MP_TAB3.Shared;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
using System.Runtime.ExceptionServices;
|
|
|
|
namespace MP_TAB3.Pages
|
|
{
|
|
public partial class StatusMap : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
ListMSE = null;
|
|
TDFeeder.dataPipe.EA_NewMessage -= DataPipe_EA_NewMessage;
|
|
TDFeeder.blinkPipe.EA_NewMessage -= BlinkPipe_EA_NewMessage;
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Public Classes
|
|
|
|
public class WindowDimension
|
|
{
|
|
#region Public Properties
|
|
|
|
public int Height { get; set; }
|
|
public int Width { get; set; }
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
#endregion Public Classes
|
|
|
|
#region Protected Fields
|
|
|
|
protected bool _showCard = false;
|
|
|
|
protected string showArt = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IConfiguration config { get; set; } = null!;
|
|
|
|
protected int Height { get; set; } = 0;
|
|
|
|
protected bool isCalcSize { get; set; } = false;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected StatusData MDataService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MsgServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
protected bool ShowCard
|
|
{
|
|
get => _showCard;
|
|
set
|
|
{
|
|
_showCard = value;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected TabDataService TabDServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataFeeder TDFeeder { get; set; } = null!;
|
|
|
|
protected int Width { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// calcola num blocchi max data dimensione larghezza
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected int calcMaxBlock()
|
|
{
|
|
int answ = 2;
|
|
if (Width > 450)
|
|
{
|
|
if (Width < 1024)
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 200);
|
|
}
|
|
else
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 220) - 1;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task getWDim()
|
|
{
|
|
var dimension = await JSRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
|
|
Height = dimension.Height;
|
|
Width = dimension.Width;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await getWDim();
|
|
isCalcSize = false;
|
|
ListMSE = await MDataService.MseGetAll(true);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
if (ListMSE != null)
|
|
{
|
|
// salvo in LocalStorage...
|
|
await MsgServ.SaveMse(ListMSE);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ListMSE = null;
|
|
setDefaults();
|
|
TDFeeder.dataPipe.EA_NewMessage += DataPipe_EA_NewMessage;
|
|
TDFeeder.blinkPipe.EA_NewMessage += BlinkPipe_EA_NewMessage;
|
|
Random rnd = new Random();
|
|
await Task.Delay(rnd.Next(1, 50));
|
|
SetupConf();
|
|
var LastOpenedPage = await MsgServ.LastOpenedPageGet();
|
|
var currMacc = await MsgServ.IdxMaccGet();
|
|
if (currMacc != "" && currMacc != null)
|
|
{
|
|
await MsgServ.IdxMaccSet(currMacc);
|
|
if (LastOpenedPage != "" && LastOpenedPage != null)
|
|
{
|
|
NavMan.NavigateTo(LastOpenedPage);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void SaveData(List<MappaStatoExpl> newList)
|
|
{
|
|
ListMSE = newList;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private bool doBlink = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string baseLang { get; set; } = "";
|
|
|
|
private List<MappaStatoExpl>? ListMSE { get; set; } = null;
|
|
|
|
private string tcMode { get; set; } = "";
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Ricezione evento blink
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void BlinkPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly List<string> --> allarmi
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
var dataRaw = JsonConvert.DeserializeObject<string>(currArgs.newMessage);
|
|
if (dataRaw != null)
|
|
{
|
|
bool.TryParse($"{dataRaw}", out doBlink);
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricevuto nuovi dati da mostrare!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private void DataPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly List<string> --> allarmi
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
List<MappaStatoExpl>? dataList = JsonConvert.DeserializeObject<List<MappaStatoExpl>>(currArgs.newMessage);
|
|
if (dataList != null)
|
|
{
|
|
SaveData(dataList);
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
private void setDefaults()
|
|
{
|
|
string df = MsgServ.UserPrefSetup("DefCardMode", "full");
|
|
baseLang = MsgServ.UserPrefSetup("Lang", "IT");
|
|
tcMode = MsgServ.UserPrefSetup("TcMode", "ms");
|
|
ShowCard = df == "shrink" ? false : true;
|
|
isCalcSize = true;
|
|
}
|
|
|
|
private void SetupConf()
|
|
{
|
|
// sistemo i parametri opzionali...
|
|
TabDServ.ConfigGetVal("sART", ref showArt);
|
|
Log.Info($"setupConf | Effettuato setup parametri | showArt: {showArt}");
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |