private void ParseAllResultsTextFiles()
        {
            DateTime timestamp    = new DateTime();
            var      nonNullFiles = labelToFileInfo.Where(p => p.Value != null).ToList();

            if (!nonNullFiles.Any())
            {
                timestamp = directoryInfos.Select(p => p.Value.CreationTime).First();
            }
            else
            {
                timestamp = labelToFileInfo.Select(p => p.Value.CreationTime).First();
            }

            ParsedRunResult = new MetaMorpheusRunResult(labelToFileInfo, timestamp);
        }
예제 #2
0
        public static void Main(string[] args)
        {
            var p = new FluentCommandLineParser <ApplicationArguments>();

            p.Setup(arg => arg.InputFolder)
            .As('i', "InputFolder")
            .Required();

            p.Setup(arg => arg.OutputFolder)
            .As('o', "OutputFolder")
            .Required();

            var result = p.Parse(args);

            if (!result.HasErrors)
            {
                // delete old output if it exists
                if (Directory.Exists(p.Object.OutputFolder))
                {
                    var dir = new DirectoryInfo(p.Object.OutputFolder);
                    dir.Delete(true);
                }

                // get results from last 5 runs
                int historyCount = 5;
                MetaMorpheusRunResultsDirectories[] runResults = new MetaMorpheusRunResultsDirectories[historyCount];

                // get last regular run result (first thing to run)
                List <DirectoryInfo> regularRunDirectories = new DirectoryInfo(p.Object.InputFolder).GetDirectories()
                                                             .Where(v => v.Name.Contains(ClassicSearchLabel))
                                                             .OrderByDescending(v => v.CreationTime)
                                                             .Take(historyCount)
                                                             .OrderBy(v => v.CreationTime).ToList();

                for (int i = 0; i < regularRunDirectories.Count; i++)
                {
                    DirectoryInfo regularRunDir = regularRunDirectories[i];

                    Dictionary <string, DirectoryInfo> directoryInfos = new Dictionary <string, DirectoryInfo> {
                        { ClassicSearchLabel, regularRunDir }
                    };

                    var    ok        = regularRunDir.Name.Split(new char[] { '[' });
                    string timestamp = regularRunDir.Name.Split(new char[] { '[' })[1].TrimEnd(new char[] { ']' });

                    var otherLabels = labels.Where(l => l != ClassicSearchLabel).ToList();

                    foreach (string label in otherLabels)
                    {
                        DirectoryInfo otherRunDirectory = new DirectoryInfo(p.Object.InputFolder)
                                                          .GetDirectories()
                                                          .Where(v => v.Name.Contains(label) && v.Name.Contains(timestamp))
                                                          .OrderByDescending(v => v.CreationTime)
                                                          .Take(historyCount)
                                                          .OrderBy(v => v.CreationTime)
                                                          .FirstOrDefault();

                        directoryInfos.Add(label, otherRunDirectory);
                    }

                    runResults[i] = new MetaMorpheusRunResultsDirectories(directoryInfos);
                }

                // set up output file
                List <string> output = new List <string> {
                    MetaMorpheusRunResult.CommaSeparatedHeader()
                };

                // add results from each run
                runResults.Where(v => v != null).ForEach(v => output.Add(v.ParsedRunResult.ToString()));

                // write results
                // create output directory
                if (!Directory.Exists(p.Object.OutputFolder))
                {
                    Directory.CreateDirectory(p.Object.OutputFolder);
                }

                File.WriteAllLines(Path.Combine(p.Object.OutputFolder, "ProcessedResults.csv"), output);

                // delete old search results (keeps 1 result for every 7 days, except it keeps all of the last 5 days)
                List <DirectoryInfo> directoriesToPotentiallyDelete = new DirectoryInfo(p.Object.InputFolder)
                                                                      .GetDirectories()
                                                                      .OrderByDescending(v => v.CreationTime).ToList();

                DateTime dateToStartDeletingAt = new DateTime(2018, 12, 9);

                directoriesToPotentiallyDelete = directoriesToPotentiallyDelete
                                                 .Take(directoriesToPotentiallyDelete.Count)
                                                 .Where(v => v.CreationTime.Date.CompareTo(dateToStartDeletingAt) > 0)
                                                 .ToList();

                var datesToKeep = new List <DateTime>();

                int weeks = 0;
                while (!datesToKeep.Any() || datesToKeep.Last().CompareTo(DateTime.Now) < 0)
                {
                    datesToKeep.Add(dateToStartDeletingAt.Date.AddDays(weeks * 7));
                    weeks++;
                }

                for (int d = 0; d < historyCount; d++)
                {
                    datesToKeep.Add(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day - d).Date);
                }

                var directoriesToDelete = directoriesToPotentiallyDelete.Where(v => !datesToKeep.Contains(v.CreationTime.Date)).ToList();

                foreach (DirectoryInfo directory in directoriesToDelete)
                {
                    Directory.Delete(directory.FullName, true);
                }
            }
        }