Merge remote-tracking branch 'origin/develop' into ProcPipeComm
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>WebDoorCreator - Egalware</i>
|
||||
<h4>Version: 0.9.2305.2909</h4>
|
||||
<h4>Version: 0.9.2305.2916</h4>
|
||||
<br /> Release note:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.9.2305.2909
|
||||
0.9.2305.2916
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>0.9.2305.2909</version>
|
||||
<version>0.9.2305.2916</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -50,10 +50,11 @@ namespace WebDoorCreator.Core
|
||||
public const string rKeyRoles = $"{redisBaseAddr}:Cache:Roles";
|
||||
public const string rKeyUsers = $"{redisBaseAddr}:Cache:Users";
|
||||
public const string rKeyUsersAll = $"{redisBaseAddr}:Cache:UsersAll";
|
||||
public const string rKeyUsersDataId = $"{redisBaseAddr}:Cache:UsersData:Id";
|
||||
public const string rKeyUsersDataSearch = $"{redisBaseAddr}:Cache:UsersData:Search";
|
||||
public const string rKeyUsersData = $"{redisBaseAddr}:Cache:UsersData";
|
||||
public const string rKeyUsersDataSearch = $"{rKeyUsersData}:Search";
|
||||
public const string rKeyUsersView = $"{redisBaseAddr}:Cache:UsersView";
|
||||
public const string rKeyVocLemma = $"{redisBaseAddr}:Cache:VocLemma";
|
||||
public const string rKeyVocLemmaTEMP = $"{redisBaseAddr}:Cache:VocLemmaTEMP";
|
||||
public const string rKeyLanguage = $"{redisBaseAddr}:Cache:Languages";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1241,18 +1241,46 @@ namespace WebDoorCreator.Data.Controllers
|
||||
}
|
||||
return DTOResult;
|
||||
}
|
||||
public Dictionary<string, Dictionary<string, string>> VocLemmaTEMPGetAll()
|
||||
{
|
||||
Dictionary<string, Dictionary<string, string>> DTOResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> lingue = new List<string>()
|
||||
{
|
||||
"IT",
|
||||
"EN"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta di un nuovo set di lemmi
|
||||
/// </summary>
|
||||
/// <param name="listNewTerms"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> VocLemmaInsert(List<VocabularyTempModel> listNewTerms)
|
||||
// extracting entire set
|
||||
var allVoc = localDbCtx
|
||||
.DbSetVocabularyTemp
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
|
||||
foreach (var lingua in lingue)
|
||||
{
|
||||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||||
foreach (var lemma in allVoc.Where(x => x.Lingua == lingua))
|
||||
{
|
||||
dict.Add(lemma.Lemma, lemma.Traduzione);
|
||||
}
|
||||
DTOResult.Add(lingua, dict);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Error in VocLemmaTEMPGetAll:{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return DTOResult;
|
||||
}
|
||||
public async Task<bool> VocLemmaInsertPrepare(List<VocabularyTempModel> listNewTerms)
|
||||
{
|
||||
bool fatto = false;
|
||||
|
||||
//var o = listNewTerms.Where(x => x.Traduzione.Length > 200).ToList();
|
||||
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
@@ -1269,8 +1297,36 @@ namespace WebDoorCreator.Data.Controllers
|
||||
.AddRange(listNewTerms);
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione durante VocLemmaInsertPrepare: {Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunta di un nuovo set di lemmi
|
||||
/// </summary>
|
||||
/// <param name="listNewTerms"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> VocLemmaInsert()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
bool fatto = false;
|
||||
|
||||
//var o = listNewTerms.Where(x => x.Traduzione.Length > 200).ToList();
|
||||
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
//bool isOk = await VocLemmaInsertPrepare(listNewTerms);
|
||||
|
||||
// stored di merge dati in vocabolario
|
||||
storedRes = localDbCtx
|
||||
var storedRes = localDbCtx
|
||||
.Database
|
||||
.ExecuteSqlRaw("exec dbo.stp_Voc_Import");
|
||||
|
||||
|
||||
@@ -2231,11 +2231,24 @@ namespace WebDoorCreator.Data.Services
|
||||
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<bool> VocLemmaInsert(string rootPath)
|
||||
public async Task<Dictionary<string, Dictionary<string, string>>?> VocLemmaTEMPGetAll()
|
||||
{
|
||||
bool fatto = false;
|
||||
string source = "DB";
|
||||
Dictionary<string, Dictionary<string, string>>? dbResult = new Dictionary<string, Dictionary<string, string>>();
|
||||
// cerco da cache
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
dbResult = dbController.VocLemmaTEMPGetAll();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public async Task<List<VocabularyTempModel>> VocLemmaInsertPrepare(string rootPath)
|
||||
{
|
||||
//bool fatto = false;
|
||||
await Task.Delay(1);
|
||||
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -2271,7 +2284,24 @@ namespace WebDoorCreator.Data.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
fatto = await dbController.VocLemmaInsert(VocLemmas);
|
||||
await dbController.VocLemmaInsertPrepare(VocLemmas);
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaInsertPrepare in: {ts.TotalMilliseconds} ms");
|
||||
return VocLemmas;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<bool> VocLemmaInsert()
|
||||
{
|
||||
bool fatto = false;
|
||||
|
||||
List<VocabularyTempModel> VocLemmas = new List<VocabularyTempModel>();
|
||||
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
fatto = await dbController.VocLemmaInsert();
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"VocLemmaInsert in: {ts.TotalMilliseconds} ms");
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebDoorCreator.Data.User
|
||||
{
|
||||
public class ClaimConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(System.Security.Claims.Claim));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
string type = (string)jo["Type"];
|
||||
string value = (string)jo["Value"];
|
||||
string valueType = (string)jo["ValueType"];
|
||||
string issuer = (string)jo["Issuer"];
|
||||
string originalIssuer = (string)jo["OriginalIssuer"];
|
||||
return new Claim(type, value, valueType, issuer, originalIssuer);
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,17 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace WebDoorCreator.Data.User
|
||||
{
|
||||
/// <summary>
|
||||
/// Classe generalizzaizone identity (user + roles + claims) x gestione semplificata in editing
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class UserData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public List<System.Security.Claims.Claim> Claims { get; set; } = new List<System.Security.Claims.Claim>();
|
||||
public List<Claim> Claims { get; set; } = new List<Claim>();
|
||||
|
||||
public IdentityUser Identity { get; set; } = null!;
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>
|
||||
|
||||
<input @bind-value="@defaultPath" />
|
||||
|
||||
@*@if (vocLemmas != null)
|
||||
{
|
||||
@foreach (var item in vocLemmas)
|
||||
{
|
||||
@foreach (var k in item.Value)
|
||||
{
|
||||
@*<div>@($"{k.Key} --> {k.Value}")</div>
|
||||
@if(vocLemmasTEMP != null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}*@
|
||||
|
||||
@if (showList)
|
||||
{
|
||||
|
||||
|
||||
@if (vocLemmas2Dict != null && vocLemmasTEMP2Dict != null)
|
||||
{
|
||||
@foreach (var item in vocLemmasTEMP2Dict)
|
||||
{
|
||||
@if (!vocLemmas2Dict.ContainsKey(item.Key))
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-12 text-success">@($"{item.Key} --> {vocLemmasTEMP2Dict[item.Key]}")</div>
|
||||
</div>
|
||||
}
|
||||
else if (item.Value != vocLemmas2Dict[item.Key])
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-6 text-danger text-decoration-line-through">@($"{item.Key} --> {vocLemmas2Dict[item.Key]}")</div>
|
||||
<div class="col-6 text-success">@($"{item.Key} --> {item.Value}")</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using WebDoorCreator.Data.Services;
|
||||
|
||||
namespace WebDoorCreator.UI.Components.FilesMan
|
||||
{
|
||||
public partial class FilesRefresh
|
||||
{
|
||||
[Inject]
|
||||
protected WebDoorCreatorService WDCService { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public string lang { get; set; } = "";
|
||||
|
||||
protected Dictionary<string, Dictionary<string, string>>? vocLemmas { get; set; } = null;
|
||||
protected Dictionary<string, string> vocLemmas2Dict { get; set; } = new Dictionary<string, string>();
|
||||
protected Dictionary<string, Dictionary<string, string>>? vocLemmasTEMP { get; set; } = null;
|
||||
protected Dictionary<string, string> vocLemmasTEMP2Dict { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
protected bool showList { get; set; } = false;
|
||||
|
||||
protected async override Task OnParametersSetAsync()
|
||||
{
|
||||
var rawVoc = await WDCService.VocLemmaGetAll();
|
||||
if (rawVoc != null)
|
||||
{
|
||||
vocLemmas = rawVoc.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
|
||||
if(vocLemmas != null)
|
||||
{
|
||||
foreach(var kvp in vocLemmas)
|
||||
{
|
||||
foreach(var item in kvp.Value)
|
||||
{
|
||||
vocLemmas2Dict.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
protected async Task refreshVoc()
|
||||
{
|
||||
vocLemmasTEMP = null;
|
||||
await Task.Delay(1);
|
||||
list2Mod = await WDCService.VocLemmaInsertPrepare(@$"{defaultPath}");
|
||||
if (list2Mod != null)
|
||||
{
|
||||
//bool ok = await WDCService.VocLemmaInsert();
|
||||
var k = await WDCService.VocLemmaTEMPGetAll();
|
||||
if (k != null)
|
||||
{
|
||||
vocLemmasTEMP = k.Where(x => x.Key == lang).ToDictionary(x => x.Key, x => x.Value);
|
||||
if (vocLemmasTEMP != null)
|
||||
{
|
||||
foreach (var kvp in vocLemmasTEMP)
|
||||
{
|
||||
foreach (var item in kvp.Value)
|
||||
{
|
||||
vocLemmasTEMP2Dict.Add(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
showList = true;
|
||||
}
|
||||
List<VocabularyTempModel> list2Mod = new List<VocabularyTempModel>();
|
||||
|
||||
protected string defaultPath { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@
|
||||
{
|
||||
@if (compToShow != null)
|
||||
{
|
||||
<input class="form-control form-control-sm" value="@compToShow.CompanyName" disabled/>
|
||||
<input class="form-control form-control-sm" value="@compToShow.CompanyName" disabled />
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Claims;
|
||||
using WebDoorCreator.Core;
|
||||
using WebDoorCreator.Data.User;
|
||||
|
||||
@@ -118,6 +119,27 @@ namespace WebDoorCreator.UI.Data
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua reset dati utente...
|
||||
/// </summary>
|
||||
/// <param name="resetAll">Indica reset completo (anche dati elenco di base)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResetUserDataCache(bool resetAll)
|
||||
{
|
||||
bool fatto = false;
|
||||
RedisValue pattern = new RedisValue($"{Constants.rKeyUsersAll}");
|
||||
if (resetAll)
|
||||
{
|
||||
fatto = await ExecFlushRedisPattern(pattern);
|
||||
}
|
||||
// ora resetto il resto
|
||||
pattern = new RedisValue($"{Constants.rKeyUsersData}:*");
|
||||
fatto = fatto && await ExecFlushRedisPattern(pattern);
|
||||
//pattern = new RedisValue($"{Constants.rKeyUsersDataSearch}:*");
|
||||
//fatto = fatto && await ExecFlushRedisPattern(pattern);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente (TUTTI) da REDIS o DB
|
||||
/// </summary>
|
||||
@@ -161,66 +183,37 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente (singolo x UserId)
|
||||
/// Dati utente (singolo x searchVal)
|
||||
/// </summary>
|
||||
/// <param name="UserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UserData> UserDataGetById(string UserId)
|
||||
{
|
||||
string source = "DB";
|
||||
string source = "FULL";
|
||||
UserData dataResult = new UserData();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersDataId}:{UserId}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = "";// await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
// uso metodi helper protected di base...
|
||||
var userRaw = await UserIdentityById(UserId);
|
||||
var userIdent = new IdentityUser
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<UserData>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dataResult = new UserData();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
Id = userRaw.Id,
|
||||
UserName = userRaw.UserName,
|
||||
Email = userRaw.Email,
|
||||
PhoneNumber = userRaw.PhoneNumber,
|
||||
PasswordHash = "*****",
|
||||
EmailConfirmed = userRaw.EmailConfirmed
|
||||
};
|
||||
// cerco ruoli & claims
|
||||
var UserRoles = await UserRolesById(userIdent);
|
||||
var UserClaims = await UserClaimsById(userIdent);
|
||||
// compongo output
|
||||
dataResult = new UserData()
|
||||
{
|
||||
// Collezione dati raw
|
||||
var userRaw = await _userManager.FindByIdAsync(UserId);
|
||||
if (userRaw != null)
|
||||
{
|
||||
var userIdent = new IdentityUser
|
||||
{
|
||||
Id = userRaw.Id,
|
||||
UserName = userRaw.UserName,
|
||||
Email = userRaw.Email,
|
||||
PhoneNumber = userRaw.PhoneNumber,
|
||||
PasswordHash = "*****",
|
||||
EmailConfirmed = userRaw.EmailConfirmed
|
||||
};
|
||||
// cerco ruoli & claims
|
||||
var UserRoles = await _userManager.GetRolesAsync(userIdent);
|
||||
var UserClaims = await _userManager.GetClaimsAsync(userIdent);
|
||||
// compongo output
|
||||
dataResult = new UserData()
|
||||
{
|
||||
Identity = userIdent,
|
||||
Roles = UserRoles.ToList(),
|
||||
Claims = UserClaims.ToList()
|
||||
};
|
||||
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new UserData();
|
||||
}
|
||||
Identity = userIdent,
|
||||
Roles = UserRoles,
|
||||
Claims = UserClaims
|
||||
};
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"UserDataGetById | {source} in: {ts.TotalMilliseconds} ms");
|
||||
@@ -228,75 +221,41 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente (filtrati da UserId)
|
||||
/// Dati utente (filtrati da searchVal)
|
||||
/// </summary>
|
||||
/// <param name="searchVal"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserData>> UserDataGetFilt(string searchVal)
|
||||
{
|
||||
string source = "DB";
|
||||
string source = "FULL";
|
||||
List<UserData> dataResult = new List<UserData>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersDataSearch}:{searchVal}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = "";// await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
// uso metodi helper protected di base...
|
||||
List<IdentityUser> RawList = await UserIdentityBySearch(searchVal);
|
||||
// conversione
|
||||
var user = RawList.Select(x => new IdentityUser
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<UserData>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dataResult = new List<UserData>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
Id = x.Id,
|
||||
UserName = x.UserName,
|
||||
Email = x.Email,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
PasswordHash = "*****",
|
||||
EmailConfirmed = x.EmailConfirmed
|
||||
}).ToList();
|
||||
foreach (var item in user)
|
||||
{
|
||||
// Collezione dati raw
|
||||
List<IdentityUser> RawList = new List<IdentityUser>();
|
||||
//List<UserData> UsersList = new List<UserData>();
|
||||
var allData = await UserDataGetAll();
|
||||
if (!string.IsNullOrEmpty(searchVal))
|
||||
{
|
||||
RawList = allData.Where(x => x.NormalizedEmail.Contains(searchVal.ToUpper()) || x.NormalizedUserName.Contains(searchVal.ToUpper())).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
RawList = allData;
|
||||
}
|
||||
var user = RawList.Select(x => new IdentityUser
|
||||
{
|
||||
Id = x.Id,
|
||||
UserName = x.UserName,
|
||||
Email = x.Email,
|
||||
PhoneNumber = x.PhoneNumber,
|
||||
PasswordHash = "*****",
|
||||
EmailConfirmed = x.EmailConfirmed
|
||||
}).ToList();
|
||||
// cerco ruoli & claims
|
||||
var UserRoles = await UserRolesById(item);
|
||||
var UserClaims = await UserClaimsById(item);
|
||||
|
||||
foreach (var item in user)
|
||||
var newItem = new UserData()
|
||||
{
|
||||
var UserRoles = await _userManager.GetRolesAsync(item);
|
||||
var UserClaims = await _userManager.GetClaimsAsync(item);
|
||||
|
||||
var newItem = new UserData()
|
||||
{
|
||||
Identity = item,
|
||||
Roles = UserRoles.ToList(),
|
||||
Claims = UserClaims.ToList()
|
||||
};
|
||||
dataResult.Add(newItem);
|
||||
}
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, FastCache);
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new List<UserData>();
|
||||
Identity = item,
|
||||
Roles = UserRoles,
|
||||
Claims = UserClaims
|
||||
};
|
||||
dataResult.Add(newItem);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
@@ -304,27 +263,6 @@ namespace WebDoorCreator.UI.Data
|
||||
return dataResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua reset dati utente...
|
||||
/// </summary>
|
||||
/// <param name="resetAll">Indica reset completo (anche dati elenco di base)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> ResetUserDataCache(bool resetAll)
|
||||
{
|
||||
bool fatto = false;
|
||||
RedisValue pattern = new RedisValue($"{Constants.rKeyUsersAll}");
|
||||
if (resetAll)
|
||||
{
|
||||
fatto = await ExecFlushRedisPattern(pattern);
|
||||
}
|
||||
// ora resetto il resto
|
||||
pattern = new RedisValue($"{Constants.rKeyUsersDataId}:*");
|
||||
fatto = fatto && await ExecFlushRedisPattern(pattern);
|
||||
pattern = new RedisValue($"{Constants.rKeyUsersDataSearch}:*");
|
||||
fatto = fatto && await ExecFlushRedisPattern(pattern);
|
||||
return fatto;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
@@ -369,6 +307,169 @@ namespace WebDoorCreator.UI.Data
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente CLAIMS da REDIS o DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<List<Claim>> UserClaimsById(IdentityUser UserIdent)
|
||||
{
|
||||
string source = "DB";
|
||||
List<Claim> dataResult = new List<Claim>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersData}:Claims:{UserIdent.Id}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<Claim>>(rawData, new ClaimConverter());
|
||||
if (tempResult != null)
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var rawResult = await _userManager.GetClaimsAsync(UserIdent);
|
||||
dataResult = rawResult.ToList();
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new List<Claim>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"UserClaimsById | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dataResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente IDENTITY da REDIS o DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<IdentityUser> UserIdentityById(string UserId)
|
||||
{
|
||||
string source = "DB";
|
||||
IdentityUser dataResult = new IdentityUser();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersData}:Identity:{UserId}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<IdentityUser>(rawData);
|
||||
if (tempResult != null)
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataResult = await _userManager.FindByIdAsync(UserId);
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new IdentityUser();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"UserIdentityById | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dataResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente IDENTITY in modalità SEARCH da REDIS o DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<List<IdentityUser>> UserIdentityBySearch(string searchVal)
|
||||
{
|
||||
string source = "DB";
|
||||
List<IdentityUser> dataResult = new List<IdentityUser>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersDataSearch}:{searchVal}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<IdentityUser>>(rawData);
|
||||
if (tempResult != null)
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var allData = await UserDataGetAll();
|
||||
if (!string.IsNullOrEmpty(searchVal))
|
||||
{
|
||||
dataResult = allData
|
||||
.Where(x => x.NormalizedEmail.Contains(searchVal.ToUpper()) || x.NormalizedUserName.Contains(searchVal.ToUpper())).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataResult = allData;
|
||||
}
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new List<IdentityUser>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"UserIdentityBySearch | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dataResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dati utente ROLES da REDIS o DB
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task<List<string>> UserRolesById(IdentityUser UserIdent)
|
||||
{
|
||||
string source = "DB";
|
||||
List<string> dataResult = new List<string>();
|
||||
// cerco da cache
|
||||
string currKey = $"{Constants.rKeyUsersData}:Roles:{UserIdent.Id}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<string>>(rawData);
|
||||
if (tempResult != null)
|
||||
{
|
||||
dataResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var rawResult = await _userManager.GetRolesAsync(UserIdent);
|
||||
dataResult = rawResult.ToList();
|
||||
rawData = JsonConvert.SerializeObject(dataResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
if (dataResult == null)
|
||||
{
|
||||
dataResult = new List<string>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"UserRolesById | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dataResult;
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn btn-warning" @onclick="()=>refreshHw()">HARDWARE REFRESH</button>
|
||||
<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>
|
||||
@*<button class="btn btn-info" @onclick="()=>refreshVoc()">VOCABULARY REFRESH</button>*@
|
||||
<button class="btn btn-info" @onclick="()=>refreshFiles()">FILES REFRESH</button>
|
||||
</div>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<UserList></UserList>
|
||||
<FilesRefresh lang="EN"></FilesRefresh>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -312,11 +312,13 @@ namespace WebDoorCreator.UI.Pages
|
||||
await Task.Delay(1);
|
||||
await WDService.CompoListSetAll(@$"{defaultPath}");
|
||||
}
|
||||
#if false
|
||||
protected async Task refreshVoc()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await WDService.VocLemmaInsert(@$"{defaultPath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
protected async Task refreshFiles()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
|
||||
@@ -101,6 +101,11 @@ else
|
||||
<h3>User Administration</h3>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between gap-3 mb-1">
|
||||
<div class="input-group" title="Search">
|
||||
<span class="input-group-text"><i class="fa-solid fa-magnifying-glass"></i></span>
|
||||
<input class="form-control" placeholder="Search" @bind="@searchVal">
|
||||
<button class="input-group-text" @onclick="resetSearch"><i class="fa-solid fa-xmark"></i></button>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-user-tag"></i></span>
|
||||
<select class="form-select" @bind="@FiltUserRole">
|
||||
@@ -112,7 +117,6 @@ else
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
@*<span class="input-group-text">ROLES</span>*@
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa-solid fa-building"></i></span>
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using WebDoorCreator.Data.Services;
|
||||
using WebDoorCreator.Data.User;
|
||||
@@ -28,19 +29,36 @@ namespace WebDoorCreator.UI.Pages
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public string searchVal
|
||||
protected string searchVal
|
||||
{
|
||||
get
|
||||
get => _searchVal;
|
||||
set
|
||||
{
|
||||
return AppMService.SearchVal;
|
||||
if (value != _searchVal)
|
||||
{
|
||||
_searchVal = value;
|
||||
var pUpd = Task.Run(async () =>
|
||||
{
|
||||
await ReloadData();
|
||||
});
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetSearch()
|
||||
{
|
||||
searchVal = "";
|
||||
}
|
||||
|
||||
|
||||
private string _searchVal { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public List<string> ConvertClaim(List<System.Security.Claims.Claim> ClaimList)
|
||||
public List<string> ConvertClaim(List<Claim> ClaimList)
|
||||
{
|
||||
List<string> answ = new List<string>();
|
||||
|
||||
@@ -126,7 +144,9 @@ namespace WebDoorCreator.UI.Pages
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
AppMService.EA_SearchUpdated -= OnSeachUpdated;
|
||||
#if false
|
||||
AppMService.EA_SearchUpdated -= OnSeachUpdated;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,9 +165,7 @@ namespace WebDoorCreator.UI.Pages
|
||||
// filtro visualizzazione x Company, SE richeisto
|
||||
if (FiltCompany != "0")
|
||||
{
|
||||
System.Security.Claims.Claim cClaim = new System.Security.Claims.Claim("CompanyId", $"{FiltCompany}");
|
||||
UsersAll = UsersAll
|
||||
//.Where(x => x.Claims.Any(c => c == cClaim))
|
||||
.Where(x => x.Claims.Any(c => c.Type == "CompanyId" && c.Value == $"{FiltCompany}"))
|
||||
.ToList();
|
||||
}
|
||||
@@ -162,7 +180,7 @@ namespace WebDoorCreator.UI.Pages
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public string ShowClaims(List<System.Security.Claims.Claim> ClaimList)
|
||||
public string ShowClaims(List<Claim> ClaimList)
|
||||
{
|
||||
string answ = string.Join(",", ConvertClaim(ClaimList));
|
||||
return answ;
|
||||
@@ -184,8 +202,10 @@ namespace WebDoorCreator.UI.Pages
|
||||
[Inject]
|
||||
protected UserManager<IdentityUser> _UserManager { get; set; } = null!;
|
||||
|
||||
#if false
|
||||
[Inject]
|
||||
protected MessageService AppMService { get; set; } = null!;
|
||||
protected MessageService AppMService { get; set; } = null!;
|
||||
#endif
|
||||
|
||||
[Inject]
|
||||
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!;
|
||||
@@ -230,8 +250,11 @@ namespace WebDoorCreator.UI.Pages
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
searchVal = "";
|
||||
#if false
|
||||
AppMService.ShowSearch = true;
|
||||
AppMService.EA_SearchUpdated += OnSeachUpdated;
|
||||
AppMService.EA_SearchUpdated += OnSeachUpdated;
|
||||
#endif
|
||||
// lettura dati
|
||||
await ReloadData();
|
||||
#if false
|
||||
@@ -298,9 +321,9 @@ namespace WebDoorCreator.UI.Pages
|
||||
[Inject]
|
||||
private IConfiguration Configuration { get; set; } = null!;
|
||||
|
||||
private System.Security.Claims.Claim CurrentUserClaim
|
||||
private Claim CurrentUserClaim
|
||||
{
|
||||
get => new System.Security.Claims.Claim(CurrentUserClaimType, CurrentUserClaimVal);
|
||||
get => new Claim(CurrentUserClaimType, CurrentUserClaimVal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.9.2305.2909</Version>
|
||||
<Version>0.9.2305.2916</Version>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
@using WebDoorCreator.UI.Components.SvgComp
|
||||
@using WebDoorCreator.UI.Components.Filters
|
||||
@using WebDoorCreator.UI.Components.Report
|
||||
@using WebDoorCreator.UI.Components.FilesMan
|
||||
@using WebDoorCreator.UI.Shared
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user