internal void SetProjectName(EventAudit eventAudit, Guid projectId, string name) { // Don't update audit because the account aggregate hasn't changed _projects .Single(p => p.Id == projectId) .SetName(name); }
public void AddProject(EventAudit eventAudit, Guid projectId, string name) { Audit.Update(eventAudit); var project = Project.Create(projectId, name); _projects.Add(project); }
public void DeleteProject(EventAudit eventAudit, Guid projectId) { Audit.Update(eventAudit); var project = _projects.Single(p => p.Id == projectId); _projects.Remove(project); }
public void DeleteEnvironment(EventAudit eventAudit, string environmentKey) { Audit.Update(eventAudit); Audit.Update(eventAudit); var environment = _environments.Single(e => e.Key == environmentKey); _environments.Remove(environment); }
public void AddToggle(EventAudit eventAudit, string toggleKey, string toggleName) { Audit.Update(eventAudit); Audit.Update(eventAudit); var toggleToAdd = Toggle.Create(toggleKey, toggleName); _toggles.Add(toggleToAdd); }
public void DeleteToggle(EventAudit eventAudit, string toggleKey) { Audit.Update(eventAudit); Audit.Update(eventAudit); var toggleToRemove = _toggles.Single(toggle => toggle.Key == toggleKey); _toggles.Remove(toggleToRemove); }
public void AddEnvironment(EventAudit eventAudit, string environmentKey, string environmentName) { Audit.Update(eventAudit); Audit.Update(eventAudit); var environment = Environment.Create(environmentKey, environmentName); _environments.Add(environment); }
public async Task HandleEvent(EventEnvelope eventEnvelope, CancellationToken stoppingToken) { try { bool initialEvent = false; var storeKey = Projections.EventHandlerState.Projection.StoreKey(typeof(TEventStream)); Projections.EventHandlerState.Projection state; try { state = await _eventHandlerStateStore.Get(storeKey).ConfigureAwait(false); if (eventEnvelope.StreamPosition <= state.Audit.StreamPosition) { _logger.LogInformation("Ignoring event with stream position {@eventStreamPosition} because we have already processed to {@currentStreamPosition}", eventEnvelope.StreamPosition, state.Audit.StreamPosition); return; } } catch (ProjectionNotFoundException) { _logger.LogInformation("No state found"); initialEvent = true; } if (_projectionBuildersByEventType.TryGetValue(eventEnvelope.Event.GetType(), out var projectionBuilders)) { var tasks = new Task[projectionBuilders.Count]; for (var index = 0; index < projectionBuilders.Count; index++) { tasks[index] = projectionBuilders[index](eventEnvelope.StreamPosition, eventEnvelope.Event, stoppingToken); } await Task.WhenAll(tasks); } var eventAudit = EventAudit.Create(DateTime.UtcNow, Constants.SystemUser, eventEnvelope.Event.Version, eventEnvelope.StreamPosition); state = Projections.EventHandlerState.Projection.Create(eventAudit); if (initialEvent) { await _eventHandlerStateStore.Create(storeKey, state).ConfigureAwait(false); } else { await _eventHandlerStateStore.Update(storeKey, state).ConfigureAwait(false); } } catch (Exception ex) { _logger.LogWarning("Failed to build projection for {@event}. Exception: {@exception}", eventEnvelope.Event, ex); throw; } }
private void GivenTheEventHasAlreadyBeenHandled() { var eventAudit = EventAudit.Create( _dataFixture.Create <DateTimeOffset>(), _dataFixture.Create <string>(), _dataFixture.Create <long>(), _eventEnvelope.StreamPosition + 1); _originalEventHandlerState = Core.ReadModel.Projections.EventHandlerState.Projection.Create(eventAudit); _eventHandlerStateStore .Get(Arg.Any <string>()) .Returns(_originalEventHandlerState); }
public void AuditEvent(string eventType, string username, string description) { try { using (ActiveAnalyticsOracleDatabaseContext dbContext = new ActiveAnalyticsOracleDatabaseContext()) { EventAudit auditInfo = new EventAudit(); auditInfo.EventId = Guid.NewGuid().ToString(); auditInfo.EventDate = DateTime.Now; auditInfo.EventType = eventType; auditInfo.Username = username; auditInfo.Description = description; dbContext.AuditInfo.Add(auditInfo); dbContext.SaveChangesAsync(); } } catch (Exception ex) { //eat any exception. Consumer should not care if audit save's fail } }
private async Task CreateOrUpdateToggleState(EventAudit eventAudit, Guid projectId, string environmentKey, string toggleKey, string toggleValue) { Projection projection; Model.ToggleState toggleState; bool toggleWasCreated = false; var storeKey = Projection.StoreKey(projectId, toggleKey); try { projection = await Projections.Get(storeKey).ConfigureAwait(false); if (projection.Audit.StreamPosition >= eventAudit.StreamPosition) { return; } toggleState = projection.ToggleState; } catch (ProjectionNotFoundException) { // TODO: fix this so we don't have to catch the an exception! toggleState = Model.ToggleState.Create(eventAudit); toggleWasCreated = true; } toggleState.AddEnvironmentState(eventAudit, environmentKey, toggleValue); projection = Projection.Create(eventAudit, toggleState); if (toggleWasCreated) { await Projections.Create(storeKey, projection).ConfigureAwait(false); } else { await Projections.Update(storeKey, projection).ConfigureAwait(false); } }
private async Task UpdateOrDeleteToggleState(EventAudit eventAudit, Guid projectId, string environmentKey, string toggleKey) { var storeKey = Projection.StoreKey(projectId, toggleKey); var projection = await Projections.Get(storeKey).ConfigureAwait(false); if (projection.Audit.StreamPosition >= eventAudit.StreamPosition) { return; } var toggleState = projection.ToggleState; toggleState.DeleteEnvironmentState(eventAudit, environmentKey); projection = Projection.Create(eventAudit, toggleState); if (projection.ToggleState.EnvironmentStates.Any()) { await Projections.Update(storeKey, projection).ConfigureAwait(false); } else { await Projections.Delete(storeKey).ConfigureAwait(false); } }
public void ChangeEnvironmentState(EventAudit eventAudit, string environmentKey, string value) { var environmentState = _environmentStates.Find(ts => ts.Key == environmentKey); environmentState.ChangeState(value, eventAudit.EventVersion); }
public void AddEnvironmentState(EventAudit eventAudit, string environmentKey, string environmentValue) { var environmentState = EnvironmentState.Create(environmentKey, environmentValue, eventAudit.EventVersion); _environmentStates.Add(environmentState); }
public static ToggleState Create(EventAudit eventAudit) { return(new ToggleState(new List <EnvironmentState>())); }
public static Projection Create(EventAudit eventAudit, Model.Project project) { return(new Projection(ProjectionAudit.Create(eventAudit), project)); }
public static Toggle Create(EventAudit eventAudit, Guid projectId, string key, string name) { return(new Toggle(projectId, key, name, AggregateAudit.Create(eventAudit))); }
public static Projection Create(EventAudit eventAudit, Model.Toggle toggle) { return(new Projection(ProjectionAudit.Create(eventAudit), toggle)); }
public static Projection Create(EventAudit eventAudit, Model.Environment environment) { return(new Projection(ProjectionAudit.Create(eventAudit), environment)); }
public static Project Create(EventAudit eventAudit, Guid id, string name) { return(new Project(id, name, new List <Environment>(), new List <Toggle>(), AggregateAudit.Create(eventAudit))); }
public void DeleteToggleState(EventAudit eventAudit, string toggleKey) { var toggleState = _toggleStates.Find(ts => ts.Key == toggleKey); _toggleStates.Remove(toggleState); }
public static Projection Create(EventAudit eventAudit, Model.Account account) { return(new Projection( ProjectionAudit.Create(eventAudit), account)); }
public void AddToggleState(EventAudit eventAudit, string toggleKey, string toggleValue) { var toggleState = ToggleState.Create(toggleKey, toggleValue, eventAudit.EventVersion); _toggleStates.Add(toggleState); }
public static EnvironmentState Create(EventAudit eventAudit, IEnumerable <ToggleState> toggleStates) { return(new EnvironmentState(toggleStates ?? new List <ToggleState>())); }
public void DeleteEnvironmentState(EventAudit eventAudit, string environmentKey) { var environmentState = _environmentStates.Find(ts => ts.Key == environmentKey); _environmentStates.Remove(environmentState); }
public static Projection Create(EventAudit eventAudit) { return(new Projection(ProjectionAudit.Create(eventAudit))); }
public static Account Create(EventAudit eventAudit, Guid accountId) { return(new Account(accountId, new List <Project>(), AggregateAudit.Create(eventAudit))); }
public void ChangeToggleState(EventAudit eventAudit, string toggleKey, string value) { var toggleState = _toggleStates.Find(ts => ts.Key == toggleKey); toggleState.ChangeState(value, eventAudit.EventVersion); }
public static Environment Create(EventAudit eventAudit, Guid projectId, string key, string name) { return(new Environment(projectId, key, name, AggregateAudit.Create(eventAudit))); }