1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-24 17:17:40 +01:00

support net core

This commit is contained in:
Kyle Spearrin 2017-11-28 22:48:31 -05:00
parent 341ef0a943
commit a8b4261a85

View File

@ -21,26 +21,31 @@ namespace Bit.Core.Repositories.TableStorage
protected CloudTable Table { get; set; } protected CloudTable Table { get; set; }
public ICollection<EventTableEntiity> GetManyByUser(Guid userId, DateTime startDate, DateTime endDate) public async Task<ICollection<EventTableEntiity>> GetManyByUserAsync(Guid userId,
DateTime startDate, DateTime endDate)
{ {
var start = CoreHelpers.DateTimeToTableStorageKey(startDate); var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
var end = CoreHelpers.DateTimeToTableStorageKey(endDate); var end = CoreHelpers.DateTimeToTableStorageKey(endDate);
return Table.CreateQuery<EventTableEntiity>().Where(e => var query = new TableQuery<EventTableEntiity>().Where(
e.PartitionKey == $"UserId={userId}" && TableQuery.CombineFilters(
e.RowKey.CompareTo($"{start}_") >= 0 && TableQuery.CombineFilters(
e.RowKey.CompareTo($"{end}`") <= 0).ToList(); 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<EventTableEntiity> GetManyByOrganization(Guid organizationId, DateTime startDate, DateTime endDate) var results = new List<EventTableEntiity>();
TableContinuationToken continuationToken = null;
do
{ {
var start = CoreHelpers.DateTimeToTableStorageKey(startDate); var queryResults = await Table.ExecuteQuerySegmentedAsync(query, continuationToken);
var end = CoreHelpers.DateTimeToTableStorageKey(endDate); continuationToken = queryResults.ContinuationToken;
results.AddRange(queryResults.Results);
} while(continuationToken != null);
return Table.CreateQuery<EventTableEntiity>().Where(e => return results;
e.PartitionKey == $"OrganizationId={organizationId}" &&
e.RowKey.CompareTo($"{start}_") >= 0 &&
e.RowKey.CompareTo($"{end}`") <= 0).ToList();
} }
public async Task CreateAsync(ITableEntity entity) public async Task CreateAsync(ITableEntity entity)
@ -48,7 +53,7 @@ namespace Bit.Core.Repositories.TableStorage
await Table.ExecuteAsync(TableOperation.Insert(entity)); await Table.ExecuteAsync(TableOperation.Insert(entity));
} }
public void CreateManyAsync(IEnumerable<ITableEntity> entities) public async Task CreateManyAsync(IEnumerable<ITableEntity> entities)
{ {
if(!entities?.Any() ?? true) if(!entities?.Any() ?? true)
{ {
@ -71,7 +76,7 @@ namespace Bit.Core.Repositories.TableStorage
batch.InsertOrReplace(entity); batch.InsertOrReplace(entity);
} }
Table.ExecuteBatch(batch); await Table.ExecuteBatchAsync(batch);
} }
} }
} }