public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback);

			var progressInfo = new ExportImportProgressInfo();

			progressInfo.Description = String.Format("{0} promotions importing...", backupObject.Promotions.Count());
			progressCallback(progressInfo);
			UpdatePromotions(originalObject.Promotions, backupObject.Promotions);

			progressInfo.Description = String.Format("{0} folders importing...", backupObject.ContentFolders.Count());
			progressCallback(progressInfo);
            UpdateContentFolders(originalObject.ContentFolders, backupObject.ContentFolders);

			progressInfo.Description = String.Format("{0} places importing...", backupObject.ContentPlaces.Count());
			progressCallback(progressInfo);
            UpdateContentPlaces(originalObject.ContentPlaces, backupObject.ContentPlaces);

			progressInfo.Description = String.Format("{0} contents importing...", backupObject.ContentItems.Count());
			progressCallback(progressInfo);
            UpdateContentItems(originalObject.ContentItems, backupObject.ContentItems);

			progressInfo.Description = String.Format("{0} publications importing...", backupObject.ContentPublications.Count());
			progressCallback(progressInfo);
            UpdateContentPublications(originalObject.ContentPublications, backupObject.ContentPublications);

        }
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();

            _inventoryService.UpsertInventories(backupObject.InventoryInfos);
            progressCallback(new ExportImportProgressInfo("update inventory done"));
        }
		public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
		{
			var backupObject = backupStream.DeserializeJson<BackupObject>();

			backupObject.FulfillmentCenters.ForEach(x => _commerceService.UpsertFulfillmentCenter(x));
			progressCallback(new ExportImportProgressInfo("update fulfillmentCenters done"));
		}
		public void DoImport(Stream backupStream, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
		{
			var progressInfo = new ExportImportProgressInfo();

			var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback, false);

			progressInfo.Description = String.Format("{0} catalogs importing...", backupObject.Catalogs.Count());
			progressCallback(progressInfo);

			UpdateCatalogs(originalObject.Catalogs, backupObject.Catalogs);

			progressInfo.Description = String.Format("{0} categories importing...", backupObject.Categories.Count());
			progressCallback(progressInfo);
			//Categories should be sorted right way 
            //first need to create virtual categories
			var orderedCategories = backupObject.Categories.Where(x=>x.Catalog.Virtual)
                                                             .OrderBy(x => x.Parents != null ? x.Parents.Count() : 0)
															 .ToList();
            //second need to create physical categories
            orderedCategories.AddRange(backupObject.Categories.Where(x => !x.Catalog.Virtual)
                                                             .OrderBy(x => x.Parents != null ? x.Parents.Count() : 0));

            backupObject.Products = backupObject.Products.OrderBy(x => x.MainProductId).ToList();
			UpdateCategories(originalObject.Categories, orderedCategories);
			UpdateProperties(originalObject.Properties, backupObject.Properties);

			//Binary data
			if (manifest.HandleBinaryData)
			{
				var allBackupImages = backupObject.Products.SelectMany(x => x.Images);
				allBackupImages = allBackupImages.Concat(backupObject.Categories.SelectMany(x => x.Images));
				allBackupImages = allBackupImages.Concat(backupObject.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images));

				var allOrigImages = originalObject.Products.SelectMany(x => x.Images);
				allOrigImages = allOrigImages.Concat(originalObject.Categories.SelectMany(x => x.Images));
				allOrigImages = allOrigImages.Concat(originalObject.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images));

				var allNewImages = allBackupImages.Where(x => !allOrigImages.Contains(x)).Where(x=>x.BinaryData != null);
				var index = 0;
				var progressTemplate = "{0} of " + allNewImages.Count() + " images uploading";
				foreach (var image in allNewImages)
				{
					progressInfo.Description = String.Format(progressTemplate, index);
					progressCallback(progressInfo);
					using (var stream = new MemoryStream(image.BinaryData))
					{
						image.Url = _blobStorageProvider.Upload(new UploadStreamInfo { FileByteStream = stream, FileName = image.Name, FolderName = "catalog" });
					}

					index++;
				}
			}

			progressInfo.Description = String.Format("{0} products importing...", backupObject.Products.Count());
			progressCallback(progressInfo);
			UpdateCatalogProducts(originalObject.Products, backupObject.Products);
		}
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();

            var progressInfo = new ExportImportProgressInfo();
            progressInfo.Description = String.Format("{0} RFQs importing", backupObject.QuoteRequests.Count());
            progressCallback(progressInfo);
            _quoteRequestService.SaveChanges(backupObject.QuoteRequests.ToArray());
        }
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var prodgressInfo = new ExportImportProgressInfo { Description = "loading data..." };
            progressCallback(prodgressInfo);

            var backupObject = backupStream.DeserializeJson<BackupObject>();
            var originalObject = GetBackupObject();

            UpdateStores(originalObject.Stores, backupObject.Stores);
        }
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback);

			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = String.Format("{0} stores importing...", backupObject.Stores.Count());
			progressCallback(progressInfo);

            UpdateStores(originalObject.Stores, backupObject.Stores);
        }
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback);

			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = String.Format("{0} members importing...", backupObject.Members.Count());
            progressCallback(progressInfo);
            _memberService.CreateOrUpdate(backupObject.Members.OrderByDescending(x => x.MemberType).ToArray());

        }
        public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback);

			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = String.Format("{0} organizations importing...", backupObject.Organizations.Count());
			progressCallback(progressInfo);
            UpdateOrganizations(originalObject.Organizations, backupObject.Organizations);

			progressInfo.Description = String.Format("{0} contacts importing...", backupObject.Contacts.Count());
			progressCallback(progressInfo);
            UpdateContacts(originalObject.Contacts, backupObject.Contacts);
        }
		public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
		{
			var backupObject = backupStream.DeserializeJson<BackupObject>();
            progressCallback(new ExportImportProgressInfo("importing fulfillmentCenters"));
            if (backupObject.FulfillmentCenters != null)
            {
                backupObject.FulfillmentCenters.ForEach(x => _commerceService.UpsertFulfillmentCenter(x));
            }
            progressCallback(new ExportImportProgressInfo("imporing currencies"));
            if (backupObject.Currencies != null)
            {
                _commerceService.UpsertCurrencies(backupObject.Currencies);
            }

        }
        public void DoImport(Stream backupStream, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            var backupObject = backupStream.DeserializeJson<BackupObject>();
            var originalObject = GetBackupObject(progressCallback, false);

            var progressInfo = new ExportImportProgressInfo();
            progressInfo.Description = String.Format("{0} menu link lists importing...", backupObject.MenuLinkLists.Count());
            progressCallback(progressInfo);
            UpdateMenuLinkLists(backupObject.MenuLinkLists);

            if (manifest.HandleBinaryData)
            {
                progressInfo.Description = String.Format("importing binary data:  themes and pages importing...");
                progressCallback(progressInfo);
                foreach (var folder in backupObject.ContentFolders)
                {
                    SaveContentFolderRecursive(folder);
                }
            }
        }
		public void DoImport(Stream backupStream, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
		{
			var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback, manifest.HandleBinaryData);

			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = String.Format("{0} menu link lists importing...", backupObject.MenuLinkLists.Count());
			progressCallback(progressInfo);

			UpdateMenuLinkLists(originalObject.MenuLinkLists, backupObject.MenuLinkLists);
			if (manifest.HandleBinaryData)
			{
				progressInfo.Description = String.Format("importing binary data: {0} pages importing...", backupObject.Pages.Count());
				progressCallback(progressInfo);

				UpdatePages(originalObject.Pages, backupObject.Pages);

				progressInfo.Description = String.Format("importing binary data: {0} theme assets importing...", backupObject.ThemeAssets.Count());
				progressCallback(progressInfo);

				UpdateThemeAssets(originalObject.ThemeAssets, backupObject.ThemeAssets);
			}
		}
        public void DoImport(Stream backupStream, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();

            var backupObject = backupStream.DeserializeJson<BackupObject>();
            foreach(var category in backupObject.Categories)
            {
                category.Catalog = backupObject.Catalogs.FirstOrDefault(x => x.Id == category.CatalogId);
                if(category.Parents != null)
                {
                    category.Level = category.Parents.Count();
                }
            }
            var originalObject = GetBackupObject(progressCallback, false);

            progressInfo.Description = String.Format("{0} catalogs importing...", backupObject.Catalogs.Count());
            progressCallback(progressInfo);

            UpdateCatalogs(originalObject.Catalogs, backupObject.Catalogs);

            progressInfo.Description = String.Format("{0} categories importing...", backupObject.Categories.Count());
            progressCallback(progressInfo);
          
            backupObject.Products = backupObject.Products.OrderBy(x => x.MainProductId).ToList();
            UpdateCategories(originalObject.Categories, backupObject.Categories);
            UpdateProperties(originalObject.Properties, backupObject.Properties);

            //Binary data
            if (manifest.HandleBinaryData)
            {
                var allBackupImages = backupObject.Products.SelectMany(x => x.Images);
                allBackupImages = allBackupImages.Concat(backupObject.Categories.SelectMany(x => x.Images));
                allBackupImages = allBackupImages.Concat(backupObject.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images));

                var allOrigImages = originalObject.Products.SelectMany(x => x.Images);
                allOrigImages = allOrigImages.Concat(originalObject.Categories.SelectMany(x => x.Images));
                allOrigImages = allOrigImages.Concat(originalObject.Products.SelectMany(x => x.Variations).SelectMany(x => x.Images));
                //Import only new images
                var allNewImages = allBackupImages.Where(x => !allOrigImages.Contains(x));
                var index = 0;
                var progressTemplate = "{0} of " + allNewImages.Count() + " images uploading";
                foreach (var image in allNewImages)
                {
                    progressInfo.Description = String.Format(progressTemplate, index);
                    progressCallback(progressInfo);
                    try
                    {
                        //do not save images with external url
                        if (image.Url != null && !image.Url.IsAbsoluteUrl())
                        {
                            using (var sourceStream = new MemoryStream(image.BinaryData))
                            using (var targetStream = _blobStorageProvider.OpenWrite(image.Url))
                            {
                                sourceStream.CopyTo(targetStream);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        progressInfo.Errors.Add(String.Format("{0}: {1}", "CatalogModule", ex.ExpandExceptionMessage()));
                        progressCallback(progressInfo);
                    }

                    index++;
                }
            }

            progressInfo.Description = String.Format("{0} products importing...", backupObject.Products.Count());
            progressCallback(progressInfo);
            UpdateCatalogProducts(originalObject.Products, backupObject.Products);
        }
		public void DoImport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
		{
			var prodgressInfo = new ExportImportProgressInfo { Description = "loading data..." };
			progressCallback(prodgressInfo);

			var backupObject = backupStream.DeserializeJson<BackupObject>();
			var originalObject = GetBackupObject(progressCallback);

			UpdateCatalogs(originalObject.Catalogs, backupObject.Catalogs);

			//Categories should be sorted right way (because it have a hierarchy structure and links to virtual categories)
			backupObject.Categories = backupObject.Categories.Where(x => x.Links == null || !x.Links.Any())
															.OrderBy(x => x.Parents != null ? x.Parents.Count() : 0)
															.Concat(backupObject.Categories.Where(x => x.Links != null && x.Links.Any()))
															.ToList();
			UpdateCategories(originalObject.Categories, backupObject.Categories);
			UpdateProperties(originalObject.Properties, backupObject.Properties);
			UpdateCatalogProducts(originalObject.Products, backupObject.Products);


		}