Example #1
0
        private static string FindUninstallString(string[] lines, string name, TemplateNameParser.TemplateNameKind kind)
        {
            var index = 0;

            while (true)
            {
                var sourceName = GetNextSource(lines, ref index);
                if (String.IsNullOrEmpty(sourceName))
                {
                    break;
                }

                if (kind == TemplateNameParser.TemplateNameKind.Directory)
                {
                    var dirName = Path.GetFileName(sourceName);
                    if (String.Compare(dirName, name, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        continue;
                    }
                }
                else
                {
                    var templates = GetTemplates(lines, ref index);
                    var found     = FindMatchingTemplate(name, kind, templates);
                    if (!found)
                    {
                        continue;
                    }
                }
                var uninstallCommand = GetUninstallCommand(lines, ref index);
                return(uninstallCommand);
            }
            return(null);
        }
Example #2
0
        private static bool FindMatchingTemplate(string name, TemplateNameParser.TemplateNameKind kind, string[] templates)
        {
            var found = false;

            foreach (var template in templates)
            {
                ExtractName(template, out var name1, out var shortName, out _);
                var nameToCompare = GetNameToCompare(kind, name1, shortName);
                if (string.Compare(nameToCompare, name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    found = true;
                    break;
                }
            }
            return(found);
        }
Example #3
0
        private static string GetNameToCompare(TemplateNameParser.TemplateNameKind kind, string name1, string shortName)
        {
            string nameToCompare;

            switch (kind)
            {
            case TemplateNameParser.TemplateNameKind.Name:
                nameToCompare = name1;
                break;

            case TemplateNameParser.TemplateNameKind.ShortName:
                nameToCompare = shortName;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
            }

            return(nameToCompare);
        }