private bool SaveProductInformation(int vendorID, artikelInformatie artInfo) { var alliantieName = VendorSettingsHelper.GetAlliantieName(vendorID); var retailPartnerCode = VendorSettingsHelper.GetRetailPartnerCode(vendorID); var sequenceNumberArtikelInformatie = CommunicatorHelper.GetSequenceNumber(vendorID); artInfo.header.berichtDatumTijd = DateTime.Now; artInfo.header.berichtNaam = "artikelInformatie"; artInfo.header.retailPartnerCode = retailPartnerCode; artInfo.header.bestandsNaam = string.Format("{0}{1}artikelInformatie.xml", sequenceNumberArtikelInformatie, alliantieName); var messageIDArtInfo = MessageHelper.InsertMessage(MessageHelper.WehkampMessageType.ProductInformation, artInfo.header.bestandsNaam, vendorID); try { artInfo.SaveToFile(Path.Combine(ConfigurationHelper.ProductInformationRootFolder, vendorID.ToString(CultureInfo.InvariantCulture), artInfo.header.bestandsNaam)); MessageHelper.UpdateMessageStatus(messageIDArtInfo, WehkampMessageStatus.Success); } catch (Exception ex) { log.Fatal("Error while saving artikelInfo file", ex); MessageHelper.UpdateMessageStatus(messageIDArtInfo, WehkampMessageStatus.Error); return(false); } return(true); }
/// <summary> /// Deserializes workflow markup into an artikelInformatie object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output artikelInformatie object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out artikelInformatie obj, out System.Exception exception) { exception = null; obj = default(artikelInformatie); try { obj = Deserialize(xml); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
/// <summary> /// Deserializes xml markup from file into an artikelInformatie object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output artikelInformatie object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool LoadFromFile(string fileName, out artikelInformatie obj, out System.Exception exception) { exception = null; obj = default(artikelInformatie); try { obj = LoadFromFile(fileName); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
protected override void Process() { _monitoring.Notify(Name, 0); log.InfoFormat("Start processing Product Information"); var vendorIDsToProcess = VendorSettingsHelper.GetVendorIDsToExportToWehkamp(log); foreach (var vendorID in vendorIDsToProcess) { _monitoring.Notify(Name, vendorID); log.InfoFormat("Start processing Product Information for VendorID {0}", vendorID); var productIDsInFile = new List <int>(); //Get all products that we need to export to Wehkamp var products = GetProductInformationData(vendorID); if (products == null || products.Count == 0) { log.InfoFormat("No 'export to wehkamp' products found for VendorID {0}", vendorID); continue; } //Add all products to the artikelInformatie file var artInfo = new artikelInformatie(); log.InfoFormat("Start processing {0} products for VendorID {1}", products.Count, vendorID); var start = DateTime.Now; var processedCount = 0; foreach (var product in products) { artikelInformatieArtikel artikel; try { artikel = CreateNewArtikelInformatieArtikel(product); productIDsInFile.Add(product.ProductID); } catch (Exception e) { log.AuditError(string.Format("Can't create Wehkamp article for product: id='{0}' - vendoritemnumber='{1}'. Product isn't exported to Wehkamp", product.ProductID, product.VendorItemNumber), e); continue; } var sizes = GetProductSizes(vendorID, product.ProductID); foreach (var size in sizes) { artikel.maatlijst.Add(CreateNewArtikelInformatieMaatGegevens(size)); } artInfo.artikel.Add(artikel); processedCount++; if (DateTime.Now > start.AddSeconds(30)) { log.InfoFormat("Processed {0} products for VendorID {1}", processedCount, vendorID); start = DateTime.Now; } } //Create productattributes (artikelEigenschap) for all products in artikelInformatie file var artikelEigenschapData = CreateProductAttributes(products); //Save data to disk log.InfoFormat("Start saving Product Information"); var productInformationSaved = SaveProductInformation(vendorID, artInfo); log.InfoFormat("Start saving Product Attributes"); var productAttributesSaved = SaveProductAttributes(vendorID, artikelEigenschapData); if (productInformationSaved && productAttributesSaved) { //Set all products as SentToWehkamp = true log.InfoFormat("Start setting products as SentToWehkamp"); SetProductsAsSentToWehkamp(productIDsInFile); //Remove SentAsDummy attribute if sent before as a dummy product log.InfoFormat("Start cleaning SentAsDummy attribute"); RemoveSentAsDummy(productIDsInFile); //Process products which needs a price update file ProcessResendPriceUpdateToWehkampProducts(products, vendorID); } log.InfoFormat("Finished processing Product Information for VendorID {0}", vendorID); } //end foreach (var vendorID in vendorIDsToProcess) log.InfoFormat("Finished processing Product Information"); _monitoring.Notify(Name, 1); }
public static bool LoadFromFile(string fileName, out artikelInformatie obj) { System.Exception exception = null; return(LoadFromFile(fileName, out obj, out exception)); }
public static bool Deserialize(string xml, out artikelInformatie obj) { System.Exception exception = null; return(Deserialize(xml, out obj, out exception)); }
protected override void Process() { _monitoring.Notify(Name, 0); log.InfoFormat("Start processing Shipment Notification"); var vendorIDsToProcess = VendorSettingsHelper.GetVendorIDsToExportToWehkamp(log); foreach (var vendorID in vendorIDsToProcess) { _monitoring.Notify(Name, vendorID); log.InfoFormat("Start processing Shipment Notification for VendorID {0}", vendorID); var dummyProductIDsInFile = new List <int>(); //Get all products in shipment notification that we need to export to Wehkamp var products = GetShipmentNotificationProductInformationData(vendorID); if (products == null || products.Count == 0) { continue; } //Add all products to the artikelInformatie file that aren't sent to Wehkamp before var artInfo = new artikelInformatie(); //Add all products to the aankomst file var shipmentInfo = new aankomst(); foreach (var product in products) { shipmentInfo.aankomsten.Add(CreateNewShipmentItem(product, vendorID)); //Create dummy product if parentproduct isn't sent to Wehkamp (as dummy or regular product) if ((string.IsNullOrEmpty(product.ParentSentToWehkamp) || product.ParentSentToWehkamp.ToLower(CultureInfo.InvariantCulture) == "false") && (string.IsNullOrEmpty(product.ParentSentToWehkampAsDummy) || product.ParentSentToWehkampAsDummy.ToLower(CultureInfo.InvariantCulture) == "false") && !dummyProductIDsInFile.Contains(product.ParentProductID)) { var artikel = CreateNewDummyArtikelInformatieArtikel(product); var sizes = GetDummyProductSizes(vendorID, product.ParentProductID); foreach (var size in sizes) { artikel.maatlijst.Add(CreateNewDummyArtikelInformatieMaatGegevens(size)); } artInfo.artikel.Add(artikel); if (!dummyProductIDsInFile.Contains(product.ParentProductID)) { dummyProductIDsInFile.Add(product.ParentProductID); } if (!dummyProductIDsInFile.Contains(product.ProductID)) { dummyProductIDsInFile.Add(product.ProductID); } } } var orderIDs = products.Select(p => p.OrderID).Distinct().ToList(); using (var db = new PetaPoco.Database(Environments.Current.Connection, "System.Data.SqlClient")) { db.BeginTransaction(System.Data.IsolationLevel.ReadCommitted); db.CommandTimeout = 60; try { var updateOrdersSql = string.Format("UPDATE [Order] SET IsDispatched = 1, DispatchToVendorDate = getdate() WHERE OrderID IN ({0})", string.Join(",", orderIDs.ToArray())); db.Execute(updateOrdersSql); foreach (var orderID in orderIDs) { var id = orderID; var item = from p in products where p.OrderID == id select p; var orderLineIDs = item.Select(p => p.OrderLineID).Distinct().ToList(); var updateOrderLinesSql = string.Format("UPDATE [OrderLine] SET IsDispatched = 1, DispatchedToVendorID = {1} WHERE OrderLineID IN ({0})", string.Join(",", orderLineIDs.ToArray()), vendorID); db.Execute(updateOrderLinesSql); } //Save data to disk if (artInfo.artikel.Count != 0) { SaveProductInformation(vendorID, artInfo, db); //Set all dummy products as SentToAsDummyWehkamp = true SetDummyProductsAsSentAsDummyToWehkamp(dummyProductIDsInFile, db); } SaveShipmentInformation(vendorID, shipmentInfo, db); db.CompleteTransaction(); } catch (Exception e) { db.AbortTransaction(); log.AuditError("Something went wrong while updating the order dispatched status or saving the files in the wehkamp drives", e); } } log.InfoFormat("Finished processing Shipment Notification for VendorID {0}", vendorID); } //end foreach (var vendorID in vendorIDsToProcess) log.InfoFormat("Finished processing Shipment Notification"); _monitoring.Notify(Name, 1); }