Ejemplo n.º 1
0
        /// <summary>
        /// 获取某一个
        /// </summary>
        /// <param name="sqlId"></param>
        /// <returns></returns>
        public SqlTag Get(string sqlId)
        {
            SqlTag sqlTag = null;

            TryGet(sqlId, out sqlTag);
            return(sqlTag);
        }
Ejemplo n.º 2
0
        private void QueryReplaceNode(SqlTagProvider sqlTagProvider, XmlNode parentNode, Dictionary <XmlNode, List <XmlNode> > replace)
        {
            var childnodes = parentNode.ChildNodes;

            foreach (XmlNode node in childnodes)
            {
                if (node.NodeType == XmlNodeType.Text)
                {
                    continue;
                }

                if (node.LocalName.IsEquals("include") || node.Name.IsEquals("include"))
                {
                    var id = node.Attributes.GetNamedItem("refid");
                    if (id == null || id.Value.IsNullOrEmpty())
                    {
                        throw new KeyNotExistedException("Id", string.Format("can not build the {0} tag,because the include has not attribue name id", this.Id));
                    }

                    SqlTag sql = null;
                    sqlTagProvider.TryGet(id.Value, out sql);
                    if (sql != null && sql.Node != null)
                    {
                        if (sql.CommandType.IsNotEquals("sql", StringComparison.CurrentCultureIgnoreCase))
                        {
                            throw new DataFormatException("tag just allow to include sql tag");
                        }

                        foreach (XmlNode j in sql.Node)
                        {
                            if (j.LocalName.IsEquals("include") || j.Name.IsEquals("include"))
                            {
                                throw new DataFormatException("sql tag can not include other resource");
                            }
                        }
                    }

                    if (sql == null)
                    {
                        throw new KeyNotExistedException("Id", string.Format("can not build the {0} tag,because the include has not attribue name id", this.Id));
                    }

                    if (sql.Node == null || !sql.Node.HasChildNodes)
                    {
                        continue;
                    }

                    replace[node] = new List <XmlNode>(sql.Node.ChildNodes.Count);
                    foreach (XmlNode subNode in sql.Node.ChildNodes)
                    {
                        replace[node].Add(subNode.CloneNode(true));
                    }
                }

                if (node.HasChildNodes)
                {
                    this.QueryReplaceNode(sqlTagProvider, node, replace);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取命令名字
        /// </summary>
        /// <param name="node"></param>
        /// <param name="sqlTag"></param>
        /// <returns></returns>
        private static bool LoadCommandName(System.Xml.XmlNode node, SqlTag sqlTag)
        {
            switch (node.Name)
            {
            case "sql":
            {
                sqlTag.CommandType = node.Name;
            }
            break;

            case "select":
            {
                var indented = node.Attributes.GetNamedItem("indented");
                sqlTag.IndentedOnSqlTag = indented == null ? true : indented.Value.AsBool();
                sqlTag.CommandType      = node.Name;
            }
            break;

            case "delete":
            {
                var indented = node.Attributes.GetNamedItem("indented");
                sqlTag.IndentedOnSqlTag = indented == null ? true : indented.Value.AsBool();
                sqlTag.CommandType      = node.Name;
            }
            break;

            case "update":
            {
                var indented = node.Attributes.GetNamedItem("indented");
                sqlTag.IndentedOnSqlTag = indented == null ? true : indented.Value.AsBool();
                sqlTag.CommandType      = node.Name;
            }
            break;

            case "insert":
            {
                var indented = node.Attributes.GetNamedItem("indented");
                sqlTag.IndentedOnSqlTag = indented == null ? true : indented.Value.AsBool();
                sqlTag.CommandType      = node.Name;
            }
            break;

            case "procedure":
            {
                var indented = node.Attributes.GetNamedItem("indented");
                sqlTag.IndentedOnSqlTag = indented == null ? true : indented.Value.AsBool();
                sqlTag.CommandType      = node.Name;
            }
            break;

            default:
            {
                return(false);
            }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取某一个
        /// </summary>
        /// <param name="sqlId"></param>
        /// <param name="sqlTag"></param>
        /// <returns></returns>
        public bool TryGet(string sqlId, out SqlTag sqlTag)
        {
            if (!this.sortedSet.TryGetValue(sqlId, out sqlTag))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取某一个
        /// </summary>
        /// <param name="sqlTag"></param>
        /// <returns></returns>
        internal void Add(SqlTag sqlTag)
        {
            SqlTag temp = null;

            if (this.TryGet(sqlTag.Id, out temp))
            {
                return;
            }

            this.sortedSet[sqlTag.Id] = sqlTag;
            return;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 加载所有的tag
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public SqlTagProvider Load(Stream stream, string filename = null)
        {
            var doc = new System.Xml.XmlDocument();

            doc.Load(stream);
            var @namespaces = doc["namespace"];

            if (@namespaces == null)
            {
                return(this);
            }

            var idele       = namespaces.Attributes.GetNamedItem("id");
            var indentedele = namespaces.Attributes.GetNamedItem("indented");
            var id          = idele == null ? "" : idele.Value;
            var indented    = indentedele == null ? true : indentedele.Value.AsBool();

            var next = @namespaces.FirstChild;

            while (next != null)
            {
                if (next.NodeType == System.Xml.XmlNodeType.Comment)
                {
                    next = next.NextSibling;
                    continue;
                }

                var name      = next.Name;
                var nextIdele = next.Attributes.GetNamedItem("id");
                if (nextIdele == null)
                {
                    throw new Never.Exceptions.KeyNotExistedException("can not find the id atrribute in this {0} file", filename);
                }

                var nextId = nextIdele.Value;
                if (nextId.IsNullOrEmpty())
                {
                    throw new Never.Exceptions.DataFormatException("can not find the id atrribute in this {0} file", filename);
                }

                if (this.sortedSet.ContainsKey(nextId))
                {
                    throw new DataFormatException("the {0} is duplicated", nextId);
                }

                var sqlTag = new SqlTag();
                sqlTag.Id                  = nextId;
                sqlTag.NameSpace           = id;
                sqlTag.IndentedOnNameSpace = indented;
                if (!LoadCommandName(next, sqlTag))
                {
                    next = next.NextSibling;
                    break;
                }
                sqlTag.Node            = next;
                this.sortedSet[nextId] = sqlTag;
                next = next.NextSibling;
            }

            return(this);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sqlTag"></param>
        internal void Remove(SqlTag sqlTag)
        {
            SqlTag id = null;

            this.sortedSet.TryRemove(sqlTag.Id, out id);
        }