129 lines
4.0 KiB
C#
129 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
|
|
using MagData;
|
|
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
|
|
namespace MP_MAG.Controllers
|
|
{
|
|
public class PrintQueueLenController : ApiController
|
|
{
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// oggetto static/singleton per fare chiamate sul datalayer
|
|
/// </summary>
|
|
protected MagDataLayer MagDataLayerObj = new MagDataLayer();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Conteggio elementi in attesa stampa da DB
|
|
/// </summary>
|
|
protected int countWaitingDb
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
// resetto conteggio in redis...
|
|
DS_Report.PrintJobQueueDataTable tabPJQ = MagDataLayerObj.taPJQ.getWaiting();
|
|
if (tabPJQ != null)
|
|
{
|
|
answ = tabPJQ.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Conteggio elementi in attesa stampa da DB che fanno parte di un SET di queue
|
|
/// </summary>
|
|
protected int countWaitingDbQueueMult(string queueSet)
|
|
{
|
|
int answ = 0;
|
|
// resetto conteggio in redis...
|
|
DS_Report.PrintJobQueueDataTable tabPJQ = MagDataLayerObj.taPJQ.getWaiting();
|
|
if (tabPJQ != null)
|
|
{
|
|
var selQueue = tabPJQ.Where(x => queueSet.Contains($"|{x.prtName}|")).ToList();
|
|
if (selQueue != null)
|
|
{
|
|
answ = selQueue.Count;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <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(MagDataLayer.redQueueCount);
|
|
// cerco in redis se ci sia chiave..
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// recupero
|
|
int.TryParse(redVal, out answ);
|
|
}
|
|
else
|
|
{
|
|
// recupero da db e salvo
|
|
answ = countWaitingDb;
|
|
memLayer.ML.setRSV(MagDataLayer.redQueueCount, $"{answ}", memLayer.ML.CRI("cacheQueueSec"));
|
|
// chiudo gli zombie (stampe non chiuse)...
|
|
MagDataLayerObj.taPJQ.chiudiZoombie(DateTime.Now.AddMilliseconds(-memLayer.ML.CRI("zombieMsTime")));
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce numero jobs aperti (stato = 0...), se 0 = NESSUNO
|
|
/// GET: api/PrintQueue?queueList=|queueOffline|
|
|
/// </summary>
|
|
/// <param name="queueList">Elenco code delimitate da |..|</param>
|
|
/// <returns></returns>
|
|
public int Get(string queueList)
|
|
{
|
|
// restituisco...
|
|
int answ = 0;
|
|
string redVal = memLayer.ML.getRSV($"{MagDataLayer.redQueueCountSet}:{queueList}");
|
|
// cerco in redis se ci sia chiave..
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// recupero
|
|
int.TryParse(redVal, out answ);
|
|
}
|
|
else
|
|
{
|
|
// recupero da db e salvo
|
|
answ = countWaitingDbQueueMult(queueList);
|
|
memLayer.ML.setRSV($"{MagDataLayer.redQueueCountSet}:{queueList}", $"{answ}", memLayer.ML.CRI("cacheQueueSec"));
|
|
// chiudo gli zombie (stampe non chiuse)...
|
|
MagDataLayerObj.taPJQ.chiudiZoombie(DateTime.Now.AddMilliseconds(-memLayer.ML.CRI("zombieMsTime")));
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |