예제 #1
0
        public async Task setPersonIdAsync(string userId, string personId)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <TokenCacheEntity>(PartitionKey, userId);
            TableResult    retrievedResult   = await _tokenCache.ExecuteAsync(retrieveOperation);

            TokenCacheEntity entity = (TokenCacheEntity)retrievedResult.Result;

            entity.PersonId = personId;

            TableOperation insertOrReplaceOperation = TableOperation.InsertOrReplace(entity);
            await _tokenCache.ExecuteAsync(insertOrReplaceOperation);
        }
            private TokenCacheEntity cachedEntity;      // data entity stored in the Azure Table

            public AzureTableTokenCache(string userId, CloudTable cacheTable)
            {
                signInUserId    = userId;
                tokenCacheTable = cacheTable;

                this.AfterAccess = AfterAccessNotification;

                cachedEntity = ReadFromTableStorage();
                if (null != cachedEntity)
                {
                    Deserialize(cachedEntity.CacheBits);
                }
            }
            private void AfterAccessNotification(TokenCacheNotificationArgs args)
            {
                if (this.HasStateChanged)
                {
                    if (cachedEntity == null)
                    {
                        cachedEntity = new TokenCacheEntity();
                    }
                    cachedEntity.RowKey    = signInUserId;
                    cachedEntity.CacheBits = Serialize();
                    cachedEntity.LastWrite = DateTime.Now;

                    TableOperation insert = TableOperation.InsertOrReplace(cachedEntity);
                    tokenCacheTable.Execute(insert);

                    this.HasStateChanged = false;
                }
            }