예제 #1
0
 public BlackboardConstraint()
 {
     m_firstValue          = new MemoryVar();
     m_secondValue         = new MemoryVar();
     m_valueType           = ConditionValueType.Boolean;
     m_booleanComparison   = BooleanComparison.IsTrue;
     m_numericComparison   = NumericComparison.Equal;
     m_referenceComparison = ReferenceComparison.IsNotNull;
 }
예제 #2
0
파일: QueryBuilder.cs 프로젝트: Jusas/sd2
        public Expression <Func <TSourceType, bool> > NumericValueComparison <TSourceType>(string propertyName, NumericComparison comparison, double value)
        {
            var        expTargetValue = Expression.Constant(value);
            var        expParameter   = Expression.Parameter(typeof(TSourceType), "x");
            Expression expGetProperty = Expression.PropertyOrField(expParameter, propertyName);

            Expression body = null;

            switch (comparison)
            {
            case NumericComparison.Eq:
                body = Expression.Equal(expGetProperty, expTargetValue);
                break;

            case NumericComparison.Gt:
                body = Expression.GreaterThan(expGetProperty, expTargetValue);
                break;

            case NumericComparison.Gte:
                body = Expression.GreaterThanOrEqual(expGetProperty, expTargetValue);
                break;

            case NumericComparison.Lt:
                body = Expression.LessThan(expGetProperty, expTargetValue);
                break;

            case NumericComparison.Lte:
                body = Expression.LessThanOrEqual(expGetProperty, expTargetValue);
                break;
            }

            var lambda = Expression.Lambda <Func <TSourceType, bool> >(body, expParameter);

            return(lambda);
        }
예제 #3
0
        /// <summary>
        /// Does a comparison with the given operator to a numeric FITS keyword value.
        /// </summary>
        /// <param name="fitsKeyword"></param>
        /// <param name="value"></param>
        /// <param name="comparison"></param>
        /// <returns></returns>
        public IFitsQueryExpression NumericValueComparison(string fitsKeyword, double value,
                                                           NumericComparison comparison)
        {
            var exprParamType      = typeof(FitsSearchResult);
            var headerType         = typeof(FitsHeaderIndexedRow);
            var headerKeywordProps = headerType.GetProperties().Where(p => p.HasAttribute <FitsFieldAttribute>());
            var matchingProp       = headerKeywordProps.FirstOrDefault(p =>
                                                                       p.GetCustomAttribute <FitsFieldAttribute>().Name == fitsKeyword);

            if (matchingProp == null)
            {
                throw new FitsDatabaseException($"Cannot add keyword matching for keyword '{fitsKeyword}' to the query, " +
                                                $"this keyword doesn't exist in the indexed keywords");
            }

            if (matchingProp.PropertyType != typeof(double))
            {
                throw new FitsDatabaseException($"Cannot add keyword matching for keyword '{fitsKeyword}' to the query, " +
                                                $"the given value is not of type '{matchingProp.PropertyType.Name}'");
            }

            var        targetValue = Expression.Constant(value);
            var        parameter   = Expression.Parameter(exprParamType, "x");
            Expression property    = Expression.PropertyOrField(parameter, nameof(FitsSearchResult.HeaderData));

            property = Expression.PropertyOrField(property, matchingProp.Name);

            Expression body = null;

            switch (comparison)
            {
            case NumericComparison.Eq:
                body = Expression.Equal(property, targetValue);
                break;

            case NumericComparison.Gt:
                body = Expression.GreaterThan(property, targetValue);
                break;

            case NumericComparison.Gte:
                body = Expression.GreaterThanOrEqual(property, targetValue);
                break;

            case NumericComparison.Lt:
                body = Expression.LessThan(property, targetValue);
                break;

            case NumericComparison.Lte:
                body = Expression.LessThanOrEqual(property, targetValue);
                break;
            }

            var lambda = Expression.Lambda <Func <FitsSearchResult, bool> >(body, parameter);

            var expr = new FitsQueryExpression()
            {
                Expression = lambda
            };

            return(expr);
        }