示例#1
0
        /// <summary>
        /// Visits a <see cref="DeclareJobStatement"/>.
        /// </summary>
        /// <param name="node">
        /// The node.
        /// </param>
        /// <returns>
        /// The node, or a new version of the node.
        /// </returns>
        protected internal override Node VisitDeclareJobStatement([NotNull] DeclareJobStatement node)
        {
            base.VisitDeclareJobStatement(node);

            var context        = Expression.Parameter(typeof(IExecutionContext), "context");
            var replaceContext = GenericVisitor.Create((ExecutionContextExpression e) => context);

            var expr = Expression.Convert(
                Expression.NewArrayInit(
                    typeof(JobTrigger),
                    node.Triggers.Select(t =>
                                         Expression.New(
                                             typeof(JobTrigger).GetTypeInfo().DeclaredConstructors.First(),
                                             replaceContext.Visit(this.data.ConvertToLinqExpression(t.Function)),
                                             Expression.Constant(t.GetDisplay())))),
                typeof(IEnumerable <JobTrigger>)).RewriteTasksToAsyncExpression();

            if (!expr.Type.IsConstructedGenericType || expr.Type.GetGenericTypeDefinition() != typeof(Task <>))
            {
                var fromResult = typeof(Task).GetGenericMethod(nameof(Task.FromResult), (Type)null).MakeGenericMethod(typeof(IEnumerable <JobTrigger>));

                expr = Expression.Call(null, fromResult, expr);
            }

            var factories = Expression.Lambda <Func <IExecutionContext, Task <IEnumerable <IJobTrigger> > > >(expr, context).Compile();

            var plan = node.Statements.Count == 1
                           ? this.data.GetQueryPlan(node.Statements[0])
                           : new CombinedQueryPlan(node.Statements.Select(this.data.GetQueryPlan));

            this.data.SetQueryPlan(node, new DeclareJobPlan(node.Name, plan, factories));

            return(base.VisitDeclareJobStatement(node));
        }
示例#2
0
 /// <summary>
 /// Visits a <see cref="DeclareJobStatement"/>.
 /// </summary>
 /// <param name="node">
 /// The node.
 /// </param>
 /// <returns>
 /// The node, or a new version of the node.
 /// </returns>
 protected internal virtual Node VisitDeclareJobStatement([NotNull] DeclareJobStatement node)
 {
     return(node.VisitChildren(this));
 }
示例#3
0
            protected internal override Node VisitDeclareJobStatement([NotNull] DeclareJobStatement node)
            {
                this.Builder.Append($"DECLARE JOB {node.Name}");

                return(node);
            }
示例#4
0
 /// <summary>
 /// Visits a <see cref="DeclareJobStatement"/>.
 /// </summary>
 /// <param name="node">
 /// The node.
 /// </param>
 /// <returns>
 /// The node, or a new version of the node.
 /// </returns>
 protected internal override Node VisitDeclareJobStatement(DeclareJobStatement node)
 {
     return(this.VisitImplementation(node) ?? base.VisitDeclareJobStatement(node));
 }