//--------------------// #region Normalize /// <summary> /// Sets missing default values and handles legacy elements. /// </summary> /// <param name="feedUri">The feed the data was originally loaded from; can be <see langword="null"/>.</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 = null) { 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 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); } // Parse manifest digest from ID if missing if (!string.IsNullOrEmpty(ID)) { _manifestDigest.ParseID(ID); } }
/// <summary> /// Creates a version range matching exactly one version. /// </summary> /// <param name="version">The exact version to match.</param> public VersionRange([NotNull] ImplementationVersion version) { #region Sanity checks if (version == null) { throw new ArgumentNullException(nameof(version)); } #endregion _parts = new VersionRangePart[] { new VersionRangeExact(version) }; }
public override bool Match(ImplementationVersion version) { #region Sanity checks if (version == null) { throw new ArgumentNullException("version"); } #endregion return(!_version.Equals(version)); }
public VersionRangeExclude(ImplementationVersion version) { #region Sanity checks if (version == null) { throw new ArgumentNullException("version"); } #endregion _version = version; }
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}"); }
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); } }
/// <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); } }
/// <summary> /// Determines whether a specific version lies within this range. /// </summary> public bool Match(ImplementationVersion version) { #region Sanity checks if (version == null) { throw new ArgumentNullException(nameof(version)); } #endregion if (_parts.Length == 0) { return(true); } return(_parts.Any(part => part.Match(version))); }
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 TestTryCreate() { var validVersions = new[] { "0.1", "1", "1.0", "1.1", "1.1-", "1.2-pre", "1.2-pre1", "1.2-rc1", "1.2", "1.2-0", "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" }; foreach (string version in validVersions) { ImplementationVersion result; ImplementationVersion.TryCreate(version, out result).Should().BeTrue(because: version); result.ToString().Should().Be(version); } var invalidVersions = new[] { "", "a", "pre-1", "1.0-1post" }; foreach (string version in invalidVersions) { ImplementationVersion result; ImplementationVersion.TryCreate(version, out result).Should().BeFalse(because: version); } }
public static VersionRangePart FromString([NotNull] string value) { #region Sanity checks if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("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 single interval version range. /// </summary> /// <param name="notBefore">The lower, inclusive border of the range; can be <c>null</c>.</param> /// <param name="before">The upper, exclusive border of the range; can be <c>null</c>.</param> public VersionRange([CanBeNull] ImplementationVersion notBefore, [CanBeNull] ImplementationVersion before) { _parts = new VersionRangePart[] { new VersionRangeRange(notBefore, before) }; }
/// <summary> /// Determines whether a specific version lies within this range. /// </summary> public abstract bool Match([NotNull] ImplementationVersion version);
public VersionRangeRange(ImplementationVersion startVersion, ImplementationVersion endVersion) { _startVersion = startVersion; _endVersion = endVersion; }