Beispiel #1
0
        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 (!_fileWatcher.RawDataExists(filePath))
                {
                    // User may have deleted this file.
                    Log("{0} no longer exists. Skipping...", filePath);
                    continue;
                }

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

                ImportFile(e, importContext);
            }

            Log("Finished importing existing files...");
            return(!_panoramaUploadError);
        }
Beispiel #2
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());
        }
        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);
        }
Beispiel #4
0
        private bool ImportFile(DoWorkEventArgs e, ImportContext importContext, bool addToReimportQueueOnFailure = true)
        {
            var filePath = importContext.GetCurrentFile();

            try
            {
                _fileWatcher.WaitForFileReady(filePath);
            }
            catch (FileStatusException fse)
            {
                if (fse.Message.Contains(FileStatusException.DOES_NOT_EXIST))
                {
                    _logger.LogError("{0} does not exist.", GetFilePathForLog(filePath));
                }
                else
                {
                    _logger.LogException(fse, "Error getting status of file {0}.", GetFilePathForLog(filePath));
                }
                // Put the file in the re-import queue
                if (addToReimportQueueOnFailure)
                {
                    AddToReimportQueue(filePath);
                }
                return(false);
            }

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

            _panoramaUploadError = false;
            var docImported = ProcessOneFile(importContext);

            if (!docImported)
            {
                if (addToReimportQueueOnFailure)
                {
                    AddToReimportQueue(filePath);
                }
            }

            return(docImported);
        }
Beispiel #5
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));
        }
Beispiel #6
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);
        }
Beispiel #7
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();
        }
        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;
        }
        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;
        }
            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>();
            }