private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback) { const ResponseGroup responseGroup = ResponseGroup.Full; var searchResponse = _catalogSearchService.Search(new SearchCriteria { Count = int.MaxValue, GetAllCategories = true, Start = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); var progressNotifier = new ProgressNotifier("{0} of {1} catalogs loaded", searchResponse.Catalogs.Count(), progressCallback); foreach (var catalog in searchResponse.Catalogs) { retVal.Catalogs.Add(_catalogService.GetById(catalog.Id)); progressNotifier.Notify(); } progressNotifier = new ProgressNotifier("{0} of {1} categories loaded", searchResponse.Categories.Count(), progressCallback); foreach (var category in searchResponse.Categories) { retVal.Categories.Add(_categoryService.GetById(category.Id)); progressNotifier.Notify(); } progressNotifier = new ProgressNotifier("{0} of {1} products loaded", searchResponse.TotalCount, progressCallback); foreach (var product in searchResponse.Products) { retVal.Products.Add(_itemService.GetById(product.Id, ItemResponseGroup.ItemMedium | ItemResponseGroup.Variations | ItemResponseGroup.Seo)); progressNotifier.Notify(); } var catalogsPropertiesIds = retVal.Catalogs.SelectMany(x => _propertyService.GetCatalogProperties(x.Id)).Select(x => x.Id).ToArray(); var categoriesPropertiesIds = retVal.Categories.SelectMany(x => _propertyService.GetCategoryProperties(x.Id)).Select(x => x.Id).ToArray(); var propertiesIds = catalogsPropertiesIds.Concat(categoriesPropertiesIds).Distinct().ToArray(); progressNotifier = new ProgressNotifier("{0} of {1} properties loaded", propertiesIds.Count(), progressCallback); foreach (var propertyId in propertiesIds) { var property = _propertyService.GetById(propertyId); retVal.Properties.Add(property); progressNotifier.Notify(); } return(retVal); }
private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback, bool loadBinaryData) { var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); const ResponseGroup responseGroup = ResponseGroup.WithCatalogs | ResponseGroup.WithCategories | ResponseGroup.WithProducts; var searchResponse = _catalogSearchService.Search(new SearchCriteria { Count = int.MaxValue, GetAllCategories = true, Start = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); progressInfo.Description = String.Format("{0} catalogs loading", searchResponse.Catalogs.Count()); progressCallback(progressInfo); //Catalogs retVal.Catalogs = searchResponse.Catalogs.Select(x => _catalogService.GetById(x.Id)).ToList(); progressInfo.Description = String.Format("{0} categories loading", searchResponse.Categories.Count()); progressCallback(progressInfo); //Categories retVal.Categories = searchResponse.Categories.Select(x => _categoryService.GetById(x.Id)).ToList(); //Products for (int i = 0; i < searchResponse.Products.Count(); i += 50) { var products = _itemService.GetByIds(searchResponse.Products.Skip(i).Take(50).Select(x => x.Id).ToArray(), ItemResponseGroup.ItemMedium | ItemResponseGroup.Variations | ItemResponseGroup.Seo); retVal.Products.AddRange(products); progressInfo.Description = String.Format("{0} of {1} products loaded", Math.Min(searchResponse.TotalCount, i), searchResponse.TotalCount); progressCallback(progressInfo); } //Binary data if (loadBinaryData) { var allImages = retVal.Products.SelectMany(x => x.Images); allImages = allImages.Concat(retVal.Categories.SelectMany(x => x.Images)); allImages = allImages.Concat(retVal.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images)); var index = 0; var progressTemplate = "{0} of " + allImages.Count() + " images downloading"; foreach (var image in allImages) { progressInfo.Description = String.Format(progressTemplate, index); progressCallback(progressInfo); try { image.BinaryData = _blobStorageProvider.OpenReadOnly(image.Url).ReadFully(); } catch(Exception ex) { progressInfo.Errors.Add(ex.ToString()); progressCallback(progressInfo); } index++; } } //Properties var catalogsPropertiesIds = retVal.Catalogs.SelectMany(x => _propertyService.GetCatalogProperties(x.Id)).Select(x => x.Id).ToArray(); var categoriesPropertiesIds = retVal.Categories.SelectMany(x => _propertyService.GetCategoryProperties(x.Id)).Select(x => x.Id).ToArray(); var propertiesIds = catalogsPropertiesIds.Concat(categoriesPropertiesIds).Distinct().ToArray(); progressInfo.Description = String.Format("{0} properties loading", propertiesIds.Count()); progressCallback(progressInfo); retVal.Properties = propertiesIds.Select(x => _propertyService.GetById(x)).ToList(); return retVal; }
private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback, bool loadBinaryData) { var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); const ResponseGroup responseGroup = ResponseGroup.WithCatalogs | ResponseGroup.WithCategories | ResponseGroup.WithProducts; var searchResponse = _catalogSearchService.Search(new SearchCriteria { Count = int.MaxValue, GetAllCategories = true, Start = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); progressInfo.Description = String.Format("{0} catalogs loading", searchResponse.Catalogs.Count()); progressCallback(progressInfo); //Catalogs retVal.Catalogs = searchResponse.Catalogs.Select(x => _catalogService.GetById(x.Id)).ToList(); progressInfo.Description = String.Format("{0} categories loading", searchResponse.Categories.Count()); progressCallback(progressInfo); //Categories retVal.Categories = searchResponse.Categories.Select(x => _categoryService.GetById(x.Id)).ToList(); //Products for (int i = 0; i < searchResponse.Products.Count(); i += 50) { var products = _itemService.GetByIds(searchResponse.Products.Skip(i).Take(50).Select(x => x.Id).ToArray(), ItemResponseGroup.ItemMedium | ItemResponseGroup.Variations | ItemResponseGroup.Seo); retVal.Products.AddRange(products); progressInfo.Description = String.Format("{0} of {1} products loaded", Math.Min(searchResponse.TotalCount, i), searchResponse.TotalCount); progressCallback(progressInfo); } //Binary data if (loadBinaryData) { var allImages = retVal.Products.SelectMany(x => x.Images); allImages = allImages.Concat(retVal.Categories.SelectMany(x => x.Images)); allImages = allImages.Concat(retVal.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images)); var index = 0; var progressTemplate = "{0} of " + allImages.Count() + " images downloading"; foreach (var image in allImages) { progressInfo.Description = String.Format(progressTemplate, index); progressCallback(progressInfo); try { image.BinaryData = _blobStorageProvider.OpenReadOnly(image.Url).ReadFully(); } catch (Exception ex) { progressInfo.Errors.Add(ex.ToString()); progressCallback(progressInfo); } index++; } } //Properties var catalogsPropertiesIds = retVal.Catalogs.SelectMany(x => _propertyService.GetCatalogProperties(x.Id)).Select(x => x.Id).ToArray(); var categoriesPropertiesIds = retVal.Categories.SelectMany(x => _propertyService.GetCategoryProperties(x.Id)).Select(x => x.Id).ToArray(); var propertiesIds = catalogsPropertiesIds.Concat(categoriesPropertiesIds).Distinct().ToArray(); progressInfo.Description = String.Format("{0} properties loading", propertiesIds.Count()); progressCallback(progressInfo); retVal.Properties = propertiesIds.Select(x => _propertyService.GetById(x)).ToList(); return(retVal); }
private BackupObject GetBackupObject(Action <ExportImportProgressInfo> progressCallback, bool loadBinaryData) { var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); const SearchResponseGroup responseGroup = SearchResponseGroup.WithCatalogs | SearchResponseGroup.WithCategories | SearchResponseGroup.WithProducts; var searchResponse = _catalogSearchService.Search(new SearchCriteria { Take = int.MaxValue, Skip = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); progressInfo.Description = String.Format("{0} catalogs loading", searchResponse.Catalogs.Count()); progressCallback(progressInfo); //Catalogs retVal.Catalogs = searchResponse.Catalogs.Select(x => _catalogService.GetById(x.Id)).ToList(); progressInfo.Description = String.Format("{0} categories loading", searchResponse.Categories.Count()); progressCallback(progressInfo); //Categories retVal.Categories = _categoryService.GetByIds(searchResponse.Categories.Select(x => x.Id).ToArray(), CategoryResponseGroup.Full); //Products for (int i = 0; i < searchResponse.Products.Count(); i += 50) { var products = _itemService.GetByIds(searchResponse.Products.Skip(i).Take(50).Select(x => x.Id).ToArray(), ItemResponseGroup.ItemLarge); retVal.Products.AddRange(products); progressInfo.Description = String.Format("{0} of {1} products loaded", Math.Min(searchResponse.ProductsTotalCount, i), searchResponse.ProductsTotalCount); progressCallback(progressInfo); } //Binary data if (loadBinaryData) { var allImages = retVal.Products.SelectMany(x => x.Images); allImages = allImages.Concat(retVal.Categories.SelectMany(x => x.Images)); allImages = allImages.Concat(retVal.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images)); var index = 0; var progressTemplate = "{0} of " + allImages.Count() + " images downloading"; foreach (var image in allImages) { progressInfo.Description = String.Format(progressTemplate, index); progressCallback(progressInfo); try { using (var stream = _blobStorageProvider.OpenRead(image.Url)) { image.BinaryData = stream.ReadFully(); } } catch (Exception ex) { progressInfo.Errors.Add(ex.ToString()); progressCallback(progressInfo); } index++; } } //Properties progressInfo.Description = String.Format("Properties loading"); progressCallback(progressInfo); retVal.Properties = _propertyService.GetAllProperties(); //Reset some props to descrease resulting json size foreach (var catalog in retVal.Catalogs) { catalog.Properties = null; } foreach (var category in retVal.Categories) { category.Catalog = null; category.Properties = null; category.Children = null; category.Parents = null; foreach (var propvalue in category.PropertyValues) { propvalue.Property = null; } } foreach (var product in retVal.Products.Concat(retVal.Products.SelectMany(x => x.Variations))) { product.Catalog = null; product.Category = null; product.Properties = null; product.MainProduct = null; foreach (var propvalue in product.PropertyValues) { propvalue.Property = null; } } return(retVal); }
private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback, bool loadBinaryData) { var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); const SearchResponseGroup responseGroup = SearchResponseGroup.WithCatalogs | SearchResponseGroup.WithCategories | SearchResponseGroup.WithProducts; var searchResponse = _catalogSearchService.Search(new SearchCriteria { WithHidden = true, Take = int.MaxValue, Skip = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); progressInfo.Description = String.Format("{0} catalogs loading", searchResponse.Catalogs.Count()); progressCallback(progressInfo); //Catalogs retVal.Catalogs = searchResponse.Catalogs.Select(x => _catalogService.GetById(x.Id)).ToList(); progressInfo.Description = String.Format("{0} categories loading", searchResponse.Categories.Count()); progressCallback(progressInfo); //Categories retVal.Categories = _categoryService.GetByIds(searchResponse.Categories.Select(x=>x.Id).ToArray(), CategoryResponseGroup.Full); //Products for (int i = 0; i < searchResponse.Products.Count(); i += 50) { var products = _itemService.GetByIds(searchResponse.Products.Skip(i).Take(50).Select(x => x.Id).ToArray(), ItemResponseGroup.ItemLarge); retVal.Products.AddRange(products); progressInfo.Description = String.Format("{0} of {1} products loaded", Math.Min(searchResponse.ProductsTotalCount, i), searchResponse.ProductsTotalCount); progressCallback(progressInfo); } //Binary data if (loadBinaryData) { var allImages = retVal.Products.SelectMany(x => x.Images); allImages = allImages.Concat(retVal.Categories.SelectMany(x => x.Images)); allImages = allImages.Concat(retVal.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images)); var index = 0; var progressTemplate = "{0} of " + allImages.Count() + " images downloading"; foreach (var image in allImages) { progressInfo.Description = String.Format(progressTemplate, index); progressCallback(progressInfo); try { using (var stream = _blobStorageProvider.OpenRead(image.Url)) { image.BinaryData = stream.ReadFully(); } } catch (Exception ex) { progressInfo.Errors.Add(ex.ToString()); progressCallback(progressInfo); } index++; } } //Properties progressInfo.Description = String.Format("Properties loading"); progressCallback(progressInfo); retVal.Properties = _propertyService.GetAllProperties(); //Reset some props to descrease resulting json size foreach (var catalog in retVal.Catalogs) { catalog.Properties = null; } foreach (var category in retVal.Categories) { category.Catalog = null; category.Properties = null; category.Children = null; category.Parents = null; foreach (var propvalue in category.PropertyValues) { propvalue.Property = null; } } foreach (var product in retVal.Products.Concat(retVal.Products.SelectMany(x=>x.Variations))) { product.Catalog = null; product.Category = null; product.Properties = null; product.MainProduct = null; foreach (var propvalue in product.PropertyValues) { propvalue.Property = null; } } return retVal; }
private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback) { const ResponseGroup responseGroup = ResponseGroup.Full; var searchResponse = _catalogSearchService.Search(new SearchCriteria { Count = int.MaxValue, GetAllCategories = true, Start = 0, ResponseGroup = responseGroup }); var retVal = new BackupObject(); var progressNotifier = new ProgressNotifier("{0} of {1} catalogs loaded", searchResponse.Catalogs.Count(), progressCallback); foreach (var catalog in searchResponse.Catalogs) { retVal.Catalogs.Add(_catalogService.GetById(catalog.Id)); progressNotifier.Notify(); } progressNotifier = new ProgressNotifier("{0} of {1} categories loaded", searchResponse.Categories.Count(), progressCallback); foreach (var category in searchResponse.Categories) { retVal.Categories.Add(_categoryService.GetById(category.Id)); progressNotifier.Notify(); } progressNotifier = new ProgressNotifier("{0} of {1} products loaded", searchResponse.TotalCount, progressCallback); foreach (var product in searchResponse.Products) { retVal.Products.Add(_itemService.GetById(product.Id, ItemResponseGroup.ItemMedium | ItemResponseGroup.Variations | ItemResponseGroup.Seo)); progressNotifier.Notify(); } var catalogsPropertiesIds = retVal.Catalogs.SelectMany(x => _propertyService.GetCatalogProperties(x.Id)).Select(x => x.Id).ToArray(); var categoriesPropertiesIds = retVal.Categories.SelectMany(x => _propertyService.GetCategoryProperties(x.Id)).Select(x => x.Id).ToArray(); var propertiesIds = catalogsPropertiesIds.Concat(categoriesPropertiesIds).Distinct().ToArray(); progressNotifier = new ProgressNotifier("{0} of {1} properties loaded", propertiesIds.Count(), progressCallback); foreach (var propertyId in propertiesIds) { var property = _propertyService.GetById(propertyId); retVal.Properties.Add(property); progressNotifier.Notify(); } return retVal; }