Exemplo n.º 1
0
        public static IEnumerable <SorterService.ClassLibrary.FileListener> InitializeFileSystemSorters()
        {
            var fileSystemProvider = new FileSystemWorker();

            foreach (ListenDirectoryElement directory in Config.Configuration.ListenDirectories)
            {
                var directoryWatcher = new DirectoryWorker(directory.Path)
                {
                    IncludeSubdirectories = true
                };

                var fileSystemSorter = new SorterService.ClassLibrary.FileListener(directoryWatcher,
                                                                                   Config.Configuration.DefaultDirectory.Path, fileSystemProvider)
                {
                    Rules = Config.Configuration.patternPathDictionary,
                    GenerateNewFileName = NameWorker.GenerateNewFileName
                };


                fileSystemSorter.directoryWorker.Created += OnCreated;
                fileSystemSorter.directoryWorker.Changed += OnChanged;
                fileSystemSorter.directoryWorker.Deleted += OnDeleted;

                fileSystemSorter.RuleFound += (s, e) =>
                                              Console.WriteLine(ResourceManagment.GetString("FileFoundMessage"), e.Rule, e.FileName, e.PathToMove);
                fileSystemSorter.RuleNotFound += (s, e) =>
                                                 Console.WriteLine(ResourceManagment.GetString("FileNotFoundMessage"), e.FileName, e.DefaultPath);

                yield return(fileSystemSorter);
            }
        }
Exemplo n.º 2
0
        public void FileListener_Correct_MoveFile_With_NoRule()
        {
            var defaultPath = Path.Combine(directoryToWatchPath, defaultPathToMove);
            var sourcePath  = Path.Combine(directoryToWatchPath, filesToAddNames[0]);

            fileListener = new SorterService.ClassLibrary.FileListener(directoryWorkerMock, defaultPath, fileSystemWorkerMock);
            fileSystemWorkerMock.Stub(y => y.IsFileExists(sourcePath)).Return(true);
            fileSystemWorkerMock.Stub(x => x.MoveFile(sourcePath, defaultPath));
            directoryWorkerMock.Raise(directoryWorker => directoryWorker.Created += (s, e) => { }, new object(),
                                      new FileSystemEventArgs(WatcherChangeTypes.Created, directoryToWatchPath, filesToAddNames[2]));

            fileSystemWorkerMock.Expect(x => x.MoveFile(sourcePath, defaultPath));
            fileListener.RuleNotFound += (s, e) => Assert.AreEqual(defaultPath, e.DefaultPath);
        }
Exemplo n.º 3
0
        public void FileListener_Correct_MoveFile_With_Rules()
        {
            var defaultPath = Path.Combine(directoryToWatchPath, defaultPathToMove);
            var sourcePath  = Path.Combine(directoryToWatchPath, filesToAddNames[0]);
            var targetPath  = Path.Combine(existingDirectoryPaths[1], filesToAddNames[0]);
            var rules       = new Dictionary <Regex, string> {
                { new Regex("[a-c]"), existingDirectoryPaths[1] }
            };

            fileListener = new SorterService.ClassLibrary.FileListener(directoryWorkerMock, defaultPath, fileSystemWorkerMock)
            {
                Rules = rules
            };

            fileSystemWorkerMock.Stub(y => y.IsFileExists(sourcePath)).Return(true);
            directoryWorkerMock.Raise(directoryWatcher => directoryWatcher.Created += (s, e) => { }, new object(),
                                      new FileSystemEventArgs(WatcherChangeTypes.Created, directoryToWatchPath, filesToAddNames[0]));


            fileSystemWorkerMock.Expect(x => x.MoveFile(sourcePath, targetPath));

            fileListener.RuleFound += (s, e) => Assert.AreEqual(targetPath, e.PathToMove);
        }
Exemplo n.º 4
0
 public void FileSystemSorter_DefaultDirectoryIsNull_ThrowsException()
 {
     fileListener = new SorterService.ClassLibrary.FileListener(directoryWorkerMock, null, null);
 }
Exemplo n.º 5
0
 public void FileListener_ListedDirectoryIsNull_ThrowsException()
 {
     fileListener = new SorterService.ClassLibrary.FileListener(null, existingDirectoryPaths[1], fileSystemWorkerMock);
 }