Files
NKC/NKC_WF/Controllers/ReportController.cs
T
2020-02-12 10:45:10 +01:00

110 lines
3.0 KiB
C#

using Newtonsoft.Json;
using SteamWare;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
namespace NKC_WF.Controllers
{
public class ReportController : ApiController
{
/// <summary>
/// Restituisce un array JSon dei files report template del progetto
/// GET: api/Report
/// </summary>
/// <param name="id">ID della printer associata</param>
/// <returns>Oggetto Json in formato SteamwareSDK.filePack</returns>
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)
{
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)
{
logger.lg.scriviLog($"Errore in get elenco reports{Environment.NewLine}{exc}");
}
return answ;
}
/// <summary>
/// Restituisce oggetto JSon del files report template richeisto
/// GET: api/Report/print_01
/// </summary>
/// <param name="id">nome report (SENZA estensione .rdlc)</param>
/// <returns>Oggetto Json in formato SteamwareSDK.filePack</returns>
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)
{
logger.lg.scriviLog($"Errore in get singolo report{Environment.NewLine}{exc}");
}
return answ;
}
#if false
// POST: api/Report
public void Post([FromBody]string value)
{
}
// PUT: api/Report/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE: api/Report/5
public void Delete(int id)
{
}
#endif
}
}