Esempio n. 1
0
 public override ProcessInfo RunAfter(ImportContext importContext)
 {
     string archiveArgs = null;
     var currentDate = DateTime.Today;
     if (importContext.ImportExisting && importContext.ImportingLast())
     {
         // If we are importing existing files in the folder, create an archive (if required) of the
         // Skyline document AFTER importing the last results file.
         var oldestFileDate = importContext.GetOldestImportedFileDate(Settings.LastAcquiredFileDate);
         var today = DateTime.Today;
         if(oldestFileDate.Year < today.Year || oldestFileDate.Month < today.Month)
         {
             archiveArgs = GetArchiveArgs(currentDate.AddMonths(-1), currentDate);
         }
     }
     if (String.IsNullOrEmpty(archiveArgs))
     {
         return null;
     }
     var args = string.Format("--in=\"{0}\" {1}", Settings.SkylineFilePath, archiveArgs);
     return new ProcessInfo(AutoQCForm.SkylineRunnerPath, AutoQCForm.SKYLINE_RUNNER, args, args);
 }
Esempio n. 2
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());
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
 public override ProcessInfo RunBefore(ImportContext importContext)
 {
     return null;
 }
        private bool ImportFile(DoWorkEventArgs e, ImportContext importContext, bool addToReimportQueueOnFailure = true)
        {
            var filePath = importContext.GetCurrentFile();
            try
            {
                _fileWatcher.WaitForFileReady(filePath);
            }
            catch (FileStatusException fse)
            {
                if (!FileStatusException.DOES_NOT_EXIST.Equals(fse.Message))
                {
                    _logger.LogError("File does not exist: {0}.", filePath);
                }
                else
                {
                    _logger.LogException(fse);
                }
                // Put the file in the re-import queue
                if (addToReimportQueueOnFailure)
                {
                    _logger.Log("Adding file to re-import queue: {0}", filePath);
                    _fileWatcher.AddToReimportQueue(filePath);
                }
                return false;
            }

            if (_worker.CancellationPending)
            {
                e.Result = CANCELLED;
                return false;
            }

            if (!ProcessOneFile(importContext))
            {
                if (addToReimportQueueOnFailure)
                {
                    _logger.Log("Adding file to re-import queue: {0}", filePath);
                    _fileWatcher.AddToReimportQueue(filePath);
                }
                return false;
            }

            return true;
        }
Esempio n. 6
0
 /// <summary>
 /// Returns information about a process that should be run after running SkylineRunner.
 /// </summary>
 /// <param name="importContext"></param>
 /// <returns></returns>
 public abstract ProcessInfo RunAfter(ImportContext importContext);
Esempio n. 7
0
 /// <summary>
 /// Returns the command-line arguments to be passed to SkylineRunner.
 /// </summary>
 /// <param name="importContext">Contains information about the results file we are importing</param>
 /// <param name="toPrint">True if the arguments will be logged</param>
 /// <returns></returns>
 public abstract string SkylineRunnerArgs(ImportContext importContext, bool toPrint = false);
Esempio n. 8
0
 public override ProcessInfo RunAfter(ImportContext importContext)
 {
     return(null);
 }
Esempio n. 9
0
 /// <summary>
 /// Returns the command-line arguments to be passed to SkylineRunner.
 /// </summary>
 /// <param name="importContext">Contains information about the results file we are importing</param>
 /// <param name="toPrint">True if the arguments will be logged</param>
 /// <returns></returns>
 public abstract string SkylineRunnerArgs(ImportContext importContext, bool toPrint = false);
        private void TryReimportOldFiles(DoWorkEventArgs e, bool forceImport)
        {
            var reimportQueue = _fileWatcher.GetFilesToReimport();
            var failed = new List<RawFile>();

            while (reimportQueue.Count > 0)
            {
                var file = reimportQueue.Dequeue();
                if (forceImport || file.TryReimport())
                {
                    var importContext = new ImportContext(file.FilePath) { TotalImportCount = _totalImportCount };
                    _logger.Log("Attempting to re-import file {0}.", file.FilePath);
                    if (!ImportFile(e, importContext, false))
                    {
                        _logger.Log("Adding file to re-import queue: {0}", file.FilePath);
                        file.LastImportTime = DateTime.Now;
                        failed.Add(file);
                    }
                }
                else
                {
                    failed.Add(file); // We are going to try to re-import later
                }
            }

            foreach (var file in failed)
            {
                _fileWatcher.AddToReimportQueue(file);
            }
        }
Esempio n. 11
0
 public override ProcessInfo RunBefore(ImportContext importContext)
 {
     return(null);
 }
 private bool ProcessOneFile(ImportContext importContext)
 {
     var processInfos = _processControl.GetProcessInfos(importContext);
     if (processInfos.Any(procInfo => !_processControl.RunProcess(procInfo)))
     {
         return false;
     }
     _totalImportCount++;
     return true;
 }
        private void ProcessNewFiles(DoWorkEventArgs e)
        {
            LogWithSpace("Importing new files...");
            var inWait = false;
            while (true)
            {
                if (_worker.CancellationPending)
                {
                    e.Result = CANCELLED;
                    break;
                }

                var filePath = _fileWatcher.GetFile();

                if (filePath != null)
                {
                    var importContext = new ImportContext(filePath) { TotalImportCount = _totalImportCount };
                    ImportFile(e, importContext);

                    if (!_fileWatcher.IsFolderAvailable())
                    {
                        // We may have lost connection to a mapped network drive.
                        continue;
                    }

                    // Make one last attempt to import any old files.
                    TryReimportOldFiles(e, true);

                    inWait = false;
                }
                else
                {
                    // Try to import any older files that resulted in an import error the first time.
                    TryReimportOldFiles(e, false);

                    if (!inWait)
                    {
                        LogWithSpace("Waiting for files...");
                    }

                    inWait = true;
                    Thread.Sleep(WAIT_FOR_NEW_FILE);
                }
            }
        }
        private bool ProcessExistingFiles(DoWorkEventArgs e)
        {
            // Queue up any existing data files in the folder
            _logger.Log("Importing existing files...", 1, 0);
            var files = _fileWatcher.GetExistingFiles();

            // Enable notifications on new files that get added to the folder.
            _fileWatcher.StartWatching();

            if (files.Count == 0)
            {
                Log("No existing files found.");
                return true;
            }

            Log("Existing files found: {0}", files.Count);

            var importContext = new ImportContext(files) {TotalImportCount = _totalImportCount};
            while (importContext.GetNextFile() != null)
            {
                if (_worker.CancellationPending)
                {
                    e.Result = CANCELLED;
                    return false;
                }

                var filePath = importContext.GetCurrentFile();
                if (!(new FileInfo(filePath).Exists))
                {
                    // User may have deleted this file.
                    Log("File {0} no longer exists. Skipping...", filePath);
                    continue;
                }

                var fileLastWriteTime = File.GetLastWriteTime(filePath);
                if (fileLastWriteTime.CompareTo(_lastAcquiredFileDate.AddSeconds(1)) < 0)
                {
                    Log(
                        "File {0} was acquired ({1}) before the acquisition date ({2}) on the last imported file in the Skyline document. Skipping...",
                        Path.GetFileName(filePath),
                        fileLastWriteTime,
                        _lastAcquiredFileDate);
                    continue;
                }

                ImportFile(e, importContext);
            }

            LogWithSpace("Finished importing existing files...");
            return true;
        }
Esempio n. 15
0
 public override ProcessInfo RunBefore(ImportContext importContext)
 {
     string archiveArgs = null;
     if (!importContext.ImportExisting)
     {
         // If we are NOT importing existing results, create an archive (if required) of the
         // Skyline document BEFORE importing a results file.
         archiveArgs = GetArchiveArgs(GetLastArchivalDate(), DateTime.Today);
     }
     if (String.IsNullOrEmpty(archiveArgs))
     {
         return null;
     }
     var args = string.Format("--in=\"{0}\" {1}", Settings.SkylineFilePath, archiveArgs);
     return new ProcessInfo(AutoQCForm.SkylineRunnerPath, AutoQCForm.SKYLINE_RUNNER, args, args);
 }
Esempio n. 16
0
 /// <summary>
 /// Returns information about a process that should be run before running SkylineRunner.
 /// </summary>
 /// <param name="importContext"></param>
 /// <returns></returns>
 public abstract ProcessInfo RunBefore(ImportContext importContext);
Esempio n. 17
0
        public override string SkylineRunnerArgs(ImportContext importContext, bool toPrint = false)
        {
            // Get the current results time window
            var currentDate = DateTime.Today;
            var accumulationWindow = AccumulationWindow.Get(currentDate, Settings.ResultsWindow);
            if (toPrint)
            {
                Log("Current results time window is {0} TO {1}",
                    accumulationWindow.StartDate.ToShortDateString(), accumulationWindow.EndDate.ToShortDateString());
            }

            var args = new StringBuilder();
            // Input Skyline file
            args.Append(string.Format(" --in=\"{0}\"", Settings.SkylineFilePath));

            string importOnOrAfter = "";
            if (importContext.ImportExisting)
            {
                // We are importing existing files in the folder.  The import-on-or-after is determined
                // by the last acquisition date on the files already imported in the Skyline document.
                // If the Skyline document does not have any results files, we will import all existing
                // files in the folder.
                if (Settings.LastAcquiredFileDate != DateTime.MinValue)
                {
                    importOnOrAfter = string.Format(" --import-on-or-after={0}", Settings.LastAcquiredFileDate);
                }
            }
            else
            {
                importOnOrAfter = string.Format(" --import-on-or-after={0}",
                    accumulationWindow.StartDate.ToShortDateString());

                // Add arguments to remove files older than the start of the rolling window.
                args.Append(string.Format(" --remove-before={0}", accumulationWindow.StartDate.ToShortDateString()));
            }

            // Add arguments to import the results file
            args.Append(string.Format(" --import-file=\"{0}\"{1}", importContext.GetCurrentFile(), importOnOrAfter));

            // Save the Skyline file
            args.Append(" --save");

            return args.ToString();
        }
Esempio n. 18
0
 /// <summary>
 /// Returns information about a process that should be run after running SkylineRunner.
 /// </summary>
 /// <param name="importContext"></param>
 /// <returns></returns>
 public abstract ProcessInfo RunAfter(ImportContext importContext);
Esempio n. 19
0
 /// <summary>
 /// Returns information about a process that should be run before running SkylineRunner.
 /// </summary>
 /// <param name="importContext"></param>
 /// <returns></returns>
 public abstract ProcessInfo RunBefore(ImportContext importContext);
Esempio n. 20
0
 public override ProcessInfo RunAfter(ImportContext importContext)
 {
     return null;
 }
Esempio n. 21
0
        public override ProcessInfo RunAfter(ImportContext importContext)
        {
            var thresholdCount = Settings.Threshold;
            if (thresholdCount > importContext.TotalImportCount)
            {
                // Don't do anything if we have imported fewer files than the number of required threshold files.
                return null;
            }

            var saveQcPath = Path.GetDirectoryName(importContext.GetCurrentFile()) + "\\QC.pdf";
            var args = String.Format(@"""{0}"" ""{1}"" {2} {3} 1 {4} ""{5}""",
                SProCoPrScript,
                ReportFilePath,
                thresholdCount,
                Settings.IsHighRes ? 1 : 0,
                Settings.MMA,
                saveQcPath);
            return new ProcessInfo(Settings.RScriptPath, args);
        }
Esempio n. 22
0
        public override string SkylineRunnerArgs(ImportContext importContext, bool toPrint = false)
        {
            if (!IsSelected() || (importContext.ImportExisting && !importContext.ImportingLast()))
            {
                // Do not upload to Panorama if this we are importing existing documents and this is not the
                // last file being imported.
                return string.Empty;
            }

            var passwdArg = toPrint ? "" : string.Format("--panorama-password=\"{0}\"", DecryptPassword(Settings.PanoramaPassword));
            var uploadArgs = string.Format(
                    " --panorama-server=\"{0}\" --panorama-folder=\"{1}\" --panorama-username=\"{2}\" {3}",
                    Settings.PanoramaServerUrl,
                    Settings.PanoramaFolder,
                    Settings.PanoramaUserEmail,
                    passwdArg);
            return uploadArgs;
        }
Esempio n. 23
0
        public override string SkylineRunnerArgs(ImportContext importContext, bool toPrint = false)
        {
            var exportReportPath = Path.GetDirectoryName(ReportFilePath) + "\\" + "report.csv";
            var args =
                String.Format(
                    @""" --report-conflict-resolution=overwrite --report-add=""{0}"" --report-name=""{1}"" --report-file=""{2}""",
                    ReportFilePath, "SProCoP Input", exportReportPath);

            return args;
        }
            public IEnumerable<ProcessInfo> GetProcessInfos(ImportContext importContext)
            {
                var file = Path.GetFileName(importContext.GetCurrentFile());
                Assert.IsNotNull(file);

                if (file.Equals("test1.txt"))
                {
                    var procInfo1 = new ProcessInfo("Process1", "");
                    procInfo1.SetMaxTryCount(2);
                    var procInfo2 = new ProcessInfo("Process2", "");
                    procInfo2.SetMaxTryCount(2);
                    return new List<ProcessInfo> {
                        procInfo1, // Exit code 0; successful
                        procInfo2  // Exit code 1 first time; success second time
                    };
                }
                if (file.Equals("test2.txt"))
                {
                    var procInfo3 = new ProcessInfo("Process3", "");
                    procInfo3.SetMaxTryCount(2);
                    var procInfo4 = new ProcessInfo("Process4", "");
                    procInfo4.SetMaxTryCount(2);

                    return new List<ProcessInfo>
                    {
                        procInfo3, // Exit code 0 but error during execution; succeed second time
                        procInfo4 // Exit code 1; Fails both times
                    };
                }
                return Enumerable.Empty<ProcessInfo>();
            }