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 = Task.Run(() => _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)
                {
                    var userExt = Task.Run(() => _securityService.FindByIdAsync(user.Id, UserDetails.Export)).Result;
                    if (userExt != null)
                    {
                        platformExportObj.Users.Add(userExt);
                    }
                }
            }

            //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();

            //Notification templates
            progressInfo.Description = String.Format("Notifications: load templates...");
            progressCallback(progressInfo);
            platformExportObj.NotificationTemplates = _notificationTemplateService.GetAllTemplates().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);
            }
        }
Esempio n. 2
0
        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 = Task.Run(() => _securityService.SearchUsersAsync(new UserSearchRequest {
                    TakeCount = int.MaxValue
                })).Result;
                progressInfo.Description = $"Security: {usersResult.Users.Count()} users exporting...";
                progressCallback(progressInfo);

                foreach (var user in usersResult.Users)
                {
                    var userExt = Task.Run(() => _securityService.FindByIdAsync(user.Id, UserDetails.Export)).Result;
                    if (userExt != null)
                    {
                        platformExportObj.Users.Add(userExt);
                    }
                }
            }

            //Export setting for selected modules
            if (manifest.HandleSettings)
            {
                progressInfo.Description = "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 = "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();

            //Notification templates
            progressInfo.Description = "Notifications: load templates...";
            progressCallback(progressInfo);
            platformExportObj.NotificationTemplates = _notificationTemplateService.GetAllTemplates().ToList();

            //Asset entries
            progressInfo.Description = "Asset: Evaluate asset entries count...";
            progressCallback(progressInfo);
            const int batchSize = 50;
            var       totalAssetsEntriesCount = _assetEntrySearchService.SearchAssetEntries(new AssetEntrySearchCriteria {
                Skip = 0, Take = 0
            }).TotalCount;

            for (var i = 0; i <= totalAssetsEntriesCount; i += batchSize)
            {
                progressInfo.Description = $"Asset: {Math.Min(totalAssetsEntriesCount, i + batchSize) } of {totalAssetsEntriesCount} asset entries have been loaded...";
                progressCallback(progressInfo);
                platformExportObj.AssetEntries.AddRange(_assetEntrySearchService.SearchAssetEntries(new AssetEntrySearchCriteria {
                    Skip = i, Take = batchSize
                }).Results);
            }

            //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(partStream);
            }
        }