示例#1
0
 protected SyntaxNodeVisitor(
     IReadOnlyDictionary <SyntaxKind, VisitorAction> actions,
     VisitorAction defaultAction)
 {
     _actions       = actions;
     _defaultAction = defaultAction;
 }
        public bool Enter(
            FilterOperationField field,
            ObjectFieldNode node,
            ISyntaxNode parent,
            IReadOnlyList <object> path,
            IReadOnlyList <ISyntaxNode> ancestors,
            Stack <QueryableClosure> closures,
            bool inMemory,
            out VisitorAction action
            )
        {
            if (
                field.Operation.Kind == FilterOperationKind.ArraySome ||
                field.Operation.Kind == FilterOperationKind.ArrayNone ||
                field.Operation.Kind == FilterOperationKind.ArrayAll
                )
            {
                MemberExpression nestedProperty = Expression.Property(
                    closures.Peek().Instance.Peek(),
                    field.Operation.Property
                    );

                closures.Peek().Instance.Push(nestedProperty);

                Type closureType = GetTypeFor(field.Operation);

                closures.Push(new QueryableClosure(closureType, "_s" + closures.Count, inMemory));
                action = VisitorAction.Continue;
                return(true);
            }
            action = VisitorAction.Default;
            return(false);
        }
示例#3
0
        // 请求开始无法获取用户信息
        void context_BeginRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication app = (System.Web.HttpApplication)sender;
            // url rewrite
            HttpContext context  = app.Context;
            string      actionId = System.Guid.NewGuid().ToString();

            context.Response.AddHeader("ACTION-ID", actionId);
            VisitorAction action = new VisitorAction(actionId, context.Request.Url.AbsoluteUri);

            BlueFramework.User.Session.Current.PushAction(action);
        }
示例#4
0
        internal bool method_12(VisitorAction A_0)
        {
            int num = 4;

            switch (A_0)
            {
            case VisitorAction.Continue:
            case VisitorAction.SkipThisElement:
                return(true);

            case VisitorAction.Stop:
                return(false);
            }
            throw new InvalidOperationException(BookmarkStart.b("缩䈫䔭帯崱䌳堵ᠷ䰹唻䴽⤿㙁⭃㑅桇⭉⽋㩍㥏㵑㩓硕", num));
        }
示例#5
0
        // 请求错误日志
        void context_Error(object sender, EventArgs e)
        {
            HttpContext context = ((HttpApplication)sender).Context;
            Exception   ex      = context.Server.GetLastError();
            string      error   = string.Format("错误信息:{0}. 堆栈信息:{1}.", ex.Message, ex.StackTrace);

            if (UserContext.CurrentVisitor != null)
            {
                string        actionId = context.Request.Headers["ACTION-ID"];
                VisitorAction action   = BlueFramework.User.Session.Current.PopAction(actionId);
                if (action != null)
                {
                    action.EndTime = DateTime.Now;
                    action.Status  = ActionStatus.ErrorRequest;
                    action.Content = error;
                    UserContext.CurrentVisitor.AddAction(action);
                }
            }
        }
示例#6
0
        // 请求结束里面获取用户信息
        void context_EndRequest(object sender, EventArgs e)
        {
            System.Web.HttpApplication app = (System.Web.HttpApplication)sender;
            // url rewrite
            HttpContext   context  = app.Context;
            string        url      = context.Request.Url.AbsolutePath;
            string        actionId = context.Response.Headers["ACTION-ID"];
            VisitorAction action   = BlueFramework.User.Session.Current.PopAction(actionId);

            if (UserContext.CurrentVisitor != null)
            {
                if (action != null)
                {
                    action.EndTime = DateTime.Now;
                    action.Status  = ActionStatus.EndRequest;
                    UserContext.CurrentVisitor.AddAction(action);
                }
            }
        }
示例#7
0
 public bool Enter(
     FilterOperationField field,
     ObjectFieldNode node,
     ISyntaxNode parent,
     IReadOnlyList <object> path,
     IReadOnlyList <ISyntaxNode> ancestors,
     Stack <QueryableClosure> closures,
     out VisitorAction action)
 {
     if (field.Operation.Kind == FilterOperationKind.Object)
     {
         var nestedProperty = Expression.Property(
             closures.Peek().Instance.Peek(),
             field.Operation.Property);
         closures.Peek().Instance.Push(nestedProperty);
         action = VisitorAction.Continue;
         return(true);
     }
     action = VisitorAction.Default;
     return(false);
 }
示例#8
0
 public void PushAction(VisitorAction action)
 {
     lastActions.Add(action.ActionId, action);
 }
示例#9
0
 protected SyntaxNodeVisitor(
     IReadOnlyDictionary <SyntaxKind, VisitorAction> actions)
 {
     _actions       = actions;
     _defaultAction = VisitorAction.Skip;
 }
示例#10
0
 protected SyntaxNodeVisitor(VisitorAction defaultAction)
 {
     _actions       = null;
     _defaultAction = defaultAction;
 }
示例#11
0
 protected SyntaxNodeVisitor()
 {
     _actions       = null;
     _defaultAction = VisitorAction.Skip;
 }
示例#12
0
        public static void Accept(
            this ISyntaxNode node,
            ISyntaxNodeVisitor visitor,
            IVisitationMap visitationMap,
            Func <ISyntaxNode, VisitorAction> defaultAction)
        {
            if (node is null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (visitor is null)
            {
                throw new ArgumentNullException(nameof(visitor));
            }

            if (visitationMap is null)
            {
                throw new ArgumentNullException(nameof(visitationMap));
            }

            var path          = new List <object>();
            var ancestors     = new List <SyntaxNodeInfo>();
            var ancestorNodes = new List <ISyntaxNode>();
            var level         = new List <List <SyntaxNodeInfo> >();

            var root = new List <SyntaxNodeInfo>();

            root.Push(new SyntaxNodeInfo(node, null));
            level.Push(root);

            int index = 0;

            while (level.Count != 0)
            {
                bool           isLeaving = level[index].Count == 0;
                VisitorAction  action    = default;
                SyntaxNodeInfo parent    = default;
                SyntaxNodeInfo current   = default;

                if (isLeaving)
                {
                    if (index == 0)
                    {
                        break;
                    }

                    level.Pop();
                    ancestorNodes.Pop();
                    current = ancestors.Pop();
                    parent  = ancestors.Count == 0
                        ? default
                        : ancestors.Peek();

                    action = Leave(
                        visitor,
                        current.Node,
                        parent.Node,
                        path,
                        ancestorNodes);

                    if (action == VisitorAction.Default)
                    {
                        action = defaultAction?.Invoke(current.Node)
                                 ?? VisitorAction.Skip;
                    }

                    if (current.Name != null)
                    {
                        path.Pop();
                    }

                    if (current.Index.HasValue)
                    {
                        path.Pop();
                    }

                    index--;
                }
                else
                {
                    current = level[index].Pop();

                    if (current.Name != null)
                    {
                        path.Push(current.Name);
                    }

                    if (current.Index.HasValue)
                    {
                        path.Push(current.Index.Value);
                    }

                    action = Enter(
                        visitor,
                        current.Node,
                        parent.Node,
                        path,
                        ancestorNodes);

                    if (action == VisitorAction.Default)
                    {
                        action = defaultAction?.Invoke(current.Node)
                                 ?? VisitorAction.Skip;
                    }

                    if (action == VisitorAction.Continue)
                    {
                        level.Push(GetChildren(current.Node, visitationMap));
                    }
                    else if (action == VisitorAction.Skip)
                    {
                        // TODO : replace with empty
                        level.Push(new List <SyntaxNodeInfo>());
                    }

                    parent = current;
                    ancestors.Push(current);
                    ancestorNodes.Push(current.Node);
                    index++;
                }

                if (action == VisitorAction.Break)
                {
                    break;
                }
            }

            level.Clear();
        }