Beispiel #1
0
        public async Task AddAsync(IExpiryEntry entry)
        {
            var alreadyExisted = !await
                                 _tableStorage.TryInsertAsync(
                new ExpiryEntryEntity
            {
                PartitionKey   = ExpiryEntryEntity.ByClient.GeneratePartitionKey(entry.ClientId),
                RowKey         = ExpiryEntryEntity.ByClient.GenerateRowKey(entry.RequestId),
                ClientId       = entry.ClientId,
                RequestId      = entry.RequestId,
                ExpiryDateTime = entry.ExpiryDateTime
            });

            if (!alreadyExisted)
            {
                await _tableStorage.InsertAsync(
                    new ExpiryEntryEntity
                {
                    PartitionKey   = ExpiryEntryEntity.ByDateTime.GeneratePartitionKey(),
                    RowKey         = ExpiryEntryEntity.ByDateTime.GenerateRowKey(entry.ExpiryDateTime, entry.RequestId),
                    ClientId       = entry.ClientId,
                    RequestId      = entry.RequestId,
                    ExpiryDateTime = entry.ExpiryDateTime
                });
            }
        }
Beispiel #2
0
 public Task RemoveAsync(IExpiryEntry entry)
 {
     return(Task.WhenAll(
                _tableStorage.DeleteIfExistAsync(
                    ExpiryEntryEntity.ByClient.GeneratePartitionKey(entry.ClientId),
                    ExpiryEntryEntity.ByClient.GenerateRowKey(entry.RequestId)),
                _tableStorage.DeleteIfExistAsync(
                    ExpiryEntryEntity.ByDateTime.GeneratePartitionKey(),
                    ExpiryEntryEntity.ByDateTime.GenerateRowKey(entry.ExpiryDateTime, entry.RequestId))));
 }
 public static bool IsDue(this IExpiryEntry entry)
 {
     return(entry.ExpiryDateTime <= DateTime.UtcNow);
 }