using Microsoft.AspNetCore.Mvc; using MP.IOC.Data; using NLog; namespace MP.IOC.Controllers { [Route("api/[controller]")] [ApiController] public class RecipeArchiveController : ControllerBase { #region Public Constructors public RecipeArchiveController(IConfiguration configuration, MpDataService DataService) { Log.Info("Starting RecipeArchiveController"); _configuration = configuration; DService = DataService; Log.Info("Avviata classe RecipeArchiveController"); } #endregion Public Constructors #region Public Methods [HttpGet("GetByPODL")] public async Task GetByPODL(string idxMacc, int idxPODL) { string answ = "NO DATA"; string archPath = await DService.MacchineRecipeArchive(idxMacc); var podlData = await DService.POdlGetByKey(idxPODL); if (podlData != null) { string fileName = podlData?.Recipe ?? ""; string fullPath = Path.Combine(archPath, fileName); if (!string.IsNullOrEmpty(fullPath)) { try { if (System.IO.File.Exists(fullPath)) { answ = System.IO.File.ReadAllText(fullPath); if (string.IsNullOrEmpty(answ)) { Log.Error($"Errore in GetByPODL: contenuto file vuoto | idxMacc: {idxMacc} | idxPODL: {idxPODL}"); } } else { Log.Error($"Errore in GetByPODL: il file non esiste | fullPath {fullPath}"); } } catch (Exception exc) { Log.Error($"Eccezione in GetByPODL:{Environment.NewLine}{exc}"); } } else { Log.Error($"Errore in GetByPODL: fullPath null "); } } else { Log.Error($"Errore in GetByPODL: podlData null | idxPODL: {idxPODL}"); } return answ; } [HttpGet("GetFile")] public async Task GetFile(string idxMacc, string fileName) { string answ = "NO DATA"; string archPath = await DService.MacchineRecipeArchive(idxMacc); if (!string.IsNullOrEmpty(archPath)) { string fullPath = Path.Combine(archPath, fileName); if (!string.IsNullOrEmpty(fullPath)) { try { if (System.IO.File.Exists(fullPath)) { answ = System.IO.File.ReadAllText(fullPath); if (string.IsNullOrEmpty(answ)) { Log.Error($"Errore in GetFile: contenuto file vuoto | idxMacc: {idxMacc} | fileName: {fileName}"); } } else { Log.Error($"Errore in GetFile: il file non esiste | fullPath {fullPath}"); } } catch (Exception exc) { Log.Error($"Eccezione in GetFile:{Environment.NewLine}{exc}"); } } else { Log.Error($"Errore in GetFile: fullPath null "); } } else { Log.Error($"Errore in GetFile: archPath null "); } return answ; } #endregion Public Methods #region Protected Properties /// /// Dataservice x accesso DB /// protected MpDataService DService { get; set; } #endregion Protected Properties #region Private Fields private static IConfiguration _configuration = null!; private static Logger Log = LogManager.GetCurrentClassLogger(); #endregion Private Fields } }