Esempio n. 1
0
        private void BeforeAccessNotification(TokenCacheNotificationArgs args)
        {
            System.Diagnostics.Debug.WriteLine($"BeforeAccessNotification for {User}");

            // Look up the persisted entry
            var persistedEntry = LoadPersistedCacheEntry();

            if (CachedEntity == null)
            {
                // first time access
                CachedEntity = persistedEntry;
                System.Diagnostics.Debug.WriteLine($"BeforeAccessNotification for {User} - first time access");
            }
            else
            {
                // if the in-memory copy is older than the persistent copy
                if (persistedEntry != null && persistedEntry.LastWrite > CachedEntity.LastWrite)
                {
                    //// read from from storage, update in-memory copy
                    CachedEntity = persistedEntry;
                    System.Diagnostics.Debug.WriteLine($"BeforeAccessNotification for {User} - update in-memory cache");
                }
            }

            if (null != CachedEntity)
            {
                System.Diagnostics.Debug.WriteLine($"BeforeAccessNotification for {User} - Deserialize cached entity");
                this.Deserialize(CachedEntity.CacheBits);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"BeforeAccessNotification for {User} - No cached entry exists");
                this.Deserialize(null);
            }
        }
Esempio n. 2
0
        public AzureTableTokenCache(string user)
        {
            this.User         = user;
            this.AfterAccess  = AfterAccessNotification;
            this.BeforeAccess = BeforeAccessNotification;
            this.BeforeWrite  = BeforeWriteNotification;

            CachedEntity = LoadPersistedCacheEntry();
            this.Deserialize((CachedEntity == null) ? null : CachedEntity.CacheBits);
        }
Esempio n. 3
0
        public override void Clear()
        {
            base.Clear();

            var entry = LoadPersistedCacheEntry();

            if (null != entry)
            {
                TableOperation delete = TableOperation.Delete(entry);
                tables.UserTokenCacheTable.Execute(delete);
            }
            CachedEntity = null;
        }
Esempio n. 4
0
        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            System.Diagnostics.Debug.WriteLine($"AfterAccessNotification for {User}");

            if (this.HasStateChanged)
            {
                if (CachedEntity == null)
                {
                    CachedEntity = new TokenCacheEntity();
                }
                CachedEntity.RowKey    = User;
                CachedEntity.CacheBits = this.Serialize();
                CachedEntity.LastWrite = DateTime.Now;

                TableOperation insert = TableOperation.InsertOrReplace(CachedEntity);
                tables.UserTokenCacheTable.Execute(insert);
                this.HasStateChanged = false;

                System.Diagnostics.Debug.WriteLine($"Wrote value to persistent cache for {User}");
            }
        }