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 AutoQCForm()
        {
            InitializeComponent();

            // Remove the SProCoP settings tab for now.  No way to hide the tab in the designer
            tabControl.TabPages.Remove(tabSprocopSettings);

            _settingsTabs = new List <SettingsTab>
            {
                new MainSettingsTab(this, this),
                new PanoramaSettingsTab(this, this)
            };

            // Initialize the tabs from default settings.
            foreach (var settings in _settingsTabs)
            {
                settings.InitializeFromDefaultSettings();
            }

            _worker        = new AutoQCBackgroundWorker(this, this, this);
            _processRunner = new ProcessRunner(this);
        }