Example #1
0
        /// <summary>
        /// 递归读取CommandQueue
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private FilterDefinition <T> GetTempBuilder <T>(TempCommandQueue comm)
        {
            Console.WriteLine($@"TempCommandQueue>>{comm.GroupId}");
            FilterDefinition <T> filterDefinition = null;

            if (!comm.HasExcuted) //未被调用过
            {
                foreach (var communit in comm.TempLine)
                {
                    if (communit.CommandReader()) //解析自身命令
                    {
                        if (filterDefinition == null)
                        {
                            filterDefinition = RunBuilder <T>(communit);
                        }
                        else
                        {
                            filterDefinition &= RunBuilder <T>(communit);
                            //filterDefinition |= communit.ToBuilder<T, string>("沙");
                        }
                    }
                    else
                    {
                        if (communit.IsLinked)
                        {
                            //调用Link命令,转到其他解析
                            var id            = communit.LinkedId;
                            var temp          = tempCommandQueues.Where(e => e.GroupId == id).First();
                            var ret_sub_cline = GetTempBuilder <T>(temp);
                            if (ret_sub_cline != null)
                            {
                                (filterDefinition) &= ret_sub_cline;
                            }
                        }
                    }
                }
                comm.HasExcuted = true;
            }
            return(filterDefinition);
        }
Example #2
0
        public void GetWhereTrees()
        {
            List <SentencesUnit>       sentences    = new List <SentencesUnit>();
            List <string>              treelist     = new List <string>();
            List <SQLWhereCommandLine> CommandLines = new List <SQLWhereCommandLine>();

            foreach (var e in TempExecuteSentence)
            {
                // Console.WriteLine(e);
                //改判断标识当前新语句e在sentens外围( eeee /....sentence executed ..../ eeee),则替换
                var nodes = sentences.FindAll(s => s.BeginPos > e.BeginPos && s.EndPos < e.EndPos);
                if (nodes.Count > 0)
                {
                    var str = e.Command;
                    foreach (var n in nodes)
                    {
                        str = str.Replace(n.Command, $@" [node{n.Id}] ");
                    }
                    treelist.Add($@"{e.Id} >>" + str);
                    //判断标识当前新语句e在sentens外围,则去除原语句,并加入新语句
                    sentences.RemoveAll(s => s.BeginPos > e.BeginPos && s.EndPos < e.EndPos);
                    sentences.Add(e);
                }
                else
                {
                    treelist.Add($@"{e.Id} >>" + e.Command);
                    //判断标识当前新语句e不在sentens外围,则添加
                    sentences.Add(e);
                }
            }
            //解析树
            //50405199-3f6f-4993-bf1e-3762bca14724 >>( Name like @Name )
            //9415faac-f6c8-4e03-8edb-cddf5a3e56a2 >>( Name = 123 or Age > 25 or  [node50405199-3f6f-4993-bf1e-3762bca14724] )
            //f5a9e106-8584-4df2-9858-c87ecede8002 >>( Name <> 123 or Age <=10 )
            //81557301-79ca-443b-84ab-ebe2949eb8e6 >>(  [node9415faac-f6c8-4e03-8edb-cddf5a3e56a2] or  [nodef5a9e106-8584-4df2-9858-c87ecede8002] and CreateDate > @NOW )

            foreach (var list in treelist)
            {
                var splitchars = new string[] { "or", "and" };
                var _comm      = list.Split(">>");

                var Id = _comm[0];

                if (_comm[1].Trim().StartsWith("(") && _comm[1].Trim().EndsWith(")"))
                {
                    _comm[1] = _comm[1].Replace("(", string.Empty).Replace(")", string.Empty);
                }
                var commands = _comm[1].Trim().Split(splitchars, StringSplitOptions.RemoveEmptyEntries);
                foreach (var comm in commands)
                {
                    if (comm.Trim().ToLower().StartsWith("[node") && comm.Trim().ToLower().EndsWith("]"))
                    {
                        var linkid = comm.Trim().Replace("[node", string.Empty).Replace("]", string.Empty);

                        CommandLines.Add(new SQLWhereCommandLine {
                            _id = Id.Trim(), LinkedId = linkid.Trim()
                        });
                    }
                    else
                    {
                        CommandLines.Add(new SQLWhereCommandLine {
                            _id = Id.Trim(), Command = comm.Trim()
                        });
                        //thetrees.Add(new WhereTree { ExecuteCode = comm, NodeType = WhereNodeType.AND,_id = _comm[0].Trim() });
                    }
                }
                //Console.WriteLine(list);
            }
            //908892ef-c6ae-4ed5-a3dd-c77c3c4cf2a6  >> Name like @Name
            //7238d3d1-e1a9-470c-9094-e14a3318d12e  >> Name = 123
            //7238d3d1-e1a9-470c-9094-e14a3318d12e  >> Age > 25
            //7238d3d1-e1a9-470c-9094-e14a3318d12e  >> Linked >> 908892ef-c6ae-4ed5-a3dd-c77c3c4cf2a6
            //779e8819-9d1c-4e18-bc16-3b77bd5d262a  >> Name <> 123
            //779e8819-9d1c-4e18-bc16-3b77bd5d262a  >> Age <=10
            //58973e7d-7605-4a37-bd30-d2946a6a6d24  >> Linked >> 7238d3d1-e1a9-470c-9094-e14a3318d12e
            //58973e7d-7605-4a37-bd30-d2946a6a6d24  >> Linked >> 779e8819-9d1c-4e18-bc16-3b77bd5d262a
            //58973e7d-7605-4a37-bd30-d2946a6a6d24  >> CreateDate > @NOW
            //测试输出顺序
            foreach (var _command in CommandLines)
            {
                Console.WriteLine(_command);
            }
            //执行分组
            foreach (var group in CommandLines.GroupBy(e => e._id))
            {
                TempCommandQueue tcq = new TempCommandQueue();
                tcq.GroupId = group.FirstOrDefault()._id; //执行组id
                foreach (var commtable in group)
                {
                    tcq.TempLine.Enqueue(commtable);
                    //只要有一个为Link节点,则整个队列属性为Linked
                    if (commtable.IsLinked)
                    {
                        tcq.HasLinked = true;
                    }
                }
                tempCommandQueues.Add(tcq);
            }
        }
Example #3
0
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="tempCommand"></param>
 private void ExecutedTempCommandQueue(TempCommandQueue tempCommand)
 {
 }