public void TestBackgroundWorker_ProcessNewFiles()
        {
            // Create a test directory to monitor
            var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            Assert.IsNotNull(dir);
            var testDir = Path.Combine(dir, "TestBackgroundWorker");

            if (Directory.Exists(testDir))
            {
                Directory.Delete(testDir, true);
            }
            Assert.IsFalse(Directory.Exists(testDir));
            Directory.CreateDirectory(testDir);
            Assert.IsTrue(Directory.Exists(testDir));

            var appControl = new TestAppControl();
            var logger = new TestLogger();
            var processControl = new TestProcessControl(logger);
            var mainSettings = new MainSettings
            {
                FolderToWatch = testDir,
                InstrumentType = "NoInstrument",
                ResultsWindowString = "31",
                AcquisitionTimeString = "0"
            };

            // Start the background worker.
            var backgroundWorker = new AutoQCBackgroundWorker(appControl, processControl, logger);
            backgroundWorker.Start(mainSettings);
            Assert.IsTrue(backgroundWorker.IsRunning());

            // Create a new file in the test directory.
            Thread.Sleep(1000);
            CreateNewFile(testDir, "test1.txt");

            // Wait till the the file has been processed.
            while (!processControl.IsDone())
            {
                Thread.Sleep(500);
            }
            Assert.IsTrue(backgroundWorker.IsRunning());

            // Create another file in the test directory.
            Thread.Sleep(1000);
            CreateNewFile(testDir, "test2.txt");

            // Wait till the the file has been processed.
            // Process4 returns exit code 1 both times. This should stop the program.
            while (!processControl.IsDone())
            {
                Thread.Sleep(500);
            }

            // Assert.IsTrue(appControl.Waiting);
            Thread.Sleep(2 * AutoQCBackgroundWorker.WAIT_5SEC);
            Assert.IsTrue(appControl.Stopped);

            Assert.AreEqual(Regex.Replace(logger.GetLog(), @"\s+", ""),
                Regex.Replace(GetExpectedLog_ProcessNew(), @"\s+", ""));
        }
示例#2
0
        public void TestSkylineRunnerArgs()
        {
            const string skyFile = @"C:\Dummy\path\Test_file.sky";
            const string dataFile1 = @"C:\Dummy\path\Test1.raw";

            var logger = new TestLogger();
            var mainSettings = new MainSettings()
            {
                SkylineFilePath = skyFile,
                ResultsWindowString = MainSettings.ACCUM_TIME_WINDOW.ToString()
            };

            var mainSettingsTab = new MainSettingsTab(null, logger)
            {
                Settings = mainSettings
            };

            var accumulationWindow = MainSettingsTab.AccumulationWindow.Get(DateTime.Now, MainSettings.ACCUM_TIME_WINDOW);
            Assert.AreEqual(accumulationWindow.EndDate.Subtract(accumulationWindow.StartDate).Days + 1,
                MainSettings.ACCUM_TIME_WINDOW);

            var expected =
                string.Format("--in=\"{0}\" --remove-before={1} --import-file=\"{3}\" --import-on-or-after={2} --save", skyFile,
                    accumulationWindow.StartDate.ToShortDateString(),
                    accumulationWindow.StartDate.ToShortDateString(), dataFile1);

            var importContext = new ImportContext(dataFile1);
            Assert.IsFalse(importContext.ImportExisting);

            var args = mainSettingsTab.SkylineRunnerArgs(importContext);
            Assert.AreEqual(expected, args.Trim());
        }
        public void TestValidatePanoramaSettings()
        {
            var logger = new TestLogger();
            var settings = new PanoramaSettings();

            var mainControl = new TestAppControl();
            mainControl.SetUIPanoramaSettings(settings);

            var panoramaSettingsTab = new PanoramaSettingsTab(mainControl, logger);

            Assert.IsTrue(panoramaSettingsTab.ValidateSettings());
            var log = logger.GetLog();
            Assert.IsTrue(log.Contains("Will NOT publish Skyline documents to Panorama."));

            settings.PublishToPanorama = true;
            logger.Clear();
            panoramaSettingsTab.Settings = settings;
            Assert.IsFalse(panoramaSettingsTab.ValidateSettings());
            log = logger.GetLog();
            Assert.IsTrue(log.Contains("Please specify a Panorama server URL."));
            Assert.IsTrue(log.Contains("Please specify a Panorama login name."));
            Assert.IsTrue(log.Contains("Please specify a Panorama user password."));
            Assert.IsTrue(log.Contains("Please specify a folder on the Panorama server."));
        }
示例#4
0
        public void TestBackgroundWorker_ProcessNewFiles()
        {
            // Create a test directory to monitor
            var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Assert.IsNotNull(dir);
            var testDir = Path.Combine(dir, "TestBackgroundWorker");

            if (Directory.Exists(testDir))
            {
                Directory.Delete(testDir, true);
            }
            Assert.IsFalse(Directory.Exists(testDir));
            Directory.CreateDirectory(testDir);
            Assert.IsTrue(Directory.Exists(testDir));

            var appControl = new TestAppControl();
            var logger     = new TestLogger();
            // var processControl = new TestProcessControl(logger);
            var mainSettings = MainSettings.GetDefault();

            mainSettings.FolderToWatch  = testDir;
            mainSettings.InstrumentType = "NoInstrument";

            AutoQcConfig config = new AutoQcConfig();

            config.MainSettings     = mainSettings;
            config.PanoramaSettings = PanoramaSettings.GetDefault();
            config.Name             = "Test Config";
            config.IsEnabled        = true;

            var configRunner = new ConfigRunner(config, appControl);

            // Start the background worker.
//            configRunner.Start();
            //Thread.Sleep(1000);
//            Assert.IsTrue(configRunner.IsBusy());

            // Create a new file in the test directory.
//            Thread.Sleep(1000);
            CreateNewFile(testDir, "test1.txt");

//            // Wait till the the file has been processed.
//            while (!processControl.IsDone())
//            {
//                Thread.Sleep(500);
//            }
//            Assert.IsTrue(configRunner.IsRunning());
//
//            // Create another file in the test directory.
//            Thread.Sleep(1000);
//            CreateNewFile(testDir, "test2.txt");
//
//            // Wait till the the file has been processed.
//            // Process4 returns exit code 1. This should put the file in the re-import queue.
//            while (!processControl.IsDone())
//            {
//                Thread.Sleep(500);
//            }
//
//            // Assert.IsTrue(appControl.Waiting);
//            Thread.Sleep(2 * AutoQCBackgroundWorker.WAIT_FOR_NEW_FILE);
//            //Assert.IsTrue(appControl.Waiting);
//
//            Assert.AreEqual(Regex.Replace(logger.GetLog(), @"\s+", ""),
//                Regex.Replace(GetExpectedLog_ProcessNew(), @"\s+", ""));
        }
示例#5
0
        public void TestValidateSettings()
        {
            var logger = new TestLogger();
            var mainControl = new TestAppControl();
            var mainSettingsTab = new MainSettingsTab(mainControl, logger);
            Assert.IsFalse(mainSettingsTab.ValidateSettings());
            var log = logger.GetLog();
            Assert.IsTrue(log.Contains("Please specify path to a Skyline file."));
            Assert.IsTrue(log.Contains("Please specify path to a folder where mass spec. files will be written."));
            Assert.IsTrue(log.Contains("Please specify a value for the \"Accumulation time window\"."));

            const string skyPath = "C:\\dummy\\path\\Test.sky";
            const string folderPath = "C:\\dummy\\path";
            var accumWindow = "not a number";

            var settings = new MainSettings()
            {
                SkylineFilePath = skyPath,
                FolderToWatch = folderPath,
                ResultsWindowString = "not a number",
                // ImportExistingFiles = false
            };
            mainControl = new TestAppControl();
            mainControl.SetUIMainSettings(settings);

            mainSettingsTab = new MainSettingsTab(mainControl, logger);
            logger.Clear();
            Assert.IsFalse(mainSettingsTab.ValidateSettings());
            log = logger.GetLog();
            Assert.IsTrue(log.Contains(string.Format("Skyline file {0} does not exist.", skyPath)));
            Assert.IsTrue(log.Contains(string.Format("Folder {0} does not exist.", folderPath)));
            Assert.IsTrue(log.Contains(string.Format("Invalid value for \"Accumulation time window\": {0}.", accumWindow)));

            accumWindow = "-1";
            settings.ResultsWindowString = accumWindow;
            logger.Clear();
            mainSettingsTab = new MainSettingsTab(mainControl, logger);
            Assert.IsFalse(mainSettingsTab.ValidateSettings());
            log = logger.GetLog();
            Assert.IsTrue(
                log.Contains(string.Format("\"Accumulation time window\" cannot be less than {0} days.",
                    MainSettings.ACCUM_TIME_WINDOW)));
        }
示例#6
0
        public void TestSkylineRunnerArgsImportExisting()
        {
            const string skyFile = @"C:\Dummy\path\Test_file.sky";
            const string dataFile1 = @"C:\Dummy\path\Test1.raw";
            const string dataFile2 = @"C:\Dummy\path\Test2.raw";

            var logger = new TestLogger();
            var mainSettings = new MainSettings()
            {
                SkylineFilePath = skyFile,
                ResultsWindowString = MainSettings.ACCUM_TIME_WINDOW.ToString()
            };

            var mainSettingsTab = new MainSettingsTab(null, logger)
            {
                Settings = mainSettings
            };

            // Create an import context.
            var importContext = new ImportContext(new List<string>() { dataFile1, dataFile2 });
            Assert.IsTrue(importContext.ImportExisting);

            // Arguments for the first file.
            var expected =
                string.Format("--in=\"{0}\" --import-file=\"{1}\" --save", skyFile, dataFile1);
            importContext.GetNextFile();
            var args = mainSettingsTab.SkylineRunnerArgs(importContext);
            Assert.AreEqual(expected, args.Trim());

            // Arguments for the second file
            importContext.GetNextFile();
            Assert.IsTrue(importContext.ImportingLast());
            expected =
                string.Format("--in=\"{0}\" --import-file=\"{1}\" --save", skyFile, dataFile2);

            args = mainSettingsTab.SkylineRunnerArgs(importContext);
            Assert.AreEqual(expected, args.Trim());

            Assert.IsNull(importContext.GetNextFile());
        }
        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 defaultFileFilter = FileFilter.GetFileFilter(AllFileFilter.NAME, string.Empty);
            var mainSettings      = new MainSettings(skyFile, folderToWatch, false, defaultFileFilter, true,
                                                     MainSettings.ACCUM_TIME_WINDOW, instrument, MainSettings.ACQUISITION_TIME);

            config.MainSettings = mainSettings;
            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.IncludeSubfolders = true; // watch sub-folders
            mainSettings = new MainSettings(skyFile, folderToWatch, true, defaultFileFilter, true,
                                            MainSettings.ACCUM_TIME_WINDOW, instrument, MainSettings.ACQUISITION_TIME);

            config.MainSettings = mainSettings;
            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.IncludeSubfolders = true; // watch sub-folders
            var fileFilter = FileFilter.GetFileFilter(ContainsFilter.NAME, "_QC_"); // file name pattern

            mainSettings = new MainSettings(skyFile, folderToWatch, true, fileFilter, true,
                                            MainSettings.ACCUM_TIME_WINDOW, instrument, MainSettings.ACQUISITION_TIME);

            config.MainSettings = mainSettings;
            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 = new MainSettings(skyFile, folderToWatch, false, defaultFileFilter, true,
                                            MainSettings.ACCUM_TIME_WINDOW, instrument, MainSettings.ACQUISITION_TIME);

            config.MainSettings = mainSettings;
            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();
        }
示例#8
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]));
        }