private string ReadToEnd(ProcessStreamReader processStream, CancellationToken cancellationToken) { var readStreamTask = Task.Run( () => { var streamMessage = string.Empty; while (processStream.Peek() >= 0) { streamMessage += processStream.ReadLine(); } return(streamMessage); }); var successful = readStreamTask.Wait((int)_maxTime.TotalMilliseconds, cancellationToken); return(successful ? readStreamTask.Result : "Stuck when reading from stream!"); }
private bool ReadToEnd(ProcessStreamReader processStream, TimeSpan maxTime, CancellationToken cancellationToken, out string message) { var readStreamTask = Task.Run( () => { var streamMessage = string.Empty; while (processStream.Peek() >= 0) { streamMessage += processStream.ReadLine(); } return(streamMessage); }, cancellationToken); // We also have a max time in the test runner so add a bit of extra here // just in case so we don't fail it to early. var successful = readStreamTask.Wait((int)maxTime.Add(TimeSpan.FromSeconds(30)).TotalMilliseconds, cancellationToken); message = successful ? readStreamTask.Result : "Stuck when reading from stream!"; return(successful); }
// ReSharper restore NonLocalizedString public static List <string> ConvertPilotFiles(IList <string> inputFiles, IProgressMonitor progress, ProgressStatus status) { string groupConverterExePath = null; var inputFilesPilotConverted = new List <string>(); for (int index = 0; index < inputFiles.Count; index++) { string inputFile = inputFiles[index]; if (!inputFile.EndsWith(BiblioSpecLiteBuilder.EXT_PILOT)) { inputFilesPilotConverted.Add(inputFile); continue; } string outputFile = Path.ChangeExtension(inputFile, BiblioSpecLiteBuilder.EXT_PILOT_XML); // Avoid re-converting files that have already been converted if (File.Exists(outputFile)) { // Avoid duplication, in case the user accidentally adds both .group and .group.xml files // for the same results if (!inputFiles.Contains(outputFile)) { inputFilesPilotConverted.Add(outputFile); } continue; } string message = string.Format(Resources.VendorIssueHelper_ConvertPilotFiles_Converting__0__to_xml, Path.GetFileName(inputFile)); int percent = index * 100 / inputFiles.Count; progress.UpdateProgress(status = status.ChangeMessage(message).ChangePercentComplete(percent)); if (groupConverterExePath == null) { var key = Registry.LocalMachine.OpenSubKey(KEY_PROTEIN_PILOT, false); if (key != null) { string proteinPilotCommandWithArgs = (string)key.GetValue(string.Empty); var proteinPilotCommandWithArgsSplit = proteinPilotCommandWithArgs.Split(new[] { "\" \"" }, StringSplitOptions.RemoveEmptyEntries); // Remove " "%1" // Not L10N string path = Path.GetDirectoryName(proteinPilotCommandWithArgsSplit[0].Trim(new[] { '\\', '\"' })); // Remove preceding " if (path != null) { var groupFileExtractorPath = Path.Combine(path, EXE_GROUP_FILE_EXTRACTOR); if (File.Exists(groupFileExtractorPath)) { groupConverterExePath = groupFileExtractorPath; } else { var group2XmlPath = Path.Combine(path, EXE_GROUP2_XML); if (File.Exists(group2XmlPath)) { groupConverterExePath = group2XmlPath; } else { string errorMessage = string.Format(Resources.VendorIssueHelper_ConvertPilotFiles_Unable_to_find__0__or__1__in_directory__2____Please_reinstall_ProteinPilot_software_to_be_able_to_handle__group_files_, EXE_GROUP_FILE_EXTRACTOR, EXE_GROUP2_XML, path); throw new IOException(errorMessage); } } } } if (groupConverterExePath == null) { throw new IOException(Resources.VendorIssueHelper_ConvertPilotFiles_ProteinPilot_software__trial_or_full_version__must_be_installed_to_convert___group__files_to_compatible___group_xml__files_); } } // run group2xml // ReSharper disable NonLocalizedString var argv = new[] { "XML", "\"" + inputFile + "\"", "\"" + outputFile + "\"" }; // ReSharper restore NonLocalizedString var psi = new ProcessStartInfo(groupConverterExePath) { CreateNoWindow = true, UseShellExecute = false, // Common directory includes the directory separator WorkingDirectory = Path.GetDirectoryName(groupConverterExePath) ?? string.Empty, Arguments = string.Join(" ", argv.ToArray()), // Not L10N RedirectStandardError = true, RedirectStandardOutput = true, }; var sbOut = new StringBuilder(); var proc = new Process { StartInfo = psi }; proc.Start(); var reader = new ProcessStreamReader(proc); string line; while ((line = reader.ReadLine()) != null) { if (progress.IsCanceled) { proc.Kill(); throw new LoadCanceledException(status.Cancel()); } sbOut.AppendLine(line); } while (!proc.WaitForExit(200)) { if (progress.IsCanceled) { proc.Kill(); return(inputFilesPilotConverted); } } if (proc.ExitCode != 0) { throw new IOException(TextUtil.LineSeparate(string.Format(Resources.VendorIssueHelper_ConvertPilotFiles_Failure_attempting_to_convert_file__0__to__group_xml_, inputFile), string.Empty, sbOut.ToString())); } inputFilesPilotConverted.Add(outputFile); } progress.UpdateProgress(status.ChangePercentComplete(100)); return(inputFilesPilotConverted); }
private static void ConvertBrukerToMzml(string filePathBruker, string outputPath, IProgressMonitor monitor, ProgressStatus status) { // We use CompassXport, if it is installed, to convert a Bruker raw file to mzML. This solves two // issues: the Bruker reader can't be called on any thread other than the main thread, and there // is no 64-bit version of the reader. So we start CompassXport in its own 32-bit process, // and use it to convert the raw data to mzML in a temporary file, which we read back afterwards. var key = Registry.LocalMachine.OpenSubKey(KEY_COMPASSXPORT, false); string compassXportExe = (key != null) ? (string)key.GetValue(string.Empty) : null; if (compassXportExe == null) { throw new IOException(Resources.VendorIssueHelper_ConvertBrukerToMzml_CompassXport_software_must_be_installed_to_import_Bruker_raw_data_files_); } // CompassXport arguments // ReSharper disable NonLocalizedString var argv = new[] { "-a \"" + filePathBruker + "\"", // input file (directory) "-o \"" + outputPath + "\"", // output file (directory) "-mode 2", // mode 2 (mzML) "-raw 0" // export line spectra (profile data is HUGE and SLOW!) }; // ReSharper restore NonLocalizedString // Start CompassXport in its own process. var psi = new ProcessStartInfo(compassXportExe) { CreateNoWindow = true, UseShellExecute = false, // Common directory includes the directory separator WorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, Arguments = string.Join(" ", argv), // Not L10N RedirectStandardError = true, RedirectStandardOutput = true, }; var proc = new Process { StartInfo = psi }; proc.Start(); // CompassXport starts by calculating a hash of the input file. This takes a long time, and there is // no intermediate output during this time. So we set the progress bar some fraction of the way and // let it sit there and animate while we wait for the start of spectra processing. const int hashPercent = 25; // percentage of import time allocated to calculating the input file hash int spectrumCount = 0; var sbOut = new StringBuilder(); var reader = new ProcessStreamReader(proc); string line; while ((line = reader.ReadLine()) != null) { if (monitor.IsCanceled) { proc.Kill(); throw new LoadCanceledException(status.Cancel()); } sbOut.AppendLine(line); line = line.Trim(); // The main part of conversion starts with the hash calculation. if (line.StartsWith("Calculating hash")) // Not L10N { status = status.ChangeMessage(Resources.VendorIssueHelper_ConvertBrukerToMzml_Calculating_hash_of_input_file) .ChangePercentComplete(hashPercent); monitor.UpdateProgress(status); continue; } // Determine how many spectra will be converted so we can track progress. var match = Regex.Match(line, @"Converting (\d+) spectra"); // Not L10N if (match.Success) { spectrumCount = int.Parse(match.Groups[1].Value); continue; } // Update progress as each spectra batch is converted. match = Regex.Match(line, @"Spectrum \d+ - (\d+)"); // Not L10N if (match.Success) { var spectrumEnd = int.Parse(match.Groups[1].Value); var percentComplete = hashPercent + (100 - hashPercent) * spectrumEnd / spectrumCount; status = status.ChangeMessage(line).ChangePercentComplete(percentComplete); monitor.UpdateProgress(status); } } while (!proc.WaitForExit(200)) { if (monitor.IsCanceled) { proc.Kill(); throw new LoadCanceledException(status.Cancel()); } } if (proc.ExitCode != 0) { throw new IOException(TextUtil.LineSeparate(string.Format(Resources.VendorIssueHelper_ConvertBrukerToMzml_Failure_attempting_to_convert__0__to_mzML_using_CompassXport_, filePathBruker), string.Empty, sbOut.ToString())); } }
private static void ConvertLocalWiffToMzxml(string filePathWiff, int sampleIndex, string outputPath, IProgressMonitor monitor) { var argv = new[] { "--mzXML", // Not L10N "-s" + (sampleIndex + 1), // Not L10N "\"" + filePathWiff + "\"", // Not L10N "\"" + outputPath + "\"", // Not L10N }; var psi = new ProcessStartInfo(EXE_MZ_WIFF) { CreateNoWindow = true, UseShellExecute = false, // Common directory includes the directory separator WorkingDirectory = Path.GetDirectoryName(filePathWiff) ?? string.Empty, Arguments = string.Join(" ", argv.ToArray()), // Not L10N RedirectStandardError = true, RedirectStandardOutput = true, }; var sbOut = new StringBuilder(); var proc = new Process { StartInfo = psi }; proc.Start(); var reader = new ProcessStreamReader(proc); string line; while ((line = reader.ReadLine()) != null) { if (monitor.IsCanceled) { proc.Kill(); throw new LoadCanceledException(new ProgressStatus(string.Empty).Cancel()); } sbOut.AppendLine(line); } while (!proc.WaitForExit(200)) { if (monitor.IsCanceled) { proc.Kill(); throw new LoadCanceledException(new ProgressStatus(string.Empty).Cancel()); } } // Exit code -4 is a compatibility warning but not necessarily an error if (proc.ExitCode != 0 && !IsCompatibilityWarning(proc.ExitCode)) { var message = TextUtil.LineSeparate(string.Format(Resources.VendorIssueHelper_ConvertLocalWiffToMzxml_Failure_attempting_to_convert_sample__0__in__1__to_mzXML_to_work_around_a_performance_issue_in_the_AB_Sciex_WiffFileDataReader_library, sampleIndex, filePathWiff), string.Empty, sbOut.ToString()); throw new IOException(message); } }