private bool BackupExtensionFolder(string extensionFolder, string extensionId)
        {
            var source = new DirectoryInfo(_virtualPathProvider.MapPath(_virtualPathProvider.Combine("~", extensionFolder, extensionId)));

            if (source.Exists)
            {
                var    tempPath      = _virtualPathProvider.Combine("~/App_Data", "_Backup", extensionFolder, extensionId);
                string localTempPath = null;
                for (int i = 0; i < 1000; i++)
                {
                    localTempPath = _virtualPathProvider.MapPath(tempPath) + (i == 0 ? "" : "." + i.ToString());
                    if (!System.IO.Directory.Exists(localTempPath))
                    {
                        System.IO.Directory.CreateDirectory(localTempPath);
                        break;
                    }
                    localTempPath = null;
                }

                if (localTempPath == null)
                {
                    throw new SmartException(T("Admin.Packaging.TooManyBackups", tempPath));
                }

                var backupFolder = new DirectoryInfo(localTempPath);
                _folderUpdater.Backup(source, backupFolder);
                _notifier.Information(T("Admin.Packaging.BackupSuccess", backupFolder.Name));

                return(true);
            }

            return(false);
        }
示例#2
0
        private bool BackupExtensionFolder(string extensionFolder, string extensionId)
        {
            var source = new DirectoryInfo(_virtualPathProvider.MapPath(_virtualPathProvider.Combine("~", extensionFolder, extensionId)));

            if (source.Exists)
            {
                var    tempPath      = _virtualPathProvider.Combine("~", extensionFolder, "_Backup", extensionId);
                string localTempPath = null;
                for (int i = 0; i < 1000; i++)
                {
                    localTempPath = _virtualPathProvider.MapPath(tempPath) + (i == 0 ? "" : "." + i.ToString());
                    if (!Directory.Exists(localTempPath))
                    {
                        Directory.CreateDirectory(localTempPath);
                        break;
                    }
                    localTempPath = null;
                }

                if (localTempPath == null)
                {
                    throw new OrchardException(T("Backup folder {0} has too many backups subfolder (limit is 1,000)", tempPath));
                }

                var backupFolder = new DirectoryInfo(localTempPath);
                _folderUpdater.Backup(source, backupFolder);
                _notifier.Information(T("Successfully backed up local package to local folder \"{0}\"", backupFolder));

                return(true);
            }

            return(false);
        }
示例#3
0
        public void BackupTest()
        {
            DirectoryInfo sourceDirectoryInfo = Directory.CreateDirectory(Path.Combine(_basePath, "Source"));

            File.CreateText(Path.Combine(sourceDirectoryInfo.FullName, "file1.txt")).Close();
            File.CreateText(Path.Combine(sourceDirectoryInfo.FullName, "file2.txt")).Close();

            IFolderUpdater folderUpdater = _container.Resolve <IFolderUpdater>();

            DirectoryInfo targetDirectoryInfo = new DirectoryInfo(Path.Combine(_basePath, "Target"));

            folderUpdater.Backup(sourceDirectoryInfo, targetDirectoryInfo);

            Assert.That(File.Exists(Path.Combine(targetDirectoryInfo.FullName, "file1.txt")), Is.True);
            Assert.That(File.Exists(Path.Combine(targetDirectoryInfo.FullName, "file2.txt")), Is.True);
        }