LAND:
- ok spedizione ZIP - ok password zip - ok test in DEV
This commit is contained in:
@@ -2,13 +2,18 @@
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MP.AppAuth.DTO;
|
||||
using MP.AppAuth.Models;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using static Egw.Core.LiManObj;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace MP.Land.Data
|
||||
@@ -21,10 +26,8 @@ namespace MP.Land.Data
|
||||
/// Init classe
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="logger"></param>
|
||||
public SyncService(IConfiguration configuration, ILogger<LicenseService> logger)
|
||||
public SyncService(IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -147,6 +150,55 @@ namespace MP.Land.Data
|
||||
return await Task.FromResult(answ);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invio file zip di backup al server centrale
|
||||
/// </summary>
|
||||
/// <param name="CodApp">Cod Applicazione</param>
|
||||
/// <param name="CodInst">CLiente / Installazione</param>
|
||||
/// <param name="DoUnzip">Invia richiesta UnZip</param>
|
||||
/// <param name="ForceApprov">Invia richiesta Approvazione</param>
|
||||
/// <param name="ZipFile">ZipFile da inviare</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> SendZipFile(string CodApp, string CodInst, bool DoUnzip, bool ForceApprov, FileInfo ZipFile)
|
||||
{
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// client chiamate rest
|
||||
var client = new RestClient(restOptStd);
|
||||
// Chiamo il metodo!
|
||||
var actReq = new RestRequest($"/api/filesave/zipbackup", Method.Post);
|
||||
actReq.AddParameter("CodApp", $"{CodApp}");
|
||||
actReq.AddParameter("CodInst", $"{CodInst}");
|
||||
actReq.AddParameter("DoUnzip", $"{DoUnzip}");
|
||||
actReq.AddParameter("ForceApprov", $"{ForceApprov}");
|
||||
actReq.AddFile("ZipFile", ZipFile.FullName);
|
||||
actReq.AddHeader("Content-Type", "multipart/form-data");
|
||||
// effettuo vera chiamata
|
||||
var currResp = await client.ExecuteAsync(actReq);
|
||||
if (currResp.StatusCode == System.Net.HttpStatusCode.OK && currResp.Content != null)
|
||||
{
|
||||
// mi restituisce esito upload
|
||||
var currList = JsonConvert.DeserializeObject<List<UploadResult>>(currResp.Content);
|
||||
if (currList != null)
|
||||
{
|
||||
// se contiene anche la richiesta è ok...
|
||||
var recUpd = currList.FirstOrDefault(x => x.FileName == ZipFile.Name);
|
||||
if (recUpd != null)
|
||||
{
|
||||
answ = recUpd.Uploaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error($"Eccezione in fase gestione REST services SendZipFile{Environment.NewLine}{exc}");
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Methods
|
||||
@@ -179,14 +231,24 @@ namespace MP.Land.Data
|
||||
/// <summary>
|
||||
/// URL dell'API x chiamate gestione licenze
|
||||
/// </summary>
|
||||
#if DEBUG
|
||||
private static string apiUrl = "https://localhost:5003/";
|
||||
#else
|
||||
private static string apiUrl = "https://liman.egalware.com/ELM.API/";
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Classe logger
|
||||
/// </summary>
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Conf client RestSharp standard:
|
||||
/// - base URI al sito
|
||||
/// - timeout 1 min
|
||||
/// </summary>
|
||||
private static RestClientOptions restOptStd = new RestClientOptions { Timeout = TimeSpan.FromSeconds(60), BaseUrl = new Uri(apiUrl) };
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private static ILogger<LicenseService> _logger { get; set; } = null!;
|
||||
|
||||
#endregion Private Properties
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user