Exemplo n.º 1
0
        private static void DoPacking(ExportImportJob exportJob, string dbName)
        {
            var exportFileArchive = Path.Combine(ExportFolder, exportJob.Directory, Constants.ExportZipDbName);
            var folderOffset      = exportFileArchive.IndexOf(Constants.ExportZipDbName, StringComparison.Ordinal);

            File.Delete(CompressionUtil.AddFileToArchive(dbName, exportFileArchive, folderOffset)
                ? dbName
                : exportFileArchive);
        }
Exemplo n.º 2
0
        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());
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 4
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;
            }

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