/// <inheritdoc/> public override int CompareTo(IVersionFact other) { switch (other) { case VersionBase <int> version: return(VersionValue.CompareTo(version.VersionValue)); case VersionBase <long> version: return(VersionValue.CompareTo(version.VersionValue)); case VersionBase <uint> version: return(VersionValue.CompareTo(version.VersionValue)); case VersionBase <ulong> version: return(VersionValue.CompareTo(version.VersionValue)); case FactBase <int> version: return(VersionValue.CompareTo(version.Value)); case FactBase <long> version: return(VersionValue.CompareTo(version.Value)); case FactBase <uint> version: return(VersionValue.CompareTo(version.Value)); case FactBase <ulong> version: return(VersionValue.CompareTo(version.Value)); default: throw CreateIncompatibilityVersionException(other); } }
/// <summary> /// Checks the value of the version of the <paramref name="fact"/>. /// </summary> /// <typeparam name="TFact">Type fact.</typeparam> /// <param name="fact">Fact.</param> /// <param name="version">Version fact.</param> /// <returns>Does the version match the fact of the <paramref name="version"/>?</returns> public static bool HasVersionParameter <TFact>(this TFact fact, IVersionFact version) where TFact : IFact { var factVersion = fact.FindVersionParameter(); if (version == null) { return(factVersion == null); } if (factVersion == null) { return(false); } return(version.CompareTo(factVersion) == 0); }
/// <inheritdoc/> public override int CompareTo(IVersionFact other) { switch (other) { case MajorMinorPatchVersionBase version: return(_version.CompareTo(version._version)); case FactBase <string> version: string pattern = @"^(\*|\d+(\.\d+){0,2}(\.\*)?)$"; if (!Regex.IsMatch(version.Value, pattern)) { throw new ArgumentException($"{version} version doesn't match regular expression <{pattern}>."); } return(_version.CompareTo(new Version(version.Value))); default: throw CreateIncompatibilityVersionException(other); } }
/// <summary> /// Checks if a fact contains a valid version. /// </summary> /// <typeparam name="TFact">Type fact.</typeparam> /// <param name="fact">Fact.</param> /// <param name="maxVersion">Max version (optional).</param> /// <returns>Whether the version of the fact is within the valid versions?</returns> public static bool IsRelevantFactByVersioned <TFact>(this TFact fact, IVersionFact maxVersion) where TFact : IFact { if (maxVersion == null || !fact.IsCalculatedByRule()) { return(true); } var value = fact.GetParameter(VersionedFactParametersCodes.Version)?.Value; if (value == null) { return(false); } if (value is IVersionFact factVersion) { return(maxVersion.CompareTo(factVersion) >= 0); } return(false); }
/// <summary> /// Compares rules based on version facts. /// </summary> /// <typeparam name="TFactRule">Type rule.</typeparam> /// <typeparam name="TWantAction">Type wantAction.</typeparam> /// <typeparam name="TFactContainer">Type fact container.</typeparam> /// <param name="x">First rule.</param> /// <param name="y">Second rule.</param> /// <param name="context">Context.</param> /// <returns> /// 1 - <paramref name="x"/> rule is greater than the <paramref name="y"/>, /// 0 - <paramref name="x"/> rule is equal than the <paramref name="y"/>, /// -1 - <paramref name="x"/> rule is less than the <paramref name="y"/>. /// </returns> public static int CompareByVersion <TFactRule, TWantAction, TFactContainer>(this TFactRule x, TFactRule y, IWantActionContext <TWantAction, TFactContainer> context) where TFactRule : IFactRule where TWantAction : IWantAction where TFactContainer : IFactContainer { var xVersionType = x.InputFactTypes?.SingleOrDefault(type => type.IsFactType <IVersionFact>()); var yVersionType = y.InputFactTypes?.SingleOrDefault(type => type.IsFactType <IVersionFact>()); if (xVersionType == null) { return(yVersionType == null ? 0 : 1); } if (yVersionType == null) { return(-1); } IVersionFact xVersion = context.Container.FirstVersionFactByFactType(xVersionType, context.Cache); IVersionFact yVersion = context.Container.FirstVersionFactByFactType(yVersionType, context.Cache); return(xVersion.CompareTo(yVersion)); }
public static TFact SetVersionParam <TFact>(this TFact fact, IVersionFact version) where TFact : IFact { fact.AddParameter(new FactParameter(VersionedFactParametersCodes.Version, version)); return(fact); }
/// <summary> /// Adds a version fact to parameters. /// </summary> /// <param name="fact">Fact.</param> /// <param name="version">Verion fact.</param> /// <returns><paramref name="fact"/>.</returns> public static IFact AddVerionParameter(this IFact fact, IVersionFact version) { fact.AddParameter(new FactParameter(VersionedFactParametersCodes.Version, version)); return(fact); }
internal static bool CompatibleRule <TFactRule, TWantAction, TFactContainer>(this TFactRule factRule, IVersionFact maxVersion, IWantActionContext <TWantAction, TFactContainer> context) where TFactRule : IFactRule where TWantAction : IWantAction where TFactContainer : IFactContainer { var version = factRule.InputFactTypes.GetVersionFact(context); if (version == null) { return(false); } return(maxVersion.CompareTo(version) >= 0); }
/// <summary> /// Compares the version fact to the <paramref name="other"/>. /// </summary> /// <param name="other">Version fact for comparison</param> /// <returns>1 - more, 0 - equal, -1 less.</returns> public abstract int CompareTo(IVersionFact other);
/// <summary> /// Error creating version incompatibility. /// </summary> /// <param name="versionedFact"></param> /// <returns></returns> protected virtual FactFactoryException CreateIncompatibilityVersionException(IVersionFact versionedFact) { return(CommonHelper.CreateException(ErrorCode.InvalidFactType, $"Unable to compare versions {GetFactType().FactName} and {versionedFact.GetFactType().FactName}.")); }