public ControllerInfo(Type type)
        {
            try
            {
                this.Type = type;
                this.Name = GetControllerName();

                entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(type);

                BeeControllerAttribute beeControllerAttribute = entityProxy.GetCustomerAttribute <BeeControllerAttribute>();
                if (beeControllerAttribute != null)
                {
                    DefaultFlag = beeControllerAttribute.DefaultFlag;

                    if (!string.IsNullOrEmpty(beeControllerAttribute.ControllerName))
                    {
                        if (!string.IsNullOrEmpty(beeControllerAttribute.AreaName))
                        {
                            this.Name = "{0}|{1}".FormatWith(beeControllerAttribute.AreaName, beeControllerAttribute.ControllerName);
                        }
                        else
                        {
                            this.Name = beeControllerAttribute.ControllerName;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(beeControllerAttribute.AreaName))
                        {
                            this.Name = "{0}|{1}".FormatWith(beeControllerAttribute.AreaName, this.Name);
                        }
                    }
                }

                this.LowerName = Name.ToLower();

                DefaultAction = "Index";
                foreach (MethodSchema item in entityProxy.GetMethodList())
                {
                    ActionAttribute actionAttribute = item.GetCustomerAttribute <ActionAttribute>();
                    if (actionAttribute != null && actionAttribute.DefaultFlag)
                    {
                        DefaultAction = item.Name;
                        break;
                    }
                }

                // 构造一个Controller实例, 以初始化类静态构造函数。
                //ReflectionUtil.CreateInstance(type);
                entityProxy.CreateInstance();
            }
            catch (Exception e)
            {
                throw new CoreException("type:{0}".FormatWith(type), e);
            }
        }
Beispiel #2
0
        public static string GetTableName(Type typeInfo)
        {
            string typeName = typeInfo.FullName;

            return(CacheManager.Instance.GetEntity <string, string>(Constants.BeeDataTableNameTypeCategory, typeName, TimeSpan.FromHours(4), (para) =>
            {
                IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(typeInfo);

                OrmTableAttribute ormTableAttribute =
                    entityProxy.GetCustomerAttribute <OrmTableAttribute>();

                string tableName = typeInfo.Name;
                if (ormTableAttribute != null)
                {
                    if (!string.IsNullOrEmpty(ormTableAttribute.TableName))
                    {
                        tableName = ormTableAttribute.TableName;
                    }
                }

                return tableName;
            }));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the conditions via the attribute of the modeltype and the data from page.
        /// </summary>
        /// <param name="modelType">the model type.</param>
        /// <param name="dataAdapter">the data from page.</param>
        /// <returns>the condition.</returns>
        protected virtual SqlCriteria GetQueryCondition(Type modelType, BeeDataAdapter dataAdapter)
        {
            IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(modelType);
            SqlCriteria  result      = new SqlCriteria();

            dataAdapter = new BeeDataAdapter(dataAdapter);
            dataAdapter.RemoveEmptyOrNull();

            ModelAttribute modelAttribute = entityProxy.GetCustomerAttribute <ModelAttribute>();

            foreach (PropertySchema propertySchema in entityProxy.GetPropertyList())
            {
                string propertyName = propertySchema.Name;
                ModelPropertyAttribute modelPropertyAttribute
                    = propertySchema.GetCustomerAttribute <ModelPropertyAttribute>();
                if (modelPropertyAttribute != null)
                {
                    if (dataAdapter.ContainsKey(propertyName))
                    {
                        if (modelPropertyAttribute.Queryable)
                        {
                            object conditionValue = dataAdapter[propertyName];

                            if (propertySchema.PropertyType == typeof(string))
                            {
                                conditionValue = HttpUtility.HtmlDecode(conditionValue.ToString());
                            }

                            if (modelPropertyAttribute.QueryType == ModelQueryType.Equal &&
                                propertySchema.PropertyType == typeof(bool))
                            {
                                bool value = false;
                                bool.TryParse(conditionValue.ToString(), out value);
                                if (value)
                                {
                                    conditionValue = 1;
                                }
                                else
                                {
                                    conditionValue = 0;
                                }
                            }

                            if (propertySchema.PropertyType == typeof(DateTime))
                            {
                                DateTime propertyValue = dataAdapter.TryGetValue <DateTime>(propertyName, DateTime.MinValue);
                                if (propertyValue != DateTime.MinValue)
                                {
                                    conditionValue = propertyValue;
                                }
                                else
                                {
                                    // 若是时间,而又没有赋值, 则略过
                                    continue;
                                }
                            }

                            AddCondition(result, modelPropertyAttribute.QueryType, propertyName, conditionValue);
                        }
                    }
                    else
                    {
                        if (modelPropertyAttribute.Queryable &&
                            modelPropertyAttribute.QueryType == ModelQueryType.Between)
                        {
                            if (dataAdapter.ContainsKey(propertyName + "begin"))
                            {
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    DateTime beginTime = dataAdapter.TryGetValue <DateTime>(propertyName + "begin", DateTime.MinValue);
                                    result.GreaterThanOrEqual(propertyName, beginTime);
                                }
                                else
                                {
                                    result.GreaterThanOrEqual(propertyName, dataAdapter[propertyName + "begin"]);
                                }
                            }

                            if (dataAdapter.ContainsKey(propertyName + "end"))
                            {
                                DateTime endTime = dataAdapter.TryGetValue <DateTime>(propertyName + "end", DateTime.MinValue);
                                if (propertySchema.PropertyType == typeof(DateTime))
                                {
                                    if (endTime == endTime.Date)
                                    {
                                        endTime = endTime.AddDays(1);
                                    }

                                    //result.LessThan(propertyName, endTime.ToString("yyyy-MM-dd"));
                                    result.LessThan(propertyName, endTime);
                                }
                                else
                                {
                                    result.LessThanOrEqual(propertyName, dataAdapter[propertyName + "end"]);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }