Exemple #1
0
 protected void ValidateArchSelection(BundleArch archSelection)
 {
     if ((int)archSelection < 1 || archSelection > Enum.GetValues(typeof(BundleArch)).OfType <BundleArch>().Aggregate((BundleArch)0, (orSum, next) => orSum | next))
     {
         throw new ArgumentOutOfRangeException();
     }
 }
Exemple #2
0
        internal void TestFrom <TBundleVersion>(TBundleVersion version, BundleArch arch, string uninstallCommand, string displayName)
            where TBundleVersion : BundleVersion, IComparable <TBundleVersion>
        {
            var bundle = Bundle.From(version, arch, uninstallCommand, displayName);

            bundle.Should().BeOfType <Bundle <TBundleVersion> >();
            bundle.Version.Type.Should().Be(version.Type);
        }
Exemple #3
0
        public Bundle(BundleVersion version, BundleArch arch, string uninstallCommand, string displayName)
        {
            if (version == null || uninstallCommand == null || displayName == null)
            {
                throw new ArgumentNullException();
            }

            Version          = version;
            Arch             = arch;
            UninstallCommand = uninstallCommand;
            DisplayName      = displayName;
        }
Exemple #4
0
        private static IEnumerable <Bundle> GetInstalledBundles <TBundleVersion>(BundleArch arch, params string[] paths)
            where TBundleVersion : BundleVersion, IComparable <TBundleVersion>, new()
        {
            string bundleTypeString;

            switch (new TBundleVersion().Type)
            {
            case BundleType.Sdk: bundleTypeString = "SDK"; break;

            case BundleType.Runtime: bundleTypeString = "Runtime"; break;

            default: throw new ArgumentException();
            }

            return(paths
                   .SelectMany(path => GetInstalledVersionsAndUninstallCommands <TBundleVersion>(path))
                   .GroupBy(tuple => tuple.Version)
                   .Select(group => Bundle.From(
                               group.First().Version,
                               arch,
                               GetUninstallCommand(group.Select(tuple => tuple.Path)),
                               string.Format(LocalizableStrings.MacOsBundleDisplayNameFormat, bundleTypeString, group.First().Version.ToString()))));
        }
Exemple #5
0
        internal virtual void TestFiltererException <TException>(IEnumerable <Bundle> testBundles, string argValue, BundleType typeSelection, BundleArch archSelection, string errorMessage)
            where TException : Exception
        {
            var    parseResult = CommandLineConfigs.UninstallRootCommand.Parse($"--{Option.Name} {argValue}");
            Action action      = () => OptionFilterer.Filter(parseResult, Option, testBundles, typeSelection, archSelection);

            action.Should().Throw <TException>(errorMessage);
        }
Exemple #6
0
        private static Bundle <TBundleVersion> GetBundleFromInput <TBundleVersion>(string input, BundleArch arch)
            where TBundleVersion : BundleVersion, IComparable <TBundleVersion>, new()
        {
            var version = BundleVersion.FromInput <TBundleVersion>(input);

            return(Bundle.From(version, arch, TestUninstallCommand, TestDisplayName) as Bundle <TBundleVersion>);
        }
        private static void ParseVersionAndArch(RegistryKey registryKey, string displayName, string bundleCachePath, out BundleVersion version, out BundleArch arch)
        {
            var match                = Regexes.BundleDisplayNameRegex.Match(displayName);
            var cachePathMatch       = Regexes.BundleCachePathRegex.Match(bundleCachePath);
            var archString           = cachePathMatch.Groups[Regexes.ArchGroupName].Value ?? string.Empty;
            var versionFromCachePath = cachePathMatch.Groups[Regexes.VersionGroupName].Value;
            // Note: ASP.NET Core runtimes do not include version in the cache path, need to get version from registry:
            var versionFromRegistry = string.Join('.', (registryKey.GetValue("DisplayVersion") as string).Split('.').Take(3));
            var versionString       = string.IsNullOrEmpty(versionFromCachePath) ? versionFromRegistry : versionFromCachePath;
            var hasAuxVersion       = cachePathMatch.Groups[Regexes.AuxVersionGroupName].Success;
            var footnote            = hasAuxVersion ?
                                      string.Format(LocalizableStrings.HostingBundleFootnoteFormat, displayName, versionString) :
                                      null;

            if (string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(versionString) || string.IsNullOrEmpty(archString))
            {
                version = null;
                arch    = BundleArch.X64 | BundleArch.X86;
                return;
            }

            switch (match.Groups[Regexes.TypeGroupName].Value)
            {
            case "SDK": version = new SdkVersion(versionString); break;

            case "Runtime": version = new RuntimeVersion(versionString); break;

            case "ASP.NET": version = new AspNetRuntimeVersion(versionString); break;

            case "Windows Server Hosting": version = new HostingBundleVersion(versionString, footnote); break;

            default: throw new ArgumentException();
            }

            switch (archString)
            {
            case "x64": arch = BundleArch.X64; break;

            case "x86": arch = BundleArch.X86; break;

            case "": arch = BundleArch.X64 | BundleArch.X86; break;

            default: throw new ArgumentException();
            }
        }
Exemple #8
0
        internal virtual void TestFiltererGood(IEnumerable <Bundle> testBundles, string argValue, IEnumerable <Bundle> expected, BundleType typeSelection, BundleArch archSelection)
        {
            var parseResult = CommandLineConfigs.UninstallRootCommand.Parse($"--{Option.Name} {argValue}");

            OptionFilterer.Filter(parseResult, Option, testBundles, typeSelection, archSelection)
            .Should().BeEquivalentTo(expected);
        }
Exemple #9
0
 internal void TestToString(RuntimeVersion version, BundleArch arch)
 {
     new Bundle <RuntimeVersion>(version, arch, TestUninstallCommand1, TestDisplayName1).ToString()
     .Should().Be($"{version.ToString()} ({arch.ToString().ToLower()})");
 }
Exemple #10
0
        internal void TestConstructorNull(RuntimeVersion version, BundleArch arch, string uninstallCommand, string displayName)
        {
            Action action = () => new Bundle <RuntimeVersion>(version, arch, uninstallCommand, displayName);

            action.Should().Throw <ArgumentNullException>();
        }
Exemple #11
0
        internal override void TestFiltererGood(IEnumerable <Bundle> testBundles, string argValue, IEnumerable <Bundle> expected, BundleType typeSelection, BundleArch archSelection)
        {
            var parseResult = CommandLineConfigs.UninstallRootCommand.Parse($"{argValue}");

            (OptionFilterer as ArgFilterer <IEnumerable <string> >).Filter(
                parseResult.RootCommandResult.Tokens.Select(t => t.Value),
                testBundles,
                typeSelection,
                archSelection)
            .Should().BeEquivalentTo(expected);
        }
Exemple #12
0
        internal override void TestFiltererException <TException>(IEnumerable <Bundle> testBundles, string argValue, BundleType typeSelection, BundleArch archSelection, string errorMessage)
        {
            var    parseResult = CommandLineConfigs.UninstallRootCommand.Parse($"{argValue}");
            Action action      = () => (OptionFilterer as ArgFilterer <IEnumerable <string> >).Filter(
                parseResult.RootCommandResult.Tokens.Select(t => t.Value),
                testBundles,
                typeSelection,
                archSelection);

            action.Should().Throw <TException>(errorMessage);
        }
 internal void TestAllPreviewsButLatestOptionFiltererGood(IEnumerable <Bundle> testBundles, IEnumerable <Bundle> expected, BundleType typeSelection, BundleArch archSelection)
 {
     TestFiltererGood(testBundles, DefaultTestArgValue, expected, typeSelection, archSelection);
 }
 public override Bundle ToBundle(BundleArch arch, string uninstallCommand, string displayName)
 {
     return(new Bundle <AspNetRuntimeVersion>(this, arch, uninstallCommand, displayName));
 }
Exemple #15
0
        public IEnumerable <Bundle> Filter(IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection)
        {
            ValidateTypeSelection(typeSelection);
            ValidateArchSelection(archSelection);

            var filteredBundlesByArch = bundles.Where(bundle => archSelection.HasFlag(bundle.Arch));

            var sdks = Bundle <SdkVersion> .FilterWithSameBundleType(filteredBundlesByArch);

            var runtimes = Bundle <RuntimeVersion> .FilterWithSameBundleType(filteredBundlesByArch);

            var aspNetRuntimes = Bundle <AspNetRuntimeVersion> .FilterWithSameBundleType(filteredBundlesByArch);

            var hostingBundles = Bundle <HostingBundleVersion> .FilterWithSameBundleType(filteredBundlesByArch);

            var filteredSdks = typeSelection.HasFlag(BundleType.Sdk) ?
                               Filter(sdks).OrderBy(sdk => sdk).Select(sdk => sdk as Bundle) :
                               new List <Bundle>();

            var filteredRuntimes = typeSelection.HasFlag(BundleType.Runtime) ?
                                   Filter(runtimes).OrderBy(runtime => runtime).Select(runtime => runtime as Bundle) :
                                   new List <Bundle>();

            var filteredAspNetRuntimes = typeSelection.HasFlag(BundleType.AspNetRuntime) ?
                                         Filter(aspNetRuntimes).OrderBy(aspNetRuntime => aspNetRuntime).Select(aspNetRuntime => aspNetRuntime as Bundle) :
                                         new List <Bundle>();

            var filteredHostingBundles = typeSelection.HasFlag(BundleType.HostingBundle) ?
                                         Filter(hostingBundles).OrderBy(hostingBundle => hostingBundle).Select(hostingBundle => hostingBundle as Bundle) :
                                         new List <Bundle>();

            return(filteredSdks
                   .Concat(filteredRuntimes)
                   .Concat(filteredAspNetRuntimes)
                   .Concat(filteredHostingBundles));
        }
Exemple #16
0
 public override IEnumerable <Bundle> Filter(ParseResult parseResult, Option option, IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection)
 {
     return(Filter(bundles, typeSelection, archSelection));
 }
Exemple #17
0
        public override IEnumerable <Bundle> Filter(ParseResult parseResult, Option option, IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection)
        {
            var argValue = parseResult.ValueForOption <TArg>(option.Name);

            return(Filter(argValue, bundles, typeSelection, archSelection));
        }
Exemple #18
0
        private static void ParseVersionAndArch(string displayName, string bundleCachePath, out BundleVersion version, out BundleArch arch)
        {
            var match          = Regexes.BundleDisplayNameRegex.Match(displayName);
            var cachePathMatch = Regexes.BundleCachePathRegex.Match(bundleCachePath);
            var archString     = cachePathMatch.Groups[Regexes.ArchGroupName].Value ?? string.Empty;
            var versionString  = cachePathMatch.Groups[Regexes.VersionGroupName].Value;
            var hasAuxVersion  = cachePathMatch.Groups[Regexes.AuxVersionGroupName].Success;
            var footnote       = hasAuxVersion ?
                                 string.Format(LocalizableStrings.HostingBundleFootnoteFormat, displayName, versionString) :
                                 null;

            switch (match.Groups[Regexes.TypeGroupName].Value)
            {
            case "SDK": version = new SdkVersion(versionString); break;

            case "Runtime": version = new RuntimeVersion(versionString); break;

            case "ASP.NET": version = new AspNetRuntimeVersion(versionString); break;

            case "Windows Server Hosting": version = new HostingBundleVersion(versionString, footnote); break;

            default: throw new ArgumentException();
            }

            switch (archString)
            {
            case "x64": arch = BundleArch.X64; break;

            case "x86": arch = BundleArch.X86; break;

            case "": arch = BundleArch.X64 | BundleArch.X86; break;

            default: throw new ArgumentException();
            }
        }
Exemple #19
0
 public abstract IEnumerable <Bundle> Filter(ParseResult parseResult, Option option, IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection);
Exemple #20
0
 public abstract Bundle ToBundle(BundleArch arch, string uninstallCommand, string displayName);
Exemple #21
0
 public static Bundle From(BundleVersion version, BundleArch arch, string uninstallCommand, string displayName)
 {
     return(version.ToBundle(arch, uninstallCommand, displayName));
 }
Exemple #22
0
 internal void TestMajorMinorOptionFiltererGood(IEnumerable <Bundle> testBundles, string argValue, IEnumerable <Bundle> expected, BundleType typeSelection, BundleArch archSelection)
 {
     TestFiltererGood(testBundles, argValue, expected, typeSelection, archSelection);
 }
Exemple #23
0
 internal void TestNoOptionFiltererSpecifiedVersionNotFoundException(string argValue, BundleType typeSelection, BundleArch archSelection)
 {
     TestFiltererException <SpecifiedVersionNotFoundException>(DefaultTestBundles, argValue, typeSelection, archSelection, string.Format(LocalizableStrings.SpecifiedVersionNotFoundExceptionMessageFormat, argValue));
 }