Beispiel #1
0
        public static string ReplaceMacrosHelper(SrmDocument doc, IToolMacroProvider toolMacroProvider, ToolDescription tool, IProgressMonitor progressMonitor, string replacein, Macro[] macros)
        {
            string workingString = replacein;

            foreach (Macro macro in macros)
            {
                if (workingString.Contains(macro.ShortText))
                {
                    string contents;
                    if (macro.PlainText == Resources.ToolMacros__listArguments_Input_Report_Temp_Path)
                    {
                        contents = macro.GetContents(new ToolMacroInfo(toolMacroProvider, tool.Title, tool.ReportTitle, doc, progressMonitor));
                        tool.ReportTempPath_toDelete = contents;
                    }
                    else if (macro.ShortText == COLLECTED_ARGS)
                    {
                        //Do Nothing. (this gets replaced later after we actually run the args collector.
                        continue;
                    }
                    else
                    {
                        /* null is fine for the ProgramPathContainer argument because ProgramPathContainer
                         * is only used when working with the command text and this function is only used for
                         * arguments and initial directory. */
                        contents = macro.GetContents(new ToolMacroInfo(toolMacroProvider, tool.Title, tool.ReportTitle, doc, progressMonitor, null, tool.ToolDirPath));
                    }
                    if (contents == null)
                    {
                        throw new ToolExecutionException(macro.ErrorMessage);
                    }
                    workingString = workingString.Replace(macro.ShortText, contents);
                }
            }
            return(workingString);
        }
Beispiel #2
0
 public ToolMacroInfo(IToolMacroProvider macroProvider,
                      string toolTitle,
                      string reportName,
                      SrmDocument document,
                      IProgressMonitor progressMonitor)
     : this(macroProvider, toolTitle, reportName, document, progressMonitor, null, null)
 {
 }
Beispiel #3
0
 public CopyToolMacroProvider(IToolMacroProvider iToolMacroProvider)
 {
     DocumentFilePath        = iToolMacroProvider.DocumentFilePath;
     SelectedProteinName     = iToolMacroProvider.SelectedProteinName;
     SelectedPeptideSequence = iToolMacroProvider.SelectedPeptideSequence;
     SelectedPrecursor       = iToolMacroProvider.SelectedPrecursor;
     ResultNameCurrent       = iToolMacroProvider.ResultNameCurrent;
     _getProgramPath         = iToolMacroProvider.FindProgramPath;
 }
Beispiel #4
0
 private void RunExecutable(SrmDocument document, IToolMacroProvider toolMacroProvider, TextWriter textWriter, IProgressMonitor progressMonitor, Control parent)
 {
     ActionUtil.RunAsync(() =>
     {
         try
         {
             RunExecutableBackground(document, toolMacroProvider, textWriter, progressMonitor, parent);
         }
         catch (Exception e)
         {
             progressMonitor.UpdateProgress(new ProgressStatus(string.Empty).ChangeErrorException(e));
         }
     }, @"Run Executable");
 }
Beispiel #5
0
 public ToolMacroInfo(IToolMacroProvider macroProvider,
                      string toolTitle,
                      string reportName,
                      SrmDocument document,
                      IProgressMonitor progressMonitor,
                      ProgramPathContainer pathContainer,
                      string toolDirPath)
 {
     _macroProvider       = macroProvider;
     ToolTitle            = toolTitle;
     ReportName           = reportName;
     Doc                  = document;
     ProgressMonitor      = progressMonitor;
     programPathContainer = pathContainer;
     ToolDirPath          = toolDirPath;
 }
Beispiel #6
0
        private void RunExecutable(SrmDocument document, IToolMacroProvider toolMacroProvider, TextWriter textWriter, IProgressMonitor progressMonitor, Control parent)
        {
            var thread = new Thread(() =>
            {
                try
                {
                    RunExecutableBackground(document, toolMacroProvider, textWriter, progressMonitor, parent);
                }
                catch (Exception e)
                {
                    progressMonitor.UpdateProgress(new ProgressStatus(string.Empty).ChangeErrorException(e));
                }
            });

            LocalizationHelper.InitThread(thread);
            thread.Start();
        }
        /// <summary>
        /// Run the tool. When you call run tool. call it on a different thread.
        /// </summary>
        /// <param name="document"> The document to base reports off of. </param>
        /// <param name="toolMacroProvider"> Interface for replacing Tool Macros with the correct strings. </param>
        /// <param name="textWriter"> A textWriter to write to when the tool redirects stdout. (eg. Outputs to an Immediate Window) </param>
        /// <param name="progressMonitor"> Progress monitor. </param>
        /// <param name="parent">A parent control to invoke to display args collectors in, if necessary. Can be null. </param>
        public void RunTool(SrmDocument document, IToolMacroProvider toolMacroProvider, TextWriter textWriter, IProgressMonitor progressMonitor, Control parent)
        {
            if (Annotations != null && Annotations.Count != 0)
            {
                VerifyAnnotations(document);
            }

            if (IsWebPage)
            {
                if (Equals(Title, ToolList.DEPRECATED_QUASAR.Title) && Equals(Command, ToolList.DEPRECATED_QUASAR.Command))
                {
                    MessageDlg.Show(parent, TextUtil.LineSeparate(
                                        Resources.ToolDescription_RunTool_Support_for_the_GenePattern_version_of_QuaSAR_has_been_discontinued_,
                                        Resources.ToolDescription_RunTool_Please_check_the_External_Tools_Store_on_the_Skyline_web_site_for_the_most_recent_version_of_the_QuaSAR_external_tool_));
                    return;
                }
                var webHelpers = WebHelpers ?? new WebHelpers();

                string url = GetUrl(document, toolMacroProvider, progressMonitor);
                if (string.IsNullOrEmpty(url))
                {
                    return;
                }

                if (string.IsNullOrEmpty(ReportTitle))
                {
                    webHelpers.OpenLink(url);
                }
                else // It has a selected report that must be posted.
                {
                    PostToLink(url, document, progressMonitor, webHelpers);
                }
            }
            else // Not a website. Needs its own thread.
            {
                if (Arguments.Contains("$(SkylineConnection)")) // Not L10N
                {
                    Program.StartToolService();
                }

                // To eliminate a cross thread error make a copy of the IToolMacroProvider.
                IToolMacroProvider newToolMacroProvider = new CopyToolMacroProvider(toolMacroProvider);
                RunExecutable(document, newToolMacroProvider, textWriter, progressMonitor, parent);
            }
        }
        public string GetUrl(SrmDocument doc, IToolMacroProvider toolMacroProvider, IProgressMonitor progressMonitor)
        {
            if (!IsWebPage)
            {
                return(null);
            }
            string       url      = Command;
            const string querySep = "?"; // Not L10N
            const string paramSep = "&"; // Not L10N

            if (!string.IsNullOrEmpty(Arguments))
            {
                string query = GetArguments(doc, toolMacroProvider, progressMonitor);
                if (query == null)
                {
                    return(null);
                }

                url += (!url.Contains(querySep) ? querySep : paramSep) + query;
            }
            return(url);
        }
Beispiel #9
0
        public static string ReplaceMacrosCommand(SrmDocument doc, IToolMacroProvider toolMacroProvider, ToolDescription toolDescription, IProgressMonitor progressMonitor)
        {
            string workingString = toolDescription.Command;

            foreach (Macro macro in LIST_COMMAND)
            {
                if (macro.ShortText == PROGRAM_PATH)
                {
                    ProgramPathContainer ppc = GetProgramPathContainer(workingString);
                    if (ppc == null)
                    {
                        // Leave command as is.
                    }
                    else
                    {
                        string path = macro.GetContents(new ToolMacroInfo(toolMacroProvider, toolDescription.Title,
                                                                          toolDescription.ReportTitle, doc, progressMonitor, ppc, toolDescription.ToolDirPath));
                        if (string.IsNullOrEmpty(path))
                        {
                            throw new ToolExecutionException(macro.ErrorMessage);
                        }
                        workingString = path;
                    }
                }
                if (macro.ShortText == TOOL_DIR)
                {
                    if (workingString.Contains(TOOL_DIR))
                    {
                        if (string.IsNullOrEmpty(toolDescription.ToolDirPath))
                        {
                            throw new ToolExecutionException(macro.ErrorMessage);
                        }
                        workingString = workingString.Replace(TOOL_DIR, toolDescription.ToolDirPath);
                    }
                }
            }
            return(workingString);
        }
Beispiel #10
0
 private static string GetActiveReplicateName(IToolMacroProvider toolMacroProvider)
 {
     return(toolMacroProvider.ResultNameCurrent);
 }
Beispiel #11
0
 private static string GetSelectedPrecursor(IToolMacroProvider toolMacroProvider)
 {
     return(toolMacroProvider.SelectedPrecursor);
 }
Beispiel #12
0
 private static string GetSelectedPeptideSequence(IToolMacroProvider toolMacroProvider)
 {
     return(toolMacroProvider.SelectedPeptideSequence);
 }
Beispiel #13
0
 private static string GetSelectedProteinName(IToolMacroProvider toolMacroProvider)
 {
     return(toolMacroProvider.SelectedProteinName);
 }
Beispiel #14
0
 private static string GetDocumentFileNameWithoutExtension(IToolMacroProvider toolMacroProvider)
 {
     return(Path.GetFileNameWithoutExtension(toolMacroProvider.DocumentFilePath));
 }
Beispiel #15
0
 private static string GetDocumentFileName(IToolMacroProvider toolMacroProvider)
 {
     return(Path.GetFileName(toolMacroProvider.DocumentFilePath));
 }
 /// <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));
 }
 private string GetCommand(SrmDocument doc, IToolMacroProvider toolMacroProvider, IProgressMonitor progressMonitor)
 {
     return(ToolMacros.ReplaceMacrosCommand(doc, toolMacroProvider, this, progressMonitor));
 }
Beispiel #18
0
 /// <summary>
 /// Checks the string initialDirectory of the tool for the ShortText of each macro in the macro list.
 /// If the short text is present, get the actual value and replace it.
 /// If the actual value turns out to be null an exception will be thrown.
 /// </summary>
 /// <param name="doc"> A SrmDocument to base reports off of </param>
 /// <param name="toolMacroProvider"> Method provider for getting macro actual values </param>
 /// <param name="tool"> The tool to run this on. </param>
 /// <param name="progressMonitor"> Progress monitor. </param>
 /// <returns> InitialDirectory string with macros replaced or a thrown exception with error message. </returns>
 public static string ReplaceMacrosInitialDirectory(SrmDocument doc, IToolMacroProvider toolMacroProvider, ToolDescription tool, IProgressMonitor progressMonitor)
 {
     return(ReplaceMacrosHelper(doc, toolMacroProvider, tool, progressMonitor, tool.InitialDirectory, LIST_INITIAL_DIRECTORY));
 }
Beispiel #19
0
 /// <summary>
 /// Checks the string arguments of the tool for the ShortText of each macro in the macro list.
 /// If the short text is present, get the actual value and replace it.
 /// If the actual value turns out to be null an exception will be thrown.
 /// </summary>
 /// <param name="doc"> A SrmDocument to base reports off of </param>
 /// <param name="toolMacroProvider"> Method provider for getting macro actual values </param>
 /// <param name="tool"> The tool to run this on. </param>
 /// <param name="progressMonitor">Progress monitor. </param>
 /// <returns> Arguments string with macros replaced or a thrown exception with error message. </returns>
 public static string ReplaceMacrosArguments(SrmDocument doc, IToolMacroProvider toolMacroProvider, ToolDescription tool, IProgressMonitor progressMonitor)
 {
     return(ReplaceMacrosHelper(doc, toolMacroProvider, tool, progressMonitor, tool.Arguments, LIST_ARGUMENTS));
 }
        /// <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;
//                }
            }
        }
Beispiel #21
0
 private static string GetDocumentFilePath(IToolMacroProvider toolMacroProvider)
 {
     return(toolMacroProvider.DocumentFilePath);
 }
 /// <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));
 }