139 lines
3.4 KiB
C#
139 lines
3.4 KiB
C#
using GPW.CORE.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Shared.Smart.Common
|
|
{
|
|
public partial class CmpTop : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public ConfigDTO CurrConf { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public UserDTO? CurrUser { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_ForceReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_ReturnHome { get; set; }
|
|
|
|
[Parameter]
|
|
public bool IpIsLocal { get; set; } = false;
|
|
|
|
|
|
[Parameter]
|
|
public string LocalNet { get; set; } = "###";
|
|
|
|
#endregion Public Properties
|
|
|
|
[Inject]
|
|
private UserStateService UState { get; set; } = null!;
|
|
|
|
#if false
|
|
[Inject]
|
|
private MessageService MService { get; set; } = null!;
|
|
#endif
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_subscribed)
|
|
{
|
|
UState.OnChange -= UState_OnChange;
|
|
_subscribed = false;
|
|
}
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await Task.Delay(10);
|
|
//await InvokeAsync(StateHasChanged);
|
|
//return base.OnParametersSetAsync();
|
|
|
|
// verifico isLocal...
|
|
if (!string.IsNullOrEmpty(LocalNet))
|
|
{
|
|
}
|
|
}
|
|
private string currIpv4 = "";
|
|
|
|
private bool _subscribed = false;
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
//if (firstRender)
|
|
//{
|
|
// // iscriviti qui nell'istanza client
|
|
// UState.OnChange += UState_OnChange;
|
|
// _subscribed = true;
|
|
//}
|
|
if (!_subscribed)
|
|
{
|
|
_subscribed = true;
|
|
UState.OnChange += UState_OnChange;
|
|
}
|
|
if (CurrUser == null)
|
|
{
|
|
if (UState.CurrentUser != null)
|
|
{
|
|
CurrUser = UState.CurrentUser;
|
|
//await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
//await base.OnAfterRenderAsync(firstRender);
|
|
}
|
|
|
|
private void UState_OnChange()
|
|
{
|
|
// siamo in un callback non-UI thread: usa InvokeAsync
|
|
_ = InvokeAsync(() =>
|
|
{
|
|
CurrUser = UState.CurrentUser;
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#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()
|
|
{
|
|
await EC_ForceReset.InvokeAsync(true);
|
|
}
|
|
|
|
protected async Task ReturnHome()
|
|
{
|
|
await EC_ReturnHome.InvokeAsync(true);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |