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 { /// /// Restituisce SE C'E' la richiesta di elaborazione BATCH corrente /// /// // 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(redVal); } catch { } } return answ; } /// /// Restituisce UNA SPECIFICA richiesta di elaborazione BATCH /// /// // 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(redVal); } catch { } } return answ; } /// /// Processa una chiamata POST per l'invio in blocco status BUNK /// POST: api/BatchProc /// /// ID dell'IOB /// // 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(content); // se non nullo... if (currBunk != null) { /************************************************* * IN BASE al tipo di risposta saprò se * - è BatchReq / OfflineOrder * - è stima iniziale o dettaglio (x batch) * ... * *************************************************/ // deserializzo come BatchreqIniziale // deserializzo come BatchreqFinale // deserializzo come OfflineOrder // SALVO!!! #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 answ = "OK"; } 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 } }