コード例 #1
0
        public static void EqualStructure(IDirectoryObject source, IDirectoryObject target)
        {
            var sourceFiles = source.GetFiles().ToList();
            var targetFiles = target.GetFiles().ToList();

            foreach (var sourceFile in sourceFiles)
            {
                Assert.IsTrue(targetFiles.Any(t => t.Name == sourceFile.Name));
            }

            var subDirectories = source.GetDirectories();

            foreach (var sourceSubDir in subDirectories)
            {
                var targetSubDir = target.GetDirectory(sourceSubDir.Name);
                Assert.IsTrue(targetSubDir.Exists);
                EqualStructure(sourceSubDir, targetSubDir);
            }
        }
コード例 #2
0
        public DirectoryStorageInstance(DirectoryStorage storage, IExecutionContext context)
        {
            var textFormatter = context.ServiceContainer.Get <ITextFormatter>();
            var fileSystem    = context.ServiceContainer.Get <IFileSystem>();
            var path          = textFormatter.Format(storage.Path);
            var directoryName = textFormatter.Format(storage.Options.DirectoryName);

            _storage          = storage;
            _storageDirectory = new DirectoryObject(path, fileSystem);
            _backupDirectory  = _storageDirectory.CombineDirectory(directoryName);

            if (_storageDirectory.Exists)
            {
                _oldBackupDirectories = _storageDirectory.GetDirectories(context).ToArray();
            }
            else
            {
                _oldBackupDirectories = new DirectoryObject[0];
            }

            _hardLinksEnabled = _storage.Options.EnableHardLinks && _storageDirectory.Drive.SupportsHardLinks;
        }
コード例 #3
0
        public void RenamesDirectory()
        {
            IDirectoryObject sourceDirectory = DirectoryHelper.CreateFullDirectory();

            IDirectoryObject targetDirectory = new MemoryDirectoryObject("targetDir");

            var mock = new Mock <ITaskQueue>();

            var syncNet = new Processor(sourceDirectory, targetDirectory, mock.Object);

            syncNet.ProcessSourceDirectory();

            var newName      = "newName";
            var subDirectory = sourceDirectory.GetDirectories().First();

            syncNet.RenameDirectory(subDirectory, newName);

            var targetFile = targetDirectory.GetDirectories().First();

            mock.Verify(x => x.Queue(
                            It.Is <RenameDirectoryTask>(t => t.Directory.FullName == targetFile.FullName && t.NewName == newName))
                        );
        }
コード例 #4
0
        private List <IFileObject> GetFilesToCopy(IDirectoryObject source, IDirectoryObject target)
        {
            var filesToUpload = new List <IFileObject>();
            var sourceFiles   = source.GetFiles();

            foreach (var sourceFile in sourceFiles)
            {
                var targetFile = target.GetFile(sourceFile.Name);
                if (!targetFile.Exists || sourceFile.ModifiedDate >= targetFile.ModifiedDate)
                {
                    filesToUpload.Add(sourceFile);
                }
            }

            var subDirectories = source.GetDirectories();

            foreach (var sourceSubDirectory in subDirectories)
            {
                var targetSubDirectory = target.GetDirectory(sourceSubDirectory.Name);
                filesToUpload.AddRange(GetFilesToCopy(sourceSubDirectory, targetSubDirectory));
            }

            return(filesToUpload);
        }