200 lines
5.8 KiB
C#
200 lines
5.8 KiB
C#
using Newtonsoft.Json;
|
|
using SteamWare.IO;
|
|
using SteamWare.Reports;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Web;
|
|
|
|
namespace MagData
|
|
{
|
|
public class MagDataLayer
|
|
{
|
|
#region oggetti public
|
|
|
|
// reports
|
|
public DS_ReportTableAdapters.PrintJobQueueTableAdapter taPJQ;
|
|
public DS_ReportTableAdapters.stp_prt_CartellinoFinitiOdetteTableAdapter taCFOdette;
|
|
public DS_ReportTableAdapters.stp_prt_CartellinoPedaneTableAdapter taCPed;
|
|
|
|
#endregion
|
|
|
|
#region init classe
|
|
|
|
public MagDataLayer()
|
|
{
|
|
// inizializzaizone classe
|
|
initTA();
|
|
setupConnString();
|
|
}
|
|
|
|
private void setupConnString()
|
|
{
|
|
string connString = memLayer.ML.CRS("NKC_WFConnectionString");
|
|
// reports
|
|
taPJQ.Connection.ConnectionString = connString;
|
|
taCFOdette.Connection.ConnectionString = connString;
|
|
taCPed.Connection.ConnectionString = connString;
|
|
}
|
|
private void initTA()
|
|
{
|
|
// reports
|
|
taPJQ = new DS_ReportTableAdapters.PrintJobQueueTableAdapter();
|
|
taCFOdette = new DS_ReportTableAdapters.stp_prt_CartellinoFinitiOdetteTableAdapter();
|
|
taCPed = new DS_ReportTableAdapters.stp_prt_CartellinoPedaneTableAdapter();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// oggetto static/singleton per fare chiamate sul datalayer
|
|
/// </summary>
|
|
public static MagDataLayer man = new MagDataLayer();
|
|
|
|
#endregion
|
|
|
|
#region helpers e utils
|
|
|
|
public static string redQueueConf = "MP-CTRACK:MAG:queueConf";
|
|
|
|
/// <summary>
|
|
/// Restituisce un array JSon x le conf delle code di stampa leggendo dal file
|
|
/// </summary>
|
|
/// <returns>lista oggetto Json in formato SteamwareSDK.queueConf</returns>
|
|
public List<queueConf> queueConfJson
|
|
{
|
|
get
|
|
{
|
|
List<queueConf> answ = new List<queueConf>();
|
|
string dirPath = HttpContext.Current.Server.MapPath("~/Reports/");
|
|
string nomeFile = "queueConf.json";
|
|
bool fileExist = fileMover.obj.fileExist(dirPath, nomeFile);
|
|
if (fileExist)
|
|
{
|
|
string rawData = File.ReadAllText($"{dirPath}\\{nomeFile}");
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<List<queueConf>>(rawData);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SteamWare.Logger.Logging.Instance.Error(exc, "Eccezione in decodifica file conf printQueue");
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Cache redis della conf delle code
|
|
/// </summary>
|
|
/// <returns>lista oggetto Json in formato SteamwareSDK.queueConf</returns>
|
|
public List<queueConf> queueConfRedis
|
|
{
|
|
get
|
|
{
|
|
List<queueConf> answ = new List<queueConf>();
|
|
string redKey = memLayer.ML.redHash(redQueueConf);
|
|
string rawData = memLayer.ML.getRSV(redKey);
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<List<queueConf>>(rawData);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SteamWare.Logger.Logging.Instance.Error(exc, "Eccezione in recupero dati queueConf da redis");
|
|
}
|
|
}
|
|
// controllo se vuoto rileggo da file
|
|
if (answ.Count == 0)
|
|
{
|
|
answ = queueConfJson;
|
|
// a quesot punto salvo in Redis
|
|
queueConfRedis = queueConfJson;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
string redKey = memLayer.ML.redHash(redQueueConf);
|
|
string rawData = "";
|
|
// salvo inc ache per 1 h...
|
|
memLayer.ML.setRSV(redKey, rawData, 3600);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua la stampa di un documento
|
|
/// </summary>
|
|
/// <param name="keyParam">Codice UNIVOCO del documento</param>
|
|
/// <param name="printQueue">stampante specifica (da postazione o std da web.config, a cura dell'utente</param>
|
|
/// <param name="clientIp">IP del chiamante</param>
|
|
/// <returns></returns>
|
|
public bool stampaDoc(string keyParam, string printQueue, string clientIp)
|
|
{
|
|
bool answ = false;
|
|
// controllo se esista UDC
|
|
if (checkDoc(printQueue, keyParam))
|
|
{
|
|
answ = reportPrinter.obj.stampaReport(keyParam, printQueue);
|
|
if (answ)
|
|
{
|
|
SteamWare.Logger.Logging.Instance.Info($" | {clientIp} | salvata richiesta stampa su coda {printQueue} | key {keyParam}");
|
|
}
|
|
else
|
|
{
|
|
SteamWare.Logger.Logging.Instance.Error($"ERRORE | {clientIp} | richiesta stampa su coda {printQueue} | key {keyParam}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SteamWare.Logger.Logging.Instance.Error($"Impossibile | {clientIp} | richiesta stampa su coda {printQueue} | key {keyParam}");
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Verifica esistenza record da NOME CODA stampa + chiave...
|
|
/// </summary>
|
|
/// <param name="printQueue"></param>
|
|
/// <param name="keyParam"></param>
|
|
/// <returns></returns>
|
|
private bool checkDoc(string printQueue, string keyParam)
|
|
{
|
|
bool answ = false;
|
|
reportRichiesto tipoReport = reportRichiesto.ND;
|
|
//cerco in setup queueConf
|
|
|
|
var coda = queueConfRedis.Find(a => a.name == printQueue);
|
|
if (coda != null)
|
|
{
|
|
try
|
|
{
|
|
tipoReport = (reportRichiesto)Enum.Parse(typeof(reportRichiesto), coda.template.Replace(".rdlc", ""));
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
// ricerco!
|
|
switch (tipoReport)
|
|
{
|
|
case reportRichiesto.CartellinoFinitiOdette:
|
|
var tabFiniti = taCFOdette.GetData(keyParam);
|
|
answ = tabFiniti.Count > 0;
|
|
break;
|
|
case reportRichiesto.CartellinoPedane:
|
|
var tabPedane = taCPed.GetData(keyParam);
|
|
answ = tabPedane.Count > 0;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|