Update modalità confronto dati conf
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
using Egw.Core;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MP.AppAuth.Models;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace MP.Land.Data
|
||||
{
|
||||
public class SyncService
|
||||
{
|
||||
/// <summary>
|
||||
/// Init classe
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="logger"></param>
|
||||
public SyncService(IConfiguration configuration, ILogger<LicenseService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
private static ILogger<LicenseService> _logger { get; set; } = null!;
|
||||
private static IConfiguration? _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// URL dell'API x chiamate gestione licenze
|
||||
/// </summary>
|
||||
private static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
|
||||
/// <summary>
|
||||
/// Stato server gestione licenze
|
||||
/// </summary>
|
||||
public async Task<string> checkLimanServer()
|
||||
{
|
||||
string answ = "ND";
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
var request = new RestRequest($"api/health", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// verifico risposta
|
||||
if (response.Content != null)
|
||||
{
|
||||
answ = response.Content.Replace("\"", "");
|
||||
}
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
public List<AnagKeyValueModel> AKVList { get; set; } = new List<AnagKeyValueModel>();
|
||||
public string Applicazione { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Codice cliente/installazione
|
||||
/// </summary>
|
||||
public string Installazione { get; set; } = "";
|
||||
/// <summary>
|
||||
/// Cerca di recuperare valore string da elenco AKV
|
||||
/// </summary>
|
||||
/// <param name="varReq">Chiave AKV richiesta</param>
|
||||
/// <returns></returns>
|
||||
protected string getAVKStr(string varReq)
|
||||
{
|
||||
string answ = "";
|
||||
if (AKVList != null && AKVList.Count > 0)
|
||||
{
|
||||
var currRec = AKVList.Where(x => x.NomeVar == varReq).FirstOrDefault();
|
||||
if (currRec != null)
|
||||
{
|
||||
answ = $"{currRec.ValString}";
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Init della classe con variabili di base da Redis/DB
|
||||
/// </summary>
|
||||
public bool InitAkv()
|
||||
{
|
||||
bool fatto = false;
|
||||
Applicazione = "MAPO";
|
||||
Installazione = getAVKStr("Installazione");
|
||||
MasterKey = getAVKStr(Applicazione);
|
||||
fatto = !string.IsNullOrEmpty($"{Installazione}{MasterKey}");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Master key licenza principale
|
||||
/// </summary>
|
||||
public string MasterKey { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Lista record AnagKeyVal
|
||||
/// </summary>
|
||||
public async Task<List<AnagKeyValueModel>?> OnlineListAnagKeyVal()
|
||||
{
|
||||
List<AnagKeyValueModel>? answ = new List<AnagKeyValueModel>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
var request = new RestRequest($"api/dbsync/anagkeyval/{Installazione}?CodApp={Applicazione}", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// salvo in redis contenuto serializzato
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<AnagKeyValueModel>?>(rawData);
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lista record Config
|
||||
/// </summary>
|
||||
public async Task<List<ConfigModel>?> OnlineListConfig()
|
||||
{
|
||||
List<ConfigModel>? answ = new List<ConfigModel>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
var request = new RestRequest($"api/dbsync/conf/{Installazione}?CodApp={Applicazione}", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// salvo in redis contenuto serializzato
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<ConfigModel>?>(rawData);
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lista record Vocabolario
|
||||
/// </summary>
|
||||
public async Task<List<VocabolarioModel>?> OnlineListVocabolario()
|
||||
{
|
||||
List<VocabolarioModel>? answ = new List<VocabolarioModel>();
|
||||
// cerco online
|
||||
RestClient client = new RestClient(apiUrl);
|
||||
string MKeyEnc = HttpUtility.UrlEncode(MasterKey);
|
||||
var request = new RestRequest($"api/dbsync/vocabolario/{Installazione}?CodApp={Applicazione}", Method.Get);
|
||||
var response = await client.GetAsync(request);
|
||||
// controllo risposta
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
// salvo in redis contenuto serializzato
|
||||
string rawData = $"{response.Content}";
|
||||
answ = JsonConvert.DeserializeObject<List<VocabolarioModel>?>(rawData);
|
||||
}
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user