internal DelegateSessionCache(int capacity)
 {
     if (capacity > 10 || capacity < 1)
     {
         throw new ArgumentOutOfRangeException("capacity");
     }
     capacity      = TestBridgeManager.GetSize(capacity);
     this.capacity = capacity;
     this.dataSet  = new List <DelegateSessionEntry>(this.capacity);
 }
        private DelegateSessionEntry AddNewEntry(DelegateSessionEntry entry)
        {
            DelegateSessionEntry delegateSessionEntry = null;

            if (this.dataSet.Count >= this.capacity)
            {
                ExTraceGlobals.SessionTracer.TraceDebug <int, int>((long)this.GetHashCode(), "DelegateSessionCache::AddNewEntry. Overflow process. Capacity = {0}, Count = {1}.", this.capacity, this.dataSet.Count);
                foreach (DelegateSessionEntry delegateSessionEntry2 in this.dataSet)
                {
                    if (delegateSessionEntry2.ExternalRefCount <= 0 && (delegateSessionEntry == null || delegateSessionEntry2.LastAccessed < delegateSessionEntry.LastAccessed))
                    {
                        delegateSessionEntry = delegateSessionEntry2;
                    }
                }
                if (delegateSessionEntry == null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("CallStack for active DelegateSessionEntry:");
                    foreach (DelegateSessionEntry delegateSessionEntry3 in this.dataSet)
                    {
                        if (delegateSessionEntry3.ExternalRefCount > 0)
                        {
                            stringBuilder.AppendLine(delegateSessionEntry3.GetCallStack());
                        }
                    }
                    InvalidOperationException ex = new InvalidOperationException(string.Format("We cannot find a candidate from our internal cache. The consumer must remove unused sessions. Size = {0}, Capacity = {1}.", this.dataSet.Count, this.capacity));
                    ex.Data["ActiveEntryCallStack"] = stringBuilder.ToString();
                    throw ex;
                }
                TestBridgeManager.Removed(delegateSessionEntry.LegacyDn);
                this.dataSet.Remove(delegateSessionEntry);
                delegateSessionEntry.ForceDispose();
                delegateSessionEntry = null;
            }
            this.dataSet.Add(entry);
            TestBridgeManager.Added(entry.LegacyDn);
            return(entry);
        }
 internal static void UnSetTestBridge()
 {
     TestBridgeManager.SetBridge(null);
 }
 internal static void SetTestBridge(ITestBridgeDelegateSessionCache bridge)
 {
     TestBridgeManager.SetBridge(bridge);
 }