182 lines
4.9 KiB
C#
182 lines
4.9 KiB
C#
using AppData;
|
|
using Newtonsoft.Json;
|
|
using NKC_SDK;
|
|
using SteamWare;
|
|
using System;
|
|
using System.IO;
|
|
using System.Web.Http;
|
|
|
|
namespace NKC_WF.Controllers
|
|
{
|
|
public class BatchProcController : ApiController
|
|
{
|
|
|
|
/// <summary>
|
|
/// Restituisce SE C'E' la richiesta di elaborazione BATCH corrente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/BatchProc
|
|
[HttpGet]
|
|
public batchRequest Get()
|
|
{
|
|
batchRequest answ = new batchRequest();
|
|
// in primis: controllo su redis SE HO una richiista CURRENT di processing...
|
|
string redKey = $"{ComLib.redOutPath}:CURR";
|
|
string redVal = memLayer.ML.getRSV(redKey);
|
|
// se c'è carico "la busta" come ID
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// cerco in REDIS se ci sia l'item richiesto
|
|
redKey = $"{ComLib.redOutPath}:{redVal}";
|
|
// leggo da redis la stringa...
|
|
redVal = memLayer.ML.getRSV(redKey);
|
|
// PROVO a deserializzare...
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<batchRequest>(redVal);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce UNA SPECIFICA richiesta di elaborazione BATCH
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
// GET: api/BatchProc/5
|
|
[HttpGet]
|
|
public batchRequest Get(int id)
|
|
{
|
|
batchRequest answ = new batchRequest();
|
|
// in primis: controllo su redis SE HO una richiista CURRENT di processing...
|
|
string redKey = $"{ComLib.redOutPath}:{id}";
|
|
string redVal = memLayer.ML.getRSV(redKey);
|
|
// se c'è carico "la busta" come ID
|
|
if (!string.IsNullOrEmpty(redVal))
|
|
{
|
|
// PROVO a deserializzare...
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<batchRequest>(redVal);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Processa una chiamata POST per l'invio in blocco Batch
|
|
/// POST: api/BatchProc
|
|
/// </summary>
|
|
/// <param name="id">ID dell'IOB</param>
|
|
/// <returns></returns>
|
|
// POST: api/BatchProc
|
|
[HttpPost]
|
|
public string Post()
|
|
{
|
|
string answ = "";
|
|
// 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
|
|
{
|
|
// DEBUG: salvo su redis x fare DEBUG
|
|
string redKey = $"{ComLib.redNestAnsw}:LAST_CALL";
|
|
memLayer.ML.setRSV(redKey, content);
|
|
|
|
// deserializzo.
|
|
baseNestAnsw currBunk = JsonConvert.DeserializeObject<baseNestAnsw>(content);
|
|
// se non nullo...
|
|
if (currBunk != null)
|
|
{
|
|
/*************************************************
|
|
* IN BASE al tipo di risposta saprò se
|
|
* - è BatchReq / OfflineOrder
|
|
* - è stima iniziale o dettaglio (x batch)
|
|
* ...
|
|
*
|
|
*************************************************/
|
|
|
|
if (currBunk.orderType == oType.BatchRequest)
|
|
{
|
|
if (currBunk.procType == 1)
|
|
{
|
|
// deserializzo come BatchreqIniziale (stima)
|
|
nestReplyBatchInitial rispStima = JsonConvert.DeserializeObject<nestReplyBatchInitial>(content);
|
|
// SALVO!!!
|
|
|
|
|
|
answ = "OK";
|
|
}
|
|
else
|
|
{
|
|
// deserializzo come BatchreqFinale
|
|
nestReplyBatchFinal rispNest = JsonConvert.DeserializeObject<nestReplyBatchFinal>(content);
|
|
// SALVO!!!
|
|
|
|
|
|
answ = "OK";
|
|
}
|
|
}
|
|
else if (currBunk.orderType == oType.OfflineOrder)
|
|
{
|
|
// deserializzo come OfflineOrder
|
|
nestReplyOffOrd rispNest = JsonConvert.DeserializeObject<nestReplyOffOrd>(content);
|
|
// SALVO!!!
|
|
|
|
|
|
answ = "OK";
|
|
}
|
|
|
|
|
|
#if false
|
|
foreach (var item in currBunk.SheetList)
|
|
{
|
|
DataLayer.man.taSHL.updateDate(item.SheetId, item.Printing.DtStart, item.Printing.DtEnd, item.Machining.DtStart, item.Machining.DtEnd, item.Unloading.DtStart, item.Unloading.DtEnd);
|
|
}
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
answ = "WRONG DATA (expected baseNestAnsw object)";
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
answ = "NO";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#if false
|
|
|
|
// POST: api/BatchProc
|
|
public void Post([FromBody]string value)
|
|
{
|
|
}
|
|
|
|
// PUT: api/BatchProc/5
|
|
public void Put(int id, [FromBody]string value)
|
|
{
|
|
}
|
|
|
|
// DELETE: api/BatchProc/5
|
|
public void Delete(int id)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
}
|