예제 #1
0
        public IDictionary <string, IStorageContext> GenerateStorageContexts <T>(T target,
                                                                                 BuildFakeCommandByRoutingsHandler <T>
                                                                                 buildFakeCommandByRoutingsHandler,
                                                                                 BuildFakeCommandByRoutingHandler <T>
                                                                                 buildFakeCommandByRoutingHandler)
            where T : IAlbianObject
        {
            if (null == target)
            {
                throw new ArgumentNullException("target");
            }

            Type   type        = target.GetType();
            string fullName    = AssemblyManager.GetFullTypeName(target);
            object oProperties = PropertyCache.Get(fullName);

            PropertyInfo[] properties;
            if (null == oProperties)
            {
                if (null != Logger)
                {
                    Logger.Warn("Get the object property info from cache is null.Reflection now and add to cache.");
                }
                properties = type.GetProperties();
                PropertyCache.InsertOrUpdate(fullName, properties);
            }
            properties = (PropertyInfo[])oProperties;
            object oAttribute = ObjectCache.Get(fullName);

            if (null == oAttribute)
            {
                if (null != Logger)
                {
                    Logger.ErrorFormat("The {0} object attribute is null in the object cache.", fullName);
                }
                throw new Exception("The object attribute is null");
            }
            IObjectAttribute objectAttribute = (IObjectAttribute)oAttribute;
            IDictionary <string, IStorageContext> storageContexts = buildFakeCommandByRoutingsHandler(target, properties,
                                                                                                      objectAttribute,
                                                                                                      buildFakeCommandByRoutingHandler);

            if (0 == storageContexts.Count) //no the storage context
            {
                if (null != Logger)
                {
                    Logger.Warn("There is no storage contexts of the object.");
                }
                return(null);
            }
            return(storageContexts);
        }
예제 #2
0
        protected PropertyInfo[] AfterExecute <T>(IDataReader dr, out Hashtable reader,
                                                  out IDictionary <string, IMemberAttribute> members)
        {
            Type   type        = typeof(T);
            string fullName    = AssemblyManager.GetFullTypeName(type);
            object oProperties = PropertyCache.Get(fullName);

            PropertyInfo[] properties;
            if (null == oProperties)
            {
                if (null != Logger)
                {
                    Logger.Warn("Get the object property info from cache is null.Reflection now and add to cache.");
                }
                properties = type.GetProperties();
                PropertyCache.InsertOrUpdate(fullName, properties);
            }
            properties = (PropertyInfo[])oProperties;
            object oAttribute = ObjectCache.Get(fullName);

            if (null == oAttribute)
            {
                if (null != Logger)
                {
                    Logger.ErrorFormat("The {0} object attribute is null in the object cache.", fullName);
                }
                throw new Exception("The object attribute is null");
            }
            IObjectAttribute objectAttribute = (IObjectAttribute)oAttribute;

            members = objectAttribute.MemberAttributes;

            reader = new Hashtable();
            for (int i = 0; i < dr.FieldCount; i++)
            {
                reader[dr.GetName(i)] = i;
            }
            return(properties);
        }
예제 #3
0
        public IDictionary <string, IMemberAttribute> ReflectMembers(string typeFullName, out string defaultTableName)
        {
            //string typeFullName = entity.Implement;
            if (string.IsNullOrEmpty(typeFullName))
            {
                throw new ArgumentNullException("typeFullName");
            }
            Type type = Type.GetType(typeFullName, true);

            defaultTableName = type.Name;
            PropertyInfo[] propertyInfos =
                type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);

            //the interface
            Type         itf       = type.GetInterface("IAlbianObject"); //get the signature interface
            PropertyInfo idInfo    = itf.GetProperty("Id");
            PropertyInfo isNewInfo = itf.GetProperty("IsNew");

            if (null == propertyInfos || 0 == propertyInfos.Length)
            {
                throw new Exception(string.Format("Reflect the {0} property is error.", typeFullName));
            }

            IDictionary <string, IMemberAttribute> memberAttributes = new Dictionary <string, IMemberAttribute>();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                IMemberAttribute memberAttribute = ReflectProperty(propertyInfo, idInfo, isNewInfo);
                memberAttributes.Add(memberAttribute.Name, memberAttribute);
            }
            if (0 == memberAttributes.Count)
            {
                return(null);
            }

            PropertyCache.InsertOrUpdate(typeFullName, propertyInfos);  //just only have property
            MemberCache.InsertOrUpdate(typeFullName, memberAttributes); //parser object by member attributes
            return(memberAttributes);
        }