NegotiationTokenAuthenticatorStateCache.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / NegotiationTokenAuthenticatorStateCache.cs / 1 / NegotiationTokenAuthenticatorStateCache.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Security 
{
    using System; 
    using System.ServiceModel; 
    using System.Collections;
    using System.Runtime.InteropServices; 
    using System.Threading;
    using System.Diagnostics;

    sealed class NegotiationTokenAuthenticatorStateCache : TimeBoundedCache 
        where T : NegotiationTokenAuthenticatorState
    { 
        static int lowWaterMark = 50; 
        static TimeSpan purgingInterval = TimeSpan.FromMinutes(10);
        TimeSpan cachingSpan; 

        public NegotiationTokenAuthenticatorStateCache(TimeSpan cachingSpan, int maximumCachedState)
            : base(lowWaterMark, maximumCachedState, null, PurgingMode.TimerBasedPurge, TimeSpan.FromTicks(cachingSpan.Ticks >> 2), true)
        { 
            this.cachingSpan = cachingSpan;
        } 
 
        public void AddState(string context, T state)
        { 
            DateTime expirationTime = TimeoutHelper.Add(DateTime.UtcNow, this.cachingSpan);
            bool wasStateAdded = base.TryAddItem(context, state, expirationTime, false);
            if (!wasStateAdded)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityNegotiationException(SR.GetString(SR.NegotiationStateAlreadyPresent, context)));
            } 
        } 

        public T GetState(string context) 
        {
            return (this.GetItem(context) as T);
        }
 
        public void RemoveState(string context)
        { 
            this.TryRemoveItem(context); 
        }
 

        protected override ArrayList OnQuotaReached(Hashtable cacheTable)
        {
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QuotaExceededException(SR.GetString(SR.CachedNegotiationStateQuotaReached, this.Capacity))); 
        }
 
        protected override void OnRemove(object item) 
        {
            ((IDisposable)item).Dispose(); 
            base.OnRemove(item);
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK