Esempio n. 1
0
        private void JsonValidationTimerHandler(IJsonTreeNode node)
        {
            jsonTreeView.BeginUpdate();

            try
            {
                var newNode = node.AfterJsonTextChange(jsonValueEditor.Text);
                if (newNode != null)
                {
                    jsonTreeView.SelectedNode = newNode;

                    SetJsonStatus("Json format validated.", false);
                }
                else
                {
                    SetJsonStatus("INVALID Json format", true);
                }
            }
            catch (JsonReaderException exception)
            {
                SetJsonStatus(
                    $"INVALID Json format at (line {exception.LineNumber}, position {exception.LinePosition})",
                    true);
            }
            catch
            {
                SetJsonStatus("INVALID Json format", true);
            }

            jsonTreeView.EndUpdate();
        }
Esempio n. 2
0
        private IJsonTreeNode BuildNode(PropertyNodeItem root, IJsonTreeNode parent)
        {
            TreeNode node = new TreeNode(
                root.JsonName,
                root.EntityName,
                root.DisplayName,
                parent,
                root.MultiReleationShip,
                root.BuildJson,
                root.Selectable,
                root.VirtualNode
                );

            foreach (PropertyNodeItem n in root.Childs)
            {
                node.ChildNodes.Add(n.JsonName, BuildNode(n, node));
            }

            node.Parent = parent;
            node.Sql    = new CustomizedSqlDescriber(
                root.HasCustomizedSql,
                root.CustomizedSql,
                root.CustomizedSqlParameters, node);
            return(node);
        }
Esempio n. 3
0
        /// <summary>
        /// 创建与前端交互的Selection对象
        /// </summary>
        public Models.SelectCollection BuildSelections()
        {
            Models.SelectCollection selections = new Models.SelectCollection();
            foreach (IJsonTreeNode root in ExportRoot.roots)
            {
                Models.SelectableJsonList list = new Models.SelectableJsonList(root.DisplayName, root);

                //使用宽度优先搜索遴选出可选节点并标记
                Queue <IJsonTreeNode> que = new Queue <IJsonTreeNode>();
                que.Enqueue(root);
                while (que.Count != 0)
                {
                    //BFS
                    IJsonTreeNode n = que.Dequeue();
                    foreach (IJsonTreeNode i in n.ChildNodes.Values)
                    {
                        que.Enqueue(i);
                    }
                    //筛选节点
                    if (n.Selectable)
                    {
                        list.AddNode(new Models.SelectableJsonNode(n.DisplayName, n));
                    }
                }
                if (list.Nodes.Count != 0)
                {
                    selections.Source.Add(list);
                }
            }
            return(selections);
        }
Esempio n. 4
0
        /// <summary>
        /// 从配置设置构建Xml
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        private SettingNode BuildXmlFromTreeNode(IJsonTreeNode root)
        {
            //创建对象
            SettingNode xml = new SettingNode(root.JsonNodeName);

            //写属性
            xml.SetAttribute(DbEntityAttributeName, root.DbName);
            xml.SetAttribute(DbTableMultiRelated, root.MultiRelated.ToString());
            xml.SetAttribute(DbDisplayName, root.DisplayName);
            xml.SetAttribute(BuildJsonFile, root.BuildSingleFile.ToString());
            xml.SetAttribute(NodeSelectable, root.Selectable.ToString());
            xml.SetAttribute(DbCustomizedSql, root.Sql.CustomizeSQLString);
            xml.SetAttribute(DbCustomizedSqlParameters, root.Sql.Params.ToString());
            xml.SetAttribute(IsVirtual, root.IsSelectionParameter.ToString());

            //先写实节点
            foreach (String key in root.ChildNodes.Keys)
            {
                if (root.ChildNodes[key].IsDBColumn)
                {
                    xml.AppendChild(BuildXmlFromTreeNode(root.ChildNodes[key]));
                }
            }
            //虚结点做右子节点
            foreach (String key in root.ChildNodes.Keys)
            {
                if (!root.ChildNodes[key].IsDBColumn)
                {
                    xml.AppendChild(BuildXmlFromTreeNode(root.ChildNodes[key]));
                }
            }
            return(xml);
        }
Esempio n. 5
0
        /// <summary>
        /// 从Xml设置文件建立数据库配置项
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private TreeNode BuildTreeNode(SettingNode node, IJsonTreeNode parent)
        {
            //创建对象
            var t = new TreeNode(
                node.Name,
                node.Attributes[DbEntityAttributeName],
                node.Attributes[DbDisplayName],
                parent,
                Boolean.Parse(node.Attributes[DbTableMultiRelated]),
                Boolean.Parse(node.Attributes[BuildJsonFile]),
                Boolean.Parse(node.Attributes[NodeSelectable]),
                Boolean.Parse(node.Attributes[IsVirtual])
                );
            //读子节点
            Dictionary <String, IJsonTreeNode> childs = new Dictionary <string, IJsonTreeNode>();

            foreach (SettingNode n in node.ChildNodes)
            {
                TreeNode tn = BuildTreeNode(n, t);
                t.ChildNodes.Add(tn.JsonNodeName, tn);
            }
            //读属性
            t.Sql = new CustomizedSqlDescriber(
                node.Attributes[DbCustomizedSql] != String.Empty,
                node.Attributes[DbCustomizedSql],
                node.Attributes[DbCustomizedSqlParameters],
                t);

            return(t);
        }
Esempio n. 6
0
        /// <summary>
        /// 递归填充
        /// </summary>
        /// <param name="root"></param>
        /// <param name="detial"></param>
        /// <returns></returns>
        private PropertyNodeItem FillItems(IJsonTreeNode root, JsonEntityDetial detial)
        {
            PropertyNodeItem item = PropertyNodeItem.Default;

            item.DisplayName             = root.DisplayName;
            item.JsonName                = root.JsonNodeName;
            item.EntityName              = root.DbName;
            item.MultiReleationShip      = root.MultiRelated;
            item.HasChildren             = root.ChildNodes.Count != 0;
            item.BuildJson               = root.BuildSingleFile;
            item.Selectable              = root.Selectable;
            item.HasCustomizedSql        = root.Sql.HasCustomizeSQLString;
            item.CustomizedSql           = root.Sql.CustomizeSQLString;
            item.CustomizedSqlParameters = root.Sql.Params?.ToString();
            item.VirtualNode             = root.IsSelectionParameter;
            item.IsExpanded              = root.Parent == null;

            foreach (IJsonTreeNode n in root.ChildNodes.Values)
            {
                var i = FillItems(n, detial);
                i.Parent = item;
                item.Childs.Add(i);
            }
            return(item);
        }
        public CustomizedSqlParameters(String str, IJsonTreeNode current) : this()
        {
            // 检查是否参数为空
            if (!String.IsNullOrWhiteSpace(str))
            {
                // 保留预置字符串信息,用于存储
                describe = str;
                // 分割参数
                string[] paras = str.Split(',');
                // 依次处理每个参数
                foreach (string argv in paras)
                {
                    // 检查是否为参数索引
                    if (argv[0] == '>')
                    {
                        // 用数组保存两个关键节点,第一个元素为最近公共父节点,第二个元素为引用目标元素
                        IJsonTreeNode[] refNode = new IJsonTreeNode[2];
                        try
                        {
                            var qOperations = customizedDynamicParameterCheck(argv);

                            for (int i = 0; i < 2; ++i)
                            {
                                while (qOperations[i].Count != 0)
                                {
                                    refNode[i] = qOperations[i].Dequeue().Process(refNode[i]);
                                }
                                if (i == 0)
                                {
                                    refNode[i + 1] = refNode[i];
                                }
                            }

                            Parameters.Add(new Parameter()
                            {
                                ref_node = refNode[1], ref_parent = refNode[0]
                            });
                        }
                        catch (CustomizedSqlParametersException e)
                        {
                            e.Node = current.JsonNodeName;
                            throw e;
                        }
                        finally
                        {
                            Parameters.Clear();
                            describe = "";
                        }
                    }
                    else
                    {
                        Parameters.Add(new Parameter()
                        {
                            svalue = argv
                        });
                    }
                }
            }
        }
Esempio n. 8
0
 public bool Equals(IJsonTreeNode obj)
 {
     if (this.JsonNodeName == obj.JsonNodeName)
     {
         return(Parent == null ? true : Parent.Equals(obj));
     }
     else
     {
         return(false);
     }
 }
Esempio n. 9
0
 public TreeNode(string jsonNodeName, string dbName, string displayName, IJsonTreeNode parent, bool multiRelated, bool buildSingleFile, bool selectable, bool virtualNode)
 {
     JsonNodeName         = jsonNodeName;
     DbName               = dbName;
     DisplayName          = displayName;
     Parent               = parent;
     MultiRelated         = multiRelated;
     BuildSingleFile      = buildSingleFile;
     Selectable           = selectable;
     IsSelectionParameter = virtualNode;
     ChildNodes           = new Dictionary <string, IJsonTreeNode>();
 }
 public CustomizedSqlDescriber(bool hasSql, string sql, string args, IJsonTreeNode current)
 {
     if (hasSql)
     {
         customizedsql = sql;
     }
     else
     {
         CustomizeSQLString = string.Empty;
     }
     param = new CustomizedSqlParameters(args, current);
 }
            public IJsonTreeNode Process(IJsonTreeNode node)
            {
                IJsonTreeNode res;

                if (!node.ChildNodes.TryGetValue(entityName, out res))
                {
                    throw new UnSolvedInheritedLevelException()
                          {
                              ParaName = entityName,
                              Advice   = String.Format("解析时,未在节点{0}下找到{1}实体。", node.JsonNodeName, entityName)
                          };
                }
                return(res);
            }
        public async Task BuildJsonFile(IJsonTreeNode root)
        {
            JToken res;

            // 根据类型创建
            if (root.MultiRelated)
            {
                res = new JArray();
            }
            else
            {
                res = new JObject();
            }
        }
Esempio n. 13
0
        private void StartValidationTimer(IJsonTreeNode node)
        {
            jsonValidationTimer?.Stop();

            jsonValidationTimer = new System.Timers.Timer(250);

            jsonValidationTimer.Elapsed += (o, args) =>
            {
                jsonValidationTimer.Stop();

                jsonTreeView.Invoke(new Action <IJsonTreeNode>(JsonValidationTimerHandler), node);
            };

            jsonValidationTimer.Start();
        }
 public ParameterCache(Parameter param, IJsonTreeNode parent)
 {
     if (param.IsString)
     {
         IsString   = true;
         ChildRoute = new string[1] {
             param.svalue
         };
     }
     else
     {
         Stack <String> trace   = new Stack <string>();      //使用回溯,寻找调用路径
         IJsonTreeNode  tracker = param.ref_node;
         while (tracker != parent)
         {
             trace.Push(tracker.JsonNodeName);
             tracker = tracker.Parent;
         }
         ChildRoute = trace.ToArray();
     }
 }
Esempio n. 15
0
        /// <summary>
        /// 根据选项创建筛选集合
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool BuildSelection(IJsonTreeNode node, out string result)
        {
            string r = string.Empty;

            foreach (IJsonTreeNode n in node.ChildNodes.Values)
            {
                if (n.IsSelected)
                {
                    r += n.DbName + ",";
                }
            }
            if (String.IsNullOrEmpty(r))            //无选项,无筛选结果
            {
                result = r;
            }
            else
            {
                result = string.Format("({0})", r.Substring(0, r.Length - 1));    //去最后一个逗号,创建数组
            }
            return(!String.IsNullOrEmpty(r));
        }
Esempio n. 16
0
        private void JsonValidationTimerHandler(IJsonTreeNode node)
        {
            jsonTreeView.BeginUpdate();

            try
            {
                jsonTreeView.SelectedNode = node.AfterJsonTextChange(jsonValueTextBox.Text);

                SetJsonStatus("Json format validated.", false);
            }
            catch (JsonReaderException exception)
            {
                SetJsonStatus(
                    String.Format("INVALID Json format at (line {0}, position {1})", exception.LineNumber, exception.LinePosition),
                    true);
            }
            catch
            {
                SetJsonStatus("INVALID Json format", true);
            }

            jsonTreeView.EndUpdate();
        }
 public SelectableJsonList(string name, IJsonTreeNode node)
 {
     Name  = name;
     Node  = node;
     nodes = new ObservableCollection <SelectableJsonNode>();
 }
 public SelectableJsonNode(string name, IJsonTreeNode node)
 {
     Name      = name;
     Node      = node;
     IsChecked = false;
 }
Esempio n. 19
0
 public SqlCommandCache(IJsonTreeNode treeNode, String specifiedQuaryStringsArgs)
 {
     paras       = new ParameterCache[0];
     sqlTemplate = String.Format(treeNode.Sql.CustomizeSQLString, specifiedQuaryStringsArgs);
 }
Esempio n. 20
0
        /// <summary>
        /// 建立SQL查询指令缓存
        /// </summary>
        /// <param name="currentNode">当前节点的IJson抽象索引</param>
        /// <param name="parentNode">当前节点的父节点IJson抽象索引</param>
        /// <param name="specifiedQuaryStringsArgs">系统级全局参数字符串</param>
        public SqlCommandCache(IJsonTreeNode currentNode, IJsonTreeNode parentNode, String[] specifiedQuaryStringsArgs)
        {
            int  i = 0, j = 0;
            bool isallstring = true;
            ICustomizedSqlDescriber describer = currentNode.Sql;
            String dbname = currentNode.DbName;

            var tmpParas = new List <ParameterCache>();

            foreach (Parameter p in describer.Params.Parameters)
            {
                tmpParas.Add(new ParameterCache(p, parentNode));
                isallstring &= p.IsString;
                i++;
            }

            //处理SQL
            if (isallstring)
            {
                sqlTemplate = describer.HasCustomizeSQLString ?
                              describer.CustomizeSQLString :
                              String.Format("Select * From {0} Where ", dbname) + "{0} = {1}";
            }
            else
            {
                sqlTemplate = describer.HasCustomizeSQLString ?
                              describer.CustomizeSQLString :
                              String.Format("Select * From {0} Where ", dbname) + "{0} IN {1}";
            }
            i = Regex.Matches(sqlTemplate, @"{\d}").Count;
            try
            {
                //处理可选项
                if (currentNode.HasSelectionNode)
                {
                    foreach (IJsonTreeNode n in currentNode.ChildNodes.Values)
                    {
                        string str;
                        if (n.IsSelectionNode && BuildSelection(n, out str))
                        {
                            if (n.Sql.HasCustomizeSQLString)
                            {
                                str = "(" + string.Format(n.Sql.CustomizeSQLString, str) + ")";
                            }
                            sqlTemplate += String.Format(" AND {0} IN {1}", n.DbName, str);
                        }
                        else if (n.IsSelectionNode)
                        {
                            sqlTemplate += String.Format(" AND 0 = 1");
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("处理可选项时发生错误,SQL Template:" + sqlTemplate);
            }
            //处理参数列表
            try
            {
                while (i != tmpParas.Count)
                {
                    tmpParas.Add(new ParameterCache(specifiedQuaryStringsArgs[j++]));
                    if (j > specifiedQuaryStringsArgs.Length)
                    {
                        j = 0;
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception("处理参数列表发生错误,SQL Template:" + sqlTemplate);
            }
            paras = tmpParas.ToArray();
        }
 public IJsonTreeNode Process(IJsonTreeNode node)
 {
     return(node.Parent);
 }
Esempio n. 22
0
        private void JsonValidationTimerHandler(IJsonTreeNode node)
        {
            jsonTreeView.BeginUpdate();

            try
            {
                jsonTreeView.SelectedNode = node.AfterJsonTextChange(jsonValueTextBox.Text);

                SetJsonStatus("Json format validated.", false);
            }
            catch (JsonReaderException exception)
            {
                SetJsonStatus(
                    String.Format("INVALID Json format at (line {0}, position {1})", exception.LineNumber, exception.LinePosition),
                    true);
            }
            catch
            {
                SetJsonStatus("INVALID Json format", true);
            }

            jsonTreeView.EndUpdate();
        }
Esempio n. 23
0
        private void StartValidationTimer(IJsonTreeNode node)
        {
            if (jsonValidationTimer != null)
            {
                jsonValidationTimer.Stop();
            }

            jsonValidationTimer = new System.Timers.Timer(250);

            jsonValidationTimer.Elapsed += (o, args) =>
            {
                jsonValidationTimer.Stop();

                jsonTreeView.Invoke(new Action<IJsonTreeNode>(JsonValidationTimerHandler), new object[] { node });
            };

            jsonValidationTimer.Start();
        }