コード例 #1
0
 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);
 }
コード例 #2
0
        public void AddProject(EventAudit eventAudit, Guid projectId, string name)
        {
            Audit.Update(eventAudit);

            var project = Project.Create(projectId, name);

            _projects.Add(project);
        }
コード例 #3
0
        public void DeleteProject(EventAudit eventAudit, Guid projectId)
        {
            Audit.Update(eventAudit);

            var project = _projects.Single(p => p.Id == projectId);

            _projects.Remove(project);
        }
コード例 #4
0
        public void DeleteEnvironment(EventAudit eventAudit, string environmentKey)
        {
            Audit.Update(eventAudit);
            Audit.Update(eventAudit);

            var environment = _environments.Single(e => e.Key == environmentKey);

            _environments.Remove(environment);
        }
コード例 #5
0
        public void AddToggle(EventAudit eventAudit, string toggleKey, string toggleName)
        {
            Audit.Update(eventAudit);
            Audit.Update(eventAudit);

            var toggleToAdd = Toggle.Create(toggleKey, toggleName);

            _toggles.Add(toggleToAdd);
        }
コード例 #6
0
        public void DeleteToggle(EventAudit eventAudit, string toggleKey)
        {
            Audit.Update(eventAudit);
            Audit.Update(eventAudit);

            var toggleToRemove = _toggles.Single(toggle => toggle.Key == toggleKey);

            _toggles.Remove(toggleToRemove);
        }
コード例 #7
0
        public void AddEnvironment(EventAudit eventAudit, string environmentKey, string environmentName)
        {
            Audit.Update(eventAudit);
            Audit.Update(eventAudit);

            var environment = Environment.Create(environmentKey, environmentName);

            _environments.Add(environment);
        }
コード例 #8
0
        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;
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 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
     }
 }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
ファイル: ToggleState.cs プロジェクト: binarymash/evelyn
        public void ChangeEnvironmentState(EventAudit eventAudit, string environmentKey, string value)
        {
            var environmentState = _environmentStates.Find(ts => ts.Key == environmentKey);

            environmentState.ChangeState(value, eventAudit.EventVersion);
        }
コード例 #14
0
ファイル: ToggleState.cs プロジェクト: binarymash/evelyn
        public void AddEnvironmentState(EventAudit eventAudit, string environmentKey, string environmentValue)
        {
            var environmentState = EnvironmentState.Create(environmentKey, environmentValue, eventAudit.EventVersion);

            _environmentStates.Add(environmentState);
        }
コード例 #15
0
ファイル: ToggleState.cs プロジェクト: binarymash/evelyn
 public static ToggleState Create(EventAudit eventAudit)
 {
     return(new ToggleState(new List <EnvironmentState>()));
 }
コード例 #16
0
 public static Projection Create(EventAudit eventAudit, Model.Project project)
 {
     return(new Projection(ProjectionAudit.Create(eventAudit), project));
 }
コード例 #17
0
ファイル: Toggle.cs プロジェクト: binarymash/evelyn
 public static Toggle Create(EventAudit eventAudit, Guid projectId, string key, string name)
 {
     return(new Toggle(projectId, key, name, AggregateAudit.Create(eventAudit)));
 }
コード例 #18
0
ファイル: Projection.cs プロジェクト: binarymash/evelyn
 public static Projection Create(EventAudit eventAudit, Model.Toggle toggle)
 {
     return(new Projection(ProjectionAudit.Create(eventAudit), toggle));
 }
コード例 #19
0
 public static Projection Create(EventAudit eventAudit, Model.Environment environment)
 {
     return(new Projection(ProjectionAudit.Create(eventAudit), environment));
 }
コード例 #20
0
 public static Project Create(EventAudit eventAudit, Guid id, string name)
 {
     return(new Project(id, name, new List <Environment>(), new List <Toggle>(), AggregateAudit.Create(eventAudit)));
 }
コード例 #21
0
ファイル: EnvironmentState.cs プロジェクト: binarymash/evelyn
        public void DeleteToggleState(EventAudit eventAudit, string toggleKey)
        {
            var toggleState = _toggleStates.Find(ts => ts.Key == toggleKey);

            _toggleStates.Remove(toggleState);
        }
コード例 #22
0
 public static Projection Create(EventAudit eventAudit, Model.Account account)
 {
     return(new Projection(
                ProjectionAudit.Create(eventAudit),
                account));
 }
コード例 #23
0
ファイル: EnvironmentState.cs プロジェクト: binarymash/evelyn
        public void AddToggleState(EventAudit eventAudit, string toggleKey, string toggleValue)
        {
            var toggleState = ToggleState.Create(toggleKey, toggleValue, eventAudit.EventVersion);

            _toggleStates.Add(toggleState);
        }
コード例 #24
0
ファイル: EnvironmentState.cs プロジェクト: binarymash/evelyn
 public static EnvironmentState Create(EventAudit eventAudit, IEnumerable <ToggleState> toggleStates)
 {
     return(new EnvironmentState(toggleStates ?? new List <ToggleState>()));
 }
コード例 #25
0
ファイル: ToggleState.cs プロジェクト: binarymash/evelyn
        public void DeleteEnvironmentState(EventAudit eventAudit, string environmentKey)
        {
            var environmentState = _environmentStates.Find(ts => ts.Key == environmentKey);

            _environmentStates.Remove(environmentState);
        }
コード例 #26
0
ファイル: Projection.cs プロジェクト: binarymash/evelyn
 public static Projection Create(EventAudit eventAudit)
 {
     return(new Projection(ProjectionAudit.Create(eventAudit)));
 }
コード例 #27
0
 public static Account Create(EventAudit eventAudit, Guid accountId)
 {
     return(new Account(accountId, new List <Project>(), AggregateAudit.Create(eventAudit)));
 }
コード例 #28
0
ファイル: EnvironmentState.cs プロジェクト: binarymash/evelyn
        public void ChangeToggleState(EventAudit eventAudit, string toggleKey, string value)
        {
            var toggleState = _toggleStates.Find(ts => ts.Key == toggleKey);

            toggleState.ChangeState(value, eventAudit.EventVersion);
        }
コード例 #29
0
ファイル: Environment.cs プロジェクト: binarymash/evelyn
 public static Environment Create(EventAudit eventAudit, Guid projectId, string key, string name)
 {
     return(new Environment(projectId, key, name, AggregateAudit.Create(eventAudit)));
 }