Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExpiringEventArgs{TKey, TValue}" /> class.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <param name="expirationPolicy">The expiration policy.</param>
 public ExpiringEventArgs(TKey key, TValue value, ExpirationPolicy expirationPolicy)
 {
     Cancel           = false;
     ExpirationPolicy = expirationPolicy;
     Key   = key;
     Value = value;
 }
Exemple #2
0
        public static ExpirationHint GetExpirationHint(ExpirationPolicy policy, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint hint = GetExpirationHint(policy, absoluteExpiration, slidingExpiration);

            if (hint == null)
            {
                return(GetExpirationHint(dependency));
            }

            ExpirationHint hint2 = GetExpirationHint(dependency);

            if (hint2 == null)
            {
                return(hint);
            }


            AggregateExpirationHint aggregateHint = null;

            if (hint2 is AggregateExpirationHint)
            {
                aggregateHint = hint2 as AggregateExpirationHint;
                aggregateHint.Add(hint);

                return(aggregateHint);
            }

            aggregateHint = new AggregateExpirationHint();
            aggregateHint.Add(hint);
            aggregateHint.Add(hint2);

            return(aggregateHint);
        }
            public ServiceTicket grantServiceTicket(string id, Service service, ExpirationPolicy expirationPolicy, bool credentialsProvided)
            {
                ServiceTicket t = this.getTicket().grantServiceTicket(id, service, expirationPolicy, credentialsProvided);

                this.updateTicket();
                return(t);
            }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

            ExpirationPolicy ItemExpirationPolicy = new ExpirationPolicy();

            ItemExpirationPolicy.TryAddPolicy();
        }
    public async Task ExpirationPolicy_SetsResponseExpirationTimeSpan()
    {
        var duration = TimeSpan.FromDays(1);
        IOutputCachePolicy policy = new ExpirationPolicy(duration);
        var context = TestUtils.CreateUninitializedContext();

        await policy.CacheRequestAsync(context, default);

        Assert.Equal(duration, context.ResponseExpirationTimeSpan);
    }
Exemple #6
0
 public BulkFetchActionCache(
     Func <IDictionary <TKey, TValue> > bulkFetcher,
     ExpirationPolicy expirationStrategy = ExpirationPolicy.None,
     TimeSpan?expirationDuration         = null,
     bool fetchOnceOnly = false,
     NullValuePolicy nullValuePolicy      = NullValuePolicy.CacheNormally,
     IEqualityComparer <TKey> keyComparer = null
     ) : base(expirationStrategy, expirationDuration, fetchOnceOnly, nullValuePolicy, keyComparer)
 {
     _bulkFetcher = bulkFetcher;
 }
Exemple #7
0
        /// <summary>
        /// Adds a value to the cache associated with to a key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="expirationPolicy">The expiration policy.</param>
        /// <param name="override">Indicates if the key exists the value will be overridden.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="key" /> is <c>null</c>.</exception>
        public void Add(TKey key, TValue @value, ExpirationPolicy expirationPolicy, bool @override = false)
        {
            Argument.IsNotNull("key", key);

            if (!_storeNullValues)
            {
                Argument.IsNotNull("value", value);
            }

            GetFromCacheOrFetch(key, () => @value, expirationPolicy, @override);
        }
        /**
         * Constructs a new TicketGrantingTicket.
         *
         * @param id the id of the Ticket
         * @param ticketGrantingTicket the parent ticket
         * @param authentication the Authentication request for this ticket
         * @param policy the expiration policy for this ticket.
         * @throws IllegalArgumentException if the Authentication object is null
         */
        public TicketGrantingTicketImpl(string id,
                                        TicketGrantingTicketImpl ticketGrantingTicket,
                                        Authentication authentication, ExpirationPolicy policy)
            : base(id, ticketGrantingTicket, policy)
        {
            //base(id, ticketGrantingTicket, policy);

            //Assert.notNull(authentication, "authentication cannot be null");

            this.authentication = authentication;
        }
Exemple #9
0
        /**
         * Constructs a new ServiceTicket with a Unique Id, a TicketGrantingTicket,
         * a Service, Expiration Policy and a flag to determine if the ticket
         * creation was from a new Login or not.
         *
         * @param id the unique identifier for the ticket.
         * @param ticket the TicketGrantingTicket parent.
         * @param service the service this ticket is for.
         * @param fromNewLogin is it from a new login.
         * @param policy the expiration policy for the Ticket.
         * @throws IllegalArgumentException if the TicketGrantingTicket or the
         * Service are null.
         */
        public ServiceTicketImpl(string id,
                                 TicketGrantingTicketImpl ticket, Service service,
                                 bool fromNewLogin, ExpirationPolicy policy)
            : base(id, ticket, policy)
        {
            //Assert.notNull(ticket, "ticket cannot be null");
            //Assert.notNull(service, "service cannot be null");

            this.service      = service;
            this.fromNewLogin = fromNewLogin;
        }
Exemple #10
0
 public PreloadedCache(
     IDictionary <TKey, TValue> preloadedValues,
     ExpirationPolicy expirationStrategy = ExpirationPolicy.None,
     TimeSpan?expirationDuration         = null,
     bool fetchOnceOnly = false,
     NullValuePolicy nullValuePolicy      = NullValuePolicy.CacheNormally,
     IEqualityComparer <TKey> keyComparer = null
     ) : base(expirationStrategy, expirationDuration, fetchOnceOnly, nullValuePolicy, keyComparer)
 {
     _preloadedValues = preloadedValues;
 }
            public void AutomaticallyRemovesExpiredItemsOfACacheStorageWithDefaultExpirationPolicyInitializationCode()
            {
                var cache = new CacheStorage <string, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(500)));

                cache.Add("1", 1);

                Assert.IsTrue(cache.Contains("1"));

                ThreadHelper.Sleep(2000);

                Assert.IsFalse(cache.Contains("1"));
            }
        /**
     * Constructs a new Ticket with a unique id, a possible parent Ticket (can
     * be null) and a specified Expiration Policy.
     * 
     * @param id the unique identifier for the ticket
     * @param ticket the parent TicketGrantingTicket
     * @param expirationPolicy the expiration policy for the ticket.
     * @throws IllegalArgumentException if the id or expiration policy is null.
     */
        public AbstractTicket(string id, TicketGrantingTicketImpl ticket,
                              ExpirationPolicy expirationPolicy)
        {
            //Assert.notNull(expirationPolicy, "expirationPolicy cannot be null");
            //Assert.notNull(id, "id cannot be null");

            this.id = id;
            this.creationTime = System.DateTime.Now.Ticks;
            this.lastTimeUsed = System.DateTime.Now.Ticks;
            this.expirationPolicy = expirationPolicy;
            this.ticketGrantingTicket = ticket;
        }
Exemple #13
0
        public async Task <Store> GetAsync(string url, bool force = false, params object[] parameters)
        {
            var uri = new Uri(url);

            url =
                $"{uri.Scheme}://{uri.DnsSafeHost}{(uri.Port != 80 && uri.Port != 443 ? $":{uri.Port}" : string.Empty)}/{uri.Segments[1].Trim(' ', '/')}/Products?depPid=0";

            return(await this.cacheStorage.GetFromCacheOrFetchAsync(
                       url,
                       async() => await this.GetDirectAsync(url),
                       ExpirationPolicy.Duration(ScrappingConfiguration.StoreCacheExpiration),
                       force));
        }
            public void RunMultipleThreadsWithRandomAccessCalls()
            {
                var cacheStorage = new CacheStorage <Guid, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(1)));

                var threads = new List <Thread>();

                for (int i = 0; i < 25; i++)
                {
                    var thread = new Thread(() =>
                    {
                        var random = new Random();

                        for (int j = 0; j < 10000; j++)
                        {
                            var randomGuid = _randomGuids[random.Next(0, 9)];
                            cacheStorage.GetFromCacheOrFetch(randomGuid, () =>
                            {
                                var threadId = Thread.CurrentThread.ManagedThreadId;
                                Log.Info("Key '{0}' is now controlled by thread '{1}'", randomGuid, threadId);
                                return(threadId);
                            });

                            ThreadHelper.Sleep(1);
                        }
                    });

                    threads.Add(thread);
                    thread.Start();
                }

                while (true)
                {
                    bool anyThreadAlive = false;

                    foreach (var thread in threads)
                    {
                        if (thread.IsAlive)
                        {
                            anyThreadAlive = true;
                            break;
                        }
                    }

                    if (!anyThreadAlive)
                    {
                        break;
                    }

                    ThreadHelper.Sleep(500);
                }
            }
Exemple #15
0
        public override int GetHashCode()
        {
            int hashCode = 2031047851;

            if (Id != null)
            {
                hashCode += Id.GetHashCode();
            }

            if (Status != null)
            {
                hashCode += Status.GetHashCode();
            }

            if (RewardTiers != null)
            {
                hashCode += RewardTiers.GetHashCode();
            }

            if (ExpirationPolicy != null)
            {
                hashCode += ExpirationPolicy.GetHashCode();
            }

            if (Terminology != null)
            {
                hashCode += Terminology.GetHashCode();
            }

            if (LocationIds != null)
            {
                hashCode += LocationIds.GetHashCode();
            }

            if (CreatedAt != null)
            {
                hashCode += CreatedAt.GetHashCode();
            }

            if (UpdatedAt != null)
            {
                hashCode += UpdatedAt.GetHashCode();
            }

            if (AccrualRules != null)
            {
                hashCode += AccrualRules.GetHashCode();
            }

            return(hashCode);
        }
Exemple #16
0
        public async Task <Product> GetAsync(string url, bool force = false, params object[] parameters)
        {
            var store            = parameters?.OfType <Store>().FirstOrDefault();
            var department       = parameters?.OfType <Department>().FirstOrDefault();
            var disabledProducts = parameters?.OfType <ImmutableSortedSet <string> >().FirstOrDefault();

            url = UriHelper.EnsureProductUrl(url);

            return(await this.cacheStorage.GetFromCacheOrFetchAsync(
                       $"{url}/{store != null}/{department != null}",
                       async() => await this.GetDirectAsync(url, store, department, disabledProducts),
                       ExpirationPolicy.Duration(ScraperConfigurations.ProductCacheExpiration),
                       force));
        }
Exemple #17
0
 public ActionCache(
     Func <TKey, TValue> valueFetcher,
     Func <TValue, uint> sizeEstimator   = null,
     CacheReapPolicy reapStrategy        = CacheReapPolicy.None,
     ExpirationPolicy expirationStrategy = ExpirationPolicy.None,
     uint maxCapacity                     = int.MaxValue,
     TimeSpan?expirationDuration          = null,
     NullValuePolicy nullValuePolicy      = NullValuePolicy.CacheNormally,
     IEqualityComparer <TKey> keyComparer = null)
     : base(reapStrategy, expirationStrategy, maxCapacity, expirationDuration, nullValuePolicy, keyComparer)
 {
     _fetchFunc        = valueFetcher;
     _estimateSizeFunc = sizeEstimator;
 }
Exemple #18
0
        public TValue GetFromCacheOrFetch(TKey key, Func <TValue> code, ExpirationPolicy expirationPolicy, bool @override = false)
        {
            Argument.IsNotNull("key", key);
            Argument.IsNotNull("code", code);

            return(ExecuteInLock(key, () =>
            {
                TValue value;

                var containsKey = _dictionary.ContainsKey(key);
                if (!containsKey || @override)
                {
                    value = code.Invoke();
                    if (!ReferenceEquals(value, null) || _storeNullValues)
                    {
                        if (expirationPolicy == null && _defaultExpirationPolicyInitCode != null)
                        {
                            expirationPolicy = _defaultExpirationPolicyInitCode.Invoke();
                        }

                        var valueInfo = new CacheStorageValueInfo <TValue>(value, expirationPolicy);
                        lock (_syncObj)
                        {
                            _dictionary[key] = valueInfo;
                        }

                        if (valueInfo.CanExpire)
                        {
                            _checkForExpiredItems = true;
                        }

                        if (expirationPolicy != null)
                        {
                            if (_expirationTimer == null)
                            {
                                UpdateTimer();
                            }
                        }
                    }
                }
                else
                {
                    value = _dictionary[key].Value;
                }

                return value;
            }));
        }
Exemple #19
0
        public TicketGrantingTicket grantTicketGrantingTicket(
            string id, Authentication authentication,
            ExpirationPolicy expirationPolicy)
        {
            {
                if (this.grantedTicketAlready)
                {
                    throw new Exception(
                              "TicketGrantingTicket already generated for this ServiceTicket.  Cannot grant more than one TGT for ServiceTicket");
                }
                this.grantedTicketAlready = true;
            }

            return(new TicketGrantingTicketImpl(id, (TicketGrantingTicketImpl)this.getGrantingTicket(),
                                                authentication, expirationPolicy));
        }
Exemple #20
0
            private void RunMultipleThreadsWithRandomAccessCalls(Func <ICacheStorage <Guid, int>, Guid, int> retrievalFunc)
            {
                var cacheStorage = new CacheStorage <Guid, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(250)));

                var threads = new List <Thread>();

                for (var i = 0; i < 50; i++)
                {
                    var thread = new Thread(() =>
                    {
                        var random = new Random();

                        for (var j = 0; j < 1000; j++)
                        {
                            var randomGuid = _randomGuids[random.Next(0, 9)];

                            retrievalFunc(cacheStorage, randomGuid);

                            ThreadHelper.Sleep(10);
                        }
                    });

                    threads.Add(thread);
                    thread.Start();
                }

                while (true)
                {
                    var anyThreadAlive = false;

                    foreach (var thread in threads)
                    {
                        if (thread.IsAlive)
                        {
                            anyThreadAlive = true;
                            break;
                        }
                    }

                    if (!anyThreadAlive)
                    {
                        break;
                    }

                    ThreadHelper.Sleep(500);
                }
            }
Exemple #21
0
        //public CentralAuthenticationServiceImpl(AuthenticationManager authenticationManager,
        //                                        TicketRegistry ticketRegistry,
        //                                        TicketRegistry serviceTicketRegistry,
        //                                        UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
        //                                        ExpirationPolicy ticketGrantingTicketExpirationPolicy,
        //                                        ExpirationPolicy serviceTicketExpirationPolicy,
        //                                        ServicesManager servicesManager)
        //    : this(authenticationManager, ticketRegistry, serviceTicketRegistry, ticketGrantingTicketUniqueTicketIdGenerator, null, ticketGrantingTicketExpirationPolicy, serviceTicketExpirationPolicy, servicesManager)
        //{
        //}

        public CentralAuthenticationServiceImpl(AuthenticationManager authenticationManager,
                                                TicketRegistry ticketRegistry,
                                                TicketRegistry serviceTicketRegistry,
                                                UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
                                                Dictionary <string, UniqueTicketIdGenerator> uniqueTicketIdGeneratorsForService,
                                                ExpirationPolicy ticketGrantingTicketExpirationPolicy,
                                                ExpirationPolicy serviceTicketExpirationPolicy,
                                                ServicesManager servicesManager)
        {
            this.authenticationManager = authenticationManager;
            this.ticketRegistry        = ticketRegistry;
            this.serviceTicketRegistry = serviceTicketRegistry;
            this.ticketGrantingTicketUniqueTicketIdGenerator = ticketGrantingTicketUniqueTicketIdGenerator;
            this.uniqueTicketIdGeneratorsForService          = uniqueTicketIdGeneratorsForService;
            this.ticketGrantingTicketExpirationPolicy        = ticketGrantingTicketExpirationPolicy;
            this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
            this.servicesManager = servicesManager;
        }
        public ServiceTicket grantServiceTicket(string id,
                                                Service service, ExpirationPolicy expirationPolicy,
                                                bool credentialsProvided)
        {
            ServiceTicket serviceTicket = new ServiceTicketImpl(id, this,
                                                                service, this.getCountOfUses() == 0 || credentialsProvided,
                                                                expirationPolicy);

            this.updateState();

            List <Authentication> authentications = this.getChainedAuthentications();

            service.setPrincipal(principal: authentications.Last().getPrincipal());

            this.services.Add(id, service);

            return(serviceTicket);
        }
Exemple #23
0
        public async Task <Product> GetAsync(string url, bool force = false, params object[] parameters)
        {
            var store            = parameters?.OfType <Store>().FirstOrDefault();
            var department       = parameters?.OfType <Department>().FirstOrDefault();
            var disabledProducts = parameters?.OfType <ImmutableSortedSet <string> >().FirstOrDefault();

            url = Regex.Replace(
                url,
                @"(&?)(page=\d+(&?)|img=\d+(&?))",
                string.Empty,
                RegexOptions.IgnoreCase).Trim(' ');

            return(await this.cacheStorage.GetFromCacheOrFetchAsync(
                       $"{url}/{store != null}/{department != null}",
                       async() => await this.GetDirectAsync(url, store, department, disabledProducts),
                       ExpirationPolicy.Duration(ScrappingConfiguration.ProductCacheExpiration),
                       force));
        }
Exemple #24
0
 protected CacheBase(
     CacheReapPolicy reapStrategy        = CacheReapPolicy.None,
     ExpirationPolicy expirationStrategy = ExpirationPolicy.None,
     uint maxCapacity                     = int.MaxValue,
     TimeSpan?expirationDuration          = null,
     NullValuePolicy nullValuePolicy      = NullValuePolicy.CacheNormally,
     IEqualityComparer <TKey> keyComparer = null
     )
 {
     if (!expirationDuration.HasValue)
     {
         expirationDuration = TimeSpan.MaxValue;
     }
     NullValuePolicy    = nullValuePolicy;
     InternalStorage    = keyComparer == null ? new Dictionary <TKey, CachedItem <TValue> >() : new Dictionary <TKey, CachedItem <TValue> >(keyComparer);
     CurrentSize        = 0;
     ReapPolicy         = reapStrategy;
     ExpirationPolicy   = expirationStrategy;
     MaxCapacity        = maxCapacity;
     ExpirationDuration = expirationDuration.Value;
     _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 }
Exemple #25
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is LoyaltyProgram other &&
                   ((Id == null && other.Id == null) || (Id?.Equals(other.Id) == true)) &&
                   ((Status == null && other.Status == null) || (Status?.Equals(other.Status) == true)) &&
                   ((RewardTiers == null && other.RewardTiers == null) || (RewardTiers?.Equals(other.RewardTiers) == true)) &&
                   ((ExpirationPolicy == null && other.ExpirationPolicy == null) || (ExpirationPolicy?.Equals(other.ExpirationPolicy) == true)) &&
                   ((Terminology == null && other.Terminology == null) || (Terminology?.Equals(other.Terminology) == true)) &&
                   ((LocationIds == null && other.LocationIds == null) || (LocationIds?.Equals(other.LocationIds) == true)) &&
                   ((CreatedAt == null && other.CreatedAt == null) || (CreatedAt?.Equals(other.CreatedAt) == true)) &&
                   ((UpdatedAt == null && other.UpdatedAt == null) || (UpdatedAt?.Equals(other.UpdatedAt) == true)) &&
                   ((AccrualRules == null && other.AccrualRules == null) || (AccrualRules?.Equals(other.AccrualRules) == true)));
        }
Exemple #26
0
        public TValue GetFromCacheOrFetch(TKey key, Func <TValue> code, ExpirationPolicy expirationPolicy, bool @override = false)
        {
            Argument.IsNotNull("key", key);
            Argument.IsNotNull("code", code);

            return(ExecuteInLock(key, () =>
            {
                if (!@override && _dictionary.TryGetValue(key, out var cacheStorageValueInfo))
                {
                    return cacheStorageValueInfo.Value;
                }

                var value = code();
                if (!ReferenceEquals(value, null) || _storeNullValues)
                {
                    if (expirationPolicy is null && _defaultExpirationPolicyInitCode != null)
                    {
                        expirationPolicy = _defaultExpirationPolicyInitCode();
                    }

                    var valueInfo = new CacheStorageValueInfo <TValue>(value, expirationPolicy);
                    lock (_syncObj)
                    {
                        _dictionary[key] = valueInfo;
                    }

                    if (valueInfo.CanExpire)
                    {
                        _checkForExpiredItems = true;
                    }

                    if (expirationPolicy != null && _expirationTimer is null)
                    {
                        UpdateTimer();
                    }
                }
 public void ReturnsNullIfTicksOfTimeSpanIsLessOrEqualsToZero()
 {
     Assert.IsNull(ExpirationPolicy.Sliding(new TimeSpan(0)));
 }
 public void NotReturnsNullIfTicksOfTimeSpanIsLessOrEqualsToZeroIfForceIsEqualsTrue()
 {
     Assert.IsNotNull(ExpirationPolicy.Duration(new TimeSpan(0), true));
 }
 public void NotReturnsNullIfExpirationDateTimeIsInThePassIfForceIsEqualsTrue()
 {
     Assert.IsNotNull(ExpirationPolicy.Absolute(DateTime.Now.AddDays(-1), true));
 }
 public void ReturnsNullIfExpirationDateTimeIsInThePass()
 {
     Assert.IsNull(ExpirationPolicy.Absolute(DateTime.Now.AddDays(-1)));
 }
Exemple #31
0
        /**
     * Constructs a new Ticket with a unique id, a possible parent Ticket (can
     * be null) and a specified Expiration Policy.
     * 
     * @param id the unique identifier for the ticket
     * @param ticket the parent TicketGrantingTicket
     * @param expirationPolicy the expiration policy for the ticket.
     * @throws IllegalArgumentException if the id or expiration policy is null.
     */
        public AbstractTicket(string id, TicketGrantingTicketImpl ticket,
                              ExpirationPolicy expirationPolicy)
        {
            //Assert.notNull(expirationPolicy, "expirationPolicy cannot be null");
            //Assert.notNull(id, "id cannot be null");

            this.id = id;
            this.creationTime = System.DateTime.Now.Ticks;
            this.lastTimeUsed = System.DateTime.Now.Ticks;
            this.expirationPolicy = expirationPolicy;
            this.ticketGrantingTicket = ticket;
        }
 public void setSessionExpirationPolicy(ExpirationPolicy sessionExpirationPolicy)
 {
     this.sessionExpirationPolicy = sessionExpirationPolicy;
 }
        /**
     * Constructs a new TicketGrantingTicket.
     * 
     * @param id the id of the Ticket
     * @param ticketGrantingTicket the parent ticket
     * @param authentication the Authentication request for this ticket
     * @param policy the expiration policy for this ticket.
     * @throws IllegalArgumentException if the Authentication object is null
     */
        public TicketGrantingTicketImpl(string id,
                                        TicketGrantingTicketImpl ticketGrantingTicket,
                                        Authentication authentication, ExpirationPolicy policy)
            : base(id, ticketGrantingTicket, policy)
        {
            //base(id, ticketGrantingTicket, policy);

            //Assert.notNull(authentication, "authentication cannot be null");

            this.authentication = authentication;
        }
        public ServiceTicket grantServiceTicket(string id,
                                                Service service, ExpirationPolicy expirationPolicy,
                                                bool credentialsProvided)
        {
            ServiceTicket serviceTicket = new ServiceTicketImpl(id, this,
                                                                service, this.getCountOfUses() == 0 || credentialsProvided,
                                                                expirationPolicy);

            this.updateState();

            List<Authentication> authentications = this.getChainedAuthentications();
            service.setPrincipal(principal: authentications.Last().getPrincipal());

            this.services.Add(id, service);

            return serviceTicket;
        }
 public void setRememberMeExpirationPolicy(
     ExpirationPolicy rememberMeExpirationPolicy)
 {
     this.rememberMeExpirationPolicy = rememberMeExpirationPolicy;
 }
    /**
 * Constructs a new TicketGrantingTicket without a parent
 * TicketGrantingTicket.
 * 
 * @param id the id of the Ticket
 * @param authentication the Authentication request for this ticket
 * @param policy the expiration policy for this ticket.
 */
    public TicketGrantingTicketImpl(string id,
                                    Authentication authentication, ExpirationPolicy policy)
        : this(id, null, authentication, policy)
    {
        ;
    }
        //public CentralAuthenticationServiceImpl(AuthenticationManager authenticationManager,
        //                                        TicketRegistry ticketRegistry,
        //                                        TicketRegistry serviceTicketRegistry,
        //                                        UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
        //                                        ExpirationPolicy ticketGrantingTicketExpirationPolicy,
        //                                        ExpirationPolicy serviceTicketExpirationPolicy,
        //                                        ServicesManager servicesManager)
        //    : this(authenticationManager, ticketRegistry, serviceTicketRegistry, ticketGrantingTicketUniqueTicketIdGenerator, null, ticketGrantingTicketExpirationPolicy, serviceTicketExpirationPolicy, servicesManager)
        //{
        //}

        public CentralAuthenticationServiceImpl(AuthenticationManager authenticationManager,
            TicketRegistry ticketRegistry,
            TicketRegistry serviceTicketRegistry,
            UniqueTicketIdGenerator ticketGrantingTicketUniqueTicketIdGenerator,
            Dictionary<string, UniqueTicketIdGenerator> uniqueTicketIdGeneratorsForService,
            ExpirationPolicy ticketGrantingTicketExpirationPolicy,
            ExpirationPolicy serviceTicketExpirationPolicy,
            ServicesManager servicesManager)
        {
            this.authenticationManager = authenticationManager;
            this.ticketRegistry = ticketRegistry;
            this.serviceTicketRegistry = serviceTicketRegistry;
            this.ticketGrantingTicketUniqueTicketIdGenerator = ticketGrantingTicketUniqueTicketIdGenerator;
            this.uniqueTicketIdGeneratorsForService = uniqueTicketIdGeneratorsForService;
            this.ticketGrantingTicketExpirationPolicy = ticketGrantingTicketExpirationPolicy;
            this.serviceTicketExpirationPolicy = serviceTicketExpirationPolicy;
            this.servicesManager = servicesManager;
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            ExpirationPolicy ItemExpirationPolicy = new ExpirationPolicy();

            ItemExpirationPolicy.TryDeletePolicy();
        }
        public TicketGrantingTicket grantTicketGrantingTicket(
            string id, Authentication authentication,
            ExpirationPolicy expirationPolicy)
        {
            {
                if (this.grantedTicketAlready)
                {
                    throw new Exception(
                        "TicketGrantingTicket already generated for this ServiceTicket.  Cannot grant more than one TGT for ServiceTicket");
                }
                this.grantedTicketAlready = true;
            }

            return new TicketGrantingTicketImpl(id, (TicketGrantingTicketImpl)this.getGrantingTicket(),
                                                authentication, expirationPolicy);
        }
        /**
     * Constructs a new ServiceTicket with a Unique Id, a TicketGrantingTicket,
     * a Service, Expiration Policy and a flag to determine if the ticket
     * creation was from a new Login or not.
     * 
     * @param id the unique identifier for the ticket.
     * @param ticket the TicketGrantingTicket parent.
     * @param service the service this ticket is for.
     * @param fromNewLogin is it from a new login.
     * @param policy the expiration policy for the Ticket.
     * @throws IllegalArgumentException if the TicketGrantingTicket or the
     * Service are null.
     */
        public ServiceTicketImpl(string id,
                                     TicketGrantingTicketImpl ticket, Service service,
                                     bool fromNewLogin, ExpirationPolicy policy)
            : base(id, ticket, policy)
        {


            //Assert.notNull(ticket, "ticket cannot be null");
            //Assert.notNull(service, "service cannot be null");

            this.service = service;
            this.fromNewLogin = fromNewLogin;
        }