Ejemplo n.º 1
0
        /// <summary>
        /// -99 = null input
        /// -1 = wrong type
        /// 0 = same type, wrong id
        /// 1 = same reference (same id, same type)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(ICacheKey other)
        {
            if (other != null)
            {
                try
                {
                    if (other.GetType() != GetType())
                    {
                        return(-1);
                    }

                    if (other.KeyHash().Equals(KeyHash()))
                    {
                        return(1);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(-99);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a list of possible resourceIds from MultiCacheKey or get single
        /// resourceId from ICacheKey.
        /// </summary>
        public static IList <string> GetResourceIds(ICacheKey key)
        {
            try
            {
                IList <string> ids;
                if (key.GetType() == typeof(MultiCacheKey))
                {
                    IList <ICacheKey> keys = ((MultiCacheKey)key).CacheKeys;
                    ids = new List <string>(keys.Count);
                    foreach (var entry in keys)
                    {
                        ids.Add(SecureHashKey(entry));
                    }
                }
                else
                {
                    ids = new List <string>(1);
                    ids.Add(SecureHashKey(key));
                }

                return(ids);
            }
            catch (EncoderFallbackException)
            {
                // This should never happen. All VMs support UTF-8
                throw;
            }
        }
Ejemplo n.º 3
0
        public static async Task <IList <ICacheKey <TEntry> > > KeysAsync <TEntry>(this ICacheKey <TEntry> entry, Installation installation = Installation.Default)
            where TEntry : new()
        {
            Type keyType = entry.GetType();
            IList <ICacheKey <TEntry> > keys = new List <ICacheKey <TEntry> >();

            foreach (string key in await entry.Manager <ICacheKey <TEntry>, TEntry>().ListAsync(installation))
            {
                ICacheKey <TEntry>   multitonKey = (ICacheKey <TEntry>)Activator.CreateInstance(keyType);
                IEnumerator <string> keyValues   = PropertyValue(key);
                if (!keyValues.MoveNext())
                {
                    continue;
                }
                foreach (PropertyInfo property in keyType.FetchProperties(ICacheKey <TEntry> .CacheIgnore))
                {
                    property.SetValue(multitonKey, Convert.ChangeType(keyValues.Current, property.PropertyType));
                    if (!keyValues.MoveNext())
                    {
                        break;
                    }
                }
                keys.Add(multitonKey);
            }
            return(keys);
Ejemplo n.º 4
0
        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(ICacheKey other)
        {
            if (other != default(ICacheKey))
            {
                try
                {
                    return(other.GetType() == GetType() && other.KeyHash().Equals(KeyHash()));
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(false);
        }
        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(ICacheKey other)
        {
            if (other != default(ICacheKey))
            {
                try
                {
                    return(other.GetType() == GetType() &&
                           other.KeyHash().Equals(KeyHash()));
                }
                catch
                {
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Get the resourceId from the first key in MultiCacheKey or get single
 /// resourceId from ICacheKey.
 /// </summary>
 public static string GetFirstResourceId(ICacheKey key)
 {
     try
     {
         if (key.GetType() == typeof(MultiCacheKey))
         {
             IList <ICacheKey> keys = ((MultiCacheKey)key).CacheKeys;
             return(SecureHashKey(keys[0]));
         }
         else
         {
             return(SecureHashKey(key));
         }
     }
     catch (EncoderFallbackException)
     {
         // This should never happen. All VMs support UTF-8
         throw;
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Get the hash code for comparison purposes
 /// </summary>
 /// <param name="obj">the thing to get the hashcode for</param>
 /// <returns>the hash code</returns>
 public int GetHashCode(ICacheKey obj)
 {
     return(obj.GetType().GetHashCode() + obj.KeyHash().GetHashCode());
 }
Ejemplo n.º 8
0
 private string BuildUniqueStringKey(ICacheKey key)
 {
     return String.Format("{0};{1};{2}", GetType().FullName, key.GetType().FullName, key.GetStringKey());
 }