142 lines
3.6 KiB
C#
142 lines
3.6 KiB
C#
using GPW.CORE.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using NLog;
|
|
|
|
namespace GPW.CORE.Smart8.Shared.Components.Common
|
|
{
|
|
public partial class CmpTop : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public ConfigDTO CurrConf { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_ForceReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_ReturnHome { get; set; }
|
|
|
|
[Parameter]
|
|
public string LocalNet { get; set; } = "###";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_subscribed)
|
|
{
|
|
UState.OnChange -= UState_OnChange;
|
|
_subscribed = false;
|
|
}
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected string currDip
|
|
{
|
|
get => CurrUser != null ? CurrUser.DisplayName : "N.A. [0]";
|
|
}
|
|
|
|
protected string homeCss
|
|
{
|
|
get => IpIsLocal ? "text-light" : "text-danger";
|
|
}
|
|
|
|
protected string homeMessage
|
|
{
|
|
get => IpIsLocal ? "INT" : "EXT";
|
|
}
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
protected string Nome { get; set; } = "";
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task ForceReset()
|
|
{
|
|
//Log.Debug($"IsBrowser: {OperatingSystem.IsBrowser()}");
|
|
//Log.Debug($"IsServer: {OperatingSystem.IsWindows()}");
|
|
//Log.Debug("CmpTop.ForceReset");
|
|
await EC_ForceReset.InvokeAsync(true);
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (!_subscribed)
|
|
{
|
|
_subscribed = true;
|
|
UState.OnChange += UState_OnChange;
|
|
}
|
|
if (CurrUser == null)
|
|
{
|
|
if (UState.CurrentUser != null)
|
|
{
|
|
CurrUser = UState.CurrentUser;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected async Task ReturnHome()
|
|
{
|
|
//Log.Debug($"IsBrowser: {OperatingSystem.IsBrowser()}");
|
|
//Log.Debug($"IsServer: {OperatingSystem.IsWindows()}");
|
|
//Log.Debug("CmpTop.ReturnHome");
|
|
await EC_ReturnHome.InvokeAsync(true);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private bool _subscribed = false;
|
|
private string CurrIpv4 = "0.0.0.0";
|
|
private UserDTO? CurrUser = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool IpIsLocal { get; set; } = false;
|
|
|
|
[Inject]
|
|
private UserStateService UState { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void UState_OnChange()
|
|
{
|
|
// siamo in un callback non-UI thread: usa InvokeAsync
|
|
_ = InvokeAsync(() =>
|
|
{
|
|
if (UState.CurrentUser != null)
|
|
CurrUser = UState.CurrentUser;
|
|
|
|
if (UState.CurrIpv4 != null)
|
|
{
|
|
CurrIpv4 = UState.CurrIpv4;
|
|
if (!string.IsNullOrEmpty(CurrIpv4))
|
|
{
|
|
IpIsLocal = CurrIpv4.Contains(LocalNet);
|
|
}
|
|
}
|
|
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |