示例#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
        public IDictionary <string, IStorageContext> GenerateFakeCommandByRoutings <T>(T target, PropertyInfo[] properties,
                                                                                       IObjectAttribute objectAttribute,
                                                                                       BuildFakeCommandByRoutingHandler <T>
                                                                                       buildFakeCommandByRoutingHandler)
            where T : IAlbianObject
        {
            if (null == properties || 0 == properties.Length)
            {
                throw new ArgumentNullException("properties");
            }
            if (null == objectAttribute)
            {
                throw new ArgumentNullException("objectAttribute");
            }
            if (null == objectAttribute.RoutingAttributes || null == objectAttribute.RoutingAttributes.Values ||
                0 == objectAttribute.RoutingAttributes.Values.Count)
            {
                if (null != Logger)
                {
                    Logger.Error("The routing attributes or routings is null");
                }
                throw new Exception("The routing attributes or routing is null");
            }

            IDictionary <string, IStorageContext> storageContexts = new Dictionary <string, IStorageContext>();

            foreach (var routing in objectAttribute.RoutingAttributes.Values)
            {
                IFakeCommandAttribute fakeCommandAttrribute = buildFakeCommandByRoutingHandler(PermissionMode.W, target,
                                                                                               routing, objectAttribute,
                                                                                               properties);
                if (null == fakeCommandAttrribute) //the PermissionMode is not enough
                {
                    if (null != Logger)
                    {
                        Logger.WarnFormat("The permission is not enough in the {0} routing.", routing.Name);
                    }
                    continue;
                }
                if (storageContexts.ContainsKey(fakeCommandAttrribute.StorageName))
                {
                    storageContexts[fakeCommandAttrribute.StorageName].FakeCommand.Add(fakeCommandAttrribute);
                }
                else
                {
                    IStorageContext storageContext = new StorageContext
                    {
                        FakeCommand = new List <IFakeCommandAttribute>(),
                        StorageName = fakeCommandAttrribute.StorageName,
                    };
                    storageContext.FakeCommand.Add(fakeCommandAttrribute);
                    storageContexts.Add(fakeCommandAttrribute.StorageName, storageContext);
                }
            }
            return(storageContexts);
        }