Beispiel #1
0
        public void SaveFieldMapping(string fieldName, string mappingName)
        {
            var productRepository = new ProductInventoryRepository(Settings.ConnectionString);

            productRepository.SaveFieldMapping(fieldName, mappingName);
            Logger.Instance.Debug($"Products field mapping saved: (Field: {fieldName}, MappingField: {mappingName})");
        }
Beispiel #2
0
        public void SaveTableMapping(string dsnName, string tableName)
        {
            var productRepository = new ProductInventoryRepository(Settings.ConnectionString);

            productRepository.SaveTableMapping(dsnName, tableName, "Products");
            Logger.Instance.Debug($"Products table mapping saved: (DSN: {dsnName}, Table: {tableName})");
        }
Beispiel #3
0
        public bool Empty()
        {
            var productInventoryRepository = new ProductInventoryRepository(Settings.ConnectionString);

            productInventoryRepository.ClearAll();
            Logger.Instance.Info("Products LinkGreen transfer table emptied.");
            Logger.Instance.Debug($"{Settings.ConnectionString}.Products emptied.");
            return(true);
        }
        /// <summary>
        /// Occurs when RunWorkerAsync is called.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void LoadProductInventoriesBackground(object sender, DoWorkEventArgs e)
        {
            IProductInventoryRepository productInventoryRepository = new ProductInventoryRepository();

            BackgroundWorker source = (BackgroundWorker)sender;

            var results = productInventoryRepository.GetAllProductInventories();
            int index   = 0;

            foreach (var item in results)
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
                source.ReportProgress(++index, item);
            }
        }
 public CatalogService(RequestContext c,
                       CategoryRepository categories,
                       CategoryProductAssociationRepository crosses,
                       ProductRepository products,
                       ProductRelationshipRepository relationships,
                       ProductImageRepository productImages,
                       ProductReviewRepository productReviews,
                       VariantRepository productVariants,
                       OptionRepository productOptions,
                       ProductOptionAssociationRepository productsXOptions,
                       ProductFileRepository productFiles,
                       ProductVolumeDiscountRepository volumeDiscounts,
                       ProductPropertyValueRepository propertyValues,
                       ProductInventoryRepository inventory,
                       ProductTypeRepository types,
                       ProductTypePropertyAssociationRepository typesXProperties,
                       ProductPropertyRepository properties,
                       WishListItemRepository wishItems)
 {
     context = c;
     Categories = categories;
     CategoriesXProducts = crosses;
     ProductRelationships = relationships;
     this.Products = products;
     this.ProductImages = productImages;
     this.ProductReviews = productReviews;
     this.ProductVariants = productVariants;
     this.ProductOptions = productOptions;
     this.ProductsXOptions = productsXOptions;
     this.ProductFiles = productFiles;
     this.VolumeDiscounts = volumeDiscounts;
     this.ProductPropertyValues = propertyValues;
     this.ProductInventories = inventory;
     this.ProductTypes = types;
     this.ProductTypesXProperties = typesXProperties;
     this.ProductProperties = properties;
     this.WishListItems = wishItems;
 }
Beispiel #6
0
 public AWUnitOfWork(AWContext context)
 {
     _context                = context;
     Address                 = new AddressRepository(context);
     BusinessEntity          = new BusinessEntityRepository(context);
     BusinessEntityAddress   = new BusinessEntityAddressRepository(context);
     PersonPhone             = new PersonPhoneRepository(context);
     StateProvince           = new StateProvinceRepository(context);
     Customer                = new CustomerRepository(context);
     SalesPerson             = new SalesPersonRepository(context);
     SalesOrderHeader        = new SalesOrderHeaderRepository(context);
     SalesOrderDetail        = new SalesOrderDetailRepository(context);
     ShoppingCartItem        = new ShoppingCartItemRepository(context);
     SalesTerritory          = new SalesTerritoryRepository(context);
     Product                 = new ProductRepository(context);
     ProductCategory         = new ProductCategoryRepository(context);
     ProductDescription      = new ProductDescriptionRepository(context);
     ProductInventory        = new ProductInventoryRepository(context);
     ProductListPriceHistory = new ProductListPriceHistoryRepository(context);
     ProductPhoto            = new ProductPhotoRepository(context);
     ProductProductPhoto     = new ProductProductPhotoRepository(context);
     Person = new PersonRepository(context);
 }
Beispiel #7
0
        public bool Publish(out List <string> publishDetails, BackgroundWorker bw = null)
        {
            publishDetails = new List <string>();
            string apiKey = Settings.GetApiKey();

            if (!string.IsNullOrEmpty(apiKey))
            {
                var products           = new ProductInventoryRepository(Settings.ConnectionString).GetAll().ToList();
                var existingCategories = WebServiceHelper.GetAllCategories();

                var existingInventory = WebServiceHelper.GetAllInventory();
                var items             = 0;

                var bulkPushRequest = new List <InventoryItemRequest>();


                var productsToAdd = products.Where(p => existingInventory.All(ei => ei.PrivateSKU != p.Id));
                // Add new items
                foreach (var product in productsToAdd)
                {
                    try
                    {
                        var request = AddOrUpdateSupplierItem(product, existingInventory, ref existingCategories);
                        WebServiceHelper.PushInventoryItem(request, out var statusCode, out var content);

                        bw?.ReportProgress(0,
                                           $"Processing product sync (Pushing {++items}/{products.Count})\n\rPlease wait");
                        Logger.Instance.Debug(
                            $"Finished importing product {items} of {products.Count}. Id: {product.Id}");
                        Logger.Instance.Debug($"Adding response {product.Id} {statusCode}");
                        Logger.Instance.Debug($"Adding response {product.Id} {content}");
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Error("Adding " + JsonConvert.SerializeObject(product) + Environment.NewLine + ex.Message +
                                              Environment.NewLine + ex.StackTrace);
                    }
                }

                // Update existing items
                foreach (var product in products.Where(p => existingInventory.Any(ei => ei.PrivateSKU == p.Id)))
                {
                    try
                    {
                        var request = AddOrUpdateSupplierItem(product, existingInventory, ref existingCategories);
                        if (request != null)
                        {
                            bulkPushRequest.Add(request);
                        }
                        if (bulkPushRequest.Count > 10)
                        {
                            WebServiceHelper.PushBulkUpdateInventoryItem(bulkPushRequest.ToArray(), out var statusCode,
                                                                         out var content);
                            Logger.Instance.Debug($"Bulk Push: Response: {statusCode}");
                            Logger.Instance.Debug($"Bulk Push: Response Content: {content}");
                            bulkPushRequest.Clear();
                        }

                        bw?.ReportProgress(0,
                                           $"Processing product sync (Pushing {++items}/{products.Count})\n\rPlease wait");
                        Logger.Instance.Debug(
                            $"Finished importing product {items} of {products.Count}. Id: {product.Id}");
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Error("Updating " + JsonConvert.SerializeObject(product) + Environment.NewLine + ex.Message +
                                              Environment.NewLine + ex.StackTrace);
                    }
                }

                if (bulkPushRequest.Count > 0)
                {
                    WebServiceHelper.PushBulkUpdateInventoryItem(bulkPushRequest.ToArray(), out var statusCode, out var content);
                    Logger.Instance.Debug($"Bulk Push Response {statusCode}");
                    Logger.Instance.Debug($"Bulk Push Response {content}");
                }


                WebServiceHelper.PostInventoryImport();
                publishDetails.Insert(0, $"{items} products published to LinkGreen");
                return(true);
            }

            publishDetails.Insert(0, "No Api Key set while executing products publish.");
            Logger.Instance.Warning("No Api Key set while executing products publish.");

            return(false);
        }
Beispiel #8
0
        public bool Publish(out List <string> publishDetails, BackgroundWorker bw = null)
        {
            publishDetails = new List <string>();
            string apiKey = Settings.GetApiKey();

            if (!string.IsNullOrEmpty(apiKey))
            {
                var products           = new ProductInventoryRepository(Settings.ConnectionString).GetAll().ToList();
                var existingCategories = WebServiceHelper.GetAllCategories();

                var existingInventory = WebServiceHelper.GetAllInventory();
                var items             = 0;

                var bulkPushRequest = new List <InventoryItemRequest>();


                var productsToAdd = products.Where(p => existingInventory.All(ei => ei.PrivateSKU != p.Id));
                // Add new items
                foreach (var product in productsToAdd)
                {
                    var request = AddOrUpdateSupplierItem(product, existingInventory, ref existingCategories);
                    WebServiceHelper.PushInventoryItem(request);

                    bw?.ReportProgress(0, $"Processing product sync (Pushing {++items}/{products.Count})\n\rPlease wait");
                    Logger.Instance.Debug($"Finished importing product {items} of {products.Count}. Id: {product.Id}");
                }

                // Update existing items
                foreach (var product in products.Where(p => existingInventory.Any(ei => ei.PrivateSKU == p.Id)))
                {
                    var request = AddOrUpdateSupplierItem(product, existingInventory, ref existingCategories);
                    if (request != null)
                    {
                        bulkPushRequest.Add(request);
                    }
                    if (bulkPushRequest.Count > 10)
                    {
                        WebServiceHelper.PushBulkUpdateInventoryItem(bulkPushRequest.ToArray());
                        bulkPushRequest.Clear();
                    }

                    bw?.ReportProgress(0, $"Processing product sync (Pushing {++items}/{products.Count})\n\rPlease wait");
                    Logger.Instance.Debug($"Finished importing product {items} of {products.Count}. Id: {product.Id}");
                }

                if (bulkPushRequest.Count > 0)
                {
                    WebServiceHelper.PushBulkUpdateInventoryItem(bulkPushRequest.ToArray());
                }


                WebServiceHelper.PostInventoryImport();
                publishDetails.Insert(0, $"{items} products published to LinkGreen");
                return(true);
            }

            publishDetails.Insert(0, "No Api Key set while executing products publish.");
            Logger.Instance.Warning("No Api Key set while executing products publish.");

            return(false);
        }