예제 #1
0
        public bool Publish(out List <string> publishDetails, BackgroundWorker bw = null)
        {
            publishDetails = new List <string>();

            var apiKey = Settings.GetApiKey();

            if (!string.IsNullOrEmpty(apiKey))
            {
                var categoriesToImport = new ProductCategoryRepository(Settings.ConnectionString).GetAll().ToList();

                var existingCategories = WebServiceHelper.GetAllCategories();

                //create all categories if they don't exist
                var numOfPublishedCategories = 0;
                foreach (var category in categoriesToImport)
                {
                    if (existingCategories.All(s => s?.Name != category.Category))
                    {
                        var pushableCategory = new PrivateCategory {
                            Name = category.Category
                        };
                        //if (!string.IsNullOrWhiteSpace(category.ParentCategoryName))
                        //{
                        //    pushableCategory.ParentCategoryId = GetParentCategoryID(existingCategories, category);
                        //}
                        //else
                        //{
                        pushableCategory.Depth = 0;
                        //}
                        existingCategories.Add(WebServiceHelper.PushCategory(pushableCategory));
                        publishDetails.Add($"Added category: {category.Category}");
                        numOfPublishedCategories++;
                    }
                }

                if (numOfPublishedCategories == 0)
                {
                    Logger.Instance.Warning("No categories were found to import.");
                }

                publishDetails.Insert(0, $"{numOfPublishedCategories} Categories published.");

                Logger.Instance.Info($"{numOfPublishedCategories} Categories published.");
                Logger.Instance.Debug($"{numOfPublishedCategories} Categories published. ApiKey: {apiKey}");

                return(true);
            }

            Logger.Instance.Warning("No Api Key set.");

            return(false);
        }
예제 #2
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);
        }
        public WebResponseContentModel <List <CategorieModel> > GetAllCategories()
        {
            WebResponseContentModel <List <CategorieModel> > categories = new WebResponseContentModel <List <CategorieModel> >();

            try
            {
                categories = GetResponseFromWebRequest <WebResponseContentModel <List <CategorieModel> > >(WebServiceHelper.GetAllCategories(), "get");
            }
            catch (Exception ex)
            {
                categories.ValidationErrorAppSide = ConcatenateExceptionMessage(ex);
            }

            return(categories);
        }
예제 #4
0
        public bool Publish(out List <string> publishDetails, BackgroundWorker bw = null)
        {
            publishDetails = new List <string>();
            Empty();

            var mappedDsnName = new Mapping().GetDsnName("BuyerInventories");
            var newMapping    = new Mapping(mappedDsnName);

            if (newMapping.MigrateData("BuyerInventories"))
            {
                Logger.Instance.Debug($"Buyer Inventory migrated using DSN: {mappedDsnName}");
            }
            else
            {
                Logger.Instance.Warning("Failed to migrate Buyer Inventory.");
            }

            var apiKey = Settings.GetApiKey();

            if (string.IsNullOrEmpty(apiKey))
            {
                Logger.Instance.Warning("No Api Key set while executing products publish.");
                return(false);
            }

            var products           = _repository.GetAll().ToList();
            var existingCategories = WebServiceHelper.GetAllCategories();

            // TODO: There's no GetAll() for the BuyerInventory service
            var existingInventory = WebServiceHelper.GetAllInventory();
            var items             = 0;

            foreach (var product in products)
            {
                var existingCategory = existingCategories.FirstOrDefault(c => c.Name == product.Category);
                if (existingCategory == null)
                {
                    existingCategory = WebServiceHelper.PushCategory(new PrivateCategory {
                        Name = product.Category
                    });
                    existingCategories.Add(existingCategory);
                }

                var existingProduct = existingInventory.FirstOrDefault(i => i.PrivateSKU == product.PrivateSku);

                dynamic request = new ExpandoObject();
                // NOTE: This is case-sensitive!?
                request.PrivateSKU  = product.PrivateSku;
                request.CategoryId  = (existingCategory?.Id).GetValueOrDefault();
                request.Description = product.Description ?? string.Empty;

                if (existingProduct != null)
                {
                    request.Id = existingProduct.Id;
                }
                if (product.Inactive.HasValue)
                {
                    request.Inactive = product.Inactive.Value;
                }

                //TODO: Get the location first
                if (product.LocationId.HasValue)
                {
                    request.LocationId = product.LocationId.Value;
                }
                if (!string.IsNullOrEmpty(product.UPC))
                {
                    request.UPC = product.UPC;
                }

                if (product.MinOrderSpring.HasValue)
                {
                    request.MinOrderSpring = product.MinOrderSpring.Value;
                }
                if (product.MinOrderSummer.HasValue)
                {
                    request.MinOrderSummer = product.MinOrderSummer.Value;
                }
                if (product.FreightFactor.HasValue)
                {
                    request.FreightFactor = product.FreightFactor.Value;
                }
                if (product.QuantityAvailable.HasValue)
                {
                    request.QuantityAvailable = product.QuantityAvailable >= 1 ? product.QuantityAvailable : 1;
                }
                if (!string.IsNullOrEmpty(product.Comments))
                {
                    request.Comments = product.Comments;
                }
                if (product.SuggestedRetailPrice.HasValue)
                {
                    request.SuggestedRetailPrice = product.SuggestedRetailPrice.Value;
                }
                if (!string.IsNullOrEmpty(product.OpenSizeDescription))
                {
                    request.OpenSizeDescription = product.OpenSizeDescription;
                }
                if (product.NetPrice.HasValue)
                {
                    request.NetPrice = product.NetPrice;
                }
                if (product.SlaveQuantityPerMaster.HasValue)
                {
                    request.SlaveQuantityPerMaster = product.SlaveQuantityPerMaster;
                }
                if (!string.IsNullOrEmpty(product.SlaveQuantityDescription))
                {
                    request.SlaveQuantityDescription = product.SlaveQuantityDescription;
                }
                if (!string.IsNullOrEmpty(product.MasterQuantityDescription))
                {
                    request.MasterQuantityDescription = product.MasterQuantityDescription;
                }
                if (product.RetailPrice.HasValue)
                {
                    request.RetailPrice = product.RetailPrice;
                }
                if (product.RetailOrderLevel.HasValue)
                {
                    request.RetailOrderLevel = product.RetailOrderLevel;
                }
                if (product.AmazonSell.HasValue)
                {
                    request.AmazonSell = product.AmazonSell;
                }
                if (product.OnlineSell.HasValue)
                {
                    request.OnlineSell = product.OnlineSell;
                }
                if (product.SupplierId.HasValue)
                {
                    request.SupplierId = product.SupplierId;
                }
                if (!string.IsNullOrEmpty(product.SupplierSku))
                {
                    request.SupplierSku = product.SupplierSku;
                }

                WebServiceHelper.PushBuyerInventory(request);

                Logger.Instance.Debug($"Finished importing inventory {++items} of {products.Count}. Id: {product.Id}");
            }

            publishDetails.Insert(0, $"{items} inventory items have been pushed to LinkGreen");

            return(true);
        }
예제 #5
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);
        }