예제 #1
0
        private void ExportProducts(IFtpClient ftpClient)
        {
            var skipCounter    = 0;
            var uploadCounter  = 0;
            var failureCounter = 0;
            var productCounter = _products.Count();

            foreach (var product in _products)
            {
                TraceVerbose("Processing product \"{0}\".", product.VendorItemNumber);

                if (_configurableProductWithImage.Contains(product.ProductID))
                {
                    var productModel = CreateProductBizTalkModel(product, DefaultConnector.ConnectorID);

                    var productDom = ProductExporterHelper.SerializeModel(productModel);

                    var localProductDomFilename  = Path.Combine(ExportSettings.LocalExportFolder, String.Format(Resources.ExportFileNameTemplate, product.VendorItemNumber));
                    var remoteProductDomFilename = Path.GetFileName(localProductDomFilename);

                    productDom.Save(localProductDomFilename);

                    if (File.Exists(localProductDomFilename))
                    {
                        if (UploadRequired(localProductDomFilename))
                        {
                            TransferProductFile(ftpClient, localProductDomFilename, remoteProductDomFilename);
                            uploadCounter++;
                        }
                        else
                        {
                            TraceVerbose("Skipping Product: {0}... This product already processed before; upload not required.", product.VendorItemNumber);
                            skipCounter++;
                        }
                    }
                    else
                    {
                        TraceError("XML-file \"{0}\" not ready for transfer to remote server \"{1}\"",
                                   Path.GetFileName(localProductDomFilename), ExportSettings.Server);
                        failureCounter++;
                    }
                }
                else
                {
                    skipCounter++;
                    TraceVerbose("Skipping Product: {0}... This product has no media!", product.VendorItemNumber);
                }

                TraceVerbose("Progress: {0} failure | {1} skipped | {2} uploaded | {3} Products", failureCounter, skipCounter, uploadCounter, productCounter);
            }
        }
예제 #2
0
        /// <summary>
        ///   Cache some relevant data from a Concentrator database, used for lookup during further processing
        /// </summary>
        /// <param name="connectorID">Connector ID from context</param>
        /// <param name="languageID">Language ID from context</param>
        /// <param name="vendorID">Vendor ID from context</param>
        /// <returns>Was caching successful?</returns>
        private bool LoadDatabaseCache()
        {
            var success = false;

            try
            {
                TraceVerbose("Caching product data...");

                using (var pDb = new Database(Connection, Resources.PetaPocoProvider))
                {
                    _currentProducts = pDb
                                       .Query <ConfiguredProductDBModel>(String.Format(GetConfigurableProducts, DefaultConnector.ConnectorID))
                                       .ToList();

                    _configurableProductWithImage = pDb
                                                    .Query <int>(string.Format(GetProductWithImage, DefaultConnector.ConnectorID))
                                                    .ToList();

                    if (ProductIDs.Any())
                    {
                        _currentProducts = _currentProducts
                                           .Where(x => ProductIDs.Contains(x.ProductID))
                                           .ToList();
                    }

                    if (_currentProducts.Any())
                    {
                        var productsQuery = String.Format(GetProducts,
                                                          DefaultConnector.ConnectorID,
                                                          DefaultLanguage.LanguageID,
                                                          DefaultVendor.VendorID,
                                                          ProductExporterHelper.SerializeProductsToSqlParm(_currentProducts, false));

                        _products = pDb
                                    .Query <ProductDBModel>(productsQuery)
                                    .ToList();

                        var relatedProductsQuery = String.Format(GetRelatedProducts,
                                                                 DefaultVendor.VendorID,
                                                                 ProductExporterHelper.SerializeProductsToSqlParm(_currentProducts, false));

                        _relatedProducts = pDb
                                           .Query <RelatedProductDBModel>(relatedProductsQuery)
                                           .ToList();

                        List <Int32> listOfAllProducts = _products
                                                         .Select(x => x.ProductID)
                                                         .ToList();

                        listOfAllProducts.AddRange(
                            _relatedProducts.Select(x => x.SimpleProductID)
                            );

                        var productAttributesQuery = String.Format(GetAttributes,
                                                                   DefaultVendor.VendorID,
                                                                   DefaultLanguage.LanguageID,
                                                                   ProductExporterHelper.SerializeProductsToSqlParm(listOfAllProducts));

                        _productAttributes = pDb
                                             .Query <ProductAttributeValueDBModel>(productAttributesQuery)
                                             .ToList();

                        success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                TraceError("Data retrieval aborted: ", ex.Message);
            }
            return(success);
        }