93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
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
|
|
{
|
|
/// <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)
|
|
{
|
|
// 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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Restituisce oggetto JSon del files report template richiesto
|
|
/// 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)
|
|
{
|
|
Logging.Instance.Error($"Errore in get singolo report{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
}
|