using SteamWare; //using SteamWare.IO; using SteamWare.Logger; using System; using System.IO; using System.Web; using System.Web.Http; namespace MP_MAG.Controllers { public class ReportController : ApiController { /// /// Restituisce un array JSon dei files report template del progetto /// GET: api/Report /// /// ID della printer associata /// Oggetto Json in formato SteamwareSDK.filePack public filePack Get() { filePack answ = new filePack(); // procedo a deserializzare in blocco l'oggetto... try { // recupero TUTTI i files della folder della printer richiesta string dirPath = HttpContext.Current.Server.MapPath("~/Reports/"); var fileList = fileMover.obj.elencoFilesDir(dirPath); smallFile currFile = null; string fileContent = ""; foreach (var item in fileList) { // SOLO rdlc... if (item.Nome.EndsWith("rdlc")) { fileContent = File.ReadAllText($"{dirPath}\\{item.Nome}"); currFile = new smallFile() { fileName = item.Nome, content = fileContent.Replace("\r\n", Environment.NewLine) }; answ.fileList.Add(currFile); } } } catch (Exception exc) { Logging.Instance.Error($"Errore in get elenco reports{Environment.NewLine}{exc}"); } return answ; } /// /// Restituisce oggetto JSon del files report template richiesto /// GET: api/Report/print_01 /// /// nome report (SENZA estensione .rdlc) /// Oggetto Json in formato SteamwareSDK.filePack public filePack Get(string id) { filePack answ = new filePack(); // procedo a deserializzare in blocco l'oggetto... try { // recupero TUTTI i files della folder della printer richiesta string dirPath = HttpContext.Current.Server.MapPath("~/Reports/"); var fileList = fileMover.obj.elencoFilesDir(dirPath); smallFile currFile = null; string fileContent = ""; foreach (var item in fileList) { // se è uguale all'id richeisto... if (item.Nome.Replace(".rdlc", "") == id.Replace(".rdlc", "")) { fileContent = File.ReadAllText($"{dirPath}\\{item.Nome}"); currFile = new smallFile() { fileName = item.Nome, content = fileContent.Replace("\r\n", Environment.NewLine) }; answ.fileList.Add(currFile); } } } catch (Exception exc) { Logging.Instance.Error($"Errore in get singolo report{Environment.NewLine}{exc}"); } return answ; } } }