public void AddOrLockKey(TKey key, TValue value, out TValue valueAddedOrLocked)
        {
            CacheEntry <TValue> cacheEntry = null;

            valueAddedOrLocked = value;
            CacheEntry <TValue> cacheEntry1 = new CacheEntry <TValue>(value);

            using (WriterLock writerLock = new WriterLock(this.readerWriterLock))
            {
                if (!this.cache.TryGetValue(key, out cacheEntry))
                {
                    if (this.cache.Count < base.MaxCacheSize)
                    {
                        this.cache.Add(key, cacheEntry1);
                        valueAddedOrLocked = value;
                    }
                    else
                    {
                        object[] maxCacheSize = new object[1];
                        maxCacheSize[0] = base.MaxCacheSize;
                        throw new OverflowException(ExceptionHelpers.GetExceptionMessage(Resources.CannotAddMoreToCache, maxCacheSize));
                    }
                }
                else
                {
                    cacheEntry.Lock(out valueAddedOrLocked);
                }
            }
        }
 public static void ThrowArgumentExceptionIf(string parameterName, bool condition, string message, object[] args)
 {
     if (!condition)
     {
         return;
     }
     else
     {
         string exceptionMessage = ExceptionHelpers.GetExceptionMessage(message, args);
         throw new ArgumentException(exceptionMessage, parameterName);
     }
 }
Exemple #3
0
 public void Enqueue(TItem item)
 {
     if (this.cache.Count < base.MaxCacheSize)
     {
         this.cache.Enqueue(new CacheEntry <TItem>(item));
         return;
     }
     else
     {
         object[] maxCacheSize = new object[1];
         maxCacheSize[0] = base.MaxCacheSize;
         throw new OverflowException(ExceptionHelpers.GetExceptionMessage(Resources.CannotAddMoreToCache, maxCacheSize));
     }
 }
Exemple #4
0
 public BoundedInteger(int currentValue, int lowerBound, int upperBound, bool noThrowForInvalidSet)
 {
     if (lowerBound <= upperBound)
     {
         this.LowerBound           = lowerBound;
         this.UpperBound           = upperBound;
         this.NoThrowForInvalidSet = noThrowForInvalidSet;
         this.Value = currentValue;
         return;
     }
     else
     {
         object[] objArray = new object[2];
         objArray[0] = lowerBound;
         objArray[1] = upperBound;
         throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.LowerBoundGreaterThanUpper, objArray));
     }
 }
Exemple #5
0
        public int Unlock()
        {
            int num;

            lock (this.syncobj)
            {
                if (this.lockCount != 0)
                {
                    this.lastAccessedTime = DateTimeHelper.Now;
                    CacheEntry <TValue> cacheEntry = this;
                    int num1 = cacheEntry.lockCount - 1;
                    int num2 = num1;
                    cacheEntry.lockCount = num1;
                    num = num2;
                }
                else
                {
                    throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.UnlockAlreadyLockedCache, new object[0]));
                }
            }
            return(num);
        }