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(); } }
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); }
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; }
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())))); }
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); }
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(); } }
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); }
internal void TestToString(RuntimeVersion version, BundleArch arch) { new Bundle <RuntimeVersion>(version, arch, TestUninstallCommand1, TestDisplayName1).ToString() .Should().Be($"{version.ToString()} ({arch.ToString().ToLower()})"); }
internal void TestConstructorNull(RuntimeVersion version, BundleArch arch, string uninstallCommand, string displayName) { Action action = () => new Bundle <RuntimeVersion>(version, arch, uninstallCommand, displayName); action.Should().Throw <ArgumentNullException>(); }
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); }
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)); }
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)); }
public override IEnumerable <Bundle> Filter(ParseResult parseResult, Option option, IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection) { return(Filter(bundles, typeSelection, archSelection)); }
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)); }
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(); } }
public abstract IEnumerable <Bundle> Filter(ParseResult parseResult, Option option, IEnumerable <Bundle> bundles, BundleType typeSelection, BundleArch archSelection);
public abstract Bundle ToBundle(BundleArch arch, string uninstallCommand, string displayName);
public static Bundle From(BundleVersion version, BundleArch arch, string uninstallCommand, string displayName) { return(version.ToBundle(arch, uninstallCommand, displayName)); }
internal void TestMajorMinorOptionFiltererGood(IEnumerable <Bundle> testBundles, string argValue, IEnumerable <Bundle> expected, BundleType typeSelection, BundleArch archSelection) { TestFiltererGood(testBundles, argValue, expected, typeSelection, archSelection); }
internal void TestNoOptionFiltererSpecifiedVersionNotFoundException(string argValue, BundleType typeSelection, BundleArch archSelection) { TestFiltererException <SpecifiedVersionNotFoundException>(DefaultTestBundles, argValue, typeSelection, archSelection, string.Format(LocalizableStrings.SpecifiedVersionNotFoundExceptionMessageFormat, argValue)); }