diff --git a/src/Core/Models/Data/CipherEvent.cs b/src/Core/Models/Data/CipherEvent.cs index ccd0dae962..6001ed801f 100644 --- a/src/Core/Models/Data/CipherEvent.cs +++ b/src/Core/Models/Data/CipherEvent.cs @@ -14,20 +14,20 @@ namespace Bit.Core.Models.Data CipherId = cipher.Id; Type = (int)type; ActingUserId = actingUserId; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; if(OrganizationId.HasValue) { UserId = null; PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__CipherId={1}__ActingUserId={2}__Type={3}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), CipherId, ActingUserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), CipherId, ActingUserId, Type); } else { PartitionKey = $"UserId={UserId}"; RowKey = string.Format("Date={0}__CipherId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), CipherId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), CipherId, Type); } } } diff --git a/src/Core/Models/Data/CollectionEvent.cs b/src/Core/Models/Data/CollectionEvent.cs index 64d1765088..a0a9751bc2 100644 --- a/src/Core/Models/Data/CollectionEvent.cs +++ b/src/Core/Models/Data/CollectionEvent.cs @@ -13,11 +13,11 @@ namespace Bit.Core.Models.Data CollectionId = collection.Id; Type = (int)type; ActingUserId = actingUserId; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type); } } } diff --git a/src/Core/Models/Data/EventTableEntity.cs b/src/Core/Models/Data/EventTableEntity.cs index 4285f24431..d57d59d8bd 100644 --- a/src/Core/Models/Data/EventTableEntity.cs +++ b/src/Core/Models/Data/EventTableEntity.cs @@ -6,6 +6,7 @@ namespace Bit.Core.Models.Data { public class EventTableEntity : TableEntity { + public DateTime Date { get; set; } public int Type { get; set; } public Guid? UserId { get; set; } public Guid? OrganizationId { get; set; } diff --git a/src/Core/Models/Data/GroupEvent.cs b/src/Core/Models/Data/GroupEvent.cs index 14e478abd7..c07d692ae9 100644 --- a/src/Core/Models/Data/GroupEvent.cs +++ b/src/Core/Models/Data/GroupEvent.cs @@ -13,11 +13,11 @@ namespace Bit.Core.Models.Data GroupId = group.Id; Type = (int)type; ActingUserId = actingUserId; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type); } } } diff --git a/src/Core/Models/Data/OrganizationEvent.cs b/src/Core/Models/Data/OrganizationEvent.cs index 886a8a5f51..89fd98e1c3 100644 --- a/src/Core/Models/Data/OrganizationEvent.cs +++ b/src/Core/Models/Data/OrganizationEvent.cs @@ -12,11 +12,11 @@ namespace Bit.Core.Models.Data OrganizationId = organization.Id; Type = (int)type; ActingUserId = actingUserId; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type); } } } diff --git a/src/Core/Models/Data/OrganizationUserEvent.cs b/src/Core/Models/Data/OrganizationUserEvent.cs index 0026126ebe..c83b391942 100644 --- a/src/Core/Models/Data/OrganizationUserEvent.cs +++ b/src/Core/Models/Data/OrganizationUserEvent.cs @@ -14,11 +14,11 @@ namespace Bit.Core.Models.Data OrganizationUserId = organizationUser.Id; Type = (int)type; ActingUserId = actingUserId; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type); } } } diff --git a/src/Core/Models/Data/UserEvent.cs b/src/Core/Models/Data/UserEvent.cs index 9fa4978b49..538f94f2ca 100644 --- a/src/Core/Models/Data/UserEvent.cs +++ b/src/Core/Models/Data/UserEvent.cs @@ -10,11 +10,11 @@ namespace Bit.Core.Models.Data { UserId = userId; Type = (int)type; + Date = DateTime.UtcNow; - Timestamp = DateTime.UtcNow; PartitionKey = $"UserId={UserId}"; RowKey = string.Format("Date={0}__Type={1}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), Type); + CoreHelpers.DateTimeToTableStorageKey(Date), Type); } public UserEvent(Guid userId, Guid organizationId, EventType type) @@ -22,11 +22,11 @@ namespace Bit.Core.Models.Data OrganizationId = organizationId; UserId = userId; Type = (int)type; - - Timestamp = DateTime.UtcNow; + Date = DateTime.UtcNow; + PartitionKey = $"OrganizationId={OrganizationId}"; RowKey = string.Format("Date={0}__UserId={1}__Type={2}", - CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), UserId, Type); + CoreHelpers.DateTimeToTableStorageKey(Date), UserId, Type); } } } diff --git a/src/Core/Repositories/IEventRepository.cs b/src/Core/Repositories/IEventRepository.cs index 90e6abc297..f78c185675 100644 --- a/src/Core/Repositories/IEventRepository.cs +++ b/src/Core/Repositories/IEventRepository.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.Threading.Tasks; using Bit.Core.Models.Data; -using Microsoft.WindowsAzure.Storage.Table; namespace Bit.Core.Repositories { public interface IEventRepository { Task> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate); - Task CreateAsync(ITableEntity entity); - Task CreateManyAsync(IList entities); + Task CreateAsync(EventTableEntity entity); + Task CreateManyAsync(IList entities); } } diff --git a/src/Core/Repositories/TableStorage/EventRepository.cs b/src/Core/Repositories/TableStorage/EventRepository.cs index 15cee5bf5d..3e739d89f9 100644 --- a/src/Core/Repositories/TableStorage/EventRepository.cs +++ b/src/Core/Repositories/TableStorage/EventRepository.cs @@ -49,12 +49,12 @@ namespace Bit.Core.Repositories.TableStorage return results; } - public async Task CreateAsync(ITableEntity entity) + public async Task CreateAsync(EventTableEntity entity) { await Table.ExecuteAsync(TableOperation.Insert(entity)); } - public async Task CreateManyAsync(IList entities) + public async Task CreateManyAsync(IList entities) { if(!entities?.Any() ?? true) { diff --git a/src/Core/Services/IEventWriteService.cs b/src/Core/Services/IEventWriteService.cs index e2bf59d9a7..74552bd6fa 100644 --- a/src/Core/Services/IEventWriteService.cs +++ b/src/Core/Services/IEventWriteService.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.WindowsAzure.Storage.Table; +using Bit.Core.Models.Data; namespace Bit.Core.Services { public interface IEventWriteService { - Task CreateAsync(ITableEntity entity); - Task CreateManyAsync(IList entities); + Task CreateAsync(EventTableEntity entity); + Task CreateManyAsync(IList entities); } } diff --git a/src/Core/Services/Implementations/AzureQueueEventWriteService.cs b/src/Core/Services/Implementations/AzureQueueEventWriteService.cs index f47cf1d424..1eacf11061 100644 --- a/src/Core/Services/Implementations/AzureQueueEventWriteService.cs +++ b/src/Core/Services/Implementations/AzureQueueEventWriteService.cs @@ -1,10 +1,10 @@ using System.Threading.Tasks; using Bit.Core.Repositories; using System.Collections.Generic; -using Microsoft.WindowsAzure.Storage.Table; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Queue; using Newtonsoft.Json; +using Bit.Core.Models.Data; namespace Bit.Core.Services { @@ -29,14 +29,14 @@ namespace Bit.Core.Services _globalSettings = globalSettings; } - public async Task CreateAsync(ITableEntity entity) + public async Task CreateAsync(EventTableEntity entity) { var json = JsonConvert.SerializeObject(entity, _jsonSettings); var message = new CloudQueueMessage(json); await _queue.AddMessageAsync(message); } - public async Task CreateManyAsync(IList entities) + public async Task CreateManyAsync(IList entities) { var json = JsonConvert.SerializeObject(entities, _jsonSettings); var message = new CloudQueueMessage(json); diff --git a/src/Core/Services/Implementations/EventService.cs b/src/Core/Services/Implementations/EventService.cs index e79ddfbc4e..360e35967e 100644 --- a/src/Core/Services/Implementations/EventService.cs +++ b/src/Core/Services/Implementations/EventService.cs @@ -5,7 +5,6 @@ using Bit.Core.Repositories; using Bit.Core.Models.Data; using System.Linq; using System.Collections.Generic; -using Microsoft.WindowsAzure.Storage.Table; using Bit.Core.Models.Table; namespace Bit.Core.Services @@ -31,7 +30,7 @@ namespace Bit.Core.Services public async Task LogUserEventAsync(Guid userId, EventType type) { - var events = new List { new UserEvent(userId, type) }; + var events = new List { new UserEvent(userId, type) }; IEnumerable orgEvents; if(_currentContext.UserId.HasValue) diff --git a/src/Core/Services/Implementations/RepositoryEventWriteService.cs b/src/Core/Services/Implementations/RepositoryEventWriteService.cs index 959abda31f..5171015d01 100644 --- a/src/Core/Services/Implementations/RepositoryEventWriteService.cs +++ b/src/Core/Services/Implementations/RepositoryEventWriteService.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Bit.Core.Repositories; using System.Collections.Generic; -using Microsoft.WindowsAzure.Storage.Table; +using Bit.Core.Models.Data; namespace Bit.Core.Services { @@ -18,12 +18,12 @@ namespace Bit.Core.Services _globalSettings = globalSettings; } - public async Task CreateAsync(ITableEntity entity) + public async Task CreateAsync(EventTableEntity entity) { await _eventRepository.CreateAsync(entity); } - public async Task CreateManyAsync(IList entities) + public async Task CreateManyAsync(IList entities) { await _eventRepository.CreateManyAsync(entities); } diff --git a/src/Core/Services/NoopImplementations/NoopEventWriteService.cs b/src/Core/Services/NoopImplementations/NoopEventWriteService.cs index b0d79041ae..7ac6baa01d 100644 --- a/src/Core/Services/NoopImplementations/NoopEventWriteService.cs +++ b/src/Core/Services/NoopImplementations/NoopEventWriteService.cs @@ -1,17 +1,17 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.WindowsAzure.Storage.Table; +using Bit.Core.Models.Data; namespace Bit.Core.Services { public class NoopEventWriteService : IEventWriteService { - public Task CreateAsync(ITableEntity entity) + public Task CreateAsync(EventTableEntity entity) { return Task.FromResult(0); } - public Task CreateManyAsync(IList entities) + public Task CreateManyAsync(IList entities) { return Task.FromResult(0); }