예제 #1
0
        /// <inheritdoc />
        protected override IProjection ProjectCore
        (
            MethodCallExpression expression,
            Expression subExpression,
            IProjection projection,
            HelperContext context
        )
        {
            int digits = 0;

            if (expression.Arguments.Count >= 2 && expression.Arguments[1].Type == typeof(int))
            {
                digits = ExpressionHelper.GetValue <int>(expression.Arguments[1]);
            }

            IType numberType;

            if (expression.Method.ReturnType == typeof(decimal))
            {
                numberType = NHibernateUtil.Decimal;
            }
            else
            {
                numberType = NHibernateUtil.Double;
            }

            return(new SqlFunctionProjection
                   (
                       "round",
                       numberType,
                       projection,
                       Projections.Constant(digits)
                   ));
        }
예제 #2
0
        /// <summary>将Java的毫秒数转化为时间 </summary>
        /// <param name="milliseconds">毫秒数</param>
        /// <returns>结果</returns>
        public ContentResult GetTimeByJava(string milliseconds)
        {
            var      ss   = TypeParse.ToLong(milliseconds, 0);
            DateTime time = HelperContext.GetTimeByJavaMilliseconds(ss);

            return(Content(time.ToString()));
        }
        public bool CanHandleProjectionOf(Expression expression, HelperContext context)
        {
            var methodCall = expression as MethodCallExpression;

            return(methodCall != null &&
                   methodCall.Method.Name == "ToString");
        }
예제 #4
0
        public ContentResult GetTimeByStamp(string milliseconds)
        {
            var      ss   = TypeParse.ToLong(milliseconds, 0);
            DateTime time = HelperContext.ConvertTimestamp(ss);

            return(Content(time.ToString()));
        }
예제 #5
0
        /// <inheritdoc />
        protected override IProjection ProjectCore
        (
            MethodCallExpression expression,
            Expression subExpression,
            IProjection projection,
            HelperContext context
        )
        {
            object value = ExpressionHelper.GetValue(expression.Arguments[0]);

            var criteria = value as DetachedCriteria;

            if (criteria == null)
            {
                var query = value as IDetachedImmutableFlowQuery;

                if (query != null)
                {
                    criteria = query.Criteria;
                }
            }

            if (criteria != null)
            {
                return(Projections.SubQuery(criteria));
            }

            return(null);
        }
 /// <summary>
 ///     Handles the given <see cref="MethodCallExpression" />.
 /// </summary>
 /// <param name="expression">
 ///     The <see cref="MethodCallExpression" />.
 /// </param>
 /// <param name="subExpression">
 ///     The sub-expression (normally the first argument of the method call or the property on
 ///     which the call was made).
 /// </param>
 /// <param name="projection">
 ///     The projection for the sub-expression (normally the first argument of the method call or the property on
 ///     which the call was made).
 /// </param>
 /// <param name="context">
 ///     The helper context.
 /// </param>
 /// <returns>
 ///     The <see cref="IProjection" /> or null if no <see cref="IProjection" /> could be resolved.
 /// </returns>
 protected abstract IProjection ProjectCore
 (
     MethodCallExpression expression,
     Expression subExpression,
     IProjection projection,
     HelperContext context
 );
예제 #7
0
 public bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(true);
 }
예제 #8
0
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(SupportedExpressionTypes.Contains(expression.NodeType));
 }
예제 #9
0
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(expression is LambdaExpression);
 }
예제 #10
0
 /// <inheritdoc />
 public override IProjection Project
 (
     Expression expression,
     HelperContext context
 )
 {
     return(ProjectionHelper.GetProjection(((LambdaExpression)expression).Body, context));
 }
 private static async Task SaveDecisionAsync(Decision decision)
 {
     using (HelperContext helperContext = new HelperContext())
     {
         helperContext.Decisions.Add(decision);
         await helperContext.SaveChangesAsync();
     }
 }
예제 #12
0
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(expression.NodeType == ExpressionType.Convert);
 }
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(expression.NodeType == ExpressionType.Add &&
            expression.Type == typeof(string));
 }
예제 #14
0
        public List<Parameter> GetParameters(object obj)
        {
            var context = new HelperContext();

            return obj.GetType().GetProperties()
                .Where(ShouldBeIncluded)
                .Select(p => new Parameter(p, context))
                .ToList();
        }
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(CanHandleProjection &&
            ExpressionIsOfDesiredKind(expression, _supportedMethodNames));
 }
예제 #16
0
 /// <inheritdoc />
 public override bool CanHandleProjectionOf
 (
     Expression expression,
     HelperContext context
 )
 {
     return(SupportExpressionTypes.Contains(expression.NodeType) &&
            expression.Type != typeof(string));
 }
예제 #17
0
        public List <Parameter> GetParameters(object obj)
        {
            var context = new HelperContext();

            return(obj.GetType().GetProperties()
                   .Where(ShouldBeIncluded)
                   .Select(p => new Parameter(p, context))
                   .ToList());
        }
예제 #18
0
            public IProjection Project
            (
                Expression expression,
                HelperContext context
            )
            {
                var methodCall = (MethodCallExpression)expression;

                return(ProjectionHelper.GetProjection(methodCall.Object, context));
            }
예제 #19
0
 /// <inheritdoc />
 protected override IProjection ProjectCore
 (
     MethodCallExpression expression,
     Expression subExpression,
     IProjection projection,
     HelperContext context
 )
 {
     return(Trim(projection));
 }
예제 #20
0
 /// <inheritdoc />
 protected override IProjection ProjectCore
 (
     MethodCallExpression expression,
     Expression subExpression,
     IProjection projection,
     HelperContext context
 )
 {
     return(Projections.CountDistinct(ExpressionHelper.GetPropertyName(subExpression, context.RootAlias)));
 }
예제 #21
0
 public void Init(ViewRequest viewReq)
 {
     _viewBag         = new Dictionary <string, object>();
     _httpCtx         = new StubHttpContext();
     _ctx             = new ViewContext(_httpCtx, _viewBag, new object(), viewReq);
     _serviceRegistry = CreateStubServiceRegistry();
     _modelProvider   = CreateMetadataProvider();
     _serviceRegistry._modelMetadataProvider = _modelProvider;
     _helperContext = new HelperContext(_ctx, _serviceRegistry);
 }
예제 #22
0
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            var memberInit = (MemberInitExpression)expression;

            var list = Projections.ProjectionList();

            var newProjection = ProjectionHelper.GetProjection(memberInit.NewExpression, context)
                                as ProjectionList;

            if (newProjection != null)
            {
                for (int i = 0; i < newProjection.Length; i++)
                {
                    list.Add(newProjection[i]);
                }
            }

            foreach (MemberBinding memberBinding in memberInit.Bindings)
            {
                var memberAssigment = memberBinding as MemberAssignment;

                if (memberAssigment != null)
                {
                    IProjection projection = ProjectionHelper.GetProjection(memberAssigment.Expression, context);

                    var innerList = projection as ProjectionList;

                    if (innerList != null)
                    {
                        for (int i = 0; i < innerList.Length; i++)
                        {
                            list.Add(innerList[i]);
                        }
                    }
                    else
                    {
                        string member = memberAssigment.Member.Name;

                        list.Add(new FqAliasProjection(projection, member));

                        if (!context.Data.Mappings.ContainsKey(member))
                        {
                            context.Data.Mappings.Add(member, projection);
                        }
                    }
                }
            }

            return(list);
        }
        /// <inheritdoc />
        public override IProjection Project(Expression expression, HelperContext context)
        {
            var condition = (ConditionalExpression)expression;

            return(Projections
                   .Conditional
                   (
                       RestrictionHelper.GetCriterion(condition.Test, context),
                       ProjectionHelper.GetProjection(condition.IfTrue, context),
                       ProjectionHelper.GetProjection(condition.IfFalse, context)
                   ));
        }
예제 #24
0
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            var binary = (BinaryExpression)expression;

            IProjection original = ProjectionHelper.GetProjection(binary.Left, context);
            IProjection fallback = ProjectionHelper.GetProjection(binary.Right, context);

            return(Projections.Conditional(Restrictions.IsNull(original), fallback, original));
        }
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            var methodCall = (MethodCallExpression)expression;

            Expression subExpression = methodCall.Object ?? methodCall.Arguments[0];

            IProjection projection = ProjectionHelper.GetProjection(subExpression, context);

            return(ProjectCore(methodCall, subExpression, projection, context));
        }
예제 #26
0
 /// <inheritdoc />
 public override IProjection Project
 (
     Expression expression,
     HelperContext context
 )
 {
     return(Projections
            .Conditional
            (
                RestrictionHelper.GetCriterion(expression, context),
                Projections.Constant(true),
                Projections.Constant(false)
            ));
 }
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            if (ExpressionHelper.IsRooted(expression, context.RootAlias, context.Data))
            {
                string property = ExpressionHelper.GetPropertyName(expression, context.RootAlias, true, context);

                return(Projections.Property(property));
            }

            object value = ExpressionHelper.GetValue(expression);

            return(Projections.Constant(value, TypeHelper.GuessType(expression.Type)));
        }
예제 #28
0
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            string operation = GetArithmeticOperation(expression.NodeType);

            var binary = (BinaryExpression)expression;

            return(new SqlFunctionProjection
                   (
                       new VarArgsSQLFunction("(", operation, ")"),
                       NHibernateUtil.GuessType(binary.Left.Type),
                       ProjectionHelper.GetProjection(binary.Left, context),
                       ProjectionHelper.GetProjection(binary.Right, context)
                   ));
        }
예제 #29
0
        /// <inheritdoc />
        protected override IProjection ProjectCore
        (
            MethodCallExpression expression,
            Expression subExpression,
            IProjection projection,
            HelperContext context
        )
        {
            ICriterion criterion = RestrictionHelper.GetCriterionForMethodCall(expression, context);

            return(Projections
                   .Conditional
                   (
                       criterion,
                       Projections.Constant(true, NHibernateUtil.Boolean),
                       Projections.Constant(false, NHibernateUtil.Boolean)
                   ));
        }
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            var projections = new List <IProjection>();

            var binary = (BinaryExpression)expression;

            foreach (Expression expressionPart in binary.Flatten())
            {
                IProjection projection = ProjectionHelper.GetProjection(expressionPart, context);

                projections.Add(projection);
            }

            return(new SqlFunctionProjection("concat", NHibernateUtil.String, projections.ToArray()));
        }
예제 #31
0
        /// <inheritdoc />
        public override IProjection Project
        (
            Expression expression,
            HelperContext context
        )
        {
            var unary = (UnaryExpression)expression;

            IProjection projection = ProjectionHelper.GetProjection(unary.Operand, context);

            if (!unary.IsLiftedToNull)
            {
                IType type = TypeHelper.GuessType(unary.Type, true);

                if (type != null)
                {
                    return(new FqCastProjection(type, projection));
                }
            }

            return(projection);
        }