Exemplo n.º 1
0
 public static bool StopTracking(string key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     return(EntityLocator.Remove(key));
 }
Exemplo n.º 2
0
        public static Entity LocateEntity <Entity>(string key, bool isLocatorEnabled) where Entity : class, IEntity, new()
        {
            Entity local = default(Entity);

            if (((key != null) && isLocatorEnabled) && EntityLocator.Contains(key))
            {
                local = EntityLocator.Get(key) as Entity;
            }
            return(local);
        }
Exemplo n.º 3
0
        public static Entity LocateOrCreate <Entity>(string key, string typeString, Type entityFactoryType, bool isLocatorEnabled) where Entity : class, IEntity, new()
        {
            if (string.IsNullOrEmpty(typeString))
            {
                throw new ArgumentException("typeString");
            }
            if (entityFactoryType == null)
            {
                throw new ArgumentException("entityFactoryType");
            }
            Entity entity      = default(Entity);
            Type   defaultType = typeof(Entity);

            if (defaultType.GetInterface("IEntityCacheItem") != null)
            {
                entity = EntityCache.GetItem <Entity>(key.ToString());
            }
            if (entity == null)
            {
                IEntityFactory factory = null;
                if (EntityFactories.ContainsKey(entityFactoryType.FullName))
                {
                    factory = EntityFactories[entityFactoryType.FullName];
                }
                else
                {
                    factory = TryAddEntityFactory(entityFactoryType);
                }
                if (((key != null) && isLocatorEnabled) && EntityLocator.Contains(key))
                {
                    entity = EntityLocator.Get(key) as Entity;
                }
                if (entity == null)
                {
                    entity = factory.CreateEntity(typeString, defaultType) as Entity;
                }
                if (!entity.IsEntityTracked)
                {
                    StartTracking(key, entity, isLocatorEnabled);
                }
                if (entity.GetType().GetInterface("IEntityCacheItem") != null)
                {
                    EntityCache.AddCache(key, entity);
                }
            }
            return(entity);
        }
Exemplo n.º 4
0
 public static void StartTracking(string key, IEntity entity, bool isTrackingEnabled)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     if (!(entity.IsEntityTracked || !isTrackingEnabled))
     {
         EntityLocator.Add(key, entity);
         entity.IsEntityTracked   = true;
         entity.EntityTrackingKey = key;
     }
 }