예제 #1
0
 private bool Add(string SessionID, DynamicSourcesCache value, int?timeout = DefaultTimeout)
 {
     if (SessionID != null)
     {
         bool writeAllowed = false;
         try
         {
             writeAllowed = TryEnterWriteLock((int)timeout);
             if (writeAllowed)
             {
                 innerCache.Add(SessionID, value);
                 return(true);
             }
             else
             {
             }
         }
         finally
         {
             if (writeAllowed)
             {
                 cacheLock.ExitWriteLock();
             }
         }
     }
     return(false);
 }
예제 #2
0
        public SaveStatus Save(string SessionID, DynamicSourcesCache value, int?timeout = DefaultTimeout)
        {
            SaveStatus status = SaveStatus.Undefined;

            try
            {
                if (TryEnterUpgradeableReadLock((int)timeout))
                {
                    DynamicSourcesCache result = null;
                    if (innerCache.TryGetValue(SessionID, out result))
                    {
                        if (result == value)
                        {
                            status = SaveStatus.Unchanged;
                        }
                        else if (Update(SessionID, value, timeout))
                        {
                            status = SaveStatus.Updated;
                        }
                    }
                    else
                    {
                        if (Add(SessionID, value, timeout))
                        {
                            status = SaveStatus.Added;
                        }
                    }
                }
            }
            finally { cacheLock.ExitUpgradeableReadLock(); }
            return(status);
        }
예제 #3
0
 private bool Update(string SessionID, DynamicSourcesCache value, int?timeout = DefaultTimeout)
 {
     if (SessionID != null)
     {
         try { if (TryEnterWriteLock((int)timeout))
               {
                   innerCache[SessionID] = value; return(true);
               }
         } finally { cacheLock.ExitWriteLock(); }
     }
     return(false);
 }
예제 #4
0
 private bool DeleteInternal(string SessionID)
 {
     try {
         if (SessionID != null)
         {
             DynamicSourcesCache result = null;
             if (!innerCache.TryGetValue(SessionID, out result) || result == null)
             {
                 return(true);
             }
             else if (SessionID != null)
             {
                 innerCache.Remove(SessionID); return(true);
             }
         }
         else
         {
             return(true);
         }
     }
     catch (Exception e) { }
     return(false);
 }
예제 #5
0
 internal static bool IsEmpty(DynamicSourcesCache cache)
 {
     return(cache == null || cache.userset == null || !cache.userset.Any() || !cache.userset.SelectMany(x => x.Value.Select(a => a)).Any());
 }