From a8b4261a85a44b55115e20cf09ef5d2e50c05d29 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 28 Nov 2017 22:48:31 -0500 Subject: [PATCH] support net core --- .../TableStorage/EventRepository.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Core/Repositories/TableStorage/EventRepository.cs b/src/Core/Repositories/TableStorage/EventRepository.cs index d5a6929dc5..ee353dc8c2 100644 --- a/src/Core/Repositories/TableStorage/EventRepository.cs +++ b/src/Core/Repositories/TableStorage/EventRepository.cs @@ -21,26 +21,31 @@ namespace Bit.Core.Repositories.TableStorage protected CloudTable Table { get; set; } - public ICollection GetManyByUser(Guid userId, DateTime startDate, DateTime endDate) + public async Task> GetManyByUserAsync(Guid userId, + DateTime startDate, DateTime endDate) { var start = CoreHelpers.DateTimeToTableStorageKey(startDate); var end = CoreHelpers.DateTimeToTableStorageKey(endDate); - return Table.CreateQuery().Where(e => - e.PartitionKey == $"UserId={userId}" && - e.RowKey.CompareTo($"{start}_") >= 0 && - e.RowKey.CompareTo($"{end}`") <= 0).ToList(); - } + var query = new TableQuery().Where( + TableQuery.CombineFilters( + TableQuery.CombineFilters( + TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"UserId={userId}"), + TableOperators.And, + TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, $"{start}_")), + TableOperators.And, + TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, $"{end}`"))); - public ICollection GetManyByOrganization(Guid organizationId, DateTime startDate, DateTime endDate) - { - var start = CoreHelpers.DateTimeToTableStorageKey(startDate); - var end = CoreHelpers.DateTimeToTableStorageKey(endDate); + var results = new List(); + TableContinuationToken continuationToken = null; + do + { + var queryResults = await Table.ExecuteQuerySegmentedAsync(query, continuationToken); + continuationToken = queryResults.ContinuationToken; + results.AddRange(queryResults.Results); + } while(continuationToken != null); - return Table.CreateQuery().Where(e => - e.PartitionKey == $"OrganizationId={organizationId}" && - e.RowKey.CompareTo($"{start}_") >= 0 && - e.RowKey.CompareTo($"{end}`") <= 0).ToList(); + return results; } public async Task CreateAsync(ITableEntity entity) @@ -48,7 +53,7 @@ namespace Bit.Core.Repositories.TableStorage await Table.ExecuteAsync(TableOperation.Insert(entity)); } - public void CreateManyAsync(IEnumerable entities) + public async Task CreateManyAsync(IEnumerable entities) { if(!entities?.Any() ?? true) { @@ -71,7 +76,7 @@ namespace Bit.Core.Repositories.TableStorage batch.InsertOrReplace(entity); } - Table.ExecuteBatch(batch); + await Table.ExecuteBatchAsync(batch); } } }