5b0101c30a
- review naming task/update - review condizioni invio
426 lines
17 KiB
C#
426 lines
17 KiB
C#
using Core.DTO;
|
|
using Core;
|
|
using LiMan.APi.Data;
|
|
using LiMan.DB.DTO;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NLog;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using LiMan.DB.DBModels;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Org.BouncyCastle.Asn1.Crmf;
|
|
using System;
|
|
|
|
namespace LiMan.APi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// Controller gestione RELEASE applicativi
|
|
/// </summary>
|
|
[Route("api/release")]
|
|
[ApiController]
|
|
public class ReleaseController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Init generico
|
|
/// </summary>
|
|
/// <param name="DataService"></param>
|
|
public ReleaseController(ApiDataService DataService)
|
|
{
|
|
dataService = DataService;
|
|
Log.Info("Avviata classe ReleaseController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) GET api/release/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <returns></returns>
|
|
[HttpGet("{id}")]
|
|
[Obsolete("Please use POST with api/release/getall instead.", false)]
|
|
public async Task<List<ReleaseDTO>> Get(string id)
|
|
{
|
|
var result = await dataService.ReleaseDtoGetByApp(id);
|
|
await dataService.recordCall(id, id, $"GET:api/release/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) data versione minima GET api/release/filt/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <param name="VersMin">Versione minima richiesta (attuale)</param>
|
|
/// <returns></returns>
|
|
[HttpGet("filt/{id}")]
|
|
[Obsolete("Please use POST with api/release/getfilt instead.", false)]
|
|
public async Task<List<ReleaseDTO>> GetFilt(string id, string VersMin)
|
|
{
|
|
var result = await dataService.ReleaseDtoGetByAppVers(id, VersMin);
|
|
Log.Warn($"Chiamato metodo legacy api/release/filt | id: {id} | vers: {VersMin}");
|
|
await dataService.recordCall(id, id, $"GET:api/release/filt/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) data versione minima e massima GET api/release/filtLimit/EgtBW
|
|
/// </summary>
|
|
/// <param name="id">Codice Applicazione</param>
|
|
/// <param name="VersMin">Versione minima richiesta (attuale)</param>
|
|
/// <param name="VersMax">Versione massima consentita</param>
|
|
/// <returns></returns>
|
|
[HttpGet("filtLimit/{id}")]
|
|
[Obsolete("Please use POST with api/release/getlimit instead.", false)]
|
|
public async Task<List<ReleaseDTO>> GetFiltLimit(string id, string VersMin, string VersMax)
|
|
{
|
|
var result = await dataService.ReleaseGetByAppVersLimit(id, VersMin, VersMax);
|
|
await dataService.recordCall(id, id, $"GET:api/release/filtLimit/{id}");
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) POST api/release/getall
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ReleaseReqDTO con chiavi (master o app)</param>
|
|
[HttpPost("getall")]
|
|
public async Task<List<ReleaseDTO>> GetReleases([FromBody] ReleaseReqDTO CurrReq)
|
|
{
|
|
List<ReleaseDTO> result = new List<ReleaseDTO>();
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
result = await dataService.ReleaseDtoGetByApp(CurrReq.CodApp);
|
|
// non necessario notificare UI...
|
|
#if false
|
|
// invio notifica x app...
|
|
dataService.UpdActMessPipe.sendMessage(CurrReq.CodImp);
|
|
#endif
|
|
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "GetReleases");
|
|
|
|
await dataService.recordCall(CurrReq.CodApp, CurrReq.CodApp, $"POST:api/release/getall/ | {CurrReq.MastKey} | {CurrReq.CodImp} | {CurrReq.CodApp}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release CRITICHE rilasciate (se sono ultima per singola CodApp)
|
|
/// POST api/release/get-critical
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ReleaseReqDTO con chiavi (master o app)</param>
|
|
[HttpPost("getcritical")]
|
|
public async Task<Dictionary<string, ReleaseDTO>> GetReleasesCritical([FromBody] ReleaseReqDTO CurrReq)
|
|
{
|
|
Dictionary<string, ReleaseDTO> result = new Dictionary<string, ReleaseDTO>();
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
result = await dataService.ReleaseGetCritical();
|
|
// non necessario notificare UI...
|
|
#if false
|
|
// invio notifica x app...
|
|
dataService.UpdActMessPipe.sendMessage(CurrReq.CodImp);
|
|
#endif
|
|
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "GetReleasesCritical");
|
|
|
|
await dataService.recordCall(CurrReq.CodApp, CurrReq.CodApp, $"POST:api/release/getcritical/ | {CurrReq.MastKey} | {CurrReq.CodImp} | {CurrReq.CodApp}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) data versione minima POST api/release/getfilt
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ReleaseReqDTO con chiavi (master o app)</param>
|
|
[HttpPost("getfilt")]
|
|
public async Task<List<ReleaseDTO>> GetReleasesFilt([FromBody] ReleaseReqDTO CurrReq)
|
|
{
|
|
List<ReleaseDTO> result = new List<ReleaseDTO>();
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
result = await dataService.ReleaseDtoGetByAppVers(CurrReq.CodApp, CurrReq.VersMin);
|
|
// registro stato applicativi (da richiesta...)
|
|
InstalledReleasesModel checkRec = new InstalledReleasesModel()
|
|
{
|
|
AppKey = CurrReq.AppKey,
|
|
CodApp = CurrReq.CodApp,
|
|
CodImp = CurrReq.CodImp,
|
|
DtCheck = DateTime.Now,
|
|
MastKey = CurrReq.MastKey,
|
|
NumImp = CurrReq.NumImp,
|
|
VersNum = CurrReq.VersMin
|
|
};
|
|
bool changed = dataService.InstallRelUpsert(checkRec);
|
|
// chiamata x effettuare eventuale snapshot sulle installazioni attive SE variato
|
|
await dataService.InstallRelHistSnapshot(changed);
|
|
if (changed)
|
|
{
|
|
// invio notifica x app...
|
|
dataService.UpdActMessPipe.sendMessage(CurrReq.CodImp);
|
|
}
|
|
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "GetReleasesFilt");
|
|
|
|
// registro infine chiamata
|
|
await dataService.recordCall(CurrReq.CodApp, CurrReq.CodApp, $"POST:api/release/getfilt/ | {CurrReq.MastKey} | {CurrReq.CodImp} | {CurrReq.CodApp}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera elenco dati Release (rilasciate) data versione minima e massima POST api/release/getlimit
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ReleaseReqDTO con chiavi (master o app)</param>
|
|
[HttpPost("getlimit")]
|
|
public async Task<List<ReleaseDTO>> GetReleasesLimit([FromBody] ReleaseReqDTO CurrReq)
|
|
{
|
|
List<ReleaseDTO> result = new List<ReleaseDTO>();
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
result = await dataService.ReleaseGetByAppVersLimit(CurrReq.CodApp, CurrReq.VersMin, CurrReq.VersMax);
|
|
#if false
|
|
// invio notifica x app...
|
|
dataService.UpdActMessPipe.sendMessage(CurrReq.CodImp);
|
|
#endif
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "GetReleasesLimit");
|
|
|
|
await dataService.recordCall(CurrReq.CodApp, CurrReq.CodApp, $"POST:api/release/getlimit/ | {CurrReq.MastKey} | {CurrReq.CodImp} | {CurrReq.CodApp}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva una nuova release dell'applicativo (eventualmente sovrascrivendo) POST api/release/save
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj Richiesta</param>
|
|
[HttpPost("save")]
|
|
public async Task<ReleaseDTO> SaveRelease([FromBody] AppRelVersion CurrReq)
|
|
{
|
|
ReleaseDTO result = new ReleaseDTO()
|
|
{
|
|
CodApp = CurrReq.CodApp,
|
|
ReleaseDate = CurrReq.ReleaseDate,
|
|
VersNum = CurrReq.VersNum,
|
|
VersText = CurrReq.VersText,
|
|
RelTags = CurrReq.RelTags.ToUpper()
|
|
};
|
|
// controllo valori
|
|
if (CurrReq.IsValid)
|
|
{
|
|
// verifica preliminare licenza x upload
|
|
var licUploader = await dataService.LicenzeSearch(CurrReq.CodInst, CurrReq.UplAppID, CurrReq.MasterKey, false);
|
|
if (licUploader != null && licUploader.Count > 0)
|
|
{
|
|
// in primis cerco app...
|
|
var appList = await dataService.ApplicNextGetAll(true);
|
|
ApplicativoModel recApp = new ApplicativoModel();
|
|
if (appList != null)
|
|
{
|
|
recApp = appList.FirstOrDefault(x => x.CodApp == CurrReq.CodApp);
|
|
}
|
|
// nel caso mancasse la aggiungo
|
|
if (recApp == null || string.IsNullOrEmpty(recApp.CodApp) || recApp.CodApp != CurrReq.CodApp)
|
|
{
|
|
recApp = new ApplicativoModel()
|
|
{
|
|
CodApp = CurrReq.CodApp,
|
|
Descrizione = "Nuova APP da POST api/release/save",
|
|
TplConnString = "",
|
|
Tipo = CurrReq.Tipo
|
|
};
|
|
await dataService.ApplicNextUpdate(recApp);
|
|
}
|
|
//converto in una release...
|
|
ReleaseModel newRec = new ReleaseModel()
|
|
{
|
|
CodApp = CurrReq.CodApp,
|
|
ReleaseDate = CurrReq.ReleaseDate,
|
|
RelTags = CurrReq.RelTags.ToUpper(),
|
|
VersNum = CurrReq.VersNum,
|
|
VersText = CurrReq.VersText
|
|
};
|
|
// registro versione eventualmente gestendo nuovo applicativo
|
|
var insRes = await dataService.ReleaseUpsert(newRec);
|
|
if (insRes)
|
|
{
|
|
Log.Info($"Release recorded | {CurrReq.CodApp} | {CurrReq.VersNum} | {CurrReq.VersText} | {CurrReq.ReleaseDate} | {CurrReq.RelTags}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Errore: licenza UpdateManager non TROVATA | {CurrReq.MasterKey}");
|
|
await dataService.recordCall(CurrReq.CodInst, CurrReq.CodApp, $"ERROR POST:api/release/save:{CurrReq.CodApp} | {CurrReq.MasterKey}");
|
|
}
|
|
// recupero vers applicativo...
|
|
var rawResult = await dataService.ReleaseDtoGetByApp(CurrReq.CodApp);
|
|
if (rawResult != null && rawResult.Count > 0)
|
|
{
|
|
result = rawResult.Where(x => x.VersText == CurrReq.VersText).FirstOrDefault();
|
|
}
|
|
|
|
// fisso nostra install
|
|
await dataService.recordCall(CurrReq.CodInst, CurrReq.CodApp, $"POST:api/release/save:{CurrReq.CodApp}");
|
|
}
|
|
else
|
|
{
|
|
Log.Error($"Errore: licenza UpdateManager non VALIDA | {CurrReq.MasterKey}");
|
|
await dataService.recordCall(CurrReq.CodInst, CurrReq.CodApp, $"ERROR POST:api/release/save:{CurrReq.CodApp} | {CurrReq.MasterKey}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue tentativo salvataggio rel history
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ReleaseReqDTO con chiavi (master o app)</param>
|
|
[HttpPost("save-history")]
|
|
public async Task<List<ReleaseDTO>> SaveRelHistory([FromBody] ReleaseReqDTO CurrReq)
|
|
{
|
|
List<ReleaseDTO> result = new List<ReleaseDTO>();
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
// chiamata x effettuare eventuale snapshot sulle installazioni attive
|
|
await dataService.InstallRelHistSnapshot(true);
|
|
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "SaveRelHistory");
|
|
|
|
// registro infine chiamata
|
|
await dataService.recordCall(CurrReq.CodApp, CurrReq.CodApp, $"POST:api/release/save-history/ | {CurrReq.MastKey} | {CurrReq.CodImp} | {CurrReq.CodApp}");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Conferma quale sia l'elenco delle app gestite POST api/release/setmanaged
|
|
/// </summary>
|
|
/// <param name="CurrReq">Obj ManDeclareDTO con chiavi + elenco app gestite (x eliminare altre)</param>
|
|
/// <returns>Numero di record eliminati</returns>
|
|
[HttpPost("setmanaged")]
|
|
public async Task<int> SetManaged([FromBody] ManDeclareDTO CurrReq)
|
|
{
|
|
int result = 0;
|
|
// verifica validità richiesta...
|
|
if (CheckReqKeys(CurrReq))
|
|
{
|
|
result = dataService.InstallRelClean(CurrReq.CodImp, CurrReq.AppKey, CurrReq.ListCodApp);
|
|
|
|
// registro updater...
|
|
dataService.UpdaterRecordAction(CurrReq.CodImp, "SetManaged");
|
|
|
|
// invio notifica x app...
|
|
dataService.UpdActMessPipe.sendMessage(CurrReq.CodImp);
|
|
}
|
|
await Task.Delay(1);
|
|
return result;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Dataservice x accesso DB
|
|
/// </summary>
|
|
protected ApiDataService dataService { get; set; }
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Fields
|
|
|
|
/// <summary>
|
|
/// Classe per logging
|
|
/// </summary>
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Verifica validità richiesta
|
|
/// - dati presenti in chiamata
|
|
/// - combinazioni CodApp + chiavi valide/attive
|
|
/// </summary>
|
|
/// <param name="currReq"></param>
|
|
/// <returns></returns>
|
|
private bool CheckReqKeys(ReleaseReqDTO currReq)
|
|
{
|
|
bool answ = currReq.IsValid;
|
|
if (answ)
|
|
{
|
|
// verifica validità chiavi... TBD!!!
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica validità richiesta
|
|
/// - dati presenti in chiamata
|
|
/// - combinazioni CodApp + chiavi valide/attive
|
|
/// </summary>
|
|
/// <param name="currReq"></param>
|
|
/// <returns></returns>
|
|
private bool CheckReqKeys(AuthDataDTO currReq)
|
|
{
|
|
bool answ = currReq.IsValid;
|
|
if (answ)
|
|
{
|
|
// verifica validità chiavi... TBD!!!
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica validità richiesta
|
|
/// - dati presenti in chiamata
|
|
/// - combinazioni CodApp + chiavi valide/attive
|
|
/// </summary>
|
|
/// <param name="currReq"></param>
|
|
/// <returns></returns>
|
|
private bool CheckReqKeys(ManDeclareDTO currReq)
|
|
{
|
|
bool answ = currReq.IsValid;
|
|
if (answ)
|
|
{
|
|
// verifica validità chiavi... TBD!!!
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Verifica validità richiesta
|
|
/// - dati presenti in chiamata
|
|
/// - combinazioni CodApp + chiavi valide/attive
|
|
/// </summary>
|
|
/// <param name="currReq"></param>
|
|
/// <returns></returns>
|
|
private bool CheckReqKeys(TaskResultDTO currReq)
|
|
{
|
|
bool answ = currReq.IsValid;
|
|
if (answ)
|
|
{
|
|
// verifica validità chiavi... TBD!!!
|
|
}
|
|
return answ;
|
|
}
|
|
#endif
|
|
}
|
|
} |