private static string ProcessCommand(ExternalToolProperties readin, string tempToolPath, UnzipToolReturnAccumulator accumulator) { string command = readin.Command.Trim(); var programPathContainer = ToolMacros.GetProgramPathContainer(command); if (!ToolDescription.IsWebPageCommand(command) && programPathContainer == null) { // ReSharper disable once LocalizableElement if (command.StartsWith(ToolMacros.TOOL_DIR + "\\")) { command = command.Substring(ToolMacros.TOOL_DIR.Length + 1); } if (!File.Exists(Path.Combine(tempToolPath, command))) { accumulator.AddMessage(string.Format(Resources.ToolInstaller_AddToolFromProperties_Missing_the_file__0___Tool__1__import_failed, command, readin.Title)); return(null); } command = Path.Combine(ToolMacros.TOOL_DIR, command); } else if (programPathContainer != null) // If it is a ProgramPath macro { FindPackagesToInstall(readin, accumulator, programPathContainer); } return(command); }
private static ToolInfo GetToolInfo(DirectoryInfo toolInf, UnzipToolReturnAccumulator accumulator) { var toolInfo = new ToolInfo(); string infoFile = Path.Combine(toolInf.FullName, INFO_PROPERTIES); if (File.Exists(infoFile)) { ExternalToolProperties readin; try { readin = new ExternalToolProperties(infoFile); } catch (Exception) { // Failed to read the .properties file throw new ToolExecutionException(string.Format(Resources.ToolInstaller_GetToolInfo_Failed_to_process_the__0__file, INFO_PROPERTIES)); } toolInfo.SetPackageVersion(readin.Version); toolInfo.SetPackageIdentifier(readin.Identifier); toolInfo.SetPackageName(readin.Name); //Check for Package Installation specified in info.properties var ppc = ToolMacros.GetProgramPathContainer(readin.Command); if (ppc != null) { FindPackagesToInstall(readin, accumulator, ppc); } } else //No info.properties file in the tool-inf directory. { throw new ToolExecutionException(TextUtil.LineSeparate( Resources.ToolInstaller_UnpackZipTool_The_selected_zip_file_is_not_a_valid_installable_tool_, string.Format(Resources.ToolInstaller_GetToolInfo_Error__It_does_not_contain_the_required__0__in_the__1__directory_, INFO_PROPERTIES, TOOL_INF))); } return(toolInfo); }
/// <summary> /// Method used to encapsulate the running of a executable for threading. /// </summary> /// <param name="document"> Contains the document to base reports off of, as well as to serve as the parent for args collector forms. </param> /// <param name="toolMacroProvider"> Interface for determining what to replace macros with. </param> /// <param name="textWriter"> A textWriter to write to if outputting to the immediate window. </param> /// <param name="progressMonitor"> Progress monitor. </param> /// <param name="parent">If there is an Args Collector form, it will be showed on this control. Can be null. </param> private void RunExecutableBackground(SrmDocument document, IToolMacroProvider toolMacroProvider, TextWriter textWriter, IProgressMonitor progressMonitor, Control parent) { // Need to know if $(InputReportTempPath) is an argument to determine if a report should be piped to stdin or not. bool containsInputReportTempPath = Arguments.Contains(ToolMacros.INPUT_REPORT_TEMP_PATH); string command = GetCommand(document, toolMacroProvider, progressMonitor); if (command == null) // Has already thrown the error. { return; } string args = GetArguments(document, toolMacroProvider, progressMonitor); string initDir = GetInitialDirectory(document, toolMacroProvider, progressMonitor); // If either of these fails an Exception is thrown. if (args != null && initDir != null) { ProcessStartInfo startInfo = new ProcessStartInfo(command, args) { WorkingDirectory = initDir }; if (OutputToImmediateWindow) { startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.StandardOutputEncoding = Encoding.UTF8; startInfo.StandardErrorEncoding = Encoding.UTF8; } // if it has a selected report title and its doesn't have a InputReportTempPath macro then the report needs to be piped to stdin. string reportCsv = null; if (!string.IsNullOrEmpty(ReportTitle) && !containsInputReportTempPath) // Then pipe to stdin. { reportCsv = ToolDescriptionHelpers.GetReport(document, ReportTitle, Title, progressMonitor); startInfo.RedirectStandardInput = true; } //Consider: Maybe throw an error if one is not null but the other is? //If there is an IToolArgsCollector run it! if (!string.IsNullOrEmpty(ArgsCollectorDllPath) && !string.IsNullOrEmpty(ArgsCollectorClassName)) { string pathReportCsv = !string.IsNullOrEmpty(ReportTitle) && containsInputReportTempPath ? ToolMacros.GetReportTempPath(ReportTitle, Title) : null; if (!CallArgsCollector(parent, args, reportCsv, pathReportCsv, startInfo)) { return; } } Process p = new Process { StartInfo = startInfo }; if (OutputToImmediateWindow) { p.EnableRaisingEvents = true; TextBoxStreamWriterHelper boxStreamWriterHelper = textWriter as TextBoxStreamWriterHelper; if (boxStreamWriterHelper == null) { p.OutputDataReceived += (sender, dataReceivedEventArgs) => textWriter.WriteLine(p.Id + ">" + dataReceivedEventArgs.Data); // Not L10N p.ErrorDataReceived += (sender, dataReceivedEventArgs) => textWriter.WriteLine(p.Id + ">" + dataReceivedEventArgs.Data); // Not L10N } else { p.OutputDataReceived += (sender, dataReceivedEventArgs) => boxStreamWriterHelper.WriteLineWithIdentifier(p.Id, dataReceivedEventArgs.Data); p.ErrorDataReceived += (sender, dataReceivedEventArgs) => boxStreamWriterHelper.WriteLineWithIdentifier(p.Id, dataReceivedEventArgs.Data); //p.Refresh(); p.Exited += (sender, processExitedEventArgs) => boxStreamWriterHelper.HandleProcessExit(p.Id); } } // else // { // startInfo.RedirectStandardOutput = true; // startInfo.RedirectStandardError = true; // startInfo.CreateNoWindow = true; // startInfo.UseShellExecute = false; // p.EnableRaisingEvents = true; // p.OutputDataReceived += // (sender, dataReceivedEventArgs) => Console.WriteLine(dataReceivedEventArgs.Data); // p.ErrorDataReceived += // (sender, dataReceivedEventArgs) => Console.WriteLine(dataReceivedEventArgs.Data); // } try { p.StartInfo.UseShellExecute = false; p.Start(); if (OutputToImmediateWindow) { p.BeginOutputReadLine(); p.BeginErrorReadLine(); } // write the reportCsv string to stdin. // need to only check one of these conditions. if (startInfo.RedirectStandardInput && (reportCsv != null)) { StreamWriter streamWriter = p.StandardInput; streamWriter.Write(reportCsv); streamWriter.Flush(); streamWriter.Close(); } } catch (Exception ex) { if (ex is Win32Exception) { throw new ToolExecutionException( TextUtil.LineSeparate( Resources.ToolDescription_RunTool_File_not_found_, Resources.ToolDescription_RunTool_Please_check_the_command_location_is_correct_for_this_tool_), ex); } else { throw new ToolExecutionException( TextUtil.LineSeparate( Resources.ToolDescription_RunTool_Please_reconfigure_that_tool__it_failed_to_execute__, ex.Message), ex); } } // CONSIDER: We don't delete the temp path here, because the file may be open // in a long running application like Excel. // if (ReportTempPath_toDelete != null) // { // FileEx.SafeDelete(ReportTempPath_toDelete, true); // ReportTempPath_toDelete = null; // } } }
private string GetCommand(SrmDocument doc, IToolMacroProvider toolMacroProvider, IProgressMonitor progressMonitor) { return(ToolMacros.ReplaceMacrosCommand(doc, toolMacroProvider, this, progressMonitor)); }
/// <summary> /// Return a string that is the InitialDirectoy string with the macros replaced. /// </summary> /// <param name="doc"> Document for report data. </param> /// <param name="toolMacroProvider"> Interface to use to get the current macro values </param> /// <param name="progressMonitor">Progress monitor. </param> /// <returns> InitialDirectory with macros replaced or null if one of the macros was missing /// (eg. no document for $(DocumentDir) then the return value is null </returns> public string GetInitialDirectory(SrmDocument doc, IToolMacroProvider toolMacroProvider, IProgressMonitor progressMonitor) { return(ToolMacros.ReplaceMacrosInitialDirectory(doc, toolMacroProvider, this, progressMonitor)); }
/// <summary> /// Return a string that is the Arguments string with the macros replaced. /// </summary> /// <param name="doc"> Document for report data. </param> /// <param name="toolMacroProvider"> Interface to use to get the current macro values </param> /// <param name="progressMonitor">Progress monitor. </param> /// <returns> Arguments with macros replaced or null if one of the macros was missing /// (eg. no selected peptide for $(SelPeptide) then the return value is null </returns> public string GetArguments(SrmDocument doc, IToolMacroProvider toolMacroProvider, IProgressMonitor progressMonitor) { return(ToolMacros.ReplaceMacrosArguments(doc, toolMacroProvider, this, progressMonitor)); }