예제 #1
0
파일: Cache.cs 프로젝트: rsvinay/xenadmin
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xenRef">May be null, in which case null is returned. May not be a null ref.</param>
        /// <returns></returns>
        public T Resolve <T>(XenRef <T> xenRef) where T : XenObject <T>
        {
            if (xenRef == null)
            {
                return(null);
            }

            ChangeableDictionary <XenRef <T>, T> d = (ChangeableDictionary <XenRef <T>, T>)GetCollectionForType(typeof(T));
            T result;

            return(d.TryGetValue(xenRef, out result) ? result : null);
        }
예제 #2
0
파일: Cache.cs 프로젝트: ywscr/xenadmin
        private void UpdateFrom_ <T>(Network.IXenConnection connection, ChangeableDictionary <XenRef <T>, T> target, ObjectChange source) where T : XenObject <T>, new()
        {
            XenRef <T> xenref = source.xenref as XenRef <T>;

            if (xenref == null)
            {
                xenref = new XenRef <T>((string)source.xenref);
            }

            if (source.value != null)
            {
                T to_update = null;
                lock (target)
                {
                    if (!target.TryGetValue(xenref, out to_update))
                    {
                        // add
                        T obj = new T();
                        obj.Connection = connection;
                        obj.UpdateFrom((T)source.value);
                        obj.opaque_ref = xenref.opaque_ref;
                        target.Add(xenref, obj);
                    }
                }

                // Update the object that we found above.  Note that this needs to be done out of the
                // scope of the lock(target), as UpdateFrom is going to fire events.
                if (to_update != null)
                {
                    to_update.UpdateFrom((T)source.value);
                }
            }
            else
            {
                // delete the source object from our model
                lock (target)
                {
                    target.Remove(xenref);
                }
            }
        }