Ejemplo n.º 1
0
        public const string EXE_BLIB_FILTER = "BlibFilter"; // Not L10N
        public bool Filter(string sourceFile, string destinationFile, IProgressMonitor progressMonitor, ref ProgressStatus status)
        {
            // ReSharper disable NonLocalizedString
            var argv = new List<string>
                           {
                               "-b true",
                               "\"" + sourceFile + "\"",
                               "\"" + destinationFile + "\""
                           };
            // ReSharper restore NonLocalizedString


            var psiBlibFilter = new ProcessStartInfo(EXE_BLIB_FILTER)
            {
                CreateNoWindow = true,
                UseShellExecute = false,
                WorkingDirectory = Path.GetDirectoryName(destinationFile) ?? string.Empty,
                Arguments = string.Join(" ", argv.ToArray()), // Not L10N
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };
            var processRunner = new ProcessRunner();
            processRunner.Run(psiBlibFilter, null, progressMonitor, ref status);
            return status.IsComplete;
        }
Ejemplo n.º 2
0
 public static void RunProcess(this ProcessStartInfo psi, string stdin, string messagePrefix, IProgressMonitor progress, ref ProgressStatus status)
 {
     var processRunner = new ProcessRunner
                             {
                                 StatusPrefix = messagePrefix,
                             };
     processRunner.Run(psi, stdin, progress, ref status);
 }
Ejemplo n.º 3
0
        public bool BuildLibrary(LibraryBuildAction libraryBuildAction, IProgressMonitor progressMonitor, ref ProgressStatus 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;
        }