217836099c
- fix program.cs startup - fix calcolo dim DB - fix IOB count
440 lines
14 KiB
C#
440 lines
14 KiB
C#
using DnsClient.Protocol;
|
|
using EgwCoreLib.Razor;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.JSInterop;
|
|
using MP.AppAuth.Models;
|
|
using MP.AppAuth.Services;
|
|
using MP.Data.DTO;
|
|
using MP.Data.Services;
|
|
using MP.Land.Data;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Land.Pages
|
|
{
|
|
public partial class IobList : ComponentBase, IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
ListRecords = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
#if false
|
|
public string MacIobConf(string idxMacc, string kReq)
|
|
{
|
|
string answ = "-";
|
|
if (DictMachData.ContainsKey(idxMacc))
|
|
{
|
|
var cRec = DictMachData[idxMacc];
|
|
if (cRec.ContainsKey(kReq))
|
|
{
|
|
answ = cRec[kReq];
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
#endif
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
#if false
|
|
protected Dictionary<string, Core.Objects.IOB_data> DictIobInfo = new Dictionary<string, Core.Objects.IOB_data>();
|
|
|
|
protected Dictionary<string, Dictionary<string, string>> DictMachData = new Dictionary<string, Dictionary<string, string>>();
|
|
#endif
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AppAuthService AppDService { get; set; }
|
|
|
|
[Inject]
|
|
protected LandDataService LDService { get; set; }
|
|
|
|
[Inject]
|
|
protected LMessageService AppMService { get; set; }
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
|
|
|
|
protected string BtnResetCss
|
|
{
|
|
get => string.IsNullOrEmpty(SearchValue) ? "btn-outline-secondary" : "btn-outline-primary";
|
|
}
|
|
|
|
[Inject]
|
|
protected IConfiguration Configuration { get; set; }
|
|
|
|
protected bool IsSuperAdmin
|
|
{
|
|
get => HasRight(AppAuthService.RoleSuperAdmin);
|
|
}
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected string SearchValue
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
currPage = 1;
|
|
searchVal = value;
|
|
RefreshDisplay();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine senza locazione
|
|
/// </summary>
|
|
protected bool ShowEmptyLoc
|
|
{
|
|
get => showEmptyLoc;
|
|
set
|
|
{
|
|
if (value != showEmptyLoc)
|
|
{
|
|
showEmptyLoc = value;
|
|
currPage = 1;
|
|
RefreshDisplay();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine extra (da reboot ma senza riga macchine, es -PING e -ENR)
|
|
/// </summary>
|
|
protected bool ShowExtra
|
|
{
|
|
get => showExtra;
|
|
set
|
|
{
|
|
if (value != showExtra)
|
|
{
|
|
showExtra = value;
|
|
currPage = 1;
|
|
RefreshDisplay();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine multi (es tavole)
|
|
/// </summary>
|
|
protected bool ShowMulti
|
|
{
|
|
get => showMulti;
|
|
set
|
|
{
|
|
if (value != showMulti)
|
|
{
|
|
showMulti = value;
|
|
currPage = 1;
|
|
RefreshDisplay();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected TabDataService TabSrv { get; set; } = null!;
|
|
|
|
protected List<UserDirittiModel> UserRight { get; set; } = new List<UserDirittiModel>();
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string checkSelect(IobDTO IdxODL)
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.IdxOdl == IdxODL) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DataInitAsync()
|
|
{
|
|
isLoading = true;
|
|
// recupero TUTTI i dati IobList già completi anche on i RemoteRebootLog
|
|
AllRecords = await LDService.IobListAllAsync();
|
|
|
|
|
|
#if false
|
|
// leggo i remoteRebootLog e cerco IdxMacc NON presenti, aggiungendo...
|
|
|
|
// fare!!! FixMe ToDo: aggiungere modello RRL, e query specifica x recuperare record con idxMacchina non presenti in tab Macchine..
|
|
|
|
// accodo a List di AllRecords
|
|
|
|
// leggo le info IOB x ogni record trovato...
|
|
DictIobInfo = AllRecords.ToDictionary(x => x.IdxMacchina, x => TabSrv.IobInfo(x.IdxMacchina));
|
|
DictMachData = AllRecords.ToDictionary(x => x.IdxMacchina, x => TabSrv.MachIobConf(x.IdxMacchina));
|
|
#endif
|
|
RefreshDisplay();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected bool HasRight(string codFunz)
|
|
{
|
|
bool answ = false;
|
|
if (UserRight != null && UserRight.Count > 0)
|
|
{
|
|
answ = UserRight
|
|
.Where(x => x.Funzione.Equals(codFunz, System.StringComparison.InvariantCultureIgnoreCase))
|
|
.Count() > 0;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ListRecords = null;
|
|
Titolo = "Elenco IOB Amministrati";
|
|
AppMService.ShowSearch = false;
|
|
AppMService.PageName = "IobList";
|
|
AppMService.PageIcon = "fas fa-computer pe-2";
|
|
await SetupRight();
|
|
await DataInitAsync();
|
|
}
|
|
|
|
protected void ResetSearch()
|
|
{
|
|
SearchValue = "";
|
|
}
|
|
|
|
protected void SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
RefreshDisplay();
|
|
}
|
|
|
|
protected void SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
RefreshDisplay();
|
|
}
|
|
|
|
protected void SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
if (sortField == e.ParamName)
|
|
{
|
|
sortAsc = e.IsAscending;
|
|
}
|
|
sortField = e.ParamName;
|
|
RefreshDisplay();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Classe logger
|
|
/// </summary>
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private List<IobDTO> AllRecords = new List<IobDTO>();
|
|
private int currPage = 1;
|
|
private bool isLoading = false;
|
|
private List<IobDTO> ListRecords = new List<IobDTO>();
|
|
private int numRecord = 10;
|
|
private List<IobDTO> SearchRecords = new List<IobDTO>();
|
|
private string searchVal = "";
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine senza locazione
|
|
/// </summary>
|
|
private bool showEmptyLoc = false;
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine extra (da reboot ma senza riga macchine, es -PING e -ENR)
|
|
/// </summary>
|
|
private bool showExtra = false;
|
|
|
|
/// <summary>
|
|
/// Definisce se mostrare macchine multi (es tavole)
|
|
/// </summary>
|
|
private bool showMulti = false;
|
|
|
|
private bool sortAsc = true;
|
|
private string sortField = "";
|
|
private string Titolo = "";
|
|
|
|
private int totalCount = 0;
|
|
private string userName = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void RefreshDisplay()
|
|
{
|
|
|
|
// in primis filtro conddizioni da selettori...
|
|
SearchRecords = AllRecords
|
|
.Where(x => (!string.IsNullOrEmpty(x.Locazione) || showEmptyLoc)
|
|
&& (showMulti || !x.IdxMacchina.Contains("#"))
|
|
&& (showExtra || x.IsMachine)
|
|
).ToList();
|
|
|
|
// se ho ricerca filtro...
|
|
if (!string.IsNullOrEmpty(searchVal))
|
|
{
|
|
SearchRecords = SearchRecords
|
|
.Where(x => x.Nome.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.CodMacchina.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.Descrizione.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.IdxMacchina.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.IobIpv4.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.AdapName.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
|| x.AdapType.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|
|
).ToList();
|
|
}
|
|
// conto record
|
|
totalCount = SearchRecords.Count();
|
|
|
|
// effettuo sorting
|
|
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "IdxMacc":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.IdxMacchina).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.IdxMacchina).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Nome":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Nome).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Nome).ToList();
|
|
}
|
|
break;
|
|
|
|
case "Descr":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Descrizione).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Descrizione).ToList();
|
|
}
|
|
break;
|
|
|
|
case "OS":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.OS).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.OS).ToList();
|
|
}
|
|
break;
|
|
|
|
case "IobName":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.IobName).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.IobName).ToList();
|
|
}
|
|
break;
|
|
|
|
case "AdapName":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.AdapName).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.AdapName).ToList();
|
|
}
|
|
break;
|
|
|
|
case "TargetIp":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.TargetIp).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.TargetIp).ToList();
|
|
}
|
|
break;
|
|
|
|
|
|
default:
|
|
SearchRecords = SearchRecords.OrderBy(x => x.IdxMacchina).ToList();
|
|
break;
|
|
}
|
|
}
|
|
|
|
// fix paginazione
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
|
|
private async Task SetupRight()
|
|
{
|
|
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
if (user.Identity != null && user.Identity.IsAuthenticated)
|
|
{
|
|
userName = $"{user.Identity.Name}";
|
|
}
|
|
else
|
|
{
|
|
userName = "N.A.";
|
|
}
|
|
// carico diritti...
|
|
var domUser = userName.Split("\\");
|
|
if (domUser.Length > 0)
|
|
{
|
|
string dominio = domUser[0];
|
|
string uName = domUser[1];
|
|
UserRight = await AppDService.DirittiGetByUser(uName);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |