From b5a01a632d69b7cad3cc44e5ff0b5d1c76bbd050 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 12 Feb 2020 17:20:02 +0100 Subject: [PATCH] Completata scrittura api REST x chiusura stampa --- AppData/DS_Report.Designer.cs | 40 +++-- AppData/DS_Report.xsd | 10 ++ Jenkinsfile | 2 +- NKC_WF/Controllers/PrintQueueController.cs | 198 +++++++++++++-------- NKC_WF/NKC_WF.csproj | 4 +- NKC_WF/packages.config | 2 +- 6 files changed, 164 insertions(+), 92 deletions(-) diff --git a/AppData/DS_Report.Designer.cs b/AppData/DS_Report.Designer.cs index f7ddef2..e0385bf 100644 --- a/AppData/DS_Report.Designer.cs +++ b/AppData/DS_Report.Designer.cs @@ -2258,7 +2258,7 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] private void InitCommandCollection() { - this._commandCollection = new global::System.Data.SqlClient.SqlCommand[9]; + this._commandCollection = new global::System.Data.SqlClient.SqlCommand[10]; this._commandCollection[0] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[0].Connection = this.Connection; this._commandCollection[0].CommandText = "SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLastT" + @@ -2295,25 +2295,30 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast this._commandCollection[5].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[6] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[6].Connection = this.Connection; - this._commandCollection[6].CommandText = "dbo.stp_PJQ_insert"; + this._commandCollection[6].CommandText = "dbo.stp_PJQ_getWaiting"; this._commandCollection[6].CommandType = global::System.Data.CommandType.StoredProcedure; this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); - this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@TipoReport", global::System.Data.SqlDbType.VarChar, 250, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); - this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@keyParam", global::System.Data.SqlDbType.VarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); - this._commandCollection[6].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@prtName", global::System.Data.SqlDbType.VarChar, 500, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[7] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[7].Connection = this.Connection; - this._commandCollection[7].CommandText = "dbo.stp_PJQ_updateLastTry"; + this._commandCollection[7].CommandText = "dbo.stp_PJQ_insert"; this._commandCollection[7].CommandType = global::System.Data.CommandType.StoredProcedure; this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@TipoReport", global::System.Data.SqlDbType.VarChar, 250, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@keyParam", global::System.Data.SqlDbType.VarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[7].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@prtName", global::System.Data.SqlDbType.VarChar, 500, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); this._commandCollection[8] = new global::System.Data.SqlClient.SqlCommand(); this._commandCollection[8].Connection = this.Connection; - this._commandCollection[8].CommandText = "dbo.stp_PJQ_updateStato"; + this._commandCollection[8].CommandText = "dbo.stp_PJQ_updateLastTry"; this._commandCollection[8].CommandType = global::System.Data.CommandType.StoredProcedure; this._commandCollection[8].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); - this._commandCollection[8].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IdxPrintJob", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); - this._commandCollection[8].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@stato", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[8].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@keyParam", global::System.Data.SqlDbType.VarChar, 50, global::System.Data.ParameterDirection.Input, 0, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[9] = new global::System.Data.SqlClient.SqlCommand(); + this._commandCollection[9].Connection = this.Connection; + this._commandCollection[9].CommandText = "dbo.stp_PJQ_updateStato"; + this._commandCollection[9].CommandType = global::System.Data.CommandType.StoredProcedure; + this._commandCollection[9].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[9].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IdxPrintJob", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); + this._commandCollection[9].Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@stato", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", "")); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -2402,6 +2407,17 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast return dataTable; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] + [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] + [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, false)] + public virtual DS_Report.PrintJobQueueDataTable getWaiting() { + this.Adapter.SelectCommand = this.CommandCollection[6]; + DS_Report.PrintJobQueueDataTable dataTable = new DS_Report.PrintJobQueueDataTable(); + this.Adapter.Fill(dataTable); + return dataTable; + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] @@ -2689,7 +2705,7 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] public virtual int insertQuery(string TipoReport, string keyParam, string prtName) { - global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[6]; + global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[7]; if ((TipoReport == null)) { command.Parameters[1].Value = global::System.DBNull.Value; } @@ -2729,7 +2745,7 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] public virtual int updateLastTry(string keyParam) { - global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[7]; + global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[8]; if ((keyParam == null)) { command.Parameters[1].Value = global::System.DBNull.Value; } @@ -2757,7 +2773,7 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "16.0.0.0")] [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] public virtual int updateStato(global::System.Nullable IdxPrintJob, global::System.Nullable stato) { - global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[8]; + global::System.Data.SqlClient.SqlCommand command = this.CommandCollection[9]; if ((IdxPrintJob.HasValue == true)) { command.Parameters[1].Value = ((int)(IdxPrintJob.Value)); } diff --git a/AppData/DS_Report.xsd b/AppData/DS_Report.xsd index e4dabd3..691165c 100644 --- a/AppData/DS_Report.xsd +++ b/AppData/DS_Report.xsd @@ -169,6 +169,16 @@ SELECT IdxPrintJob, TipoReport, KeyParam, prtName, dtStart, dtEnd, stato, dtLast + + + + dbo.stp_PJQ_getWaiting + + + + + + diff --git a/Jenkinsfile b/Jenkinsfile index d37266d..bb7bae1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { steps { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=258']) { + withEnv(['NEXT_BUILD_NUMBER=259']) { // env.versionNumber = VersionNumber(versionNumberString : '0.9.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2019-07-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '0.9.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2019-07-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.versionNumberBeta = VersionNumber(versionNumberString : '0.9.${BUILD_DATE_FORMATTED, "yyMM"}-beta.${BUILDS_ALL_TIME}', projectStartDate : '2019-07-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') diff --git a/NKC_WF/Controllers/PrintQueueController.cs b/NKC_WF/Controllers/PrintQueueController.cs index f508c21..9ff0c1b 100644 --- a/NKC_WF/Controllers/PrintQueueController.cs +++ b/NKC_WF/Controllers/PrintQueueController.cs @@ -16,87 +16,29 @@ namespace NKC_WF.Controllers { public class PrintQueueController : ApiController { + #region classi gestione PJQ + /// + /// chaive redis x cache conteggio coda PJQ + /// public static string redQueueCount = "NKC:SERV:PJQ"; - /// - /// Restituisce numero jobs aperti (stato = 0...), se 0 = NESSUNO - /// GET: api/PrintQueue + /// Conteggio elementi in attesa stsampa da DB /// - /// - public int Get() + protected int countWaitingDb { - // restituisco... - int answ = 0; - string redVal = memLayer.ML.getRSV(redQueueCount); - // cerco in redis se ci sia chiave.. - if (!string.IsNullOrEmpty(redVal)) + get { - // recupero - int.TryParse(redVal, out answ); - } - else - { - // recupero da db - DS_Report.PrintJobQueueDataTable nextJob = DataLayer.man.taPJQ.getNext(); - // salvo - answ = nextJob.Count; - memLayer.ML.setRSV(redQueueCount, answ.ToString(), 30); - } - return answ; - } - - /// - /// Elenco dei jobs aperti per la coda indicata - /// GET: api/PrintQueue/queue_01 - /// - /// - /// - public List Get(string id) - { - List answ = new List(); - // recupero da DB... - DS_Report.PrintJobQueueDataTable tabPJQ = DataLayer.man.taPJQ.getByQueue(id); - if (tabPJQ.Count > 0) - { - reportData currReport = new reportData(); - DataTable currTab; - // ciclo! - foreach (var pjReq in tabPJQ) + int answ = 0; + // resetto conteggio in redis... + DS_Report.PrintJobQueueDataTable nextJob = DataLayer.man.taPJQ.getWaiting(); + if (nextJob != null) { - currTab = caricaDati(reportByTipo(pjReq.TipoReport), pjReq.KeyParam); - // in base alla coda --> recupero i dati - currReport = new reportData() - { - ticketNum = pjReq.IdxPrintJob.ToString(), - rdsTable = currTab - }; - answ.Add(currReport); + answ = nextJob.Count; } + return answ; } - // compongo risposta... - return answ; } - -#if false - // POST: api/PrintQueue - public void Post([FromBody]string value) - { - } - - // PUT: api/PrintQueue/5 - public void Put(int id, [FromBody]string value) - { - } - - // DELETE: api/PrintQueue/5 - public void Delete(int id) - { - } -#endif - - - /// /// carica i dati richiesti dal report dalla StoredProcedure (filtrando quindi...) /// @@ -141,19 +83,19 @@ namespace NKC_WF.Controllers reportRichiesto report = reportRichiesto.stackLabel; switch (tipo) { - case "DocPaint": + case "docPaint": report = reportRichiesto.paintLabelPre; break; - case "DocPaintPost": + case "docPaintPost": report = reportRichiesto.paintLabelPost; break; - case "DocCart": + case "docCart": report = reportRichiesto.cartLabel; break; - case "DocPart": + case "docPart": report = reportRichiesto.partLabel; break; - case "DocStack": + case "docStack": report = reportRichiesto.stackLabel; break; default: @@ -161,5 +103,109 @@ namespace NKC_WF.Controllers } return report; } + + #endregion + + #region REST api call + + /// + /// Restituisce numero jobs aperti (stato = 0...), se 0 = NESSUNO + /// GET: api/PrintQueue + /// + /// + 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; + } + + /// + /// Elenco dei jobs aperti per la coda indicata + /// GET: api/PrintQueue/queue_01 + /// + /// + /// + public List Get(string id) + { + List answ = new List(); + // recupero da DB... + DS_Report.PrintJobQueueDataTable tabPJQ = DataLayer.man.taPJQ.getByQueue(id); + if (tabPJQ.Count > 0) + { + reportData currReport = new reportData(); + DataTable currTab; + // ciclo! + foreach (var pjReq in tabPJQ) + { + currTab = caricaDati(reportByTipo(pjReq.TipoReport), pjReq.KeyParam); + // in base alla coda --> recupero i dati + currReport = new reportData() + { + ticketNum = pjReq.IdxPrintJob.ToString(), + rdsTable = currTab + }; + answ.Add(currReport); + } + } + // compongo risposta... + return answ; + } + + /// + /// Processa una chiamata POST per l'invio in blocco del risultato dell'elaborazione + /// POST: api/PrintQueue + /// + /// + [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(content); + // verifico se mi abbia dato esito 1 --> aggiorno DB! + if (printAnsw != null) + { + int idxPJQ = 0; + int.TryParse(printAnsw.ticketNum, out idxPJQ); + DataLayer.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 + } } diff --git a/NKC_WF/NKC_WF.csproj b/NKC_WF/NKC_WF.csproj index a5cdb09..4ff7c11 100644 --- a/NKC_WF/NKC_WF.csproj +++ b/NKC_WF/NKC_WF.csproj @@ -125,8 +125,8 @@ ..\packages\StackExchange.Redis.2.0.601\lib\net461\StackExchange.Redis.dll - - ..\packages\SteamWare.3.5.2002.718\lib\net462\SteamWare.dll + + ..\packages\SteamWare.3.5.2002.719\lib\net462\SteamWare.dll ..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll diff --git a/NKC_WF/packages.config b/NKC_WF/packages.config index d95fbe4..f2fd5b3 100644 --- a/NKC_WF/packages.config +++ b/NKC_WF/packages.config @@ -56,7 +56,7 @@ - +