Exemplo n.º 1
0
        public TemplateNodeInfo CloneNotSavedTree(
            Dictionary <TemplateNodeInfo, TemplateNodeInfo> originalsAndClones,
            ConnectionData connectionData,
            TemplateNodeInfo parent = null
            )
        {
            TemplateNodeInfo clone = (TemplateNodeInfo)MemberwiseClone();

            clone._templateNodeId = null;
            clone.Parent          = parent;
            clone.Connection      = connectionData;
            clone.Childs          = new List <TemplateNodeInfo>(
                Childs.Select(
                    ch => ch.CloneNotSavedTree(
                        originalsAndClones,
                        connectionData,
                        clone
                        )
                    )
                );

            originalsAndClones.Add(this, clone);

            return(clone);
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("{");

            sb.AppendFormat("Id={0}", Id ?? string.Empty);
            if (Name != null)
            {
                sb.AppendFormat(", Name={0}", Name);
            }
            if (Parent != null)
            {
                sb.AppendFormat(", Parent={0}", Parent.Id);
            }
            if (Childs.Count != 0)
            {
                sb.AppendFormat(", Childs={0}", Childs.Select(x => x.Id).Sketch());
            }
            if (Countries.Count != 0)
            {
                sb.AppendFormat(", Countries={0}", Countries.Select(x => x.Id).Sketch());
            }
            if (RowVersion != null)
            {
                sb.AppendFormat(", RowVersion={0}", RowVersion.Sketch());
            }
            sb.Append("}"); return(sb.ToString());
        }
Exemplo n.º 3
0
 public string HTML(List<HTMLAttribute> attrs = null)
 {
     var result = "";
     try
     {
         result = String.Format("<div {0} {1} fname=\"{2}\"><span>{2}</span>{3}</div>",
             String.Join(" ", attrs.Select(a => String.Format("{0}=\"{1}\"", a.Key, a.Value))),
             Childs != null && Childs.Count > 0 ? "hc=\"1\"" : "",
             Name,
             String.Join("", Childs.Select(c => c.HTML(attrs)))
         );
     }
     catch (Exception e) { }
     return result;
 }
        public override BT_Callback CallbackState(BT_CallbackInfo info)
        {
            List <WeightedPair> weightedList = Childs.Select((t, i) => new WeightedPair(_weights[i], t)).ToList();

            weightedList = weightedList.OrderByDescending(t => t.Weight).ToList();

            foreach (I_BT_Callback btCallback in weightedList.Select(t => t.Element))
            {
                if (btCallback.CallbackState(info) == BT_Callback.True)
                {
                    //if the callback did run => selector calls back
                    return(BT_Callback.True);
                }
            }
            return(BT_Callback.False);
        }
Exemplo n.º 5
0
 private void CalculateBalance()
 {
     IsBalanced  = true;
     TotalWeight = Weight;
     if (Childs.Any())
     {
         foreach (var c in Childs)
         {
             c.CalculateBalance();
         }
         // Disc is balanced if all childs have exactly the same weight, ie 1/nth of their total weight
         var w = Childs.Select(c => c.TotalWeight).Sum();
         TotalWeight += w;
         IsBalanced   = w % Childs.Length == 0 && Childs.All(c => c.TotalWeight == w / Childs.Length);
     }
 }
Exemplo n.º 6
0
        public TV Filter <TV>(Func <T, bool> filterFunc) where TV : Node <T>, new()
        {
            var thisSatisfies = filterFunc(Value);

            if (!thisSatisfies)
            {
                return(null);
            }

            var filteredChildren = Childs.Select(x => x.Filter <TV>(filterFunc)).Where(x => x != null);
            var v = new TV
            {
                Value  = Value,
                Parent = Parent
            };

            v.AddAll(filteredChildren);
            return(v);
        }
        public IEnumerable <string> GetExpand()
        {
            string rec(OdataSelectExpand c)
            {
                var parts = new List <string>();

                var select = c.GetSelect();

                if (c.Filter != null)
                {
                    parts.Add($"$filter={c.Filter}");
                }
                if (select.Any())
                {
                    parts.Add($"$select={string.Join(",", select)}");
                }
                var sem = c.SelectMembers.Where(x => x.IsComplexType).Select(x => x.MemberPath);

                if (c.Childs.Any() || sem.Any())
                {
                    parts.Add($"$expand={string.Join(",", sem.Concat(c.Childs.Select(x => rec(x))))}");
                }
                var se = string.Join(";", parts);

                return($"{c.MemberPath}({se})");
            }

            return(SelectMembers.Where(x => x.IsComplexType).Select(x => x.MemberPath).Concat(Childs.Select(x => rec(x))));
        }
Exemplo n.º 8
0
 public int SumMetadata()
 {
     return(Metadata.Sum() + Childs.Select(q => q.SumMetadata()).Sum());
 }
Exemplo n.º 9
0
        /// <summary>按名称查找。实体缓存</summary>
        /// <param name="name">地区名称</param>
        /// <param name="withLike">未找到时,是否查找相似的地区。因为地区可能有市、县、区等字样,而查询名称没填</param>
        /// <param name="deepth">地区路径的最大可能层次。内置地区数据库只有三层</param>
        /// <returns></returns>
        public EntityList <TEntity> FindAllByName(String name, Boolean withLike = true, Int32 deepth = 0)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            if (deepth <= 0)
            {
                if ((this as IEntity).IsNullKey)
                {
                    deepth = 3;
                }
                else if (this.Parent == null || (this.Parent as IEntity).IsNullKey)
                {
                    deepth = 2;
                }
                else
                {
                    deepth = 1;
                }
            }

            //EntityList<TEntity> list = Meta.Cache.Entities.FindAll(__.Name, name);
            //EntityList<TEntity> list = Childs.FindAll(__.Name, name);
            EntityList <TEntity> list = Childs.FindAll(a => CompAreaName(a.Name, name));

            if (list != null && list.Count > 0)
            {
                return(list);
            }

            // 试试下一级
            if (deepth >= 2)
            {
                // 先用严格查找,再用模糊查找,避免在严格匹配项之前就匹配了模糊项
                foreach (var item in Childs)
                {
                    list = item.FindAllByName(name, false, deepth - 1);
                    if (list != null && list.Count > 0)
                    {
                        return(list);
                    }
                }
                if (withLike)
                {
                    foreach (var item in Childs)
                    {
                        list = item.FindAllByName(name, withLike, deepth - 1);
                        if (list != null && list.Count > 0)
                        {
                            return(list);
                        }
                    }
                }
            }

            if (!withLike)
            {
                return(list);
            }

            // 未找到,开始模糊查找
            //String[] names = Meta.Cache.Entities.Select<TEntity, String>(e => e.Name).ToArray();
            String[] names = Childs.Select <TEntity, String>(e => e.Name).ToArray();
            String[] rs    = StringHelper.LCSSearch(name, names);
            if (rs != null && rs.Length > 0)
            {
                list = new EntityList <TEntity>(Childs.Where <TEntity>(e => rs.Contains(e.Name, StringComparer.OrdinalIgnoreCase)));
                return(list);
            }

            // 如果层次大于1,开始拆分。比如江苏省南京市鼓楼区,第一段至少一个字
            if (deepth > 1)
            {
                // 应该从右往左,这样子才能做到最大匹配,否则会因为模糊查找而混杂很多其它东西
                //for (int i = name.Length - 1; i >= 1; i--)
                for (int i = 0; i < name.Length; i++)
                {
                    String first = name.Substring(0, i);
                    String last  = name.Substring(i);

                    // 必须找到左边的,否则这个匹配没有意义
                    //TEntity entity = Meta.Cache.Entities.Find(__.Name, first);
                    // 模糊查询一层
                    var list2 = FindAllByName(first, true, 1);
                    if (list2 != null && list2.Count > 0)
                    {
                        foreach (var item in list2)
                        {
                            list = item.FindAllByName(last, withLike, deepth - 1);
                            if (list != null && list.Count > 0)
                            {
                                return(list);
                            }
                        }
                    }
                }
            }

            return(list);
        }