public void FindPackage([NotNull] string name, [CanBeNull] ImplementationVersion requiredVersion, [CanBeNull] ImplementationVersion minimumVersion, [CanBeNull] ImplementationVersion maximumVersion) { FeedManager.Refresh = Refresh; VersionRange versionRange; if (requiredVersion != null) { versionRange = new VersionRange(requiredVersion); } else if (minimumVersion != null || maximumVersion != null) { versionRange = new VersionRange(minimumVersion, maximumVersion); } else { versionRange = null; } if (SearchMirror) { MirrorSearch(name, versionRange); } else { CatalogSearch(name, versionRange); } }
public ExternalSolverSession(ProcessStartInfo startInfo) { _process = startInfo.Start(); Debug.Assert(_process != null); _stdin = _process.StandardInput.BaseStream; _stdout = _process.StandardOutput.BaseStream; _stderr = new StreamConsumer(_process.StandardError); var apiNotification = GetJsonChunk(); if (apiNotification == null || apiNotification[0].ToString() != "invoke" || apiNotification[1] != null || apiNotification[2].ToString() != "set-api-version") { throw new IOException("External solver did not respond correctly to handshake."); } var apiVersion = new ImplementationVersion(apiNotification[3].ReparseAsJson <string[]>()[0]); if (apiVersion >= new ImplementationVersion(ApiVersion)) { Log.Debug("Agreed on 0install slave API version " + apiVersion); } else { throw new IOException("Failed to agree on slave API version. External solver insisted on: " + apiVersion); } }
public static VersionRangePart FromString([NotNull] string value) { #region Sanity checks if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value)); #endregion if (value.Contains("..")) { string start = value.GetLeftPartAtFirstOccurrence(".."); var startVersion = string.IsNullOrEmpty(start) ? null : new ImplementationVersion(start); ImplementationVersion endVersion; string end = value.GetRightPartAtFirstOccurrence(".."); if (string.IsNullOrEmpty(end)) endVersion = null; else { if (!end.StartsWith("!")) throw new FormatException(string.Format(Resources.VersionRangeEndNotExclusive, end)); endVersion = new ImplementationVersion(end.Substring(1)); } return new VersionRangeRange(startVersion, endVersion); } else if (value.StartsWith("!")) { return new VersionRangeExclude( new ImplementationVersion(value.Substring(1))); } else { return new VersionRangeExact( new ImplementationVersion(value)); } }
/// <summary> /// Creates a new external implementation. /// </summary> /// <param name="distribution">The name of the distribution (e.g. Debian, RPM) where this implementation comes from.</param> /// <param name="package">The name of the package in the <paramref name="distribution"/>.</param> /// <param name="version">The version number of the implementation.</param> /// <param name="cpu">For platform-specific binaries, the CPU architecture for which the implementation was compiled.</param> public ExternalImplementation(string distribution, string package, ImplementationVersion version, Cpu cpu = Cpu.All) { #region Sanity checks if (string.IsNullOrEmpty(distribution)) { throw new ArgumentNullException(nameof(distribution)); } if (string.IsNullOrEmpty(package)) { throw new ArgumentNullException(nameof(package)); } if (version == null) { throw new ArgumentNullException(nameof(version)); } #endregion ID = PackagePrefix + distribution.ToLowerInvariant() + ":" + package + ":" + version; Version = version; Stability = Stability.Packaged; Distribution = distribution; Package = package; if (cpu != Cpu.All) { ID += ":" + cpu.ConvertToString(); Architecture = new Architecture(OS.All, cpu); } }
public VersionRangeExact(ImplementationVersion version) { #region Sanity checks if (version == null) throw new ArgumentNullException("version"); #endregion _version = version; }
public override bool Match(ImplementationVersion version) { #region Sanity checks if (version == null) throw new ArgumentNullException("version"); #endregion return _version.Equals(version); }
private bool UpdateFound() { var currentVersion = new ImplementationVersion(AppInfo.Current.Version); var newVersion = Selections.Implementations[0].Version; bool updatesFound = newVersion > currentVersion || _force; return(updatesFound); }
/// <inheritdoc/> public override bool Match(ImplementationVersion version) { if (version == null) { throw new ArgumentNullException(nameof(version)); } return((LowerInclusive == null || version >= LowerInclusive) && (UpperExclusive == null || version < UpperExclusive)); }
public void TestTemplateVariable() { var version = new ImplementationVersion("1-pre{var}"); Assert.IsTrue(version.ContainsTemplateVariables); Assert.AreEqual("1-pre{var}", version.ToString()); version = new ImplementationVersion("{var}"); Assert.IsTrue(version.ContainsTemplateVariables); Assert.AreEqual("{var}", version.ToString()); }
public void TestTemplateVariable() { var version = new ImplementationVersion("1-pre{var}"); version.ContainsTemplateVariables.Should().BeTrue(); version.ToString().Should().Be("1-pre{var}"); version = new ImplementationVersion("{var}"); version.ContainsTemplateVariables.Should().BeTrue(); version.ToString().Should().Be("{var}"); }
private static bool Match(Requirements requirements, ImplementationVersion version) { VersionRange range; if (!requirements.ExtraRestrictions.TryGetValue(requirements.InterfaceUri, out range)) { return(true); } return(range.Match(version)); }
public void TemplateVariable() { var version = new ImplementationVersion("1-pre{var}"); version.ContainsTemplateVariables.Should().BeTrue(); version.ToString().Should().Be("1-pre{var}"); version = new ImplementationVersion("{var}"); version.ContainsTemplateVariables.Should().BeTrue(); version.ToString().Should().Be("{var}"); }
public void TestSort() { var sortedVersions = new[] {"0.1", "1", "1.0", "1.1", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "1.2-post", "1.2-post1-pre", "1.2-post1", "1.2.1-pre", "1.2.1.4", "1.2.2", "1.2.10", "3"}; for (int i = 0; i < sortedVersions.Length - 1; i++) { var v1 = new ImplementationVersion(sortedVersions[i]); var v2 = new ImplementationVersion(sortedVersions[i + 1]); Assert.That(v1, Is.LessThan(v2)); Assert.That(v2, Is.GreaterThan(v1)); } }
public void Sort() { var sortedVersions = new[] { "0.1", "1", "1.0", "1.1", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "1.2-post", "1.2-post1-pre", "1.2-post1", "1.2.1-pre", "1.2.1.4", "1.2.3", "1.2.10", "3" }; for (int i = 0; i < sortedVersions.Length - 1; i++) { var v1 = new ImplementationVersion(sortedVersions[i]); var v2 = new ImplementationVersion(sortedVersions[i + 1]); v1.Should().BeLessThan(v2); v2.Should().BeGreaterThan(v1); } }
public static ImplementationVersion SilentCheck() { var services = new ServiceLocator(new SilentTaskHandler()) {FeedManager = {Refresh = true}}; if (services.Config.NetworkUse == NetworkLevel.Offline) return null; // Run solver var requirements = new Requirements(services.Config.SelfUpdateUri); var selections = services.Solver.Solve(requirements); // Report version of current update if it is newer than the already installed version var currentVersion = new ImplementationVersion(AppInfo.CurrentLibrary.Version); var newVersion = selections.MainImplementation.Version; return (newVersion > currentVersion) ? newVersion : null; }
private void Parse(FileVersionInfo versionInfo) { Name = versionInfo.ProductName; Summary = string.IsNullOrEmpty(versionInfo.Comments) ? versionInfo.FileDescription : versionInfo.Comments; if (!string.IsNullOrEmpty(versionInfo.ProductVersion)) { try { Version = new ImplementationVersion(versionInfo.ProductVersion.Trim()); } catch (FormatException) {} } }
public static ImplementationVersion SilentCheck() { var services = new ServiceLocator(new SilentTaskHandler()) { FeedManager = { Refresh = true } }; if (services.Config.NetworkUse == NetworkLevel.Offline) { return(null); } // Run solver var requirements = new Requirements(services.Config.SelfUpdateUri, command: "update"); var selections = services.Solver.Solve(requirements); // Report version of current update if it is newer than the already installed version var currentVersion = new ImplementationVersion(AppInfo.Current.Version); var newVersion = selections.Implementations[0].Version; return((newVersion > currentVersion) ? newVersion : null); }
// Uses detection logic described here: http://msdn.microsoft.com/library/hh925568 private IEnumerable <ExternalImplementation> FindNetFx(ImplementationVersion version, string clrVersion, string registryVersion, int releaseNumber = 0) { // Check for system native architecture (may be 32-bit or 64-bit) int install = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Install"); int release = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Release"); if (install == 1 && release >= releaseNumber) { yield return(new ExternalImplementation(DistributionName, "netfx", version, Architecture.CurrentSystem.Cpu) { // .NET executables do not need a runner on Windows Commands = { new Command { Name = Command.NameRun, Path = "" } }, IsInstalled = true, QuickTestFile = Path.Combine(WindowsUtils.GetNetFxDirectory(clrVersion), "mscorlib.dll") }); } // Check for 32-bit on a 64-bit system if (WindowsUtils.Is64BitProcess) { install = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Install"); release = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Release"); if (install == 1 && release >= releaseNumber) { yield return(new ExternalImplementation(DistributionName, "netfx", version, Cpu.I486) { // .NET executables do not need a runner on Windows Commands = { new Command { Name = Command.NameRun, Path = "" } }, IsInstalled = true, QuickTestFile = Path.Combine(WindowsUtils.GetNetFxDirectory(clrVersion), "mscorlib.dll") }); } } }
/// <summary> /// Sets missing default values and handles legacy elements. /// </summary> /// <param name="feedUri">The feed the data was originally loaded from.</param> /// <remarks>This method should be called to prepare a <see cref="Feed"/> for solver processing. Do not call it if you plan on serializing the feed again since it may loose some of its structure.</remarks> public override void Normalize(FeedUri feedUri) { #region Sanity checks if (feedUri == null) throw new ArgumentNullException(nameof(feedUri)); #endregion base.Normalize(feedUri); // Merge the version modifier into the normal version attribute if (!string.IsNullOrEmpty(VersionModifier)) { Version = new ImplementationVersion(Version + VersionModifier); VersionModifier = null; } // Default stability rating to testing if (Stability == Stability.Unset) Stability = Stability.Testing; // Make local paths absolute try { if (!string.IsNullOrEmpty(LocalPath)) LocalPath = ModelUtils.GetAbsolutePath(LocalPath, feedUri); else if (!string.IsNullOrEmpty(ID) && ID.StartsWith(".")) // Get local path from ID LocalPath = ID = ModelUtils.GetAbsolutePath(ID, feedUri); } #region Error handling catch (UriFormatException ex) { Log.Error(ex); LocalPath = null; } #endregion // Parse manifest digest from ID if missing if (!string.IsNullOrEmpty(ID)) _manifestDigest.ParseID(ID); }
/// <inheritdoc/> public Selection([NotNull] ICommandHandler handler) : base(handler) { Options.Add("customize", () => Resources.OptionCustomize, _ => CustomizeSelections = true); Options.Add("o|offline", () => Resources.OptionOffline, _ => Config.NetworkUse = NetworkLevel.Offline); Options.Add("r|refresh", () => Resources.OptionRefresh, _ => FeedManager.Refresh = true); Options.Add("with-store=", () => Resources.OptionWithStore, delegate(string path) { if (string.IsNullOrEmpty(path)) { throw new OptionException(string.Format(Resources.MissingOptionValue, "--with-store"), "with-store"); } Store = new CompositeStore(new[] { new DirectoryStore(path), Store }); }); Options.Add("command=", () => Resources.OptionCommand, command => Requirements.Command = command); Options.Add("before=", () => Resources.OptionBefore, (ImplementationVersion version) => _before = version); Options.Add("not-before=", () => Resources.OptionNotBefore, (ImplementationVersion version) => _notBefore = version); Options.Add("version=", () => Resources.OptionVersionRange, (VersionRange range) => _version = range); Options.Add("version-for==", () => Resources.OptionVersionRangeFor, (FeedUri interfaceUri, VersionRange range) => Requirements.ExtraRestrictions[interfaceUri] = range); Options.Add("s|source", () => Resources.OptionSource, _ => Requirements.Source = true); Options.Add("os=", () => Resources.OptionOS + Environment.NewLine + SupportedValues <OS>(), (OS os) => Requirements.Architecture = new Architecture(os, Requirements.Architecture.Cpu)); Options.Add("cpu=", () => Resources.OptionCpu + Environment.NewLine + SupportedValues <Cpu>(), (Cpu cpu) => Requirements.Architecture = new Architecture(Requirements.Architecture.OS, cpu)); Options.Add("language=", () => Resources.OptionLanguage, (CultureInfo lang) => Requirements.Languages.Add(lang)); Options.Add("xml", () => Resources.OptionXml, _ => ShowXml = true); }
/// <inheritdoc/> public Selection([NotNull] ICommandHandler handler) : base(handler) { Requirements = new Requirements(); Options.Add("customize", () => Resources.OptionCustomize, _ => CustomizeSelections = true); Options.Add("o|offline", () => Resources.OptionOffline, _ => Config.NetworkUse = NetworkLevel.Offline); Options.Add("r|refresh", () => Resources.OptionRefresh, _ => FeedManager.Refresh = true); Options.Add("with-store=", () => Resources.OptionWithStore, delegate(string path) { if (string.IsNullOrEmpty(path)) throw new OptionException(string.Format(Resources.MissingOptionValue, "--with-store"), "with-store"); Store = new CompositeStore(new[] {new DirectoryStore(path), Store}); }); Options.Add("command=", () => Resources.OptionCommand, command => Requirements.Command = command); Options.Add("before=", () => Resources.OptionBefore, (ImplementationVersion version) => _before = version); Options.Add("not-before=", () => Resources.OptionNotBefore, (ImplementationVersion version) => _notBefore = version); Options.Add("version=", () => Resources.OptionVersionRange, (VersionRange range) => _version = range); Options.Add("version-for==", () => Resources.OptionVersionRangeFor, (FeedUri interfaceUri, VersionRange range) => Requirements.ExtraRestrictions[interfaceUri] = range); Options.Add("s|source", () => Resources.OptionSource, _ => Requirements.Source = true); Options.Add("os=", () => Resources.OptionOS + "\n" + SupportedValues(Architecture.KnownOS), (OS os) => Requirements.Architecture = new Architecture(os, Requirements.Architecture.Cpu)); Options.Add("cpu=", () => Resources.OptionCpu + "\n" + SupportedValues(Architecture.KnownCpu), (Cpu cpu) => Requirements.Architecture = new Architecture(Requirements.Architecture.OS, cpu)); Options.Add("language=", () => Resources.OptionLanguage, (CultureInfo lang) => Requirements.Languages.Add(lang)); Options.Add("xml", () => Resources.OptionXml, _ => ShowXml = true); }
private bool UpdateFound() { var currentVersion = new ImplementationVersion(AppInfo.Current.Version); var newVersion = Selections.Implementations[0].Version; bool updatesFound = newVersion > currentVersion || _force; return updatesFound; }
public void TestTryCreateValid(string version) { ImplementationVersion.TryCreate(version, out var result).Should().BeTrue(); result !.ToString().Should().Be(version); }
public void TestTryCreateInvalid(string version) => ImplementationVersion.TryCreate(version, out _).Should().BeFalse();
public VersionRangeRange(ImplementationVersion startVersion, ImplementationVersion endVersion) { _startVersion = startVersion; _endVersion = endVersion; }
public override bool Match(ImplementationVersion version) { #region Sanity checks if (version == null) throw new ArgumentNullException("version"); #endregion if (_startVersion != null && version < _startVersion) return false; if (_endVersion != null && version >= _endVersion) return false; return true; }
public void TestSort() { var sortedVersions = new[] {"0.1", "1", "1.0", "1.1", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "1.2-post", "1.2-post1-pre", "1.2-post1", "1.2.1-pre", "1.2.1.4", "1.2.3", "1.2.10", "3"}; for (int i = 0; i < sortedVersions.Length - 1; i++) { var v1 = new ImplementationVersion(sortedVersions[i]); var v2 = new ImplementationVersion(sortedVersions[i + 1]); v1.Should().BeLessThan(v2); v2.Should().BeGreaterThan(v1); } }
// Uses detection logic described here: http://msdn.microsoft.com/library/hh925568 private IEnumerable<ExternalImplementation> FindNetFx(ImplementationVersion version, string clrVersion, string registryVersion, int releaseNumber = 0) { // Check for system native architecture (may be 32-bit or 64-bit) int install = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Install"); int release = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Release"); if (install == 1 && release >= releaseNumber) { yield return new ExternalImplementation(DistributionName, "netfx", version, Architecture.CurrentSystem.Cpu) { // .NET executables do not need a runner on Windows Commands = {new Command {Name = Command.NameRun, Path = ""}}, IsInstalled = true, QuickTestFile = Path.Combine(WindowsUtils.GetNetFxDirectory(clrVersion), "mscorlib.dll") }; } // Check for 32-bit on a 64-bit system if (WindowsUtils.Is64BitProcess) { install = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Install"); release = RegistryUtils.GetDword(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\" + registryVersion, "Release"); if (install == 1 && release >= releaseNumber) { yield return new ExternalImplementation(DistributionName, "netfx", version, Cpu.I486) { // .NET executables do not need a runner on Windows Commands = {new Command {Name = Command.NameRun, Path = ""}}, IsInstalled = true, QuickTestFile = Path.Combine(WindowsUtils.GetNetFxDirectory(clrVersion), "mscorlib.dll") }; } } }
/// <inheritdoc/> public override bool Match(ImplementationVersion version) => Version.Equals(version ?? throw new ArgumentNullException(nameof(version)));