private void UnitTestSvcutil(string options, bool expectSuccess = true) { Assert.False(string.IsNullOrWhiteSpace(this_TestCaseName), $"{nameof(this_TestCaseName)} not initialized!"); Assert.False(options == null, $"{nameof(options)} not initialized!"); // run in the context of the test-group common project using (var cds = new CurrentDirectorySetter(this_TestCaseProject.DirectoryPath)) { Directory.SetCurrentDirectory(this_TestCaseProject.DirectoryPath); var exitCode = 0; var outputText = string.Empty; var writer = new StringWriter(); var originalOutput = Console.Out; Console.SetOut(writer); var args = options.Split(' '); exitCode = Tool.MainAsync(args, this_TestCaseLogger, CancellationToken.None).Result; outputText = writer.ToString(); Console.SetOut(originalOutput); writer.Close(); ValidateTest(options, this_TestCaseProject.DirectoryPath, exitCode, outputText, expectSuccess); } }
private void CommandOptions(string testCaseName, string options, bool serializeUpdateOptions, bool expectSuccess) { InitializeUnitTest(testCaseName); using (var cds = new CurrentDirectorySetter(this_TestCaseOutputDir)) { var args = options .Replace("$projectPath$", this_TestCaseProject.FullPath) .Replace("$testCasesDir$", g_TestCasesDir) .Replace("$testOutputDir$", this_TestGroupOutputDir) .Replace("$testCaseOutputDir$", this_TestCaseOutputDir) .Replace("$testCasesDir$", g_TestCasesDir) .Replace("$bootstrapDir$", this_TestCaseBootstrapDir) .Split(' '); var cmdOptions = CommandParser.ParseCommand(args); cmdOptions.ProcessBasicOptionsAsync(this_TestCaseLogger, CancellationToken.None).Wait(); cmdOptions.ResolveAsync(CancellationToken.None).Wait(); var cmderrors = cmdOptions.Errors.Count() == 0 ? string.Empty : Environment.NewLine + cmdOptions.Errors.Select(e => e.Message).Aggregate((errors, e) => $"{errors}{Environment.NewLine}{e}"); var cmdwarnings = cmdOptions.Warnings.Count() == 0 ? string.Empty : Environment.NewLine + cmdOptions.Warnings.Aggregate((warnings, w) => $"{warnings}{Environment.NewLine}{w}"); var optionsString = cmdOptions.ToString(); var log = $"{Environment.NewLine}Input options:{Environment.NewLine}{options}{Environment.NewLine}" + $"{Environment.NewLine}Output JSON:{Environment.NewLine}{cmdOptions.Json}{Environment.NewLine}" + $"{Environment.NewLine}Output options:{Environment.NewLine}{optionsString}{Environment.NewLine}" + $"{Environment.NewLine}Parsing warnings:{cmdwarnings}{Environment.NewLine}" + $"{Environment.NewLine}Parsing errors:{cmderrors}{Environment.NewLine}"; if (serializeUpdateOptions) { var updateOptions = cmdOptions.CloneAs <UpdateOptions>(); updateOptions.MakePathsRelativeTo(new DirectoryInfo(this_TestCaseOutputDir)); log += $"{Environment.NewLine}{cmdOptions.GetType().Name} as {updateOptions.GetType().Name}:{Environment.NewLine}{updateOptions.Json}"; } File.WriteAllText(this_TestCaseLogFile, this_FixupUtil.ReplaceText(log)); WriteLog(log, options); Assert.False(cmdOptions.Errors.Count() == 0 ^ expectSuccess, cmderrors); Assert.True(ValidateOutputs(options, out var failureMessage), failureMessage); } }
public MSAmandaSearchWrapper() { Settings = new MSAmandaSettings(); helper = new MSHelper(); helper.InitLogWriter(_baseDir.DirPath); helper.SearchProgressChanged += Helper_SearchProgressChanged; var folderForMappings = Path.Combine(_baseDir.DirPath, AmandaMap); // creates dir if not existing Directory.CreateDirectory(folderForMappings); mzID = new OutputMzid(folderForMappings); AvailableSettings = new SettingsFile(helper, Settings, mzID); AvailableSettings.AllEnzymes = new List <MSAmandaEnzyme>(); AvailableSettings.AllModifications = new List <Modification>(); using (var d = new CurrentDirectorySetter(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))) { if (!AvailableSettings.ParseEnzymeFile(ENZYME_FILENAME, "", AvailableSettings.AllEnzymes)) { throw new Exception(string.Format(Resources.DdaSearch_MSAmandaSearchWrapper_enzymes_file__0__not_found, ENZYME_FILENAME)); } if (!AvailableSettings.ParseUnimodFile(UNIMOD_FILENAME, AvailableSettings.AllModifications)) { throw new Exception(string.Format(Resources.DdaSearch_MSAmandaSearchWrapper_unimod_file__0__not_found, UNIMOD_FILENAME)); } if (!AvailableSettings.ParseOboFiles()) { throw new Exception(Resources.DdaSearch_MSAmandaSearchWrapper_Obo_files_not_found); } if (!AvailableSettings.ReadInstrumentsFile(INSTRUMENTS_FILENAME)) { throw new Exception(string.Format(Resources.DdaSearch_MSAmandaSearchWrapper_Instruments_file_not_found, INSTRUMENTS_FILENAME)); } } AdditionalSettings = new Dictionary <string, Setting> { { MAX_LOADED_PROTEINS_AT_ONCE, new Setting(MAX_LOADED_PROTEINS_AT_ONCE, 100000, 10, int.MaxValue) }, { MAX_LOADED_SPECTRA_AT_ONCE, new Setting(MAX_LOADED_SPECTRA_AT_ONCE, 10000, 100, int.MaxValue) } }; CurrentFile = 0; }
public override bool Run(CancellationTokenSource tokenSource) { bool success = true; try { using (var c = new CurrentCultureSetter(CultureInfo.InvariantCulture)) using (var d = new CurrentDirectorySetter(_baseDir.DirPath)) { foreach (var rawFileName in SpectrumFileNames) { tokenSource.Token.ThrowIfCancellationRequested(); try { string outputFilepath = GetSearchResultFilepath(rawFileName); if (File.Exists(outputFilepath)) { // CONSIDER: read the file description to see what settings were used to generate the file; // if the same settings were used, we can re-use the file, else regenerate /*string lastLine = File.ReadLines(outputFilepath).Last(); * if (lastLine == @"</MzIdentML>") * { * helper.WriteMessage($"Re-using existing mzIdentML file for {rawFileName.GetSampleOrFileName()}", true); * CurrentFile++; * continue; * } * else*/ FileEx.SafeDelete(outputFilepath); } InitializeEngine(tokenSource, rawFileName.GetSampleLocator()); amandaInputParser = new MSAmandaSpectrumParser(rawFileName.GetSampleLocator(), Settings.ConsideredCharges, true); SearchEngine.SetInputParser(amandaInputParser); SearchEngine.PerformSearch(_outputParameters.DBFile); CurrentFile++; } finally { SearchEngine?.Dispose(); amandaInputParser?.Dispose(); amandaInputParser = null; } } } } catch (AggregateException e) { if (e.InnerException is TaskCanceledException) { helper.WriteMessage(Resources.DdaSearch_Search_is_canceled, true); } else { Program.ReportException(e); } success = false; } catch (OperationCanceledException) { helper.WriteMessage(Resources.DdaSearch_Search_is_canceled, true); success = false; } catch (Exception ex) { helper.WriteMessage(string.Format(Resources.DdaSearch_Search_failed__0, ex.Message), true); success = false; } finally { helper.Dispose(); } if (tokenSource.IsCancellationRequested) { success = false; } return(success); }