Example #1
0
        /// <summary>
        /// Helper function to match on the ProgramPath Macro and extract the program title and version where relevant.
        /// </summary>
        /// <param name="command">Command string to match on</param>
        /// <returns>Internal Matchings.</returns>
        public static ProgramPathContainer GetProgramPathContainer(string command)
        {
            if (string.IsNullOrEmpty(command))
            {
                return(null);
            }

            // Example String "$(ProgramPath(R,2.12.2))
            // Want to extract R,2.12.2 and then separate the two things.
            Match match = Regex.Match(command, PROGRAM_PATH); // @"\$\(ProgramPath\((.*)\)\)";
            ProgramPathContainer ppc = null;

            if (match.Groups.Count == 2)
            {
                string   paramValues    = match.Groups[1].Value;
                string[] values         = paramValues.Split(',');
                string   programName    = values[0];
                string   programVersion = null;
                if (values.Length > 1)
                {
                    // Extract the version if specified.
                    programVersion = paramValues.Replace(programName, string.Empty).Trim().Substring(1);
                }
                ppc = new ProgramPathContainer(programName, programVersion);
            }

            return(ppc);
        }
Example #2
0
            public void AddInstallation(ProgramPathContainer ppc, List <ToolPackage> packages)
            {
                List <ToolPackage> listPackages;

                if (Installations.TryGetValue(ppc, out listPackages))
                {
                    listPackages.AddRange(packages.Where(p => !listPackages.Contains(p)));
                }
                else
                {
                    Installations.Add(ppc, packages);
                }
            }
Example #3
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;
 }
Example #4
0
        /// <summary>
        ///  Get the path to the version of the program executable.
        /// </summary>
        /// <param name="toolMacroInfo">Wrapper that has a valid ProgramPathContainer.</param>
        /// <returns>Path to program executable that was saved in settings.</returns>
        private static string GetProgramPath(ToolMacroInfo toolMacroInfo)
        {
            ProgramPathContainer ppc = toolMacroInfo.programPathContainer;
            string path = null;

            if (ppc != null)
            {
                if (Settings.Default.ToolFilePaths.ContainsKey(ppc))
                {
                    path = Settings.Default.ToolFilePaths[ppc];
                }

                if (path == null)
                {
                    path = toolMacroInfo.FindProgramPath(ppc);
                }
            }
            return(path);
        }
Example #5
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);
        }
Example #6
0
        private static void FindPackagesToInstall(ExternalToolProperties readin,
                                                  UnzipToolReturnAccumulator accumulator,
                                                  ProgramPathContainer programPathContainer)
        {
            var packages = new List <ToolPackage>();
            int i        = 1;
            var package  = readin.GetPackageWithVersion(i);

            while (package != null)
            {
                // if the package is not a uri, it is stored locally in the tool-inf directory
                //if (!package.StartsWith("http"))
                //    package = Path.Combine(tempToolPath, TOOL_INF, package);

                packages.Add(package);
                package = readin.GetPackageWithVersion(++i);
            }

            if (!Settings.Default.ToolFilePaths.ContainsKey(programPathContainer) || packages.Count > 0)
            {
                accumulator.AddInstallation(programPathContainer, packages);
            }
        }
Example #7
0
 public string FindProgramPath(ProgramPathContainer programPathContainer)
 {
     return(_getProgramPath(programPathContainer));
 }
Example #8
0
 public string FindProgramPath(ProgramPathContainer pcc)
 {
     return(_macroProvider.FindProgramPath(pcc));
 }