Esempio n. 1
0
 /// <summary>
 /// 将本对象的用户配置值保存到内存中或持久化的配置文件中
 /// </summary>
 public void Save(bool persistent = false)
 {
     if (CurrentContextDict != null)
     {
         foreach (string propertyName in CurrentContextDict.Keys.ToList())
         {
             string[] propertyNames = propertyName.Split('.');
             object   obj           = propertyNames.Length == 1 ? ContextObject : FindObject(propertyNames);
             obj = RefHelper.GetValue(obj, propertyNames[propertyNames.Length - 1]);
             if (obj == null)
             {
                 CurrentContextDict.Remove(propertyName);
             }
             else if (obj.GetType() == typeof(String) || !obj.GetType().IsClass)
             {
                 CurrentContextDict[propertyName] = new TypeAndValue {
                     TypeName = obj.GetType().AssemblyQualifiedName, Value = CommOp.ToFullStr(obj)
                 };
             }
             else
             {
                 CurrentContextDict[propertyName] = new TypeAndValue {
                     TypeName = obj.GetType().AssemblyQualifiedName, Value = JsonHelper.ToJson(obj)
                 };
             }
         }
     }
     if (persistent)
     {
         SaveAllToPersistent();
     }
 }
        /// <summary>
        /// 获取数据模型对象中的对应集合数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="itemEntityType"></param>
        /// <returns></returns>
        private IList GetCollectionInEntity(TEntity data, Type itemEntityType)
        {
            var rule = _entityRule.CollectionRules.FirstOrDefault(r => r.ModelType == itemEntityType);

            if (rule != null)
            {
                return(RefHelper.GetValue(data, rule.Name) as IList);
            }
            return(null);
        }
        /// <summary>
        /// 返回数据模型中子类的集合
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pm"></param>
        /// <returns></returns>
        public virtual ActionResult Details(string name, PageModel pm)
        {
            var obj     = Session[typeof(TModel).Name] as TModel;
            var propVal = RefHelper.GetValue(obj, name);

            if (propVal == null)
            {
                return(Content("[]"));
            }

            return(JsonNT(propVal));
        }
        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);
            var result = filterContext.Result as JsonResult;

            if (result == null)
            {
                return;
            }
            var data = RefHelper.GetValue(result.Data, "data") as Pager <TModel>;

            if (data == null)
            {
                return;
            }

            BeforeShowingPage(data);
        }
Esempio n. 5
0
        /// <summary>
        /// 处理一个查询定义节点。依次递归子节点循环。
        /// </summary>
        /// <param name="node">当前节点</param>
        /// <param name="item">查询项集合</param>
        /// <param name="odtObj"></param>
        /// <param name="exp">查询表达式</param>
        /// <param name="parameters">查询表达式参数</param>
        private void ProcessQueryNode(AdvQueryNode node, AdvQueryItem item, object odtObj, ref string exp, ref IList <object> parameters)
        {
            if (node == null)
            {
                return;
            }

            //查询当前节点的子节点
            List <AdvQueryNode> children = item.Nodes.Where(t => t.ParentId == node.Id).ToList();

            if (children.Count == 0)
            {
                //没有子节点,这是一个表达式节点

                if (node.Operator.IsEmpty())
                {
                    return;
                }

                string p = "@" + parameters.Count;

                if (node.Operator.Trim().ToUpper().Equals("LIKE"))
                {
                    exp = exp + node.Expression.Trim() + ".Contains(" + p + ") ";
                }
                else if (node.Operator.Trim().ToUpper().Equals("NOT LIKE"))
                {
                    exp = exp + " !" + node.Expression.Trim() + ".Contains(" + p + ") ";
                }
                else
                {
                    exp = exp + " (" + node.Expression.Trim() + node.Operator + p + ") ";
                }

                RefHelper.SetValue(odtObj, node.Expression, node.Value);
                parameters.Add(RefHelper.GetValue(odtObj, node.Expression));

                return;
            }
            else
            {
                //有子节点,这是一个逻辑运算符节点

                exp = exp + "(";
                int i = 0;
                foreach (AdvQueryNode child in children)
                {
                    //子节点是逻辑运算符
                    if (child.Type.ToLower() == "operator")
                    {
                        if (!item.Nodes.Exists(t => t.ParentId == child.Id))
                        {
                            continue;
                        }
                    }

                    if (i > 0)
                    {
                        exp = exp + " " + node.Expression + " ";
                    }
                    //递归子节点循环。
                    ProcessQueryNode(child, item, odtObj, ref exp, ref parameters);

                    i++;
                }
                exp = exp + ")";
            }
        }
Esempio n. 6
0
        object Init(Type catType)
        {
            int?   tParentId = null;
            object catDef;

            catDef = Activator.CreateInstance(catType);

            AssignNameValue(catDef);

            var parentTree = _catalogTree.FindTree(n => n.GetType() == catType.BaseType);

            //如果在树中找不到父结点,则它为根结点的一级子结点
            if (parentTree == null)
            {
                var tree = _catalogTree.Add(catDef);

                //判断有无其它先期加入的结点应该是它的子结点(根据类继承关系来判断)
                //判断过于复杂,先不做,这就要求初始化顺序一定要按父子关系来
                //foreach (object node in _catalogTree)
                //{
                //    if (node.GetType().IsAssignableFrom(catType))
                //    {
                //        tree.Add(node);
                //        var id = (int)RefHelper.GetValue(node, "Id");

                //        var nodeCat = SiteManager.Catalog.GetById(id);

                //    }
                //}
            }
            else
            {
                tParentId = RefHelper.GetValue(parentTree.Node, "Id") as int?;
                parentTree.Add(catDef);
            }


            var catalog = SiteManager.Catalog.GetAll().FirstOrDefault(cat => cat.ParentId == tParentId && cat.Name == (string)RefHelper.GetValue(catDef, "Name"));

            if (catalog == null)
            {
                catalog = new Base_Catalog()
                {
                    Name       = (string)RefHelper.GetValue(catDef, "Name"),
                    ParentId   = tParentId,
                    State      = ArticleState.Static + ArticleState.Published,
                    OwnerType  = CatalogOwnerType.System,
                    EditTime   = DateTime.Now,
                    CreateTime = DateTime.Now
                };

                ChangeExts(catalog, catType);
                SiteManager.Catalog.Add(catalog);
            }
            else if (ChangeExts(catalog, catType))
            {
                SiteManager.Catalog.Change(catalog);
            }

            PropertyInfo pi = catType.GetProperty("Id", BindingFlags.Public | BindingFlags.Instance);

            pi.SetValue(catDef, catalog.Id, null);

            return(catDef);
        }