/// <summary>
        /// Compares facts by priority facts in parameters.
        /// </summary>
        /// <param name="x">Fist fact.</param>
        /// <param name="y">Second fact.</param>
        /// <returns>
        /// 1 - <paramref name="x"/> fact is greater than the <paramref name="y"/>,
        /// 0 - <paramref name="x"/> fact is equal than the <paramref name="y"/>,
        /// -1 - <paramref name="x"/> fact is less than the <paramref name="y"/>.
        /// </returns>
        public static int CompareByPriorityParameter(this IFact x, IFact y)
        {
            var xPriority = x.GetParameter(PriorityFactParametersCodes.Priority)?.Value as IPriorityFact;
            var yPriority = y.GetParameter(PriorityFactParametersCodes.Priority)?.Value as IPriorityFact;

            if (xPriority == null)
            {
                return(yPriority != null ? -1 : 0);
            }
            if (yPriority == null)
            {
                return(1);
            }

            return(xPriority.CompareTo(yPriority));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compares facts by version facts in parameters.
        /// </summary>
        /// <param name="x">Fist fact.</param>
        /// <param name="y">Second fact.</param>
        /// <returns>
        /// 1 - <paramref name="x"/> fact is greater than the <paramref name="y"/>,
        /// 0 - <paramref name="x"/> fact is equal than the <paramref name="y"/>,
        /// -1 - <paramref name="x"/> fact is less than the <paramref name="y"/>.
        /// </returns>
        public static int CompareByVersionParameter(this IFact x, IFact y)
        {
            var xVersion = x.GetParameter(VersionedFactParametersCodes.Version)?.Value as IVersionFact;
            var yVersion = y.GetParameter(VersionedFactParametersCodes.Version)?.Value as IVersionFact;

            if (xVersion == null)
            {
                return(yVersion == null ? 0 : 1);
            }
            if (yVersion == null)
            {
                return(-1);
            }

            return(xVersion.CompareTo(yVersion));
        }