示例#1
0
        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);
        }
示例#2
0
        private static ToolDescription FindMostRecentVersion(List <ToolDescription> toolsToBeOverwritten)
        {
            if (toolsToBeOverwritten.Count == 0)
            {
                return(null);
            }
            ToolDescription newestTool = toolsToBeOverwritten.FirstOrDefault(t => !string.IsNullOrEmpty(t.PackageVersion));

            if (newestTool == null)
            {
                return(null);
            }

            Version newestVersion = new Version(newestTool.PackageVersion);

            foreach (var tool in toolsToBeOverwritten)
            {
                if (!string.IsNullOrEmpty(tool.PackageVersion))
                {
                    Version v = new Version(tool.PackageVersion);
                    if (v > newestVersion)
                    {
                        newestVersion = v;
                        newestTool    = tool;
                    }
                }
            }
            return(newestTool);
        }
示例#3
0
        private static bool HandleAnnotations(Func <List <AnnotationDef>, bool?> shouldOverwriteAnnotations, DirectoryInfo toolInf)
        {
            var srmSerialzer        = new XmlSerializer(typeof(SrmDocument));
            var conflictAnnotations = new List <AnnotationDef>();
            var newAnnotations      = new List <AnnotationDef>();

            // Need to filter for .sky files only, as .GetFiles(".sky") also returns .skyr files
            foreach (FileInfo file in toolInf.GetFiles().Where(file => file.Extension.Equals(SrmDocument.EXT)))
            {
                SrmDocument document;
                try
                {
                    using (var stream = File.OpenRead(file.FullName))
                    {
                        document = (SrmDocument)srmSerialzer.Deserialize(stream);
                    }
                }
                catch (Exception exception)
                {
                    throw new IOException(string.Format(Resources.SerializableSettingsList_ImportFile_Failure_loading__0__,
                                                        file.FullName), exception);
                }

                foreach (AnnotationDef annotationDef in document.Settings.DataSettings.AnnotationDefs)
                {
                    AnnotationDef existingAnnotation;
                    if (!Settings.Default.AnnotationDefList.TryGetValue(annotationDef.GetKey(), out existingAnnotation))
                    {
                        newAnnotations.Add(annotationDef);
                    }
                    else if (!ToolDescription.EquivalentAnnotations(existingAnnotation, annotationDef))
                    {
                        conflictAnnotations.Add(annotationDef);
                    }
                }
            }

            bool?overwriteAnnotations = conflictAnnotations.Count != 0
                                             ? shouldOverwriteAnnotations(conflictAnnotations)
                                             : false;

            if (!overwriteAnnotations.HasValue)
            {
                // Cancelled by user
                return(false);
            }

            if (overwriteAnnotations == true)
            {
                newAnnotations.AddRange(conflictAnnotations);
            }

            foreach (AnnotationDef annotation in newAnnotations)
            {
                Settings.Default.AnnotationDefList.SetValue(annotation);
            }
            return(true);
        }
示例#4
0
 public bool Equals(ToolDescription tool)
 {
     return((Equals(Title, tool.Title) &&
             Equals(Command, tool.Command) &&
             Equals(Arguments, tool.Arguments) &&
             Equals(InitialDirectory, tool.InitialDirectory) &&
             Equals(OutputToImmediateWindow, tool.OutputToImmediateWindow)) &&
            Equals(ReportTitle, tool.ReportTitle) &&
            Equals(ArgsCollectorDllPath, tool.ArgsCollectorDllPath) &&
            Equals(ArgsCollectorClassName, tool.ArgsCollectorClassName) &&
            Equals(ToolDirPath, tool.ToolDirPath) &&
            Equals(PackageVersion, tool.PackageVersion) &&
            Equals(PackageIdentifier, tool.PackageIdentifier) &&
            Equals(PackageName, tool.PackageName));
 }
示例#5
0
 public void AddTool(ToolDescription t)
 {
     ValidToolsFound.Add(t);
 }
示例#6
0
 public ToolMacroInfo(SkylineWindow sw, ToolDescription td) :
     this(sw, td.Title, td.ReportTitle, sw.Document, sw, null, td.ToolDirPath)
 {
 }
示例#7
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);
        }
示例#8
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));
 }
示例#9
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));
 }
示例#10
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);
        }
示例#11
0
 public ToolDescription(ToolDescription t)
     : this(t.Title, t.Command, t.Arguments, t.InitialDirectory, t.OutputToImmediateWindow, t.ReportTitle, t.ArgsCollectorDllPath, t.ArgsCollectorClassName, t.ToolDirPath, t.Annotations, t.PackageVersion, t.PackageIdentifier, t.PackageName, t.UpdateAvailable)
 {
 }