/// ************************************************************************************************* /// <summary> /// 07/06/2017 10:23 version /// Catalog Web Orders process, un-imported web orders are retreived and mapped to an object (header/detail /// sections). /// Each section is send to WebServices as a JSON string if header/detail information is complete, /// when detail info. /// All errors are send to a Webservice (Error) and included in the Service log. /// </summary> /// <param name="doc">Imported Web orders</param> /// <param name="oNumber">Web Order number</param> /// <param name="syncRow">EtlTimer sync control data)</param> /// <returns>Process status true if procees was completed ok, else false</returns> /// ------------------------------------------------------------------------------------------------- bool ICatalogTables.ProcessCatalogOrder(CatalogOrderTables doc, string oNumber, EtlTimer syncRow) { //bool rStatus = false; // WebService return status (default=false) ServiceResponse rStatus = new ServiceResponse(); DAL.SupportServices.SupportServices wsm = new DAL.SupportServices.SupportServices(); // Set WebService methods pointer /// Create error message object and initialice it ServiceResponse errMsg = new ServiceResponse(); errMsg.FileType = "1"; // Set Nis Type errMsg.FileName = "Catalog Web orders Table"; errMsg.NISOrderId = oNumber.ToString(); errMsg.Status = "Not Processed"; errMsg.Message = "No items found for this order header"; /// ********************************************************************************************* // Order header section /// --------------------------------------------------------------------------------------------- string jsonHead = "{ \"WebOrderSummary\":" + Newtonsoft.Json.JsonConvert.SerializeObject(doc.CatalogWebOrderSummary); /// ********************************************************************************************* /// Order Detail Section /// -------------------------------------------------------------------------------------------- /// =============================================================================== /// Send Imported files data content to webServices - information must be complete /// Order Header + all related Order Items. /// ------------------------------------------------------------------------------- if (doc.CatalogWebOrderItems.Count > 0) { /// Serialize Items list and complete json string for Header and Items string json2 = jsonHead + ", \"WebOrderItems\" : " + Newtonsoft.Json.JsonConvert.SerializeObject(doc.CatalogWebOrderItems) + "}"; /// ****************************************************************************** /// Call Web Service /// <param name="json2"> Header/detail object Json serialized string.</param> /// <param name="fname"> Xml file name </param> /// <param name="syncRow.WebServiceOrders">File Type, route to web service(url)</param> /// <param name="syncRow"> EtlTimer control data. /// <returns>"rStatus.IsOk" true if WebService was processed, else false</returns> /// *** Web service url is defined in the App.Config file key 'NisOrder'. /// ------------------------------------------------------------------------------ /// ==============> save order data through the defined web service rStatus = wsm.ConsumeWebService(json2, oNumber, syncRow.WebServiceOrders, syncRow); //"OrderData", syncRow); //// TEMPORARY UNCOMMENT TO SEND JSON INFO /// ------------------------------------------------------------------------------ /// UNCOMMENT IF WEB SERVICE IS USED TO SEND JSON INFO // rStatus.IsOK = true; /// set order process to ok TEMPORARY, // rStatus.NISOrderId = "Nav1234567"; /// ------------------------------------------------------------------------------ string apiMsg = ""; int resp = 0; // Order update response DAL.ImportControl.ImportControlRepository ikr = new DAL.ImportControl.ImportControlRepository(); DAL.ImportControl.ImportCatalogRepository icr = new DAL.ImportControl.ImportCatalogRepository(); // if (rStatus.IsOk) { // set order condition to imported apiMsg = " Imported"; resp = icr.updCatalogOrder(oNumber, rStatus.NISOrderId, 1); } else { // Set order contion to imported with errors. apiMsg = " Not Imported - API errors"; } string ret = ikr.writeSyncLog(1, syncRow.MwEtlTimerId, 1, syncRow.ServiceName, "> " + syncRow.Description + " Catalog Web Order: <" + doc.CatalogWebOrderSummary.OrderNumber + "> " + apiMsg + "."); // <============== } else { /// Incomplete order (No order items included and no xls file Name reported in orderHeader) jsonHead = jsonHead + " }"; /// Send Message to WebService wsm.WriteErrorFile(errMsg, syncRow); //// TEMPORARY UNCOMMENT TO SEND JSON INFO } return(rStatus.IsOk); }
/// ***************************************************************************************** /// General Tables process - Only Web/convert orders rows are processed here: /// (1) - Select order type process depending on order type. /// (2) - Route process to the corresponding order types import process using delegates. /// (3) - Unrecognized data types and Service reading errors are detected here. /// (4) - Errors are logged in service log and reported through web services. /// ----------------------------------------------------------------------------------------- public void ProcessOrder(string order, EtlTimer sync) { /// Initialize Error messages object basic information string OrdNumber = ""; ServiceResponse errMsg = new ServiceResponse(); errMsg.FileType = "1"; errMsg.FileName = "Catalog web Order: " + order.ToString(); errMsg.NISOrderId = "0"; errMsg.Status = "Not Processed"; errMsg.Message = string.Empty; try { /// ********************************************************************************* /// Select files acceptable to be process, all other file types (extension) will not /// be processed (they stay in the newFiles folder) and an error message is generated /// to the WebServices. /// Only Catalog Web Order (1) row are processed by entry. /// --------------------------------------------------------------------------------- // access catalog convert orders list if (sync.OrderType == 1) { /// ======== > CatalogConvertTable convertOrder = new CatalogConvertTable(); convertOrder = icr.getCatalogConvertOrder(order); /// <========= OrdNumber = convertOrder.CatalogConvertOrderSummary.ReferenceId; // /// Instanciate NBI Tables methods delegate DelConvert handler = null; // Declare a class instance xml: ImportProcedure_Catalog.CatalogJson.ImportProcess table = new ImportProcedure_Catalog.CatalogJson.ImportProcess(); /// Declare an interface instance Table: ImportProcedure_Catalog.CatalogJson.ICatalogTables orderClass = (ImportProcedure_Catalog.CatalogJson.ICatalogTables)table; /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Identify Catalog Web order table and route them to the corresponding import procedure /// ---------------------------------------------------------------------------- // Catalog Web Order table process handler = orderClass.ProcessConvertOrder; // /// =========== > bool ok = false; ok = handler(convertOrder, order, sync); // Process file and WebService // OrdNumber = (convertOrder.CatalogConvertOrderSummary.ReferenceId).ToString(); // } else if (sync.OrderType == 2) { CatalogOrderTables catalogOrder = new CatalogOrderTables(); catalogOrder = icr.getCatalogOrder(order); //if (catalogOrder != null && catalogOrder.CatalogWebOrderItems != null) //{ /// Instanciate NBI Tables methods delegate Del handler = null; // Declare a class instance xml: ImportProcedure_Catalog.CatalogJson.ImportProcess table = new ImportProcedure_Catalog.CatalogJson.ImportProcess(); /// Declare an interface instance Table: ImportProcedure_Catalog.CatalogJson.ICatalogTables orderClass = (ImportProcedure_Catalog.CatalogJson.ICatalogTables)table; /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// Identify Catalog Web order table and route them to the corresponding import procedure /// ---------------------------------------------------------------------------- // Catalog Web Order table process handler = orderClass.ProcessCatalogOrder; // /// =========== > bool ok = false; ok = handler(catalogOrder, order, sync); // Process file and WebService // OrdNumber = (catalogOrder.CatalogWebOrderSummary.OrderNumber).ToString(); //} //else //{ // update error order - set imported on and import problem on // ikr.writeSyncLog(1, sync.MwEtlTimerId, 1, sync.ServiceName, "Table reading error order header not found or no items in file, order " + catalogOrder.CatalogWebOrderSummary.OrderNumber); //} } else { // update error order - set imported on and import problem on ikr.writeSyncLog(1, sync.MwEtlTimerId, 1, sync.ServiceName, "Table reading error order header not found or no items in file, order " + OrdNumber); } } catch (Exception fle) { int res = ikr.updImportControl(sync.MwEtlTimerId, 0); // set EtlTimer for this service to not Running (isRunning = false) errMsg.Message = "(Catalog Web order Process) Table reading error - in order " + errMsg.FileName + ". " + fle; ikr.writeSyncLog(1, sync.MwEtlTimerId, 1, sync.ServiceName, errMsg.Message); } }