using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MP.SPEC.Data; using NLog; namespace MP.SPEC.Controllers { [Route("api/[controller]")] [ApiController] [AllowAnonymous] 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 = ""; string archPath = 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)) { answ = System.IO.File.ReadAllText(fullPath); } } return answ; } [HttpGet("GetFile")] public string GetFile(string idxMacc, string fileName) { string answ = ""; string archPath = DService.MacchineRecipeArchive(idxMacc); if (!string.IsNullOrEmpty(archPath)) { string fullPath = Path.Combine(archPath, fileName); if (!string.IsNullOrEmpty(fullPath)) { answ = System.IO.File.ReadAllText(fullPath); } } 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 } }