public HttpResponseMessage Export(ExportDto exportDto) { var controller = new ExportController(); var jobId = controller.QueueOperation(this.PortalSettings.UserId, exportDto); return(this.Request.CreateResponse(HttpStatusCode.OK, new { jobId })); }
public int QueueOperation(int userId, ExportDto exportDto) { exportDto.ProductSku = DotNetNuke.Application.DotNetNukeContext.Current.Application.SKU; exportDto.ProductVersion = Globals.FormatVersion(DotNetNuke.Application.DotNetNukeContext.Current.Application.Version, true); var dbTime = DateUtils.GetDatabaseUtcTime(); exportDto.ToDateUtc = dbTime.AddMilliseconds(-dbTime.Millisecond); var directory = dbTime.ToString("yyyy-MM-dd_HH-mm-ss"); if (exportDto.ExportMode == ExportMode.Differential) { exportDto.FromDateUtc = GetLastJobTime(exportDto.PortalId, JobType.Export); } var dataObject = JsonConvert.SerializeObject(exportDto); exportDto.IsDirty = false;//This should be set to false for new job. var jobId = DataProvider.Instance().AddNewJob(exportDto.PortalId, userId, JobType.Export, exportDto.ExportName, exportDto.ExportDescription, directory, dataObject); //Run the scheduler if required. if (exportDto.RunNow) { EntitiesController.Instance.RunSchedule(); } AddEventLog(exportDto.PortalId, userId, jobId, Constants.LogTypeSiteExport); return(jobId); }
private void TableGUI() { GUILayout.Space(10); GUILayout.BeginVertical(); _tableScrollVec = GUILayout.BeginScrollView(_tableScrollVec, false, false); for (int i = 0; i < _exportDtoList.Count; i++) { ExportDto dto = _exportDtoList[i]; GUILayout.BeginHorizontal("GroupBox"); GUILayout.Label(dto.CurrentConfig.TableName, GUILayout.Width(180)); GUILayout.Label(LanguageUtils.ExportDataCount(dto.Count)); if (GUILayout.Button(LanguageUtils.ExportImport, GUILayout.Width(50))) { ImportData(dto); } if (GUILayout.Button(LanguageUtils.ExportHead, GUILayout.Width(50))) { ExportData(dto); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); if (CheckPoint.Stage > 1) return; if (CheckCancelled(exportJob)) return; List<ExportPortalLanguage> portalLanguages = null; if (CheckPoint.Stage == 0) { var portalSettings = new List<ExportPortalSetting>(); var settingToMigrate = SettingsController.Instance.GetSetting(Constants.PortalSettingExportKey)?.SettingValue?.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (settingToMigrate != null) { portalSettings = CBO.FillCollection<ExportPortalSetting>(DataProvider.Instance().GetPortalSettings(exportJob.PortalId, toDate, fromDate)); //Migrate only allowed portal settings. portalSettings = portalSettings.Where(x => settingToMigrate.Any(setting => setting.Trim().Equals(x.SettingName, StringComparison.InvariantCultureIgnoreCase))).ToList(); //Update the total items count in the check points. This should be updated only once. CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? portalSettings.Count : CheckPoint.TotalItems; if (CheckPoint.TotalItems == portalSettings.Count) { portalLanguages = CBO.FillCollection<ExportPortalLanguage>( DataProvider.Instance().GetPortalLanguages(exportJob.PortalId, toDate, fromDate)); CheckPoint.TotalItems += portalLanguages.Count; } CheckPointStageCallback(this); Repository.CreateItems(portalSettings); } Result.AddSummary("Exported Portal Settings", portalSettings.Count.ToString()); CheckPoint.Progress = 50; CheckPoint.ProcessedItems = portalSettings.Count; CheckPoint.Stage++; if (CheckPointStageCallback(this)) return; } if (CheckPoint.Stage == 1) { if (CheckCancelled(exportJob)) return; if (portalLanguages == null) portalLanguages = CBO.FillCollection<ExportPortalLanguage>(DataProvider.Instance() .GetPortalLanguages(exportJob.PortalId, toDate, fromDate)); Repository.CreateItems(portalLanguages); Result.AddSummary("Exported Portal Languages", portalLanguages.Count.ToString()); CheckPoint.Progress = 100; CheckPoint.Completed = true; CheckPoint.Stage++; CheckPoint.ProcessedItems += portalLanguages.Count; CheckPointStageCallback(this); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { CheckPoint.Progress += 100; CheckPoint.Completed = true; CheckPoint.TotalItems = 0; CheckPoint.ProcessedItems = 0; CheckPointStageCallback(this); //No implementation required in export users child as everything is exported in parent service. }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (this.CheckPoint.Stage > 0) { return; } if (this.CheckCancelled(exportJob)) { return; } var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); var contentWorkflows = GetWorkflows(exportDto.PortalId, exportDto.IncludeDeletions); if (contentWorkflows.Count > 0) { var defaultWorkflowId = TabWorkflowSettings.Instance.GetDefaultTabWorkflowId(exportDto.PortalId); var defaultWorkflow = contentWorkflows.FirstOrDefault(w => w.WorkflowID == defaultWorkflowId); if (defaultWorkflow != null) { defaultWorkflow.IsDefault = true; } this.CheckPoint.TotalItems = contentWorkflows.Count; this.Repository.CreateItems(contentWorkflows); this.Result.AddLogEntry("Exported ContentWorkflows", contentWorkflows.Count.ToString()); foreach (var workflow in contentWorkflows) { var contentWorkflowStates = GetWorkflowStates(workflow.WorkflowID); this.Repository.CreateItems(contentWorkflowStates, workflow.Id); foreach (var workflowState in contentWorkflowStates) { var contentWorkflowStatePermissions = GetWorkflowStatePermissions(workflowState.StateID, toDate, fromDate); this.Repository.CreateItems(contentWorkflowStatePermissions, workflowState.Id); } } } this.CheckPoint.Progress = 100; this.CheckPoint.Completed = true; this.CheckPoint.Stage++; this.CheckPoint.StageData = null; this.CheckPointStageCallback(this); }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); if (this.CheckCancelled(exportJob)) { return; } if (this.CheckPoint.Stage > 0) { return; } if (this.CheckCancelled(exportJob)) { return; } var profileProperties = CBO.FillCollection <ExportProfileProperty>( DataProvider.Instance() .GetPropertyDefinitionsByPortal( exportJob.PortalId, exportDto.IncludeDeletions, toDate, fromDate)) .ToList(); this.CheckPoint.Progress = 50; // Update the total items count in the check points. This should be updated only once. this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? profileProperties.Count : this.CheckPoint.TotalItems; this.CheckPointStageCallback(this); if (this.CheckCancelled(exportJob)) { return; } this.Repository.CreateItems(profileProperties); this.Result.AddSummary("Exported Profile Properties", profileProperties.Count.ToString()); this.CheckPoint.Progress = 100; this.CheckPoint.ProcessedItems = profileProperties.Count; this.CheckPoint.Completed = true; this.CheckPoint.Stage++; this.CheckPointStageCallback(this); }
public void Convert_DtoWithNoTags_ShouldCreateExcelWithEmptyActionSheet() { // Arrange var exportDto = new ExportDto( new List <ExportTagDto>(), _usedFilterDto); // Act var xlStream = _dut.Convert(exportDto); // Assert var workbook = AssertWorkbookFromStream(xlStream, _expected3Sheets); AssertFiltersSheet(workbook.Worksheets.Worksheet(_filtersSheet), exportDto.UsedFilter); AssertActionSheet(workbook.Worksheets.Worksheet(_actionsSheet), exportDto.Tags); }
public MemoryStream Convert(ExportDto dto) { // see https://github.com/ClosedXML/ClosedXML for sample code var excelStream = new MemoryStream(); using (var workbook = new XLWorkbook()) { CreateFrontSheet(workbook, dto.UsedFilter); var exportTagDtos = dto.Tags.ToList(); CreateTagSheet(workbook, exportTagDtos); CreateActionSheet(workbook, exportTagDtos); CreateHistorySheet(workbook, exportTagDtos); workbook.SaveAs(excelStream); } return(excelStream); }
public void Convert_DtoWithOneTag_ShouldCreateExcelWith4Sheets() { // Arrange var exportDto = new ExportDto( new List <ExportTagDto> { _exportTagDtoWithoutActionsAndHistory }, _usedFilterDto); // Act var xlStream = _dut.Convert(exportDto); // Assert var workbook = AssertWorkbookFromStream(xlStream, _expected4Sheets); AssertFiltersSheet(workbook.Worksheets.Worksheet(_filtersSheet), exportDto.UsedFilter); AssertSheetExists(workbook, _historySheet, true); }
public void Convert_DtoWithOneTagWithActionsAndHistory_ShouldCreateExcelWithCorrectDataInAllSheets() { // Arrange var exportDto = new ExportDto( new List <ExportTagDto> { _exportTagDtoWithTwoActionsAndTwoHistoryItems }, _usedFilterDto); // Act var xlStream = _dut.Convert(exportDto); // Assert var workbook = AssertWorkbookFromStream(xlStream, _expected4Sheets); AssertFiltersSheet(workbook.Worksheets.Worksheet(_filtersSheet), exportDto.UsedFilter); AssertTagSheet(workbook.Worksheets.Worksheet(_tagsSheet), exportDto.Tags); AssertActionSheet(workbook.Worksheets.Worksheet(_actionsSheet), exportDto.Tags); AssertHistorySheet(workbook.Worksheets.Worksheet(_historySheet), exportDto.Tags.Single()); }
private void OnEnable() { _exportDtoList = new List <ExportDto>(); for (int i = 0; i < TSDatabaseUtils.TableConfigSerializeData.TableConfigList.Count; i++) { TableConfig config = TSDatabaseUtils.TableConfigSerializeData.TableConfigList[i]; ExportDto dto = new ExportDto(); dto.CurrentConfig = config; dto.Count = 0; if (!string.IsNullOrEmpty(config.DataPath)) { ScriptableObject assetObj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(config.DataPath); object items = assetObj.GetType().GetField("DataList").GetValue(assetObj); if (items != null) { dto.Count = (int)items.GetType().GetProperty("Count").GetValue(items, null); } } _exportDtoList.Add(dto); } }
private void TableGUI() { GUILayout.Space(10); GUILayout.BeginVertical(); GUILayout.BeginScrollView(_tableScrollVec, false, false); for (int i = 0; i < _exportDtoList.Count; i++) { ExportDto dto = _exportDtoList[i]; GUILayout.BeginHorizontal("GroupBox"); GUILayout.Label(dto.CurrentConfig.TableName); GUILayout.Label("大约有:" + dto.Count + "条数据"); if (GUILayout.Button("导出", GUILayout.Width(50))) { ExportData(dto); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
private void ImportData(ExportDto dto) { string fileName = EditorUtility.OpenFilePanel("", "", "txt"); if (!string.IsNullOrEmpty(fileName)) { List <FieldConfig> importFieldConfigList = new List <FieldConfig>(); for (int i = 0; i < dto.CurrentConfig.FieldList.Count; i++) { if (dto.CurrentConfig.FieldList[i].FieldName == dto.CurrentConfig.PrimaryKey) { if (dto.CurrentConfig.FieldList[i].IsExport == false) { if (EditorUtility.DisplayDialog("Error", "PrimaryKey 没有导出", "OK")) { return; } } } if (dto.CurrentConfig.FieldList[i].IsExport) { importFieldConfigList.Add(dto.CurrentConfig.FieldList[i]); } } int count = importFieldConfigList.Count; string[] allLine = File.ReadAllLines(fileName); if (allLine.Length < 1) { if (EditorUtility.DisplayDialog("Error", "File Error", "OK")) { return; } } string[] fieldArray = allLine[0].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (fieldArray.Length != count) { Debug.LogError("fieldArray.Length"); if (EditorUtility.DisplayDialog("Error", "File Error", "OK")) { return; } } ScriptableObject assetObj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(dto.CurrentConfig.DataPath); object items = assetObj.GetType().GetField("DataList").GetValue(assetObj); if (items == null) { if (EditorUtility.DisplayDialog("Error", "Unity data is null", "OK")) { return; } } Assembly assembly = assetObj.GetType().Assembly; Type itemType = assembly.GetType(dto.CurrentConfig.TableName); object targetItems = Activator.CreateInstance(typeof(List <>).MakeGenericType(itemType)); MethodInfo addMethod = items.GetType().GetMethod("Add"); MethodInfo getMethod = items.GetType().GetMethod("get_Item"); int orginCount = (int)items.GetType().GetProperty("Count").GetValue(items, null); if (itemType == null) { if (EditorUtility.DisplayDialog("Error", "Table type Error", "OK")) { return; } } //清空所有主键重新键入 if (TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic.ContainsKey(dto.CurrentConfig.TableName)) { TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.Clear(); } else { TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic.Add(dto.CurrentConfig.TableName, new PrimaryKeyInfo()); TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].TableName = dto.CurrentConfig.TableName; TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].PrimaryKey = dto.CurrentConfig.PrimaryKey; TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].PrimaryType = dto.CurrentConfig.PrimaryType; TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values = new Dictionary <string, int>(); } string keyName = dto.CurrentConfig.PrimaryKey; int keyIndex = 0; for (int i = 0; i < count; i++) { if (fieldArray[i] == dto.CurrentConfig.PrimaryKey) { keyIndex = i; break; } } EditorUtility.DisplayProgressBar("开始导入", "正在导入0/" + (allLine.Length - 1), 0f); try { int begin = 1; for (; begin < allLine.Length; begin++) { string[] contentArray = allLine[begin].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (contentArray.Length > count) { continue; } object o = null; object keyValue = null; //找到主键ID 一样的数据 for (int j = 0; j < orginCount; j++) { o = getMethod.Invoke(items, new object[] { j }); keyValue = o.GetType().GetField(keyName).GetValue(o); if (keyValue.ToString() == contentArray[keyIndex]) { break; } else { o = null; } } //如果原表中没有查询到,则创建新的 if (o == null) { o = assembly.CreateInstance(itemType.FullName); } for (int i = 0; i < importFieldConfigList.Count; i++) { FieldConfig fieldConfig = importFieldConfigList[i]; ///如果是Unity对象类型则不赋值 switch (fieldConfig.FieldType) { case "Sprite": case "Texture": case "GameObject": case "Texture2D": continue; case "List": switch (fieldConfig.GenericType) { case "Sprite": case "Texture": case "GameObject": case "Texture2D": continue; } break; } o.GetType().GetField(fieldConfig.FieldName).SetValue(o, GetObject(fieldConfig, contentArray[i], assembly, fieldConfig.FieldType)); if (keyName == fieldConfig.FieldName) { keyValue = o.GetType().GetField(fieldConfig.FieldName).GetValue(o); } } addMethod.Invoke(targetItems, new object[] { o }); if (TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.ContainsKey(keyValue.ToString())) { TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values[keyValue.ToString()]++; } else { TSDatabaseUtils.PrimaryKeySerializeData.PrimaryKeyDic[dto.CurrentConfig.TableName].Values.Add(keyValue.ToString(), 1); } EditorUtility.DisplayProgressBar("开始导入", "正在导入" + (begin - 1) + "/" + (allLine.Length - 1), (begin - 1) * 1f / (allLine.Length - 1)); System.Threading.Thread.Sleep(10); } assetObj.GetType().GetField("DataList").SetValue(assetObj, targetItems); EditorUtility.SetDirty(assetObj); TSDatabaseUtils.SavaGlobalData(); EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("成功", "导入成功!", "OK"); } catch (Exception ex) { EditorUtility.ClearProgressBar(); throw ex; } } else { if (EditorUtility.DisplayDialog("Error", "Path is Error", "OK")) { return; } } }
private void AssertCount(ExportDto data, int count) => Assert.AreEqual(count, data.Invitations.Count);
private void ExportData(ExportDto dto) { if (string.IsNullOrEmpty(dto.CurrentConfig.DataPath)) { if (EditorUtility.DisplayDialog(LanguageUtils.CommonSaveFailed, LanguageUtils.ExportNotFound, "OK")) { return; } } string path = EditorUtility.SaveFilePanel(LanguageUtils.ExportFile, "", dto.CurrentConfig.TableName + ".txt", "txt"); if (string.IsNullOrEmpty(path)) { if (EditorUtility.DisplayDialog(LanguageUtils.CommonSaveFailed, LanguageUtils.CommonNullPath, "OK")) { return; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < dto.CurrentConfig.FieldList.Count; i++) { if (dto.CurrentConfig.FieldList[i].IsExport) { sb.Append(dto.CurrentConfig.FieldList[i].FieldName); } sb.Append("\t"); } sb.Append("\r\n"); ScriptableObject assetObj = AssetDatabase.LoadAssetAtPath <ScriptableObject>(dto.CurrentConfig.DataPath); object items = assetObj.GetType().GetField("DataList").GetValue(assetObj); if (items != null) { int count = (int)items.GetType().GetProperty("Count").GetValue(items, null); System.Reflection.PropertyInfo property = items.GetType().GetProperty("Item"); for (int j = 0; j < count; j++) { object o = property.GetValue(items, new object[] { j }); for (int i = 0; i < dto.CurrentConfig.FieldList.Count; i++) { if (dto.CurrentConfig.FieldList[i].IsExport) { string str = ""; object obj = o.GetType().GetField(dto.CurrentConfig.FieldList[i].FieldName).GetValue(o); GetString(dto.CurrentConfig.FieldList[i].FieldType, obj, ref str); sb.Append(str); } sb.Append("\t"); } sb.Append("\r\n"); } } if (!File.Exists(path)) { File.Create(path).Dispose(); } File.WriteAllText(path, sb.ToString()); EditorUtility.DisplayDialog(LanguageUtils.ExportHead, "Success", "Ok"); }
private static HashSet <string> GetAllCategoriesToInclude( ExportDto exportDto, List <BasePortableService> implementors) { // add all child items var includedItems = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); if (exportDto.ItemsToExport != null) { foreach ( var name in exportDto.ItemsToExport.Where( x => !NotAllowedCategoriesinRequestArray.Contains(x.ToUpperInvariant()))) { includedItems.Add(name); } } includedItems.Remove(Constants.Category_Content); if (exportDto.Pages?.Length > 0) { includedItems.Add(Constants.Category_Pages); includedItems.Add(Constants.Category_Workflows); } if (exportDto.IncludeContent) { includedItems.Add(Constants.Category_Content); } if (exportDto.IncludeFiles) { includedItems.Add(Constants.Category_Assets); } if (exportDto.IncludeUsers) { includedItems.Add(Constants.Category_Users); } if (exportDto.IncludeRoles) { includedItems.Add(Constants.Category_Roles); } if (exportDto.IncludeVocabularies) { includedItems.Add(Constants.Category_Vocabularies); } if (exportDto.IncludeTemplates) { includedItems.Add(Constants.Category_Templates); } if (exportDto.IncludeProperfileProperties) { includedItems.Add(Constants.Category_ProfileProps); } // This might be added always. if (exportDto.IncludeExtensions) { includedItems.Add(Constants.Category_Packages); } var additionalItems = new List <string>(); foreach (var includedItem in includedItems) { BasePortableService basePortableService; if ( (basePortableService = implementors.FirstOrDefault(x => x.ParentCategory.Equals(includedItem, IgnoreCaseComp))) != null) { additionalItems.Add(basePortableService.Category); } } additionalItems.ForEach(i => includedItems.Add(i)); // must be included always when there is at least one other object to process if (includedItems.Any()) { includedItems.Add(Constants.Category_Portal); } return(includedItems); }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (CheckCancelled(exportJob)) { return; } //Skip the export if all the folders have been processed already. if (CheckPoint.Stage >= 1) { return; } //Create Zip File to hold files var skip = GetCurrentSkip(); var currentIndex = skip; var totalFolderExported = 0; var totalFolderPermissionsExported = 0; var totalFilesExported = 0; var portalId = exportJob.PortalId; try { var assetsFile = string.Format(_assetsFolder, exportJob.Directory.TrimEnd('\\').TrimEnd('/')); if (CheckPoint.Stage == 0) { var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); var portal = PortalController.Instance.GetPortal(portalId); var folders = CBO.FillCollection <ExportFolder>(DataProvider.Instance() .GetFolders(portalId, toDate, fromDate)).ToList(); var totalFolders = folders.Any() ? folders.Count : 0; folders = folders.Skip(skip).ToList(); //Update the total items count in the check points. This should be updated only once. CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? totalFolders : CheckPoint.TotalItems; CheckPoint.ProcessedItems = skip; CheckPoint.Progress = CheckPoint.TotalItems > 0 ? skip * 100.0 / CheckPoint.TotalItems : 0; if (CheckPointStageCallback(this)) { return; } using (var zipArchive = CompressionUtil.OpenCreate(assetsFile)) { foreach (var folder in folders) { if (CheckCancelled(exportJob)) { break; } var isUserFolder = false; var files = CBO.FillCollection <ExportFile>( DataProvider.Instance() .GetFiles(portalId, folder.FolderId, toDate, fromDate)).Where(x => x.Extension != Constants.TemplatesExtension).ToList(); int?userId; if (IsUserFolder(folder.FolderPath, out userId)) { isUserFolder = true; folder.UserId = userId; folder.Username = UserController.GetUserById(portalId, Convert.ToInt32(userId))?.Username; } if (folder.ParentId != null && folder.ParentId > 0) { //If parent id exists then change the parent folder id to parent id. folder.ParentId = Repository.GetItem <ExportFolder>( x => x.FolderId == Convert.ToInt32(folder.ParentId))?.Id; } Repository.CreateItem(folder, null); totalFolderExported++; //Include permissions only if IncludePermissions=true if (exportDto.IncludePermissions) { var permissions = CBO.FillCollection <ExportFolderPermission>(DataProvider.Instance() .GetFolderPermissionsByPath(portalId, folder.FolderPath, toDate, fromDate)); Repository.CreateItems(permissions, folder.Id); totalFolderPermissionsExported += permissions.Count; } Repository.CreateItems(files, folder.Id); totalFilesExported += files.Count; var folderOffset = portal.HomeDirectoryMapPath.Length + (portal.HomeDirectoryMapPath.EndsWith("\\") ? 0 : 1); if (folder.StorageLocation != (int)FolderController.StorageLocationTypes.DatabaseSecure) { CompressionUtil.AddFilesToArchive(zipArchive, files.Select(file => portal.HomeDirectoryMapPath + folder.FolderPath + GetActualFileName(file)), folderOffset, isUserFolder ? "TempUsers" : null); } CheckPoint.ProcessedItems++; CheckPoint.Progress = CheckPoint.ProcessedItems * 100.0 / totalFolders; CheckPoint.StageData = null; currentIndex++; //After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB. if (currentIndex % 10 == 0 && CheckPointStageCallback(this)) { return; } Repository.RebuildIndex <ExportFolder>(x => x.Id, true); Repository.RebuildIndex <ExportFolder>(x => x.UserId); Repository.RebuildIndex <ExportFile>(x => x.ReferenceId); } } CheckPoint.Completed = true; CheckPoint.Stage++; currentIndex = 0; CheckPoint.Progress = 100; } } finally { CheckPoint.StageData = currentIndex > 0 ? JsonConvert.SerializeObject(new { skip = currentIndex }) : null; CheckPointStageCallback(this); Result.AddSummary("Exported Folders", totalFolderExported.ToString()); Result.AddSummary("Exported Folder Permissions", totalFolderPermissionsExported.ToString()); Result.AddSummary("Exported Files", totalFilesExported.ToString()); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (this.CheckCancelled(exportJob)) { return; } // Skip the export if all the folders have been processed already. if (this.CheckPoint.Stage >= 1) { return; } // Create Zip File to hold files var skip = this.GetCurrentSkip(); var currentIndex = skip; var totalTemplatesExported = 0; var portalId = exportJob.PortalId; try { var templatesFile = string.Format(this.templatesFolder, exportJob.Directory.TrimEnd('\\').TrimEnd('/')); if (this.CheckPoint.Stage == 0) { var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); var portal = PortalController.Instance.GetPortal(portalId); var templates = CBO.FillCollection <ExportPageTemplate>( DataProvider.Instance() .GetFiles(portalId, null, toDate, fromDate)) .Where(x => x.Extension == Constants.TemplatesExtension) .ToList(); var totalTemplates = templates.Count; // Update the total items count in the check points. This should be updated only once. this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalTemplates : this.CheckPoint.TotalItems; if (this.CheckPointStageCallback(this)) { return; } foreach (var template in templates) { this.Repository.CreateItem(template, null); totalTemplatesExported += 1; var folderOffset = portal.HomeDirectoryMapPath.Length + (portal.HomeDirectoryMapPath.EndsWith("\\") ? 0 : 1); var folder = FolderManager.Instance.GetFolder(template.FolderId); CompressionUtil.AddFileToArchive( portal.HomeDirectoryMapPath + folder.FolderPath + this.GetActualFileName(template), templatesFile, folderOffset); this.CheckPoint.ProcessedItems++; this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalTemplates; currentIndex++; // After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB. if (currentIndex % 10 == 0 && this.CheckPointStageCallback(this)) { return; } } this.CheckPoint.Stage++; currentIndex = 0; this.CheckPoint.Completed = true; this.CheckPoint.Progress = 100; } } finally { this.CheckPoint.StageData = currentIndex > 0 ? JsonConvert.SerializeObject(new { skip = currentIndex }) : null; this.CheckPointStageCallback(this); this.Result.AddSummary("Exported Templates", totalTemplatesExported.ToString()); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (CheckPoint.Stage > 0) { return; } if (CheckCancelled(exportJob)) { return; } var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); List <TaxonomyVocabularyType> vocabularyTypes = null; if (CheckPoint.Stage == 0) { var taxonomyTerms = GetTaxonomyTerms(exportDto.PortalId, toDate, fromDate); var taxonomyVocabularies = GetTaxonomyVocabularies(exportDto.PortalId, toDate, fromDate); if (taxonomyTerms.Count > 0 || taxonomyVocabularies.Count > 0) { var scopeTypes = CBO.FillCollection <TaxonomyScopeType>(DataProvider.Instance().GetAllScopeTypes()); //Update the total items count in the check points. This should be updated only once. CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? scopeTypes.Count : CheckPoint.TotalItems; if (CheckPoint.TotalItems == scopeTypes.Count) { vocabularyTypes = CBO.FillCollection <TaxonomyVocabularyType>(DataProvider.Instance().GetAllVocabularyTypes()); taxonomyTerms = GetTaxonomyTerms(exportDto.PortalId, toDate, fromDate); taxonomyVocabularies = GetTaxonomyVocabularies(exportDto.PortalId, toDate, fromDate); CheckPoint.TotalItems += taxonomyTerms.Count + taxonomyVocabularies.Count; } CheckPointStageCallback(this); Repository.CreateItems(scopeTypes); //Result.AddSummary("Exported Taxonomy Scopes", scopeTypes.Count.ToString()); -- not imported so don't show //CheckPoint.ProcessedItems += scopeTypes.Count; } CheckPoint.Progress = 25; if (taxonomyVocabularies == null) { taxonomyVocabularies = GetTaxonomyVocabularies(exportDto.PortalId, toDate, fromDate); } if (taxonomyTerms.Count > 0 || taxonomyVocabularies.Count > 0) { if (vocabularyTypes == null) { vocabularyTypes = CBO.FillCollection <TaxonomyVocabularyType>(DataProvider.Instance().GetAllVocabularyTypes()); } Repository.CreateItems(vocabularyTypes); //Result.AddSummary("Exported Vocabulary Types", vocabularyTypes.Count.ToString()); -- not imported so don't show //CheckPoint.ProcessedItems += vocabularyTypes.Count; } Repository.CreateItems(taxonomyTerms); Result.AddSummary("Exported Vocabularies", taxonomyTerms.Count.ToString()); CheckPoint.Progress = 75; CheckPoint.ProcessedItems += taxonomyTerms.Count; CheckPoint.Stage++; if (CheckPointStageCallback(this)) { return; } if (taxonomyVocabularies == null) { taxonomyVocabularies = GetTaxonomyVocabularies(exportDto.PortalId, toDate, fromDate); } Repository.CreateItems(taxonomyVocabularies); Result.AddSummary("Exported Terms", taxonomyVocabularies.Count.ToString()); CheckPoint.Progress = 100; CheckPoint.ProcessedItems += taxonomyVocabularies.Count; CheckPoint.Stage++; CheckPoint.Completed = true; CheckPointStageCallback(this); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { var fromDate = (exportDto.FromDateUtc ?? Constants.MinDbTime).ToLocalTime(); var toDate = exportDto.ToDateUtc.ToLocalTime(); if (CheckPoint.Stage > 2) { return; } List <ExportRole> roles = null; List <ExportRoleSetting> roleSettings = null; if (CheckPoint.Stage == 0) { if (CheckCancelled(exportJob)) { return; } var roleGroups = CBO.FillCollection <ExportRoleGroup>( DataProvider.Instance().GetAllRoleGroups(exportJob.PortalId, toDate, fromDate)); //Update the total items count in the check points. This should be updated only once. CheckPoint.TotalItems = CheckPoint.TotalItems <= 0 ? roleGroups.Count : CheckPoint.TotalItems; if (CheckPoint.TotalItems == roleGroups.Count) { roles = CBO.FillCollection <ExportRole>( DataProvider.Instance().GetAllRoles(exportJob.PortalId, toDate, fromDate)); roleSettings = CBO.FillCollection <ExportRoleSetting>( DataProvider.Instance().GetAllRoleSettings(exportJob.PortalId, toDate, fromDate)); CheckPoint.TotalItems += roles.Count + roleSettings.Count; } CheckPointStageCallback(this); Repository.CreateItems(roleGroups); Result.AddSummary("Exported Role Groups", roleGroups.Count.ToString()); CheckPoint.ProcessedItems = roleGroups.Count; CheckPoint.Progress = 30; CheckPoint.Stage++; if (CheckPointStageCallback(this)) { return; } } if (CheckPoint.Stage == 1) { if (CheckCancelled(exportJob)) { return; } if (roles == null) { roles = CBO.FillCollection <ExportRole>( DataProvider.Instance().GetAllRoles(exportJob.PortalId, toDate, fromDate)); } Repository.CreateItems(roles); Result.AddSummary("Exported Roles", roles.Count.ToString()); CheckPoint.Progress = 80; CheckPoint.ProcessedItems += roles.Count; CheckPoint.Stage++; if (CheckPointStageCallback(this)) { return; } } if (CheckPoint.Stage == 2) { if (CheckCancelled(exportJob)) { return; } if (roleSettings == null) { roleSettings = CBO.FillCollection <ExportRoleSetting>( DataProvider.Instance().GetAllRoleSettings(exportJob.PortalId, toDate, fromDate)); } Repository.CreateItems(roleSettings); Result.AddSummary("Exported Role Settings", roleSettings.Count.ToString()); CheckPoint.Progress = 100; CheckPoint.ProcessedItems += roleSettings.Count; CheckPoint.Completed = true; CheckPoint.Stage++; CheckPointStageCallback(this); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (this.CheckCancelled(exportJob)) { return; } // Skip the export if all the folders have been processed already. if (this.CheckPoint.Stage >= 1) { return; } this.exportImportJob = exportJob; this.portalSettings = new PortalSettings(exportJob.PortalId); // Create Zip File to hold files var currentIndex = 0; var totalThemesExported = 0; try { var packagesZipFileFormat = $"{Globals.ApplicationMapPath}{Constants.ExportFolder}{{0}}\\{Constants.ExportZipThemes}"; var packagesZipFile = string.Format(packagesZipFileFormat, exportJob.Directory.TrimEnd('\\').TrimEnd('/')); if (this.CheckPoint.Stage == 0) { // export skin packages. var exportThemes = this.GetExportThemes(); var totalThemes = exportThemes.Count; // Update the total items count in the check points. This should be updated only once. this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalThemes : this.CheckPoint.TotalItems; if (this.CheckPointStageCallback(this)) { return; } using (var archive = CompressionUtil.OpenCreate(packagesZipFile)) { foreach (var theme in exportThemes) { var filePath = SkinController.FormatSkinSrc(theme, this.portalSettings); var physicalPath = Path.Combine(Globals.ApplicationMapPath, filePath.TrimStart('/')); if (Directory.Exists(physicalPath)) { foreach (var file in Directory.GetFiles(physicalPath, "*.*", SearchOption.AllDirectories)) { var folderOffset = Path.Combine(Globals.ApplicationMapPath, "Portals").Length + 1; CompressionUtil.AddFileToArchive(archive, file, folderOffset); } totalThemesExported += 1; } this.CheckPoint.ProcessedItems++; this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalThemes; currentIndex++; // After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB. if (currentIndex % 10 == 0 && this.CheckPointStageCallback(this)) { return; } } } this.CheckPoint.Stage++; this.CheckPoint.Completed = true; this.CheckPoint.Progress = 100; } } finally { this.CheckPointStageCallback(this); this.Result.AddSummary("Exported Themes", totalThemesExported.ToString()); } }
public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (this.CheckCancelled(exportJob)) { return; } var fromDateUtc = exportDto.FromDateUtc; var toDateUtc = exportDto.ToDateUtc; var portalId = exportJob.PortalId; var pageIndex = 0; const int pageSize = Constants.DefaultPageSize; var totalUsersExported = 0; var totalUserRolesExported = 0; var totalPortalsExported = 0; var totalProfilesExported = 0; var totalAuthenticationExported = 0; var totalAspnetUserExported = 0; var totalAspnetMembershipExported = 0; var totalUsers = DataProvider.Instance().GetUsersCount(portalId, exportDto.IncludeDeletions, toDateUtc, fromDateUtc); if (totalUsers == 0) { this.CheckPoint.Completed = true; this.CheckPointStageCallback(this); return; } var totalPages = Util.CalculateTotalPages(totalUsers, pageSize); // Skip the export if all the users has been processed already. if (this.CheckPoint.Stage >= totalPages) { return; } // Check if there is any pending stage or partially processed data. if (this.CheckPoint.Stage > 0) { pageIndex = this.CheckPoint.Stage; } // Update the total items count in the check points. This should be updated only once. this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalUsers : this.CheckPoint.TotalItems; this.CheckPoint.ProcessedItems = this.CheckPoint.Stage * pageSize; if (this.CheckPointStageCallback(this)) { return; } var includeProfile = exportDto.IncludeProperfileProperties; try { while (pageIndex < totalPages) { if (this.CheckCancelled(exportJob)) { return; } var exportUsersList = new List <ExportUser>(); var exportAspnetUserList = new List <ExportAspnetUser>(); var exportAspnetMembershipList = new List <ExportAspnetMembership>(); var exportUserRoleList = new List <ExportUserRole>(); var exportUserPortalList = new List <ExportUserPortal>(); var exportUserAuthenticationList = new List <ExportUserAuthentication>(); var exportUserProfileList = new List <ExportUserProfile>(); try { using (var reader = DataProvider.Instance() .GetAllUsers(portalId, pageIndex, pageSize, exportDto.IncludeDeletions, toDateUtc, fromDateUtc)) { CBO.FillCollection(reader, exportUsersList, false); reader.NextResult(); CBO.FillCollection(reader, exportUserAuthenticationList, false); reader.NextResult(); CBO.FillCollection(reader, exportUserRoleList, false); reader.NextResult(); if (includeProfile) { CBO.FillCollection(reader, exportUserProfileList, false); } reader.NextResult(); CBO.FillCollection(reader, exportUserPortalList, false); reader.NextResult(); CBO.FillCollection(reader, exportAspnetUserList, false); reader.NextResult(); CBO.FillCollection(reader, exportAspnetMembershipList, true); } this.Repository.CreateItems(exportUsersList, null); totalUsersExported += exportUsersList.Count; exportUserAuthenticationList.ForEach( x => { x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id; }); this.Repository.CreateItems(exportUserAuthenticationList, null); totalAuthenticationExported += exportUserAuthenticationList.Count; exportUserRoleList.ForEach( x => { x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id; }); this.Repository.CreateItems(exportUserRoleList, null); totalUserRolesExported += exportUserRoleList.Count; if (includeProfile) { exportUserProfileList.ForEach( x => { x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id; }); this.Repository.CreateItems(exportUserProfileList, null); totalProfilesExported += exportUserProfileList.Count; } exportUserPortalList.ForEach( x => { x.ReferenceId = exportUsersList.FirstOrDefault(user => user.UserId == x.UserId)?.Id; }); this.Repository.CreateItems(exportUserPortalList, null); totalPortalsExported += exportUserPortalList.Count; exportAspnetUserList.ForEach( x => { x.ReferenceId = exportUsersList.FirstOrDefault(user => user.Username == x.UserName)?.Id; }); this.Repository.CreateItems(exportAspnetUserList, null); totalAspnetUserExported += exportAspnetUserList.Count; exportAspnetMembershipList.ForEach( x => { x.ReferenceId = exportAspnetUserList.FirstOrDefault(user => user.UserId == x.UserId)?.Id; }); this.Repository.CreateItems(exportAspnetMembershipList, null); totalAspnetMembershipExported += exportAspnetMembershipList.Count; this.CheckPoint.ProcessedItems += exportUsersList.Count; } catch (Exception ex) { this.Result.AddLogEntry($"Exporting Users from {pageIndex * pageSize} to {(pageIndex * pageSize) + pageSize} exception", ex.Message, ReportLevel.Error); } this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalUsers; this.CheckPoint.Stage++; if (this.CheckPointStageCallback(this)) { return; } // Rebuild the indexes in the exported database. this.Repository.RebuildIndex <ExportUser>(x => x.Id, true); this.Repository.RebuildIndex <ExportUserPortal>(x => x.ReferenceId); this.Repository.RebuildIndex <ExportAspnetUser>(x => x.ReferenceId); this.Repository.RebuildIndex <ExportAspnetMembership>(x => x.ReferenceId); this.Repository.RebuildIndex <ExportUserAuthentication>(x => x.ReferenceId); this.Repository.RebuildIndex <ExportUserRole>(x => x.ReferenceId); if (includeProfile) { this.Repository.RebuildIndex <ExportUserProfile>(x => x.ReferenceId); } pageIndex++; } this.CheckPoint.Completed = true; this.CheckPoint.Progress = 100; } finally { this.CheckPointStageCallback(this); this.Result.AddSummary("Exported Users", totalUsersExported.ToString()); this.Result.AddSummary("Exported User Portals", totalPortalsExported.ToString()); this.Result.AddSummary("Exported User Roles", totalUserRolesExported.ToString()); if (includeProfile) { this.Result.AddSummary("Exported User Profiles", totalProfilesExported.ToString()); } this.Result.AddSummary("Exported User Authentication", totalAuthenticationExported.ToString()); this.Result.AddSummary("Exported Aspnet User", totalAspnetUserExported.ToString()); this.Result.AddSummary("Exported Aspnet Membership", totalAspnetMembershipExported.ToString()); } }
public override uint Priority => 18; // execute before pages service. public override void ExportData(ExportImportJob exportJob, ExportDto exportDto) { if (this.CheckCancelled(exportJob)) { return; } // Skip the export if all the folders have been processed already. if (this.CheckPoint.Stage >= 1) { return; } // Create Zip File to hold files var skip = this.GetCurrentSkip(); var currentIndex = skip; var totalPackagesExported = 0; try { var packagesZipFileFormat = $"{Globals.ApplicationMapPath}{Constants.ExportFolder}{{0}}\\{Constants.ExportZipPackages}"; var packagesZipFile = string.Format(packagesZipFileFormat, exportJob.Directory.TrimEnd('\\').TrimEnd('/')); if (this.CheckPoint.Stage == 0) { var fromDate = exportDto.FromDateUtc ?? Constants.MinDbTime; var toDate = exportDto.ToDateUtc; // export skin packages. var extensionPackagesBackupFolder = Path.Combine(Globals.ApplicationMapPath, DotNetNuke.Services.Installer.Util.BackupInstallPackageFolder); var skinPackageFiles = Directory.GetFiles(extensionPackagesBackupFolder).Where(f => this.IsValidPackage(f, fromDate, toDate)).ToList(); var totalPackages = skinPackageFiles.Count; // Update the total items count in the check points. This should be updated only once. this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? totalPackages : this.CheckPoint.TotalItems; if (this.CheckPointStageCallback(this)) { return; } using (var zipArchive = CompressionUtil.OpenCreate(packagesZipFile)) { foreach (var file in skinPackageFiles) { var exportPackage = this.GenerateExportPackage(file); if (exportPackage != null) { this.Repository.CreateItem(exportPackage, null); totalPackagesExported += 1; var folderOffset = Path.GetDirectoryName(file)?.Length + 1; CompressionUtil.AddFileToArchive(zipArchive, file, folderOffset.GetValueOrDefault(0)); } this.CheckPoint.ProcessedItems++; this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / totalPackages; currentIndex++; // After every 10 items, call the checkpoint stage. This is to avoid too many frequent updates to DB. if (currentIndex % 10 == 0 && this.CheckPointStageCallback(this)) { return; } } } this.CheckPoint.Stage++; currentIndex = 0; this.CheckPoint.Completed = true; this.CheckPoint.Progress = 100; } } finally { this.CheckPoint.StageData = currentIndex > 0 ? JsonConvert.SerializeObject(new { skip = currentIndex }) : null; this.CheckPointStageCallback(this); this.Result.AddSummary("Exported Packages", totalPackagesExported.ToString()); } }
public abstract void ExportData(ExportImportJob exportJob, ExportDto exportDto);