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 DoExport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var prodgressInfo = new ExportImportProgressInfo { Description = "loading data..." };
            progressCallback(prodgressInfo);

            var backupObject = GetBackupObject();
            backupObject.SerializeJson(backupStream);
        }
		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);
		}
예제 #4
0
        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());
        }
		private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo("stores loading...");
			progressCallback(progressInfo);

            return new BackupObject
            {
                Stores = _storeService.SearchStores(new SearchCriteria { Take = int.MaxValue }).Stores
            };
        }
예제 #6
0
		private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo("stores loading...");
			progressCallback(progressInfo);

            return new BackupObject
            {
                Stores = _storeService.GetStoreList().Select(x => x.Id).Select(x => _storeService.GetById(x)).ToArray()
            };
        }
예제 #7
0
		private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
			var allPricelistIds = _pricingService.GetPriceLists().Select(x => x.Id);
			var progressInfo = new ExportImportProgressInfo { Description = String.Format("{0} price lists loading..." , allPricelistIds.Count())};
			progressCallback(progressInfo);
            return new BackupObject
            {
                Pricelists = allPricelistIds.Select(x => _pricingService.GetPricelistById(x)).ToList()
            };
        }
        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);
        }
예제 #9
0
        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 ProgressNotifier(string notifyPattern, int totalCount, Action<ExportImportProgressInfo> progressCallback)
		{
			_notifyPattern = notifyPattern;
			_progressCallback = progressCallback;
			_progressInfo = new ExportImportProgressInfo
			{
				TotalCount = totalCount,
				Description = String.Format(notifyPattern, totalCount, 0),
				ProcessedCount = 0
			};
		}
        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 DoExport(Stream backupStream, Action<ExportImportProgressInfo> progressCallback)
        {
            var prodgressInfo = new ExportImportProgressInfo { Description = "loading data..." };
            progressCallback(prodgressInfo);

            var backupObject = GetBackupObject();
            //Remove from backup non active methods
            backupObject.Stores.ForEach(x => x.PaymentMethods = x.PaymentMethods.Where(s => s.IsActive).ToList());
            backupObject.Stores.ForEach(x => x.ShippingMethods = x.ShippingMethods.Where(s => s.IsActive).ToList());

            backupObject.SerializeJson(backupStream);
        }
		public BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = "loading members...";
			progressCallback(progressInfo);

            var members = _memberSearchService.SearchMembers(new MembersSearchCriteria { DeepSearch = true, Take = int.MaxValue }).Members;

            var result = new BackupObject();
            result.Members = _memberService.GetByIds(members.Select(x => x.Id).ToArray()).OrderByDescending(x=> x.MemberType).ToArray();

            return result;
        }
        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);
        }
예제 #15
0
        private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
            var retVal = new BackupObject();
            var progressInfo = new ExportImportProgressInfo();
       
            var searchResponse = _quoteRequestService.Search(new QuoteRequestSearchCriteria { Count = int.MaxValue });

            progressInfo.Description = String.Format("{0} RFQs loading", searchResponse.QuoteRequests.Count());
            progressCallback(progressInfo);

            retVal.QuoteRequests = _quoteRequestService.GetByIds(searchResponse.QuoteRequests.Select(x => x.Id).ToArray()).ToList();

            return retVal;
        }
예제 #16
0
		private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
			var retVal = new BackupObject();
			var progressInfo = new ExportImportProgressInfo();
            const CustomerOrderResponseGroup responseGroup = CustomerOrderResponseGroup.WithAddresses | CustomerOrderResponseGroup.WithItems
                | CustomerOrderResponseGroup.WithShipments | CustomerOrderResponseGroup.WithInPayments;

            var searchResponse = _customerOrderSearchService.Search(new SearchCriteria { Count = int.MaxValue });

			progressInfo.Description = String.Format("{0} orders loading", searchResponse.CustomerOrders.Count());
			progressCallback(progressInfo);

            retVal.CustomerOrders = searchResponse.CustomerOrders.Select((x) => _customerOrderService.GetById(x.Id, responseGroup)).ToList();
            
            return retVal;
        }
		public void DoImport(Stream inputStream, CsvImportInfo importInfo, Action<ExportImportProgressInfo> progressCallback)
		{
			var csvProducts = new List<CsvProduct>();


			var progressInfo = new ExportImportProgressInfo
			{
				Description = "Reading products from csv..."
			};
			progressCallback(progressInfo);


			using (var reader = new CsvReader(new StreamReader(inputStream)))
			{
				reader.Configuration.Delimiter = importInfo.Configuration.Delimiter;
				reader.Configuration.RegisterClassMap(new CsvProductMap(importInfo.Configuration));
                reader.Configuration.WillThrowOnMissingField = false;

				while (reader.Read())
				{
					try
					{
						var csvProduct = reader.GetRecord<CsvProduct>();
						csvProducts.Add(csvProduct);
					}
					catch (Exception ex)
					{
						var error = ex.Message;
						if (ex.Data.Contains("CsvHelper"))
						{
							error += ex.Data["CsvHelper"];
						}
						progressInfo.Errors.Add(error);
						progressCallback(progressInfo);
					}
				}
			}


			var catalog = _catalogService.GetById(importInfo.CatalogId);

			SaveCategoryTree(catalog, csvProducts, progressInfo, progressCallback);
			SaveProducts(catalog, csvProducts, progressInfo, progressCallback);
		}
예제 #18
0
        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);
                }
            }
        }
예제 #19
0
		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);
			}
		}
예제 #20
0
		private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback, bool handleBynaryData)
		{
			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = "cms content loading...";
			progressCallback(progressInfo);

			var stores = _storeService.GetStoreList();
			var menuLinkLists = new List<MenuLinkList>();
            var contentItems = new List<coreModels.ThemeAsset>();
            var contentPages = new List<coreModels.Page>();
			foreach(var store in stores)
			{
				var storeLists = _menuService.GetListsByStoreId(store.Id);
				menuLinkLists.AddRange(storeLists.Select(s => ConvertToExportModel(s)));

				if (handleBynaryData)
				{
					var storePages = _pagesService.GetPages(store.Id, null);
					contentPages.AddRange(storePages);

					var storeThemes = _themeService.GetThemes(store.Id).ToArray();
					foreach (var storeTheme in storeThemes)
					{
						var themeContentItems = _themeService.GetThemeAssets(store.Id, storeTheme.Name, null).ToArray();
						contentItems.AddRange(themeContentItems);
					}
				}
			}

			return new BackupObject
			{
				MenuLinkLists = menuLinkLists,
				ThemeAssets = contentItems,
				Pages = contentPages
			};
		}
예제 #21
0
		public void DoExport(Stream outStream, CsvExportInfo exportInfo, Action<ExportImportProgressInfo> progressCallback)
		{
			var prodgressInfo = new ExportImportProgressInfo
			{
				Description = "loading products..."
			};

			var streamWriter = new StreamWriter(outStream, Encoding.UTF8, 1024, true);
			streamWriter.AutoFlush = true;

			using (var csvWriter = new CsvWriter(streamWriter))
			{
				//Notification
				progressCallback(prodgressInfo);

				//Load all products to export
				var products = LoadProducts(exportInfo.CatalogId, exportInfo.CategoryIds, exportInfo.ProductIds);
				var allProductIds = products.Select(x => x.Id).ToArray();

				//Load prices for products
				var allProductPrices = new List<Price>();

				prodgressInfo.Description = "loading prices...";
				progressCallback(prodgressInfo);

				var priceEvalContext = new PriceEvaluationContext
				{
					ProductIds = allProductIds,
					PricelistIds = exportInfo.PriceListId == null ? null : new string[] { exportInfo.PriceListId },
					Currency = exportInfo.Currency
				};
				allProductPrices = _pricingService.EvaluateProductPrices(priceEvalContext).ToList();


				//Load inventories
				var allProductInventories = new List<InventoryInfo>();

				prodgressInfo.Description = "loading inventory information...";
				progressCallback(prodgressInfo);

				allProductInventories = _inventoryService.GetProductsInventoryInfos(allProductIds).Where(x => exportInfo.FulfilmentCenterId == null ? true : x.FulfillmentCenterId == exportInfo.FulfilmentCenterId).ToList();


				//Export configuration
				exportInfo.Configuration.PropertyCsvColumns = products.SelectMany(x => x.PropertyValues).Select(x => x.PropertyName).Distinct().ToArray();

				csvWriter.Configuration.Delimiter = exportInfo.Configuration.Delimiter;
				csvWriter.Configuration.RegisterClassMap(new CsvProductMap(exportInfo.Configuration));

				//Write header
				csvWriter.WriteHeader<CsvProduct>();

				prodgressInfo.TotalCount = products.Count();
				var notifyProductSizeLimit = 50;
				var counter = 0;
				foreach (var product in products)
				{
					try
					{
						var csvProduct = new CsvProduct(product, _blobUrlResolver, allProductPrices.FirstOrDefault(x => x.ProductId == product.Id), allProductInventories.FirstOrDefault(x => x.ProductId == product.Id));
						csvWriter.WriteRecord(csvProduct);
					}
					catch (Exception ex)
					{
						prodgressInfo.Errors.Add(ex.ToString());
						progressCallback(prodgressInfo);
					}

					//Raise notification each notifyProductSizeLimit products
					counter++;
					prodgressInfo.ProcessedCount = counter;
					prodgressInfo.Description = string.Format("{0} of {1} products processed", prodgressInfo.ProcessedCount, prodgressInfo.TotalCount);
					if (counter % notifyProductSizeLimit == 0 || counter == prodgressInfo.TotalCount)
					{
						progressCallback(prodgressInfo);
					}
				}
			}
		}
		public BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback)
        {
			var progressInfo = new ExportImportProgressInfo();
			progressInfo.Description = "loading organizations and contacts...";
			progressCallback(progressInfo);

            var rootOrganization = GetOrganizations(null);
            var organizations = rootOrganization != null ? rootOrganization.Traverse(ChildrenForOrganization).ToArray() : null;

            var result = new BackupObject();
            if (organizations != null)
            {
                result.Contacts = organizations.SelectMany(x => x.Contacts).Select(x => _contactService.GetById(x.Id)).ToArray();
                result.Organizations = organizations.SelectMany(x => x.Organizations).Select(x=> _organizationService.GetById(x.Id)).ToArray();
            }

            return result;
        }
예제 #23
0
        private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCallback, bool handleBynaryData)
        {
            var retVal = new BackupObject();

            var progressInfo = new ExportImportProgressInfo();
            progressInfo.Description = "cms content loading...";
            progressCallback(progressInfo);

            retVal.MenuLinkLists = _menuService.GetAllLinkLists().Select(x => x.ToWebModel()).ToList();

            if (handleBynaryData)
            {
                var result = _contentStorageProvider.Search("/", null);
                foreach (var blobFolder in result.Folders.Where(x => _exportedFolders.Contains(x.Name)))
                {
                    var contentFolder = new ContentFolder
                    {
                        Url = blobFolder.Url
                    };
                    ReadContentFoldersRecurive(contentFolder);
                    retVal.ContentFolders.Add(contentFolder);
                }
            }

            return retVal;
        }
예제 #24
0
		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;

		}
예제 #25
0
        private void ReadContentFoldersRecurive(ContentFolder folder, Action<ExportImportProgressInfo> progressCallback)
        {
            var result = _contentStorageProvider.Search(folder.Url, null);
            foreach (var blobFolder in result.Folders)
            {
                //Do not export default theme its will distributed with code
                if (blobFolder.Url != "/Themes/default")
                {
                    var contentFolder = new ContentFolder()
                    {
                        Url = blobFolder.Url
                    };
                
                    ReadContentFoldersRecurive(contentFolder, progressCallback);
                    folder.Folders.Add(contentFolder);
                }
            }

            foreach (var blobItem in result.Items)
            {
                var progressInfo = new ExportImportProgressInfo();
                progressInfo.Description = String.Format("Read {0}", blobItem.Url);
                progressCallback(progressInfo);

                var contentFile = new ContentFile
                {
                    Url = blobItem.Url
                };
                using (var stream = _contentStorageProvider.OpenRead(blobItem.Url))
                {
                    contentFile.Data = stream.ReadFully();
                }
                folder.Files.Add(contentFile);
            }
        }
        private void ExportModulesInternal(Package package, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();

            foreach (var module in manifest.Modules)
            {
                var moduleDescriptor = InnerGetModulesWithInterface(typeof(ISupportExportImportModule)).FirstOrDefault(x => x.Id == module.Id);
                if (moduleDescriptor != null)
                {
                    //Create part for module
                    var modulePartUri = PackUriHelper.CreatePartUri(new Uri(module.Id + ".json", UriKind.Relative));
                    var modulePart = package.CreatePart(modulePartUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Normal);

                    Action<ExportImportProgressInfo> modulePorgressCallback = (x) =>
                    {
                        progressInfo.Description = String.Format("{0}: {1}", module.Id, x.Description);
                        progressCallback(progressInfo);
                    };

                    progressInfo.Description = String.Format("{0}: exporting...", module.Id);
                    progressCallback(progressInfo);

                    try
                    {
                        ((ISupportExportImportModule)moduleDescriptor.ModuleInfo.ModuleInstance).DoExport(modulePart.GetStream(), manifest, modulePorgressCallback);
                    }
                    catch (Exception ex)
                    {
                        progressInfo.Errors.Add(ex.ExpandExceptionMessage());
                        progressCallback(progressInfo);
                    }

                    module.PartUri = modulePartUri.ToString();
                }
            }

        }
 private void ImportModulesInternal(Package package, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
 {
     var progressInfo = new ExportImportProgressInfo();
     foreach (var moduleInfo in manifest.Modules)
     {
         var moduleDescriptor = InnerGetModulesWithInterface(typeof(ISupportExportImportModule)).FirstOrDefault(x => x.Id == moduleInfo.Id);
         if (moduleDescriptor != null)
         {
             var modulePart = package.GetPart(new Uri(moduleInfo.PartUri, UriKind.Relative));
             using (var modulePartStream = modulePart.GetStream())
             {
                 Action<ExportImportProgressInfo> modulePorgressCallback = (x) =>
                 {
                     progressInfo.Description = String.Format("{0}: {1}", moduleInfo.Id, x.Description);
                     progressCallback(progressInfo);
                 };
                 try
                 {
                     ((ISupportExportImportModule)moduleDescriptor.ModuleInfo.ModuleInstance).DoImport(modulePartStream, manifest, modulePorgressCallback);
                 }
                 catch (Exception ex)
                 {
                     progressInfo.Errors.Add(ex.ExpandExceptionMessage());
                     progressCallback(progressInfo);
                 }
             }
         }
     }
 }
        private void ExportPlatformEntriesInternal(Package package, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();
            var platformExportObj = new PlatformExportEntries();

            if (manifest.HandleSecurity)
            {
                //Roles
                platformExportObj.Roles = _roleManagementService.SearchRoles(new RoleSearchRequest { SkipCount = 0, TakeCount = int.MaxValue }).Roles;
                //users 
                var usersResult = _securityService.SearchUsersAsync(new UserSearchRequest { TakeCount = int.MaxValue }).Result;
                progressInfo.Description = String.Format("Security: {0} users exporting...", usersResult.Users.Count());
                progressCallback(progressInfo);

                foreach (var user in usersResult.Users)
                {
                    platformExportObj.Users.Add(_securityService.FindByIdAsync(user.Id, UserDetails.Export).Result);
                }
            }

            //Export setting for selected modules
            if (manifest.HandleSettings)
            {
                progressInfo.Description = String.Format("Settings: selected modules settings exporting...");
                progressCallback(progressInfo);

                platformExportObj.Settings = manifest.Modules.SelectMany(x => _settingsManager.GetModuleSettings(x.Id)).ToList();
            }

            //Dynamic properties
            var allTypes = _dynamicPropertyService.GetAvailableObjectTypeNames();

            progressInfo.Description = String.Format("Dynamic properties: load properties...");
            progressCallback(progressInfo);

            platformExportObj.DynamicProperties = allTypes.SelectMany(x => _dynamicPropertyService.GetProperties(x)).ToList();
            platformExportObj.DynamicPropertyDictionaryItems = platformExportObj.DynamicProperties.Where(x => x.IsDictionary).SelectMany(x => _dynamicPropertyService.GetDictionaryItems(x.Id)).ToList();

            //Create part for platform entries
            var platformEntiriesPart = package.CreatePart(_platformEntriesPartUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Normal);
            using (var partStream = platformEntiriesPart.GetStream())
            {
                platformExportObj.SerializeJson<PlatformExportEntries>(partStream);
            }
        }
        private void ImportPlatformEntriesInternal(Package package, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            var progressInfo = new ExportImportProgressInfo();

            var platformEntriesPart = package.GetPart(_platformEntriesPartUri);
            if (platformEntriesPart != null)
            {
                PlatformExportEntries platformEntries;
                using (var stream = platformEntriesPart.GetStream())
                {
                    platformEntries = stream.DeserializeJson<PlatformExportEntries>();
                }

                //Import security objects
                if (manifest.HandleSecurity)
                {
                    progressInfo.Description = String.Format("Import {0} users with roles...", platformEntries.Users.Count());
                    progressCallback(progressInfo);

                    //First need import roles
                    foreach (var role in platformEntries.Roles)
                    {
                        _roleManagementService.AddOrUpdateRole(role);
                    }
                    //Next create or update users
                    foreach (var user in platformEntries.Users)
                    {
                        if (_securityService.FindByIdAsync(user.Id, UserDetails.Reduced).Result != null)
                        {
                            _securityService.UpdateAsync(user);
                        }
                        else
                        {
                            _securityService.CreateAsync(user);
                        }
                    }
                }

                //Import dynamic properties
                _dynamicPropertyService.SaveProperties(platformEntries.DynamicProperties.ToArray());
                foreach (var propDicGroup in platformEntries.DynamicPropertyDictionaryItems.GroupBy(x => x.PropertyId))
                {
                    _dynamicPropertyService.SaveDictionaryItems(propDicGroup.Key, propDicGroup.ToArray());
                }

                //Import modules settings
                if (manifest.HandleSettings)
                {
                    foreach (var module in manifest.Modules)
                    {
                        _settingsManager.SaveSettings(platformEntries.Settings.Where(x => x.ModuleId == module.Id).ToArray());
                    }
                }
            }
        }
        public void Import(Stream stream, PlatformExportManifest manifest, Action<ExportImportProgressInfo> progressCallback)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException("manifest");
            }

            var progressInfo = new ExportImportProgressInfo();
            progressInfo.Description = "Starting platform import...";
            progressCallback(progressInfo);

            using (var package = ZipPackage.Open(stream, FileMode.Open))
            {
                //Import selected platform entries
                ImportPlatformEntriesInternal(package, manifest, progressCallback);
                //Import selected modules
                ImportModulesInternal(package, manifest, progressCallback);

            }
        }