Exemplo n.º 1
0
        public async Task Handle(long streamPosition, ProjectEvents.ToggleStateDeleted @event, CancellationToken stoppingToken)
        {
            var eventAudit       = CreateEventAudit(streamPosition, @event);
            var storeKey         = Projection.StoreKey(@event.Id, @event.EnvironmentKey);
            var environmentState = (await Projections.Get(storeKey).ConfigureAwait(false)).EnvironmentState;

            environmentState.DeleteToggleState(CreateEventAudit(streamPosition, @event), @event.ToggleKey);

            var projection = Projection.Create(eventAudit, environmentState);
            await Projections.Update(storeKey, projection).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task Handle(long streamPosition, ProjectEvents.ProjectCreated @event, CancellationToken stoppingToken)
        {
            var eventAudit = CreateEventAudit(streamPosition, @event);
            var storeKey   = Projection.StoreKey(@event.AccountId);
            var account    = (await Projections.Get(storeKey).ConfigureAwait(false)).Account;

            account.SetProjectName(eventAudit, @event.Id, @event.Name);

            var projection = Projection.Create(eventAudit, account);
            await Projections.Update(storeKey, projection).ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public async Task Handle(long streamPosition, ProjectEvents.ToggleAdded @event, CancellationToken stoppingToken)
        {
            var eventAudit = CreateEventAudit(streamPosition, @event);
            var storeKey   = Projection.StoreKey(@event.Id);
            var project    = (await Projections.Get(storeKey).ConfigureAwait(false)).Project;

            project.AddToggle(CreateEventAudit(streamPosition, @event), @event.Key, @event.Name);

            var projection = Projection.Create(eventAudit, project);
            await Projections.Update(storeKey, projection).ConfigureAwait(false);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }