コード例 #1
0
        private static void TestGetNewFilesForInstrument(string testDir, string instrument)
        {
            var           logger       = new TestLogger();
            IConfigRunner configRunner = new TestConfigRunner();

            configRunner.ChangeStatus(ConfigRunner.RunnerStatus.Running);


            // folder to watch
            var folderToWatch = CreateDirectory(testDir, instrument);
            // Create a .sky files
            var skyFile = CreateFile(folderToWatch, "test2_a.sky");

            var config = new AutoQcConfig();

            // 1. Look for files in folderToWatchOnly
            var watcher      = new AutoQCFileSystemWatcher(logger, configRunner);
            var mainSettings = MainSettings.GetDefault();

            config.MainSettings = mainSettings;

            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.IncludeSubfolders = false;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.ValidateSettings();

            watcher.Init(config);
            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            // Create new files in the folder
            List <string> dataFiles;

            SetupTestFolder(folderToWatch, instrument, out dataFiles);

            // Only one file should have been added to the queue since we are not monitoring sub-folders
            Assert.AreEqual(1, watcher.GetExistingFiles().Count);
            var    files = new List <string>();
            string f;

            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(1, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));
            Assert.IsNull(watcher.GetFile()); // Nothing in the queue

            watcher.Stop();

            // 2. Look for files in subfolders
            watcher = new AutoQCFileSystemWatcher(logger, configRunner);
            // folder to watch
            folderToWatch = CreateDirectory(testDir, instrument + "_2");
            // Create a .sky files
            skyFile = CreateFile(folderToWatch, "test2_b.sky");
            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.IncludeSubfolders = true; // watch sub-folders
            mainSettings.ValidateSettings();
            watcher.Init(config);

            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            dataFiles.Clear();
            SetupTestFolder(folderToWatch, instrument, out dataFiles); // Create new files in the folder

            files = new List <string>();
            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(5, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));
            Assert.IsTrue(files.Contains(dataFiles[1]));
            Assert.IsTrue(files.Contains(dataFiles[2]));
            Assert.IsTrue(files.Contains(dataFiles[3]));
            Assert.IsTrue(files.Contains(dataFiles[4]));

            watcher.Stop();

            //  3. Look for files in subfolders matching a pattern
            watcher = new AutoQCFileSystemWatcher(logger, configRunner);
            // folder to watch
            folderToWatch = CreateDirectory(testDir, instrument + "_3");
            // Create a .sky files
            skyFile = CreateFile(folderToWatch, "test2_c.sky");
            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.IncludeSubfolders = true;                                                  // watch sub-folders
            mainSettings.QcFileFilter      = FileFilter.GetFileFilter(ContainsFilter.NAME, "_QC_"); // file name pattern
            mainSettings.ValidateSettings();
            watcher.Init(config);

            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            dataFiles.Clear();
            SetupTestFolder(folderToWatch, instrument, out dataFiles); // Create new files in the folder

            files = new List <string>();
            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(2, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));
            Assert.IsTrue(files.Contains(dataFiles[2]));

            watcher.Stop();

            // 4. Add new files in directory by first creating a temp file/directory and renaming it.
            // This should trigger a "Renamed" event for the FileSystemWatcher
            watcher = new AutoQCFileSystemWatcher(logger, configRunner);
            // folder to watch
            folderToWatch = CreateDirectory(testDir, instrument + "_4");
            // Create a .sky files
            skyFile = CreateFile(folderToWatch, "test2_d.sky");
            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.IncludeSubfolders = false;
            mainSettings.QcFileFilter      = FileFilter.GetFileFilter(AllFileFilter.NAME, string.Empty);
            mainSettings.ValidateSettings();
            watcher.Init(config);

            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            dataFiles.Clear();
            SetupTestFolder(folderToWatch, instrument, out dataFiles,
                            true); // Create temp file first and rename it

            watcher.CheckDrive();  // Otherwise UNC tests might fail on //net-lab3

            files = new List <string>();
            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(1, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));

            watcher.Stop();
        }
コード例 #2
0
        private static void TestGetNewFilesForInstrument(string testDir, string instrument)
        {
            var logger = new TestLogger();

            // folder to watch
            var folderToWatch = CreateDirectory(testDir, instrument);
            // Create a .sky files
            var skyFile = CreateFile(folderToWatch, "test2_a.sky");

            var config = new AutoQcConfig();

            // 1. Look for files in folderToWatchOnly
            var watcher      = new AutoQCFileSystemWatcher(logger);
            var mainSettings = MainSettings.GetDefault();

            config.MainSettings = mainSettings;

            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.IncludeSubfolders = false;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.ValidateSettings();

            watcher.Init(config);
            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            // Create new files in the folder
            List <string> dataFiles;

            SetupTestFolder(folderToWatch, instrument, out dataFiles);

            // Only one file should have been added to the queue since we are not monitoring sub-folders
            Assert.IsNotNull(watcher.GetFile());
            Assert.IsNull(watcher.GetFile());

            watcher.Stop();

            // 2. Look for files in subfolders
            watcher = new AutoQCFileSystemWatcher(logger);
            // folder to watch
            folderToWatch = CreateDirectory(testDir, instrument + "_2");
            // Create a .sky files
            skyFile = CreateFile(folderToWatch, "test2_b.sky");
            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.IncludeSubfolders = true; // watch sub-folders
            mainSettings.ValidateSettings();
            watcher.Init(config);

            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            dataFiles.Clear();
            SetupTestFolder(folderToWatch, instrument, out dataFiles); // Create new files in the folder

            var    files = new List <string>();
            string f;

            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(5, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));
            Assert.IsTrue(files.Contains(dataFiles[1]));
            Assert.IsTrue(files.Contains(dataFiles[2]));
            Assert.IsTrue(files.Contains(dataFiles[3]));
            Assert.IsTrue(files.Contains(dataFiles[4]));

            //  3. Look for files in subfolders matching a pattern
            watcher = new AutoQCFileSystemWatcher(logger);
            // folder to watch
            folderToWatch = CreateDirectory(testDir, instrument + "_3");
            // Create a .sky files
            skyFile = CreateFile(folderToWatch, "test2_c.sky");
            mainSettings.SkylineFilePath   = skyFile;
            mainSettings.InstrumentType    = instrument;
            mainSettings.FolderToWatch     = folderToWatch;
            mainSettings.IncludeSubfolders = true;                                                  // watch sub-folders
            mainSettings.QcFileFilter      = FileFilter.GetFileFilter(ContainsFilter.NAME, "_QC_"); // file name pattern
            mainSettings.ValidateSettings();
            watcher.Init(config);

            watcher.StartWatching();                              // Start watching
            Assert.AreEqual(0, watcher.GetExistingFiles().Count); // No existing files

            dataFiles.Clear();
            SetupTestFolder(folderToWatch, instrument, out dataFiles); // Create new files in the folder

            files = new List <string>();
            while ((f = watcher.GetFile()) != null)
            {
                files.Add(f);
            }
            Assert.AreEqual(2, files.Count);
            Assert.IsTrue(files.Contains(dataFiles[0]));
            Assert.IsTrue(files.Contains(dataFiles[2]));
        }