using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using NLog; using System; namespace MP.Mon.Components { public partial class CmpFooter : IDisposable { #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); await InvokeAsync(() => StateHasChanged()); }); pUpd.Wait(); //Log.Trace($"Elapsed Timer Footer"); } 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 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 Properties [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected async Task getWDim() { var dimension = await JSRuntime.InvokeAsync("getWindowDimensions"); Height = dimension.Height; Width = dimension.Width; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await getWDim(); StateHasChanged(); Log.Debug($"Dimensioni schermo: {Width}x{Height}"); } } protected override void OnInitialized() { var currAssembly = typeof(Program).Assembly.GetName(); version = currAssembly.Version != null ? currAssembly.Version : new Version(); StartTimer(); } #endregion Protected Methods #region Private Fields private static System.Timers.Timer aTimer = null!; private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); private Version version = null!; #endregion Private Fields #region Private Properties private int Height { get; set; } = 0; private int Width { get; set; } = 0; #endregion Private Properties } }