Update vari
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
using MagData;
|
||||
using Newtonsoft.Json;
|
||||
using SteamWare;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace MP_API.Controllers
|
||||
{
|
||||
public class PrintQueueController : ApiController
|
||||
{
|
||||
#region classi gestione PJQ
|
||||
|
||||
/// <summary>
|
||||
/// chaive redis x cache conteggio coda PJQ
|
||||
/// </summary>
|
||||
public static string redQueueCount = "MP-CTRACK:MAG:PJQ";
|
||||
/// <summary>
|
||||
/// Conteggio elementi in attesa stsampa da DB
|
||||
/// </summary>
|
||||
protected int countWaitingDb
|
||||
{
|
||||
get
|
||||
{
|
||||
int answ = 0;
|
||||
// resetto conteggio in redis...
|
||||
DS_Report.PrintJobQueueDataTable nextJob = MagDataLayer.man.taPJQ.getWaiting();
|
||||
if (nextJob != null)
|
||||
{
|
||||
answ = nextJob.Count;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) e restituisce Dictionary [nome RDS / tab RDS]
|
||||
/// </summary>
|
||||
/// <param name="tipoReport"></param>
|
||||
/// <param name="keyParam">cod UDC</param>
|
||||
/// <returns>tabella dati</returns>
|
||||
private Dictionary<string, DataTable> caricaDati(reportRichiesto tipoReport, string keyParam)
|
||||
{
|
||||
int intIdx = 0;
|
||||
Dictionary<string, DataTable> answ = new Dictionary<string, DataTable>();
|
||||
DataTable tab = new DataTable();
|
||||
switch (tipoReport)
|
||||
{
|
||||
case reportRichiesto.cartLabel:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.paintLabelPre:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.paintLabelPost:
|
||||
// int.TryParse(keyParam, out intIdx);
|
||||
// tab = (DataTable)DataLayer.man.taRepStack.GetData(intIdx);
|
||||
break;
|
||||
case reportRichiesto.partLabel:
|
||||
int.TryParse(keyParam, out intIdx);
|
||||
tab = (DataTable)MagDataLayer.man.taIL.getByKey(intIdx);
|
||||
answ.Add("stp_prt_PartLabel", tab);
|
||||
break;
|
||||
case reportRichiesto.stackLabel:
|
||||
int.TryParse(keyParam, out intIdx);
|
||||
tab = (DataTable)MagDataLayer.man.taRepStack.GetData(intIdx);
|
||||
answ.Add("stp_prt_StackLabel", tab);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
|
||||
protected reportRichiesto reportByTipo(string tipo)
|
||||
{
|
||||
reportRichiesto report = reportRichiesto.stackLabel;
|
||||
switch (tipo)
|
||||
{
|
||||
case "docPaint":
|
||||
report = reportRichiesto.paintLabelPre;
|
||||
break;
|
||||
case "docPaintPost":
|
||||
report = reportRichiesto.paintLabelPost;
|
||||
break;
|
||||
case "docCart":
|
||||
report = reportRichiesto.cartLabel;
|
||||
break;
|
||||
case "docPart":
|
||||
report = reportRichiesto.partLabel;
|
||||
break;
|
||||
case "docStack":
|
||||
report = reportRichiesto.stackLabel;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region REST api call
|
||||
|
||||
/// <summary>
|
||||
/// Restituisce numero jobs aperti (stato = 0...), se 0 = NESSUNO
|
||||
/// GET: api/PrintQueue
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Get()
|
||||
{
|
||||
// restituisco...
|
||||
int answ = 0;
|
||||
string redVal = memLayer.ML.getRSV(redQueueCount);
|
||||
// cerco in redis se ci sia chiave..
|
||||
if (!string.IsNullOrEmpty(redVal))
|
||||
{
|
||||
// recupero
|
||||
int.TryParse(redVal, out answ);
|
||||
}
|
||||
else
|
||||
{
|
||||
// recupero da dbe e salvo
|
||||
answ = countWaitingDb;
|
||||
memLayer.ML.setRSV(redQueueCount, answ.ToString(), 30);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco dei jobs aperti per la coda indicata
|
||||
/// GET: api/PrintQueue/queue_01
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public List<reportData> Get(string id)
|
||||
{
|
||||
List<reportData> answ = new List<reportData>();
|
||||
// recupero da DB...
|
||||
DS_Report.PrintJobQueueDataTable tabPJQ = MagDataLayer.man.taPJQ.getByQueue(id);
|
||||
if (tabPJQ.Count > 0)
|
||||
{
|
||||
reportData currReport = new reportData();
|
||||
Dictionary<string, DataTable> currRdsData;
|
||||
// ciclo!
|
||||
foreach (var pjReq in tabPJQ)
|
||||
{
|
||||
currRdsData = caricaDati(reportByTipo(pjReq.TipoReport), pjReq.KeyParam);
|
||||
// in base alla coda --> recupero i dati
|
||||
currReport = new reportData()
|
||||
{
|
||||
ticketNum = pjReq.IdxPrintJob.ToString(),
|
||||
rdsData = currRdsData
|
||||
};
|
||||
answ.Add(currReport);
|
||||
}
|
||||
}
|
||||
// compongo risposta...
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processa una chiamata POST per l'invio in blocco del risultato dell'elaborazione
|
||||
/// POST: api/PrintQueue
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public string Post()
|
||||
{
|
||||
string answ = "UNKN";
|
||||
// questa classe è derivata da Controller.Response... x cui recupero lo stream in altro modo...
|
||||
string content = "";
|
||||
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
||||
using (var reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream, System.Text.Encoding.UTF8, true, 4096, true))
|
||||
{
|
||||
content = reader.ReadToEnd();
|
||||
}
|
||||
//Rest
|
||||
System.Web.HttpContext.Current.Request.InputStream.Position = 0;
|
||||
// procedo a deserializzare in blocco l'oggetto...
|
||||
try
|
||||
{
|
||||
// deserializzo.
|
||||
printTask printAnsw = JsonConvert.DeserializeObject<printTask>(content);
|
||||
// verifico se mi abbia dato esito 1 --> aggiorno DB!
|
||||
if (printAnsw != null)
|
||||
{
|
||||
int idxPJQ = 0;
|
||||
int.TryParse(printAnsw.ticketNum, out idxPJQ);
|
||||
MagDataLayer.man.taPJQ.updateStato(idxPJQ, printAnsw.newStatus);
|
||||
// resetto conteggio in redis...
|
||||
memLayer.ML.setRSV(redQueueCount, countWaitingDb.ToString(), 30);
|
||||
answ = "OK";
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// restituisco esito!
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user