public void UploadsFile() { var subDirectorPath = Path.Combine(_testDirectory, _subDirectoryName); if (!Directory.Exists(subDirectorPath)) { Directory.CreateDirectory(subDirectorPath); } File.WriteAllText(Path.Combine(_testDirectory, _subDirectoryName, _subFileName), _contents); var sourceDirectory = new LocalDirectoryObject(_testDirectory); var targetDirectory = new MemoryDirectoryObject("dir"); var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue()); syncNet.CopyFile( new LocalFileObject(sourceDirectory.FullName + "\\" + _subDirectoryName + "\\" + _subFileName)); var subDirectory = targetDirectory.GetDirectories().First(); Assert.AreEqual(_subDirectoryName, subDirectory.Name); var fileObject = subDirectory.GetFiles().First(); Assert.AreEqual(_subFileName, fileObject.Name); using (var sr = new StreamReader(fileObject.GetStream())) { Assert.AreEqual(_contents, sr.ReadToEnd().Replace("\0", string.Empty)); } }
public void Start() { _fileWatcher.Created += (sender, args) => { if (_fileWatcher.IsDirectory(args.FullPath)) { StaticLogger.Log($"Directory created: {args.FullPath}, processing..."); var directory = new LocalDirectoryObject(args.FullPath); _processor.ProcessDirectory(directory); } else { StaticLogger.Log($"File created: {args.FullPath}, processing..."); var file = new LocalFileObject(args.FullPath); _processor.CopyFile(file); } }; _fileWatcher.Renamed += (sender, args) => { if (_fileWatcher.IsDirectory(args.FullPath)) { StaticLogger.Log($"Directory renamed: {args.FullPath}, processing..."); _processor.RenameDirectory(new LocalDirectoryObject(args.OldFullPath), args.Name); } else { StaticLogger.Log($"File renamed: {args.FullPath}, processing..."); _processor.RenameFile(new LocalFileObject(args.OldFullPath), args.Name); } }; _fileWatcher.WatchForChanges(_configuration.LocalDirectory); }
public IDirectoryScanner Create(ProcessorConfiguration configuration) { var localDirectoryObject = new LocalDirectoryObject(configuration.LocalDirectory); var amazonS3Client = _amazonS3ClientFactory.GetS3Client(configuration); var s3DirectoryObject = new S3DirectoryObject(amazonS3Client, configuration.S3Bucket); return(new DirectoryScanner(localDirectoryObject, s3DirectoryObject)); }
public IProcessor Create(ProcessorConfiguration configuration, ITaskQueue taskQueue) { var localDirectoryObject = new LocalDirectoryObject(configuration.LocalDirectory); var amazonS3Client = _amazonS3ClientFactory.GetS3Client(configuration); amazonS3Client.BeforeRequestEvent += AmazonS3Client_BeforeRequestEvent; amazonS3Client.AfterResponseEvent += AmazonS3Client_AfterResponseEvent; var s3DirectoryObject = new S3DirectoryObject(amazonS3Client, configuration.S3Bucket); return(new Processor(localDirectoryObject, s3DirectoryObject, taskQueue)); }
public void WritesFileToLocalFileSystem() { var directoryInfo = new DirectoryInfo(_testDirectory); if (directoryInfo.Exists) { directoryInfo.Delete(true); } directoryInfo.Create(); var targetDirectory = new LocalDirectoryObject(directoryInfo); var sourceDirectory = new MemoryDirectoryObject("integrationTests") .AddFile(_fileName, _contents) .AddFile(_fileName2, _contents); sourceDirectory.AddDirectory(new MemoryDirectoryObject(_subDirectoryName, sourceDirectory.FullName) .AddFile(_subFileName, _contents) .AddFile(_subFileName2, _contents)); var syncNet = new Processor(sourceDirectory, targetDirectory, new SyncTaskQueue()); syncNet.ProcessSourceDirectory(); var fileInfos = directoryInfo.GetFiles(); Assert.AreEqual(2, fileInfos.Length); var directoryInfos = directoryInfo.GetDirectories(); Assert.AreEqual(1, directoryInfos.Length); Assert.AreEqual(_subDirectoryName, directoryInfos[0].Name); var file = fileInfos[0]; var localContents = File.ReadAllText(file.FullName); Assert.AreEqual(_contents, localContents); }