Ejemplo n.º 1
0
        protected override void Process()
        {
            _monitoring.Notify(Name, 0);

            log.InfoFormat("Start processing Product Price Update");

            var vendorIDsToProcess = VendorSettingsHelper.GetVendorIDsToExportToWehkamp(log);

            foreach (var vendorID in vendorIDsToProcess)
            {
                _monitoring.Notify(Name, vendorID);
                log.InfoFormat("Start processing Product Price Update for VendorID {0}", vendorID);

                var runDateTime = DateTime.Now;

                //Get all price updates that we need to export to Wehkamp
                var products = GetProductsWithChangedPricesData(vendorID);
                if (products == null || products.Count == 0)
                {
                    log.InfoFormat("There are no price updates for VendorID {0}", vendorID);
                    //Update last processed datetime for vendor
                    VendorSettingsHelper.SetLastPriceExportDateTime(vendorID, runDateTime);
                    continue;
                }

                log.InfoFormat("Processing {0} Product Price Updates records for VendorID {1}", products.Count, vendorID);

                //Add all products to the artikelInformatie file
                var priceChange = new prijsAanpassing {
                    aanpassing = new List <prijsAanpassingAanpassing>()
                };

                foreach (var product in products)
                {
                    priceChange.aanpassing.Add(CreateNewPrijsAanpassingItem(product));
                }

                //Save data to disk
                SavePriceChanges(vendorID, priceChange);

                //Process products which needs a price update file
                ProcessResendProductInformationToWehkampProducts(products);

                //Update last processed datetime for vendor
                VendorSettingsHelper.SetLastPriceExportDateTime(vendorID, runDateTime);

                log.InfoFormat("Finished processing Product Price Update for VendorID {0}", vendorID);
            } //end foreach (var vendorID in vendorIDsToProcess)

            log.InfoFormat("Finished processing Product Price Update");
            _monitoring.Notify(Name, 1);
        }
Ejemplo n.º 2
0
        protected override void Process()
        {
            _monitoring.Notify(Name, 0);
            log.InfoFormat("Start processing Stock Return Request");

            var vendorIDsToProcess = VendorSettingsHelper.GetVendorIDsToExportToWehkamp(log);

            foreach (var vendorID in vendorIDsToProcess)
            {
                _monitoring.Notify(Name, vendorID);
                log.InfoFormat("Start processing Stock Return Request for VendorID {0}", vendorID);

                //Get all stock return request that we need to export to Wehkamp
                var stockReturns = GetStockReturnRequestData(vendorID);
                if (stockReturns == null || stockReturns.Count == 0)
                {
                    continue;
                }

                //Add all return requests to the retourAanvraag file
                var returnRequest = new retourAanvraag();

                log.InfoFormat("Start processing {0} Stock Return Requests for VendorID {1}", stockReturns.Count, vendorID);
                var start          = DateTime.Now;
                var processedCount = 0;
                foreach (var stockReturn in stockReturns)
                {
                    returnRequest.aanvraag.Add(CreateNewReturnRequestItem(stockReturn));

                    processedCount++;
                    if (DateTime.Now > start.AddSeconds(30))
                    {
                        log.InfoFormat("Processed {0} Stock Return Requests for VendorID {1}", processedCount, vendorID);
                        start = DateTime.Now;
                    }
                }

                //Save data to disk
                log.InfoFormat("Start saving Stock Return Requests");
                SaveStockReturn(vendorID, returnRequest);

                //Set all orders and orderlines as dispatched
                log.InfoFormat("Start setting Stock Return Requests as dispatched");
                SetReturnRequestsAsExportedToWehkamp(stockReturns);

                log.InfoFormat("Finished processing Stock Return Requests for VendorID {0}", vendorID);
            } //end foreach (var vendorID in vendorIDsToProcess)

            log.InfoFormat("Finished processing Stock Return Requests");
            _monitoring.Notify(Name, 1);
        }
        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);
        }
        protected override void Process()
        {
            _monitoring.Notify(Name, 0);

            var vendorIDsToProcess = VendorSettingsHelper.GetVendorIDsToExportToWehkamp(log);

            foreach (var vendorID in vendorIDsToProcess)
            {
                _monitoring.Notify(Name, vendorID);

                var productIDs = new List <int>();
                var id         = vendorID;
                var messages   = MessageHelper.GetMessagesByStatusAndType(Enums.WehkampMessageStatus.Created, MessageHelper.WehkampMessageType.ProductRelation).Where(m => m.VendorID == id);

                foreach (var message in messages)
                {
                    log.Info(string.Format("{0} - Loading file: {1}", Name, message.Filename));

                    MessageHelper.UpdateMessageStatus(message.MessageID, Enums.WehkampMessageStatus.InProgress);

                    artikelRelatie relatieData;
                    var            loaded = artikelRelatie.LoadFromFile(Path.Combine(message.Path, message.Filename), out relatieData);

                    if (!loaded)
                    {
                        log.AuditError(string.Format("Error while loading file {0}", message.Filename));
                        MessageHelper.Error(message);
                        continue;
                    }

                    try
                    {
                        using (var db = new Database(Environments.Current.Connection, "System.Data.SqlClient"))
                        {
                            var attributeID = db.FirstOrDefault <int>(string.Format("SELECT AttributeID FROM ProductAttributeMetaData WHERE AttributeCode = '{0}'", "WehkampProductNumber"));

                            if (attributeID == 0)
                            {
                                throw new ConfigurationErrorsException("Attribute \"WehkampProductNumber\" is missing from the ProductAttributeMetadata table");
                            }

                            foreach (var rel in relatieData.relatie)
                            {
                                var productID = ProductHelper.GetProductIDByWehkampData(rel.artikelNummer, rel.kleurNummer, message.VendorID);

                                if (productID == 0)
                                {
                                    log.Error(string.Format("No product could be found with VendorItemNumber containing {0} and {1}", rel.artikelNummer, rel.kleurNummer));
                                    continue;
                                }

                                productIDs.Add(productID);


                                var attributevalueid = db.FirstOrDefault <int>(string.Format("SELECT AttributeValueID FROM ProductAttributeValue WHERE AttributeID = '{0}' AND ProductID = '{1}'", attributeID, productID));
                                if (attributevalueid == 0)
                                {
                                    db.Execute(string.Format("INSERT INTO ProductAttributeValue (AttributeID, ProductID, Value, CreatedBy, CreationTime) VALUES ('{0}', '{1}', '{2}', '{3}', getdate())",
                                                             attributeID, productID, rel.wehkampArtikelNummer, 1));
                                }
                                else
                                {
                                    db.Execute(string.Format("UPDATE ProductAttributeValue SET Value = '{1}', LastModifiedBy = '{2}', LastModificationTime = getdate() WHERE AttributeValueID = '{0}'",
                                                             attributevalueid, rel.wehkampArtikelNummer, 1));
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Fatal(string.Format("Error while processing file {0}", message.Filename), ex);

                        MessageHelper.Error(message);
                        continue;
                    }

                    MessageHelper.Archive(message);
                }

                //Process Images for all found products
                var pme = new ProductMediaExport();
                pme.ProcessProductImages(productIDs, vendorID);
            }

            _monitoring.Notify(Name, 1);
        }
Ejemplo n.º 5
0
        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);
        }