Step x invio clienti su F.I.C.....
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<UserSecretsId>60fcdaab-6c1e-4bec-9d88-f7727ef1c12c</UserSecretsId>
|
||||
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
|
||||
<Version>1.0.2301.2618</Version>
|
||||
<Version>1.0.2301.2619</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,24 +3,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using SHERPA.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SHERPA.Data.Controllers
|
||||
{
|
||||
public class SInManController : IDisposable
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Constructors
|
||||
|
||||
public SInManController(IConfiguration configuration)
|
||||
@@ -33,6 +20,123 @@ namespace SHERPA.Data.Controllers
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Elimina item AccoDoc (Accounting Document)
|
||||
/// </summary>
|
||||
/// <param name="FattId"></param>
|
||||
/// <returns></returns>
|
||||
public bool AccoDocDelete(int FattId)
|
||||
{
|
||||
bool done = false;
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var item2del = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => x.IdxFatt == FattId)
|
||||
.FirstOrDefault();
|
||||
if (item2del != null)
|
||||
{
|
||||
dbCtx.DbSetAccoDocs.Remove(item2del);
|
||||
dbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera AccoDoc (Accounting Document) da Key
|
||||
/// </summary>
|
||||
/// <param name="newItem"></param>
|
||||
/// <returns></returns>
|
||||
public AccoDocModel AccoDocGetByKey(int DocId)
|
||||
{
|
||||
AccoDocModel currDoc = new AccoDocModel();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
currDoc = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => x.IdxFatt == DocId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return currDoc;
|
||||
}
|
||||
|
||||
/// <returns></returns>
|
||||
public List<AccoDocModel> AccoDocGetFilt(int anno, int numero, string tipoDoc, bool soloMod, string searchVal)
|
||||
{
|
||||
List<AccoDocModel> dbResult = new List<AccoDocModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => (x.Anno == anno || anno == 0) && (x.Num == numero || numero == 0) && ((x.Changed > 0 && soloMod) || !soloMod) && (x.Tipo == tipoDoc || string.IsNullOrEmpty(tipoDoc)) && ((x.CustomerNav != null && x.CustomerNav.RagSoc != null && x.CustomerNav.RagSoc.Contains(searchVal)) || string.IsNullOrEmpty(searchVal)))
|
||||
.Include(d => d.RigheFattNav)
|
||||
.Include(d => d.CustomerNav)
|
||||
.Include(d => d.ContributiNav)
|
||||
.Include(d => d.ScadenzeNav)
|
||||
.Include(d => d.PagamentiNav)
|
||||
.OrderByDescending(x => x.Anno)
|
||||
.ThenByDescending(x => x.Num)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ultimi AccoDoc (Accounting Document)
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <returns></returns>
|
||||
public List<AccoDocModel> AccoDocGetLastDesc(int numRecord)
|
||||
{
|
||||
List<AccoDocModel> dbResult = new List<AccoDocModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
// se numRecord = 0 --> passo tutti
|
||||
if (numRecord == 0)
|
||||
{
|
||||
numRecord = dbCtx.DbSetAccoDocs.Count();
|
||||
}
|
||||
dbResult = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.OrderByDescending(x => x.Anno)
|
||||
.ThenByDescending(x => x.Num)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lista configurazione
|
||||
/// </summary>
|
||||
/// <param name="dtStart"></param>
|
||||
/// <param name="dtEnd"></param>
|
||||
/// <returns></returns>
|
||||
public List<ConfigModel> ConfigGetAll()
|
||||
{
|
||||
List<ConfigModel> dbResult = new List<ConfigModel>();
|
||||
using (SHERPAFattContext localDbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetConfig
|
||||
.OrderBy(x => x.Chiave)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public int CustomersCount()
|
||||
{
|
||||
int answ = 0;
|
||||
@@ -64,7 +168,6 @@ namespace SHERPA.Data.Controllers
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Elenco Customers che richiedono sync tramite stored
|
||||
/// </summary>
|
||||
@@ -80,7 +183,7 @@ namespace SHERPA.Data.Controllers
|
||||
SqlParameter Tipo = new SqlParameter("@tipo", tipoDoc);
|
||||
SqlParameter Anno = new SqlParameter("@anno", anno);
|
||||
SqlParameter NotUpl = new SqlParameter("@notUpl", notUpl);
|
||||
|
||||
|
||||
dbResult = dbCtx
|
||||
.DbSetCustomers
|
||||
.FromSqlRaw("EXEC stp_clienti_getByAnno @tipo,@anno,@notUpl", Tipo, Anno, NotUpl)
|
||||
@@ -145,113 +248,14 @@ namespace SHERPA.Data.Controllers
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elimina item AccoDoc (Accounting Document)
|
||||
/// </summary>
|
||||
/// <param name="FattId"></param>
|
||||
/// <returns></returns>
|
||||
public bool AccoDocDelete(int FattId)
|
||||
{
|
||||
bool done = false;
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var item2del = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => x.IdxFatt == FattId)
|
||||
.FirstOrDefault();
|
||||
if (item2del != null)
|
||||
{
|
||||
dbCtx.DbSetAccoDocs.Remove(item2del);
|
||||
dbCtx.SaveChanges();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera AccoDoc (Accounting Document) da Key
|
||||
/// </summary>
|
||||
/// <param name="newItem"></param>
|
||||
/// <returns></returns>
|
||||
public AccoDocModel AccoDocGetByKey(int DocId)
|
||||
{
|
||||
AccoDocModel currDoc = new AccoDocModel();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
currDoc = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => x.IdxFatt == DocId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return currDoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ultimi AccoDoc (Accounting Document)
|
||||
/// </summary>
|
||||
/// <param name="numRecord"></param>
|
||||
/// <returns></returns>
|
||||
public List<AccoDocModel> AccoDocGetLastDesc(int numRecord)
|
||||
{
|
||||
List<AccoDocModel> dbResult = new List<AccoDocModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
// se numRecord = 0 --> passo tutti
|
||||
if (numRecord == 0)
|
||||
{
|
||||
numRecord = dbCtx.DbSetAccoDocs.Count();
|
||||
}
|
||||
dbResult = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.OrderByDescending(x => x.Anno)
|
||||
.ThenByDescending(x => x.Num)
|
||||
.Take(numRecord)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco AccoDoc (Accounting Document) filtrati
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="anno">anno di riferimento (0: tutti)</param>
|
||||
/// <param name="numero">num documento (0: tutti)</param>
|
||||
/// <param name="tipoDoc">tipo Doc</param>
|
||||
/// <param name="soloMod">Solo documenti modificati (da inviare in cloud)</param>
|
||||
/// <param name="searchVal">Ricerca libera</param>
|
||||
|
||||
/// <returns></returns>
|
||||
public List<AccoDocModel> AccoDocGetFilt(int anno, int numero, string tipoDoc, bool soloMod, string searchVal)
|
||||
{
|
||||
List<AccoDocModel> dbResult = new List<AccoDocModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetAccoDocs
|
||||
.Where(x => (x.Anno == anno || anno == 0) && (x.Num == numero || numero == 0) && ((x.Changed > 0 && soloMod) || !soloMod) && (x.Tipo == tipoDoc || string.IsNullOrEmpty(tipoDoc)) && ((x.CustomerNav != null && x.CustomerNav.RagSoc != null && x.CustomerNav.RagSoc.Contains(searchVal)) || string.IsNullOrEmpty(searchVal)))
|
||||
.Include(d => d.RigheFattNav)
|
||||
.Include(d => d.CustomerNav)
|
||||
.Include(d => d.ContributiNav)
|
||||
.Include(d => d.ScadenzeNav)
|
||||
.Include(d => d.PagamentiNav)
|
||||
.OrderByDescending(x => x.Anno)
|
||||
.ThenByDescending(x => x.Num)
|
||||
.ToList();
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiunge un nuovo item Doc
|
||||
/// </summary>
|
||||
@@ -275,6 +279,7 @@ namespace SHERPA.Data.Controllers
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Conteggio documenti x criteri
|
||||
/// </summary>
|
||||
@@ -339,10 +344,9 @@ namespace SHERPA.Data.Controllers
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Elenco AccoDoc (Accounting Document) filtrati
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="anno">anno di riferimento (0: tutti)</param>
|
||||
/// <param name="idxCli">Idx Cliente (0: tutti)</param>
|
||||
/// <param name="tipoDoc">tipo Doc (*=tutti)</param>
|
||||
@@ -378,7 +382,6 @@ namespace SHERPA.Data.Controllers
|
||||
|
||||
public List<vSelCliModel> VSelCliGetAll()
|
||||
{
|
||||
|
||||
List<vSelCliModel> dbResult = new List<vSelCliModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
@@ -389,9 +392,9 @@ namespace SHERPA.Data.Controllers
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public List<vSelGruppiModel> VSelGruppiGetAll()
|
||||
{
|
||||
|
||||
List<vSelGruppiModel> dbResult = new List<vSelGruppiModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
@@ -402,9 +405,9 @@ namespace SHERPA.Data.Controllers
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
public List<vSelTipoModel> VSelTipoGetAll()
|
||||
{
|
||||
|
||||
List<vSelTipoModel> dbResult = new List<vSelTipoModel>();
|
||||
using (SHERPAFattContext dbCtx = new SHERPAFattContext(_configuration))
|
||||
{
|
||||
@@ -417,5 +420,12 @@ namespace SHERPA.Data.Controllers
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private static IConfiguration _configuration = null!;
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace SHERPA.Data
|
||||
{
|
||||
public class QHelper
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Blazor: get query parm from the URL
|
||||
/// </summary>
|
||||
/// <param name="parmName"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetQueryParm(string fullUri, string parmName)
|
||||
{
|
||||
var uriBuilder = new UriBuilder(fullUri);
|
||||
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
|
||||
return q[parmName] ?? "";
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
</div>
|
||||
<div class="pe-2">
|
||||
<div class="btn-group" role="group">
|
||||
<button type="button" class="btn @cssToken" title="Test Token" @onclick="() => fixToken()">
|
||||
<button type="button" class="btn @cssToken" title="Test Token" @onclick="() => ReloadData()">
|
||||
<i class="fa-solid fa-cloud"></i>
|
||||
</button>
|
||||
<button type="button" class="btn @cssApi" title="Test Comunicazione">
|
||||
<button type="button" class="btn @cssApi" title="Test Comunicazione" @onclick="() => tryGetToken()">
|
||||
<i class="fa-solid fa-certificate"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ using It.FattureInCloud.Sdk.OauthHelper;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.JSInterop;
|
||||
using SHERPA.Data;
|
||||
using SHERPA.IM.Data;
|
||||
|
||||
namespace SHERPA.IM.Components
|
||||
@@ -43,15 +44,27 @@ namespace SHERPA.IM.Components
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
initConf();
|
||||
await forceReload();
|
||||
// init
|
||||
await initConf();
|
||||
// cerco x prima cosa eventuale codice OAuth in URL...
|
||||
code = QHelper.GetQueryParm(NavManager.Uri, "code");
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
// verifica token
|
||||
tryGetToken();
|
||||
}
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private string CLIENT_ID = "";
|
||||
private string CLIENT_SECRET = "";
|
||||
private string code = "";
|
||||
private bool hasToken = false;
|
||||
private string JumpUrl = "";
|
||||
private bool okApi = false;
|
||||
private string userName = "";
|
||||
|
||||
@@ -59,6 +72,9 @@ namespace SHERPA.IM.Components
|
||||
|
||||
#region Private Properties
|
||||
|
||||
[Inject]
|
||||
private IConfiguration Configuration { get; set; } = null!;
|
||||
|
||||
private string cssApi
|
||||
{
|
||||
get => okApi ? "bg-primary" : "bg-secondary";
|
||||
@@ -76,26 +92,16 @@ namespace SHERPA.IM.Components
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private async Task forceReload()
|
||||
private async Task checkToken()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
if (user.Identity != null && user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
// test token locale
|
||||
var accessToken = await MService.getUserTokenAsync();
|
||||
hasToken = !string.IsNullOrEmpty(accessToken);
|
||||
// test comunicazione ocn Fatture in Cloud...
|
||||
if (hasToken)
|
||||
var tokenData = await MService.getUserTokenAsync();
|
||||
hasToken = tokenData != null;
|
||||
// test comunicazione con Fatture in Cloud...
|
||||
if (tokenData != null)
|
||||
{
|
||||
Configuration config = new Configuration();
|
||||
config.AccessToken = accessToken.Replace(@"\", "");
|
||||
config.AccessToken = tokenData.AccessToken.Replace(@"\", "");
|
||||
try
|
||||
{
|
||||
var userApiInstance = new UserApi(config);
|
||||
@@ -109,35 +115,62 @@ namespace SHERPA.IM.Components
|
||||
}
|
||||
}
|
||||
|
||||
private string JumpUrl = "";
|
||||
private string CLIENT_ID = "Cz12xh57900cepFGMQq8yLAa7x8pcSp4";
|
||||
private string CLIENT_SECRET = "PL6kvy0czp6O5sScpovXo7zXwCtSZLPZGJAWpCPl9wGkFnRYrmw16r8C56aLMXQv\r\n";
|
||||
|
||||
/// <summary>
|
||||
/// Effettua recupero token da fatture in cloud...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async Task fixToken()
|
||||
{
|
||||
initConf();
|
||||
//string code = HttpContext.Request.Query["code"];
|
||||
//var oauth = new OAuth2AuthorizationCodeManager(CLIENT_ID, CLIENT_SECRET, "https://localhost:7208/index");
|
||||
}
|
||||
|
||||
private async void initConf()
|
||||
private async Task initConf()
|
||||
{
|
||||
JumpUrl = Configuration.GetValue<string>("Application:JumpUrl");
|
||||
//CLIENT_ID= await SDService.
|
||||
var confCliId = await SDService.ConfigGetKey("FIC_CLIENT_ID");
|
||||
CLIENT_ID = confCliId?.Valore ?? "";
|
||||
var confCliSec = await SDService.ConfigGetKey("FIC_CLIENT_SECRET");
|
||||
CLIENT_SECRET = confCliSec?.Valore ?? "";
|
||||
}
|
||||
|
||||
[Inject]
|
||||
private IConfiguration Configuration { get; set; } = null!;
|
||||
private async void MService_EA_ShowSearch()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await InvokeAsync(() => StateHasChanged());
|
||||
}
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
if (user.Identity != null && user.Identity.IsAuthenticated)
|
||||
{
|
||||
userName = $"{user.Identity.Name}";
|
||||
}
|
||||
else
|
||||
{
|
||||
userName = "N.A.";
|
||||
}
|
||||
await checkToken();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua recupero token da fatture in cloud...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async void tryGetToken()
|
||||
{
|
||||
var oauth = new OAuth2AuthorizationCodeManager(CLIENT_ID, CLIENT_SECRET, JumpUrl);
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
await checkToken();
|
||||
if (!hasToken)
|
||||
{
|
||||
var scopes = new List<Scope> { Scope.ENTITY_SUPPLIERS_ALL, Scope.ENTITY_CLIENTS_ALL };
|
||||
var url = oauth.GetAuthorizationUrl(scopes, "AUTH_SHERPA");
|
||||
// rimando a pagina fatture in cloud x auth
|
||||
NavManager.NavigateTo(url, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OAuth2AuthorizationCodeTokenResponse token = oauth.FetchToken(code);
|
||||
await MService.setUserTokenAsync(token);
|
||||
}
|
||||
await ReloadData();
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using It.FattureInCloud.Sdk.Api;
|
||||
using It.FattureInCloud.Sdk.Client;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using SHERPA.Data.DbModels;
|
||||
using SHERPA.IM.Data;
|
||||
@@ -54,10 +56,39 @@ namespace SHERPA.IM.Components
|
||||
private async Task syncCurrent(CustomerModel currItem)
|
||||
{
|
||||
IsSynching = true;
|
||||
// prova a cercare il customer dato partita iva...
|
||||
|
||||
await Task.Delay(1500);
|
||||
IsSynching = false;
|
||||
}
|
||||
|
||||
[Inject]
|
||||
protected MessageService MService { get; set; } = null!;
|
||||
private bool hasToken = false;
|
||||
private async Task checkToken(string vat)
|
||||
{
|
||||
// test token locale
|
||||
var tokenData = await MService.getUserTokenAsync();
|
||||
hasToken = tokenData != null;
|
||||
// se ho token provo a chiamare Fatture in Cloud...
|
||||
if (tokenData != null)
|
||||
{
|
||||
// Configuration config = new Configuration();
|
||||
// config.AccessToken = tokenData.AccessToken.Replace(@"\", "");
|
||||
// try
|
||||
// {
|
||||
// var userApiInstance = new UserApi(config);
|
||||
// // Retrieve User Companies
|
||||
// var userCompaniesResponse = userApiInstance.ListUserCompanies();
|
||||
// var firstCompanyId = userCompaniesResponse.Data.Companies[0].Id ?? 0;
|
||||
// okApi = firstCompanyId > 0;
|
||||
// }
|
||||
// catch
|
||||
// { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using It.FattureInCloud.Sdk.OauthHelper;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace SHERPA.IM.Data
|
||||
@@ -22,13 +25,13 @@ namespace SHERPA.IM.Data
|
||||
/// Restituisce il valore del token F.I.C. da localstorage
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<string> getUserTokenAsync()
|
||||
public async Task<OAuth2AuthorizationCodeTokenResponse?> getUserTokenAsync()
|
||||
{
|
||||
string answ = "";
|
||||
OAuth2AuthorizationCodeTokenResponse? answ = null;
|
||||
var result = await localStorage.GetItemAsync<string>(KeyTokenFIC);
|
||||
if (result != null)
|
||||
{
|
||||
answ = result;
|
||||
answ = JsonConvert.DeserializeObject<OAuth2AuthorizationCodeTokenResponse>(result);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
@@ -36,14 +39,15 @@ namespace SHERPA.IM.Data
|
||||
/// <summary>
|
||||
/// Scrive il valore del token F.I.C. nel localstoragee
|
||||
/// </summary>
|
||||
/// <param name="newVal"></param>
|
||||
/// <param name="newToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> setUserTokenAsync(string newVal)
|
||||
public async Task<bool> setUserTokenAsync(OAuth2AuthorizationCodeTokenResponse newToken)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
await localStorage.SetItemAsync(KeyTokenFIC, newVal);
|
||||
string rawData = JsonConvert.SerializeObject(newToken);
|
||||
await localStorage.SetItemAsync(KeyTokenFIC, rawData);
|
||||
answ = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -45,6 +45,90 @@ namespace SHERPA.IM.Data
|
||||
|
||||
#endregion Public Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Lista configurazione
|
||||
/// </summary>
|
||||
/// <param name="dtStart"></param>
|
||||
/// <param name="dtEnd"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ConfigModel>> ConfigGetAll()
|
||||
{
|
||||
string source = "DB";
|
||||
List<ConfigModel>? dbResult = new List<ConfigModel>();
|
||||
string currKey = $"{rKeyConfig}:Table";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<List<ConfigModel>>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
dbResult = new List<ConfigModel>();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = tempResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = dbController.ConfigGetAll();
|
||||
rawData = JsonConvert.SerializeObject(dbResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
if (dbResult == null)
|
||||
{
|
||||
dbResult = new List<ConfigModel>();
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ConfigGetAll | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupera una singola chaive di config da cache/DB
|
||||
/// </summary>
|
||||
/// <param name="chiave"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ConfigModel?> ConfigGetKey(string chiave)
|
||||
{
|
||||
string source = "DB";
|
||||
// cerco in cache direttamente la chiave... altrimenti da redis/db
|
||||
ConfigModel? keyResult = null;
|
||||
string currKey = $"{rKeyConfig}:Dict:{chiave}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
source = "REDIS";
|
||||
var tempResult = JsonConvert.DeserializeObject<ConfigModel>(rawData);
|
||||
if (tempResult == null)
|
||||
{
|
||||
keyResult = new ConfigModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
keyResult = tempResult;
|
||||
}
|
||||
keyResult = JsonConvert.DeserializeObject<ConfigModel>(rawData);
|
||||
}
|
||||
else
|
||||
{
|
||||
var listConfig = await ConfigGetAll();
|
||||
keyResult = listConfig.FirstOrDefault(x => x.Chiave == chiave);
|
||||
rawData = JsonConvert.SerializeObject(keyResult, JSSettings);
|
||||
await redisDb.StringSetAsync(currKey, rawData, UltraLongCache);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"ConfigGetKey | {chiave} | {source} in: {ts.TotalMilliseconds} ms");
|
||||
return await Task.FromResult(keyResult);
|
||||
}
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
@@ -271,6 +355,7 @@ namespace SHERPA.IM.Data
|
||||
protected const string rKeySelGruppi = $"{redisBaseAddr}:Cache:vSel:Gruppi";
|
||||
protected const string rKeySelTipo = $"{redisBaseAddr}:Cache:vSel:Tipo";
|
||||
protected const string rKeySyncCust = $"{redisBaseAddr}:Cache:CloudSync:Cust";
|
||||
protected const string rKeyConfig = $"{redisBaseAddr}:Cache:Config";
|
||||
protected static SInManController dbController = null!;
|
||||
protected Random rnd = new Random();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user