예제 #1
0
        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)
		{
			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;

		}