示例#1
0
        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 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());
            }
        }
示例#3
0
        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());
            }
        }