Beispiel #1
0
        /// <summary>
        /// 获取顶级操作对象,即获取级联操作父类属性
        /// </summary>
        /// <param name="entityElement"></param>
        /// <returns></returns>
        public void SetOperateRule(XElement entityElement)
        {
            #region 顶级变量
            List <VarRule> vars = new List <VarRule>();

            foreach (var tempElement in entityElement.Elements("Var"))
            {
                VarRule tempVar = new VarRule(tempElement);

                vars.Add(tempVar);
            }

            this.Vars = vars;
            #endregion

            #region 顶级循环
            List <ForeachRule> foreachs = new List <ForeachRule>();

            foreach (var tempElement in entityElement.Elements("Foreach"))
            {
                ForeachRule tempForeach = new ForeachRule(tempElement);

                foreachs.Add(tempForeach);
            }

            this.Foreachs = foreachs;
            #endregion

            #region 顶级判断
            List <IfRule> ifs = new List <IfRule>();

            foreach (var tempElement in entityElement.Elements("If"))
            {
                IfRule tempIf = new IfRule(tempElement);

                ifs.Add(tempIf);
            }

            this.Ifs = ifs;
            #endregion

            #region 顶级操作
            List <StorageRlue> storages = new List <StorageRlue>();

            foreach (var tempElement in entityElement.Elements("Storage"))
            {
                StorageRlue tempStorage = new StorageRlue(tempElement);

                storages.Add(tempStorage);
            }

            this.Storages = storages;
            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// 解析级联操作中中括号括号的值
        /// </summary>
        /// <param name="sourceStr"></param>
        /// <param name="varList"></param>
        /// <param name="sourceDic"></param>
        /// <returns></returns>
        public string ResolveBracket(string sourceStr, List <VarRule> varList, Dictionary <string, BsonDocument> sourceDic)
        {
            string resultStr = sourceStr;

            if (sourceStr.StartsWith("[") && sourceStr.EndsWith("]"))
            {
                resultStr = sourceStr.TrimStart('[').TrimEnd(']');

                #region 判断是否为一个数组
                if (resultStr.Contains(","))
                {
                    bool flag = false;

                    string[] tempArray = resultStr.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                    if (tempArray.Count() > 0)
                    {
                        #region 判断是不是每一段都是被 " " 包裹
                        if (flag == false)
                        {
                            foreach (var temp in tempArray)
                            {
                                if (temp.StartsWith("\"") && temp.EndsWith("\""))
                                {
                                    flag = true;
                                }
                                else                //如果不是被 "" 包裹,返回标记为假
                                {
                                    flag = false; break;
                                }
                            }
                        }
                        #endregion

                        #region 判断是不是每一段都是被 '' 包裹
                        if (flag == false)
                        {
                            foreach (var temp in tempArray)
                            {
                                if (temp.StartsWith("'") && temp.EndsWith("'"))
                                {
                                    flag = true;
                                }
                                else                //如果不是被 '' 包裹,返回标记为假
                                {
                                    flag = false; break;
                                }
                            }
                        }
                        #endregion

                        #region 判断是不是每一段都没有被任何引号包裹
                        if (flag == false)
                        {
                            foreach (var temp in tempArray)
                            {
                                if (temp.StartsWith("'") == false && temp.StartsWith("\"") == false && temp.EndsWith("'") && temp.EndsWith("\""))
                                {
                                    flag = true;
                                }
                                else                //如果有 " 或 ' 开头或结束 ,返回标记为假
                                {
                                    flag = false; break;
                                }
                            }
                        }
                        #endregion
                    }

                    if (flag == true)
                    {
                        return(sourceStr);              //如果是一个数组,返回原字符串
                    }
                }
                #endregion

                #region 判断是否为一个字符串
                if ((resultStr.StartsWith("'") && resultStr.EndsWith("'")) || (resultStr.StartsWith("\"") && resultStr.EndsWith("\"")))
                {
                    return(resultStr.TrimStart('\'').TrimStart('"').TrimEnd('\'').TrimEnd('"')); //如果是字符串,返回去掉引号后的值
                }
                #endregion

                #region 判断是否是 *.* 结构
                if (resultStr.Contains("."))       //如果是{*.*}类型,从源集合中取值,或直接数据库查询
                {
                    string[] tempArray = resultStr.Split(new string[] { "." }, StringSplitOptions.None);

                    #region 如果是 [this.column] , [var.column] 类型
                    if (tempArray.Count() == 2)
                    {
                        string tempBsonKey = tempArray[0];                                                                                 //引用变量名

                        string tempColumnKey = tempArray[1];                                                                               //字段名

                        BsonDocument tempBson = (sourceDic != null && sourceDic.ContainsKey(tempBsonKey)) ? sourceDic[tempBsonKey] : null; //对应变量BSON

                        resultStr = (tempBson != null && tempBson.Contains(tempColumnKey)) ? tempBson[tempColumnKey].ToString() : "";      //获取对应字段值
                    }
                    #endregion

                    #region 如果是 [db.*.findOne(..).column] 类型
                    if (tempArray.Count() == 4)
                    {
                        resultStr = TypeConvert.NativeQueryToResultValue(resultStr);                        //执行原生查询
                    }
                    #endregion

                    return(resultStr);
                }
                #endregion

                #region 判断是否是变量
                VarRule tempVar = varList.Where(t => t.Name == resultStr).FirstOrDefault();

                if (tempVar != null)
                {
                    resultStr = tempVar.Value.GetValue(varList, sourceDic);
                }
                #endregion
            }

            return(resultStr);
        }