Ejemplo n.º 1
0
        public static string ReportUnmappedOperators()
        {
            StringBuilder        sb             = new StringBuilder();
            List <OperatorColor> operatorColors = ViewerSettings.Instance.OperatorColors.ToList();

            foreach (OperatorColor operatorColor in operatorColors)
            {
                string        operatorName = operatorColor.OperatorName;
                OperationType operationType;
                if (Enum.TryParse <OperationType>(operatorName, out operationType))
                {
                    SqlParseTreeNode node = new SqlParseTreeNode();
                    node.Operation = operationType;
                    Icon icon = GetIconForNode(node);
                    if (icon == null)
                    {
                        sb.AppendFormat("Unmapped operator {0}", operatorName);
                        sb.AppendLine();
                    }
                }
                else
                {
                    sb.AppendFormat("Operator has no enum type: {0}", operatorName);
                    sb.AppendLine();
                }
            }

            return(sb.ToString());
        }
        private static void MeasureNode(SqlParseTreeNode node, int depth, Dictionary <int, int> levelCounts, List <TreeNodeIcon> icons)
        {
            if (levelCounts.ContainsKey(depth) == false)
            {
                levelCounts.Add(depth, 0);
            }
            levelCounts[depth]++;

            TreeNodeIcon icon = new TreeNodeIcon();

            icon.Node   = node;
            icon.X      = levelCounts[depth] - 1;
            icon.Y      = depth;
            icon.Left   = _leftMargin + icon.X * (_blockWidth + _spacingWidth);
            icon.Top    = _topMargin + icon.Y * (_blockHeight + _spacingHeight);
            icon.Width  = _blockWidth;
            icon.Height = _blockHeight;

            icons.Add(icon);

            foreach (SqlParseTreeNode child in node.Children)
            {
                MeasureNode(child, depth + 1, levelCounts, icons);
            }
        }
        private static void RemoveLowValueLeafLevelNodes(SqlParseTreeNode parentNode)
        {
            List <SqlParseTreeNode> nodesToRemove = null;

            foreach (SqlParseTreeNode childNode in parentNode.Children)
            {
                if (string.IsNullOrEmpty(childNode.Arguments) &&
                    childNode.Children.Count == 0 &&
                    lowValueNodeOperations.ContainsKey(childNode.Operation))
                {
                    if (nodesToRemove == null)
                    {
                        nodesToRemove = new List <SqlParseTreeNode>();
                    }

                    nodesToRemove.Add(childNode);
                }
            }

            if (nodesToRemove != null)
            {
                nodesToRemove.ForEach(n => parentNode.Children.Remove(n));
            }

            parentNode.Children.ForEach(n => RemoveLowValueLeafLevelNodes(n));
        }
Ejemplo n.º 4
0
        public static Icon GetIconForNode(SqlParseTreeNode node)
        {
            switch (node.Operation)
            {
            case OperationType.LogOp_Get:
                return(SqlServerQueryTreeViewerResources.Get);

            case OperationType.LogOp_Join:
                return(SqlServerQueryTreeViewerResources.InnerJoin);

            case OperationType.LogOp_LeftOuterJoin:
                return(SqlServerQueryTreeViewerResources.LeftOuterJoin);

            case OperationType.LogOp_RightOuterJoin:
                return(SqlServerQueryTreeViewerResources.RightOuterJoin);

            case OperationType.LogOp_LeftSemiJoin:
                return(SqlServerQueryTreeViewerResources.LeftSemiJoin);

            case OperationType.LogOp_LeftAntiSemiJoin:
                return(SqlServerQueryTreeViewerResources.LeftAntiSemiJoin);

            case OperationType.LogOp_RightSemiJoin:
                return(SqlServerQueryTreeViewerResources.RightSemiJoin);

            case OperationType.LogOp_RightAntiSemiJoin:
                return(SqlServerQueryTreeViewerResources.RightAntiSemiJoin);

            case OperationType.LogOp_Project:
                return(SqlServerQueryTreeViewerResources.Project);

            case OperationType.ScaOp_Comp:
                switch (node.Arguments)
                {
                case "x_cmpEq":
                    return(SqlServerQueryTreeViewerResources.CompareEqual);

                default:
                    return(null);
                }

            case OperationType.ScaOp_Const:
                return(SqlServerQueryTreeViewerResources.Const);

            case OperationType.ScaOp_Identifier:
                return(SqlServerQueryTreeViewerResources.Identifier);

            default:
                return(null);
            }
        }
        private static void FixupParentLinks(List <TreeNodeIcon> icons)
        {
            Dictionary <SqlParseTreeNode, TreeNodeIcon> iconMap = new Dictionary <SqlParseTreeNode, TreeNodeIcon>();

            icons.ForEach(i => iconMap.Add(i.Node, i));

            foreach (TreeNodeIcon icon in icons)
            {
                SqlParseTreeNode parentNode = icon.Node.Parent;
                if (parentNode != null)
                {
                    icon.Parent = iconMap[parentNode];
                }

                foreach (SqlParseTreeNode childNode in icon.Node.Children)
                {
                    icon.Children.Add(iconMap[childNode]);
                }
            }
        }
Ejemplo n.º 6
0
        private TreeNodeIcon PositionNode(SqlParseTreeNode node, int top, int left)
        {
            string nodeText = node.ToString();
            SizeF  textSize = _dummyGraphics.MeasureString(nodeText, _textFont);

            TreeNodeIcon icon = new TreeNodeIcon();

            icon.X             = left;
            icon.Y             = top;
            icon.Left          = left;
            icon.Top           = top;
            icon.Width         = (int)Math.Max(_iconWidth, textSize.Width);
            icon.Height        = _iconHeight + _iconToTextSpacing + (int)textSize.Height;
            icon.Node          = node;
            icon.Text          = nodeText;
            icon.TextRectangle = new Rectangle(left + (icon.Width - (int)textSize.Width) / 2, top + _iconHeight + _iconToTextSpacing, (int)textSize.Width + 2, (int)textSize.Height + 2);
            icon.IconRectangle = new Rectangle(left + (icon.Width - _iconWidth) / 2, top, _iconWidth, _iconHeight);
            icon.Icon          = TreeNodeIconMapper.GetIconForNode(node);

            return(icon);
        }
Ejemplo n.º 7
0
        private List <TreeNodeIcon> PositionSubtree(SqlParseTreeNode head, int top, int left)
        {
            List <TreeNodeIcon> icons = new List <TreeNodeIcon>();

            int originalTop = top;
            //int adjust = _connectorVerticalSpacing * head.Children.Count / 2 - _interIconVerticalSpacing;
            int firstArrowTop = (2 * top + _iconHeight) / 2 - _connectorVerticalSpacing * (head.Children.Count - 1) / 2;

            if (top > firstArrowTop)
            {
                top += (top - firstArrowTop) + _iconHeight / 2;
            }

            TreeNodeIcon icon = PositionNode(head, top, left);

            icons.Add(icon);

            int horizontalSpacing = Math.Max(_interIconHorizontalSpacing, _connectorHorizontalSpacing * head.Children.Count);
            int newLeft           = left + icon.Width + horizontalSpacing;
            //int newTop = originalTop;
            int altTop = (icon.IconRectangle.Top + icon.IconRectangle.Bottom) / 2 - _connectorVerticalSpacing * (icon.Children.Count - 1) / 2;
            int newTop = Math.Min(originalTop, altTop);

            foreach (SqlParseTreeNode child in head.Children)
            {
                List <TreeNodeIcon> childIcons = PositionSubtree(child, newTop, newLeft);
                if (childIcons.Count > 0)
                {
                    childIcons[0].Parent = icon;
                    icon.Children.Add(childIcons[0]);
                }
                icons.AddRange(childIcons);
                newTop += childIcons.GetHeight() + _interIconVerticalSpacing;
            }

            return(icons);
        }