Exemplo n.º 1
0
        private List <WeakReference> GetRemovedWeekRefereces(ResourceReferenceInfo resourceInfo, object owner)
        {
            var removedOwners = new List <WeakReference>();

            foreach (var weakReference in resourceInfo.Owners)
            {
                if (weakReference.Target == owner || weakReference.Target == null || weakReference.Target.ToString() == "null")
                {
                    removedOwners.Add(weakReference);
                }
            }

            return(removedOwners);
        }
Exemplo n.º 2
0
        public object Get(object owner, string key)
        {
            key = ValidateKey(key);
            ResourceReferenceInfo resourceInfo = null;

            if (_assets.TryGetValue(key, out resourceInfo))
            {
                if (!resourceInfo.ContainsOwner(owner))
                {
                    resourceInfo.AddOwner(owner);
                }

                return(resourceInfo.Resource);
            }

            throw new ResourceMemoryCacheException(string.Format("Missing resource in cach. Resource name: {0}", key));
        }
Exemplo n.º 3
0
        public void Add(object owner, string key, object resource)
        {
            key = ValidateKey(key);
            ResourceReferenceInfo resourceReference;

            if (_assets.TryGetValue(key, out resourceReference))
            {
                if (!resourceReference.ContainsOwner(owner))
                {
                    resourceReference.AddOwner(owner);
                }
            }
            else
            {
                resourceReference = new ResourceReferenceInfo(resource);
                resourceReference.AddOwner(owner);
                _assets.Add(key, resourceReference);
            }
        }