예제 #1
0
 public bool BaseGet(AkeneoProduct product, string requestUrl)
 {
     try
     {
         IBaseRequestHandler <NameValueCollection, WebClientHeader> httpManager = new BaseWebClientWriter();
         httpManager.GetData(requestUrl, new WebClientHeader("", ""));
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public void ListenerThread(string requestUrl)
        {
            ProcessStatus = (int)AkeneoProductIndexerStatuses.ListingInProgress;
            HttpManager   = new BaseWebClientWriter();
            try
            {
                var response = HttpManager.GetData(requestUrl, new WebClientHeader("Authorization", $"Bearer {AuthToken}"));
                AkeneoIndexedProductDto dto = JsonConvert.DeserializeObject <AkeneoIndexedProductDto>(response);
                if (dto.LinksCollection.NextLink != null)
                {
                    var thread = new Thread(() =>
                    {
                        ListenerThread(dto.LinksCollection.NextLink.Href);
                    });
                    thread.Start();
                }

                if (dto.Embed.ItemsCollection != null && dto.Embed.ItemsCollection.Count > 0)
                {
                    var converter = new AkeneoBaseProductIndexerConverter();
                    foreach (var selected in dto.Embed.ItemsCollection)
                    {
                        try
                        {
                            var tempProductStorage = converter.ConvertToApplicationEntity(selected);
                            lock (RequestList)
                            {
                                RequestList.Add(tempProductStorage);
                            }
                        }
                        catch (Exception e)
                        {
                            _logger.error(
                                $"(AkeneoBaseProductIndexerConverter exception): Cannot convert dto entity:  {e.Message}");
                        }
                    }
                }

                if (dto.LinksCollection.NextLink == null)
                {
                    ProcessStatus = (int)AkeneoProductIndexerStatuses.ListingFinished;
                    InvokeOnFinishedListing();
                }
            }
            catch (Exception e)
            {
                _logger.error(e.Message);
            }
        }
 public void ListenerThread(string requestUrl)
 {
     ProcessStatus = AkeneoProductIndexerStatuses.ListingInProgress;
     HttpManager   = new BaseWebClientWriter();
     try
     {
         var data = HttpManager.GetData(requestUrl, new WebClientHeader("Authorization", $"Bearer {AuthToken}"));
         AkeneoIndexedCategoriesDto dto = JsonConvert.DeserializeObject <AkeneoIndexedCategoriesDto>(data);
         if (!ReferenceEquals(dto.LinksCollection.NextLink, null))
         {
             new Thread(() => {
                 ListenerThread(dto.LinksCollection.NextLink.Href);
             }).Start();
         }
         if (dto.Embed.ItemsCollection.Count > 0)
         {
             foreach (var selected in dto.Embed.ItemsCollection)
             {
                 var _c = new AkeneoBaseCategoriesIndexerConverter();
                 try
                 {
                     var _t = _c.ConvertToApplicationEntity(selected);
                     lock (RequestList)
                     {
                         RequestList.Add(_t);
                     }
                 }
                 catch (Exception e)
                 {
                     _l.error($"AkeneoBaseCategoriesListener exception: cannot convert dto entity to application entity: {e.Message} -> {e.StackTrace}");
                 }
             }
         }
         if (ReferenceEquals(dto.LinksCollection.NextLink, null))
         {
             ProcessStatus = AkeneoProductIndexerStatuses.ListingFinished;
             InvokeOnFinishedListing();
         }
     }
     catch (Exception e)
     {
         _l.error($"Akeneo categories indexer: error occured - {e.Message} -> {e.StackTrace}");
     }
 }
예제 #4
0
 protected bool MakeProductOutOfStock(BaseShopifyProductEntity product)
 {
     _l.info($"Shopify service -> WebClient: start.");
     try
     {
         _l.info($"Shopify service -> WebClient: started with success code.");
         var httpManager = new BaseWebClientWriter();
         _l.info($"Shopify service -> WebClient: creating auth credentials");
         var credentials = new NetworkCredential(Settings.ShopifyApiKey, Settings.ShopifyApiToken);
         _l.info($"Shopify service -> WebClient: auth credentials successfully created");
         _l.info($"Shopify service -> WebClient: sending request to {Settings.ShopifyApiProtocol}{Settings.ShopifyStoreUrl}{Settings.ShopifyBaseProuctsUpdateUrl}{product.ProductId}{Settings.ShopifyBaseProuctsUpdateUrlExtension}");
         string productEncoded = httpManager.GetData($"{Settings.ShopifyApiProtocol}{Settings.ShopifyStoreUrl}{Settings.ShopifyBaseProuctsUpdateUrl}{product.ProductId}{Settings.ShopifyBaseProuctsUpdateUrlExtension}", credentials);
         _l.info("Shopify service -> request finished, checking results...");
         if (!ReferenceEquals(productEncoded, null) && !productEncoded.Equals(String.Empty))
         {
             _l.info("Shopify service: decoding json string to application dto");
             ShopifyBaseDtoObject productS = JsonConvert.DeserializeObject <ShopifyBaseDtoObject>(productEncoded);
             _l.info("Shopify service: json string successfully decoded to application dto");
             _l.info($"Shopify service: creating body for request.");
             string body = String.Concat("{\"product\":{\"id\":", product.ProductId, ", \"variants\":[{", $"\"id\":{productS.Product.ProductVariants.FirstOrDefault().VariantIdentifier}, \"inventory_policy\": \"deny\", \"inventory_quantity\":0, \"inventory_management\": \"shopify\"", "}]}}");
             _l.info($"Shopify service: body request successfuly created -> {body}");
             _l.info($"Shopify service -> WebClient: adding string body context to the request.");
             httpManager.AddBodyParameter(body);
             _l.info($"Shopify service -> WebClient: body context successfully added to the request.");
             _l.info($"Shopify service -> WebClient: sending request to the shopify");
             var response = httpManager.PutData($"{Settings.ShopifyApiProtocol}{Settings.ShopifyStoreUrl}{Settings.ShopifyBaseProuctsUpdateUrl}{product.ProductId}{Settings.ShopifyBaseProuctsUpdateUrlExtension}", credentials);
             _l.info($"Shopify service -> WebClient: request successfully processed with success code!");
             return(true);
         }
         else
         {
             _l.error($"Shopify service: fatal, cannot vaidate response from {Settings.ShopifyApiProtocol}{Settings.ShopifyStoreUrl}{Settings.ShopifyBaseProuctsUpdateUrl}{product.ProductId}{Settings.ShopifyBaseProuctsUpdateUrlExtension}");
             return(false);
         }
     }
     catch (Exception e)
     {
         _l.error($"Shopify service: fatal, {e.Message} -> {e.StackTrace}");
         return(false);
     }
 }
예제 #5
0
        public void ProductsListenerThread(string requestUrl)
        {
            var httpManager = new BaseWebClientWriter();

            try
            {
                var credentials     = new NetworkCredential(Settings.ShopifyApiKey, Settings.ShopifyApiToken);
                var ShopifyResponse = httpManager.GetData(requestUrl, credentials);
                var lastHeader      = httpManager.LastHeader;
                if (lastHeader.Contains("next"))
                {
                    string next = lastHeader.Replace("<", "").Replace(">; rel=\"next\"", "");
                    new Thread(() => {
                        ProductsListenerThread(next);
                    }).Start();
                }
                if (!ShopifyResponse.Equals(String.Empty))
                {
                    var productsList = JsonConvert.DeserializeObject <ShopifyBaseDtoObject>(ShopifyResponse);
                    if (!ReferenceEquals(productsList.ProductsCollection, null) && productsList.ProductsCollection.Count > 0)
                    {
                        foreach (var product in productsList.ProductsCollection)
                        {
                            ShopifyEntitesBaseConverter _c = new ShopifyEntitesBaseConverter();
                            ShopifyProductsList.Add(_c.ConvertToApplicationEntity(product));
                        }
                    }
                }
                if (!lastHeader.Contains("next"))
                {
                    InvokeOnShopifyIndexationFinished();
                }
            } catch (Exception e)
            {
                _l.error($"Error during sending request to {requestUrl} -> {e.Message} : {e.StackTrace}");
            }
        }