Пример #1
0
 public AkeneoCategory CreateNewCategory(AkeneoCategory category, AkeneoProduct product)
 {
     try
     {
         _logger.info($"Creating category {category.CategoryName} : {product.productName} -> start");
         IBaseRequestHandler <NameValueCollection, WebClientHeader> httpManager = new BaseWebClientWriter();
         var _c = new AkeneoBaseCategoriesIndexerConverter();
         category.CategoryId = category.CategoryName.Trim().ToLower().Replace(" ", "_").Replace("-", "_").Replace("/", "_").Replace("?", "_").Replace(".", "_").Replace(",", "_").Replace("&", "_");
         AkeneoIndexedCategoriesDtoEmbedCollectionItem dtoCat = _c.ConvertToDtoEntity(category);
         if (!ReferenceEquals(dtoCat, null) &&
             !ReferenceEquals(dtoCat.CategoryCode, null) &&
             !ReferenceEquals(dtoCat.CategoriesLocales, null) &&
             !ReferenceEquals(dtoCat.CategoriesLocales.Count, 0))
         {
             var EncodedContent = JsonConvert.SerializeObject(dtoCat);
             httpManager.AddHeader(new WebClientHeader("Authorization", $"Bearer {akeneoAuthInfo.access_token}"));
             httpManager.AddBodyParameter(EncodedContent);
             httpManager.PostDataAsStringContext($"{Akeneo.BaseAkeneoUrl}{Akeneo.AkeneoCategoryListUrl}");
             return(category);
         }
         return(null);
         //AkeneoIndexedCategoriesDtoEmbedCollectionItem
     }
     catch (Exception e)
     {
         _logger.error($"{category.CategoryName} -> {product.productName} Error in creating akeneo category: {e.Message} -> {e.StackTrace}");
         return(null);
     }
 }
 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}");
     }
 }