private async Task ExportPlatformEntriesInternalAsync(ZipArchive zipArchive, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken) { var progressInfo = new ExportImportProgressInfo(); var serializer = GetJsonSerializer(); //Create part for platform entries var platformEntiriesPart = zipArchive.CreateEntry(PlatformZipEntryName, CompressionLevel.Optimal); using (var partStream = platformEntiriesPart.Open()) { using (var sw = new StreamWriter(partStream, Encoding.UTF8)) using (var writer = new JsonTextWriter(sw)) { await writer.WriteStartObjectAsync(); if (manifest.HandleSecurity) { progressInfo.Description = "Roles exporting..."; progressCallback(progressInfo); cancellationToken.ThrowIfCancellationRequested(); await writer.WritePropertyNameAsync("Roles"); await writer.WriteStartArrayAsync(); var roles = _roleManager.Roles.ToList(); if (_roleManager.SupportsRoleClaims) { var permissions = _permissionsProvider.GetAllPermissions().ToArray(); foreach (var role in roles) { role.Permissions = (await _roleManager.GetClaimsAsync(role)).Join(permissions, c => c.Value, p => p.Name, (c, p) => p).ToArray(); serializer.Serialize(writer, role); } writer.Flush(); progressInfo.Description = $"{ roles.Count } roles exported"; progressCallback(progressInfo); } await writer.WriteEndArrayAsync(); cancellationToken.ThrowIfCancellationRequested(); await writer.WritePropertyNameAsync("Users"); await writer.WriteStartArrayAsync(); var usersResult = _userManager.Users.ToArray(); progressInfo.Description = $"Security: {usersResult.Length} users exporting..."; progressCallback(progressInfo); var userExported = 0; foreach (var user in usersResult) { var userExt = await _userManager.FindByIdAsync(user.Id); if (userExt != null) { serializer.Serialize(writer, userExt); userExported++; } } await writer.FlushAsync(); progressInfo.Description = $"{ userExported } of { usersResult.Length } users exported"; progressCallback(progressInfo); await writer.WriteEndArrayAsync(); } if (manifest.HandleSettings) { cancellationToken.ThrowIfCancellationRequested(); await writer.WritePropertyNameAsync("Settings"); await writer.WriteStartArrayAsync(); progressInfo.Description = "Settings: selected modules settings exporting..."; progressCallback(progressInfo); foreach (var module in manifest.Modules) { var moduleSettings = await _settingsManager.GetObjectSettingsAsync(_settingsManager.AllRegisteredSettings.Where(x => x.ModuleId == module.Id).Select(x => x.Name)); //Export only settings with set values foreach (var setting in moduleSettings.Where(x => x.ItHasValues)) { serializer.Serialize(writer, setting); } await writer.FlushAsync(); } progressInfo.Description = $"Settings of modules exported"; progressCallback(progressInfo); await writer.WriteEndArrayAsync(); } cancellationToken.ThrowIfCancellationRequested(); await writer.WritePropertyNameAsync("DynamicProperties"); await writer.WriteStartArrayAsync(); progressInfo.Description = "Dynamic properties: load properties..."; progressCallback(progressInfo); var dynamicProperties = (await _dynamicPropertySearchService.SearchDynamicPropertiesAsync(new DynamicPropertySearchCriteria { Take = int.MaxValue })).Results; foreach (var dynamicProperty in dynamicProperties) { serializer.Serialize(writer, dynamicProperty); } progressInfo.Description = $"Dynamic properties exported"; progressCallback(progressInfo); await writer.WriteEndArrayAsync(); cancellationToken.ThrowIfCancellationRequested(); await writer.WritePropertyNameAsync("DynamicPropertyDictionaryItems"); await writer.WriteStartArrayAsync(); progressInfo.Description = "Dynamic properties Dictionary Items: load properties..."; progressCallback(progressInfo); var dynamicPropertyDictionaryItems = (await _dynamicPropertySearchService.SearchDictionaryItemsAsync(new DynamicPropertyDictionaryItemSearchCriteria { Take = int.MaxValue })).Results; foreach (var dynamicPropertyDictionaryItem in dynamicPropertyDictionaryItems) { serializer.Serialize(writer, dynamicPropertyDictionaryItem); } progressInfo.Description = $"Dynamic properties dictionary items exported"; progressCallback(progressInfo); await writer.WriteEndArrayAsync(); await writer.WriteEndObjectAsync(); await writer.FlushAsync(); } } }
public async Task <IActionResult> GetDictionaryItems([FromBody] DynamicPropertyDictionaryItemSearchCriteria criteria) { var result = await _dynamicPropertySearchService.SearchDictionaryItemsAsync(criteria); return(Ok(result.Results)); }
private async Task ExportPlatformEntriesInternalAsync(ZipArchive zipArchive, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken) { var progressInfo = new ExportImportProgressInfo(); var platformExportObj = new PlatformExportEntries(); if (manifest.HandleSecurity) { //Roles platformExportObj.Roles = _roleManager.Roles.ToList(); if (_roleManager.SupportsRoleClaims) { var permissions = _permissionsProvider.GetAllPermissions(); foreach (var role in platformExportObj.Roles) { role.Permissions = (await _roleManager.GetClaimsAsync(role)).Join(permissions, c => c.Value, p => p.Name, (c, p) => p).ToArray(); } } //users var usersResult = _userManager.Users.ToArray(); progressInfo.Description = $"Security: {usersResult.Count()} users exporting..."; progressCallback(progressInfo); foreach (var user in usersResult) { var userExt = await _userManager.FindByIdAsync(user.Id); if (userExt != null) { platformExportObj.Users.Add(userExt); } } } //Export setting for selected modules if (manifest.HandleSettings) { progressInfo.Description = "Settings: selected modules settings exporting..."; progressCallback(progressInfo); foreach (var module in manifest.Modules) { var moduleSettings = await _settingsManager.GetObjectSettingsAsync(_settingsManager.AllRegisteredSettings.Where(x => x.ModuleId == module.Id).Select(x => x.Name)); platformExportObj.Settings = platformExportObj.Settings.Concat(moduleSettings).ToList(); } } //Dynamic properties progressInfo.Description = "Dynamic properties: load properties..."; progressCallback(progressInfo); platformExportObj.DynamicProperties = (await _dynamicPropertySearchService.SearchDynamicPropertiesAsync(new DynamicPropertySearchCriteria { Take = int.MaxValue })).Results; platformExportObj.DynamicPropertyDictionaryItems = (await _dynamicPropertySearchService.SearchDictionaryItemsAsync(new DynamicPropertyDictionaryItemSearchCriteria { Take = int.MaxValue })).Results; //Create part for platform entries var platformEntiriesPart = zipArchive.CreateEntry(_platformZipEntryName, CompressionLevel.Optimal); using (var partStream = platformEntiriesPart.Open()) { platformExportObj.SerializeJson(partStream); } }