Esempio n. 1
0
        public bool BuildLibrary(LibraryBuildAction libraryBuildAction, IProgressMonitor progressMonitor, ref IProgressStatus status, out string commandArgs, out string messageLog, out string[] ambiguous)
        {
            // Arguments for BlibBuild
            // ReSharper disable LocalizableElement
            List <string> argv = new List <string> {
                "-s", "-A", "-H"
            };                                                          // Read from stdin, get ambiguous match messages, high precision modifications

            if (DebugMode)
            {
                argv.Add("-v"); // Verbose for debugging
                argv.Add("debug");
            }
            if (libraryBuildAction == LibraryBuildAction.Create)
            {
                argv.Add("-o");
            }
            if (CutOffScore.HasValue)
            {
                argv.Add("-c");
                argv.Add(CutOffScore.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (CompressLevel.HasValue)
            {
                argv.Add("-l");
                argv.Add(CompressLevel.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (!string.IsNullOrEmpty(Authority))
            {
                argv.Add("-a");
                argv.Add(Authority);
            }
            if (!string.IsNullOrEmpty(Id))
            {
                argv.Add("-i");
                argv.Add(Id);
            }
            if (IncludeAmbiguousMatches)
            {
                argv.Add("-K");
            }
            if (PreferEmbeddedSpectra == true)
            {
                argv.Add("-E");
            }
            string dirCommon = PathEx.GetCommonRoot(InputFiles);

            string stdinFilename = Path.GetTempFileName();

            argv.Add($"-S \"{stdinFilename}\"");
            using (var stdinFile = new StreamWriter(stdinFilename, false, new UTF8Encoding(false)))
            {
                foreach (string fileName in InputFiles)
                {
                    stdinFile.WriteLine(PathEx.RemovePrefix(fileName, dirCommon));
                }

                if (TargetSequences != null)
                {
                    argv.Add("-U");
                    stdinFile.WriteLine();
                    foreach (string targetSequence in TargetSequences)
                    {
                        stdinFile.WriteLine(targetSequence);
                    }
                }
                stdinFile.Close();
            }
            // ReSharper restore LocalizableElement

            // ReSharper disable LocalizableElement
            argv.Add("\"" + OutputPath + "\"");
            // ReSharper restore LocalizableElement

            var psiBlibBuilder = new ProcessStartInfo(EXE_BLIB_BUILD)
            {
                CreateNoWindow  = true,
                UseShellExecute = false,
                // Common directory includes the directory separator
                WorkingDirectory       = dirCommon.Substring(0, dirCommon.Length - 1),
                Arguments              = string.Join(@" ", argv.ToArray()),
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = false,
                StandardOutputEncoding = Encoding.UTF8,
                StandardErrorEncoding  = Encoding.UTF8
            };

            bool isComplete = false;

            ambiguous  = new string[0];
            messageLog = string.Empty;
            try
            {
                const string ambiguousPrefix = @"AMBIGUOUS:";
                var          processRunner   = new ProcessRunner {
                    MessagePrefix = DebugMode ? string.Empty : ambiguousPrefix
                };
                processRunner.Run(psiBlibBuilder, null, progressMonitor, ref status);
                isComplete = status.IsComplete;
                if (isComplete)
                {
                    var messages = processRunner.MessageLog();
                    messageLog = string.Join(Environment.NewLine, processRunner.MessageLog());
                    if (DebugMode)
                    {
                        messages = messages.Where(l => l.StartsWith(ambiguousPrefix))
                                   .Select(l => l.Substring(ambiguousPrefix.Length));
                    }
                    ambiguous = messages.Distinct().OrderBy(s => s).ToArray();
                }
            }
            finally
            {
                // Keep a copy of what got sent to BlibBuild for debugging purposes
                commandArgs = psiBlibBuilder.Arguments + Environment.NewLine + string.Join(Environment.NewLine, File.ReadAllLines(stdinFilename));

                File.Delete(stdinFilename);
                if (!isComplete)
                {
                    // If something happened (error or cancel) to end processing, then
                    // get rid of the possibly partial library.
                    File.Delete(OutputPath);
                    File.Delete(OutputPath + EXT_SQLITE_JOURNAL);
                }
            }
            return(isComplete);
        }
Esempio n. 2
0
        public bool BuildLibrary(LibraryBuildAction libraryBuildAction, IProgressMonitor progressMonitor, ref IProgressStatus status, out string[] ambiguous)
        {
            // Arguments for BlibBuild
            // ReSharper disable NonLocalizedString
            List <string> argv = new List <string> {
                "-s", "-A"
            };                                                    // Read from stdin, get ambiguous match messages

            if (libraryBuildAction == LibraryBuildAction.Create)
            {
                argv.Add("-o");
            }
            if (CutOffScore.HasValue)
            {
                argv.Add("-c");
                argv.Add(CutOffScore.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (CompressLevel.HasValue)
            {
                argv.Add("-l");
                argv.Add(CompressLevel.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (!string.IsNullOrEmpty(Authority))
            {
                argv.Add("-a");
                argv.Add(Authority);
            }
            if (!string.IsNullOrEmpty(Id))
            {
                argv.Add("-i");
                argv.Add(Id);
            }
            if (IncludeAmbiguousMatches)
            {
                argv.Add("-K");
            }
            string dirCommon    = PathEx.GetCommonRoot(InputFiles);
            var    stdinBuilder = new StringBuilder();

            foreach (string fileName in InputFiles)
            {
                stdinBuilder.AppendLine(fileName.Substring(dirCommon.Length));
            }
            if (TargetSequences != null)
            {
                argv.Add("-U");
                stdinBuilder.AppendLine();
                foreach (string targetSequence in TargetSequences)
                {
                    stdinBuilder.AppendLine(targetSequence);
                }
            }
            // ReSharper restore NonLocalizedString

            argv.Add("\"" + OutputPath + "\""); // Not L10N

            var psiBlibBuilder = new ProcessStartInfo(EXE_BLIB_BUILD)
            {
                CreateNoWindow  = true,
                UseShellExecute = false,
                // Common directory includes the directory separator
                WorkingDirectory       = dirCommon.Substring(0, dirCommon.Length - 1),
                Arguments              = string.Join(" ", argv.ToArray()),             // Not L10N
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true
            };
            bool isComplete = false;

            ambiguous = new string[0];
            try
            {
                var processRunner = new ProcessRunner {
                    MessagePrefix = "AMBIGUOUS:"
                };                                                                    // Not L10N
                processRunner.Run(psiBlibBuilder, stdinBuilder.ToString(), progressMonitor, ref status);
                isComplete = status.IsComplete;
                if (isComplete)
                {
                    ambiguous = processRunner.MessageLog().Distinct().OrderBy(s => s).ToArray();
                }
            }
            finally
            {
                if (!isComplete)
                {
                    // If something happened (error or cancel) to end processing, then
                    // get rid of the possibly partial library.
                    File.Delete(OutputPath);
                    File.Delete(OutputPath + EXT_SQLITE_JOURNAL);
                }
            }
            return(isComplete);
        }