Exemplo n.º 1
0
        public static void UseSingleChallenge(IEventStore eventStore)
        {
            if (ChallengeViewModels.Any())
            {
                return;
            }
            var id          = ChallengeId;
            var description = "Hundre pushups hver dag";
            var createEvent = new ChallengeCreated(id, 100, description, DateTime.Now.AddDays(-5));
            var viewModel   = new ChallengeViewModel
            {
                Id               = id.Guid,
                Desciption       = description,
                DailyRepetitions = 100,
                StartDate        = DateTime.Now.AddDays(-5),
                ActiveMonday     = true,
                ActiveTuesday    = true,
                ActiveWednesday  = true,
                ActiveThursday   = true,
                ActiveFriday     = true,
                ActiveSaturday   = true,
                ActiveSunday     = true,
                Duration         = TimeSpan.FromDays(30),
                TotalRepetitions = 460
            };

            eventStore.Add(id, new List <IEvent> {
                createEvent
            });
            ChallengeViewModels.Add(viewModel);
        }
        public async Task <Result> Handle(GridValueChangeCommand request, CancellationToken cancellationToken)
        {
            //TODO: Add transaction
            await SetProperty(request.AgregateId, request.PropertyName, request.NewValue, request.OldValue);

            var newEvent = new ValueChangedEvent
            {
                PropertyName = request.PropertyName,
                NewValue     = request.NewValue,
                OldValue     = request.OldValue,
                AgregateId   = request.AgregateId,
                AgregateType = typeof(Item),
            };

            await eventStore.Add(new EventData <ValueChangedEvent>
            {
                AgregateId   = newEvent.AgregateId,
                AgregateType = newEvent.AgregateType,
                Caller       = 99999999,
                CallerName   = "test",
                CreatedAt    = DateTime.Now,
                Data         = newEvent
            });

            await context.SaveChangesAsync();

            await eventBus.Publish(newEvent);

            return(await Task.FromResult(Result.Success()));
        }
Exemplo n.º 3
0
        public void Save(TAggregateRoot item)
        {
            var uncommittedEvents = item.GetUncommittedEvents().ToArray();

            if (uncommittedEvents.Length == 0)
            {
                return;
            }

            if (_loaded.Contains(item.Id))
            {
                object[] baseAndUnseenEvents = _eventStore.Load(item.Id).ToArray();

                if (baseAndUnseenEvents.Length > 0)
                {
                    var unseenEvents = GetUnseenEvents(item, baseAndUnseenEvents);
                    var conflicts    = _concurrencyMonitor.CheckForConflicts(unseenEvents, uncommittedEvents);
                    if (conflicts.Any())
                    {
                        var exception = new ConcurrencyConflictsDetectedException(conflicts);
                        exception.Data.Add("AggregateId", item.Id);
                        throw exception;
                    }
                }

                _eventStore.Update(item.Id, uncommittedEvents);
            }
            else
            {
                _eventStore.Add(item.Id, uncommittedEvents);
                _loaded.Add(item.Id);
            }

            item.AcceptUncommittedEvents();
        }
Exemplo n.º 4
0
 public void Publish <TEvent>(TEvent evt, int sequenceId) where TEvent : IDomainEvent
 {
     _eventStore.Add(evt, sequenceId);
     foreach (var eventHandler in _eventHandlers)
     {
         eventHandler.Handle(evt);
     }
 }
        public Task Consume(ConsumeContext <ConcertCreatedEvent> context)
        {
            var projector = _projectorFactory.CreateProjector();

            projector.Project(context.Message);
            _eventStore.Add(context.Message); // posto se radi projekcija cim stigne event, ovde se samo smestaju eventi u dummy bazu
            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
        public static void UseTwoMeasurements(IEventStore eventStore)
        {
            if (MeasurementViewModels.Any())
            {
                return;
            }
            var measurementId = new MeasurementId(Guid.NewGuid());
            var type          = "Stomach";
            var unit          = "cm";
            var createEvent_1 = new MeasurementCreated(measurementId, type, unit, DateTime.Now.AddDays(-3));
            var viewModel_1   = new MeasurementViewModel
            {
                Id     = measurementId.Guid,
                Type   = type,
                Unit   = unit,
                Values = new Dictionary <DateTime, double>
                {
                    { DateTime.Now.AddDays(-3), 104.5 },
                    { DateTime.Now.AddDays(-1), 104 },
                }
            };
            var measurementId_2 = new MeasurementId(Guid.NewGuid());
            var type_2          = "High jump";
            var unit_2          = "meter";
            var createEvent_2   = new MeasurementCreated(measurementId_2, type_2, unit, DateTime.Now.AddDays(-4));
            var viewModel_2     = new MeasurementViewModel
            {
                Id     = measurementId_2.Guid,
                Type   = type_2,
                Unit   = unit_2,
                Values = new Dictionary <DateTime, double>
                {
                    { DateTime.Now.AddDays(-4), 0.34 },
                    { DateTime.Now.AddHours(-2), 0.357 }
                }
            };

            eventStore.Add(measurementId, new List <IEvent> {
                createEvent_1
            });
            eventStore.Add(measurementId_2, new List <IEvent> {
                createEvent_2
            });
            MeasurementViewModels.Add(viewModel_1);
            MeasurementViewModels.Add(viewModel_2);
        }
        public Task Consume(ConsumeContext <ConcertCreatedEvent> context)
        {
            var projector = _projectorFactory.CreateProjector();

            projector.Project(context.Message);
            _eventStore.Add(context.Message);
            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        protected async Task Update(IAggregateIdentity id, Action <T> execute)
        {
            var events    = eventStore.Get(id);
            var aggregate = BuildAggregate(events);

            execute(aggregate);
            eventStore.Add(id, aggregate.Changes);
            await ViewStore.Update(id, aggregate.Changes);
        }
Exemplo n.º 9
0
        private void OnEvent(ApiEvent @event)
        {
            _eventStore.Add(@event);

            var serializedEvent = JsonConvert.SerializeObject(@event);

            _logger.LogInformation(serializedEvent);

            _stream.Clients.All.githubEvent(@event);
        }
Exemplo n.º 10
0
 public void Handle(IEnumerable <IEvent> events)
 {
     _eventStore.UnitOfWork.ExecuteInTransaction(() =>
     {
         foreach (var @event in events)
         {
             _eventStore.Add(@event);
         }
     });
 }
Exemplo n.º 11
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var photoStudio = await _store.FindAsync <PhotoStudio>(request.PhotoStudioId);

                photoStudio.Remove(_dateTime.UtcNow);

                _store.Add(photoStudio);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 12
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var invoice = await _store.FindAsync <Invoice>(request.InvoiceId);

                invoice.Remove(_dateTime.UtcNow);

                _store.Add(invoice);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());;
            }
Exemplo n.º 13
0
            public async Task <ResponseBase> Handle(Request request, CancellationToken cancellationToken)
            {
                var account = await _store.FindAsync <Account>(request.AccountId);

                account.Remove(_dateTime.UtcNow);

                _store.Add(account);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 14
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var availability = await _store.FindAsync <Availability>(request.AvailabilityId);

                availability.Remove(_dateTime.UtcNow);

                _store.Add(availability);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 15
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var dashboard = await _store.FindAsync <Dashboard>(request.DashboardId);

                dashboard.Remove(_dateTime.UtcNow);

                _store.Add(dashboard);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 16
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var epic = await _store.FindAsync <Epic>(request.EpicId);

                epic.Remove(_dateTime.UtcNow);

                _store.Add(epic);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 17
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var survey = await _store.FindAsync <Survey>(request.SurveyId);

                survey.Remove(_dateTime.UtcNow);

                _store.Add(survey);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 18
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var offer = await _store.FindAsync <Offer>(request.OfferId);

                offer.Remove(_dateTime.UtcNow);

                _store.Add(offer);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 19
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var timeEntry = await _store.FindAsync <TimeEntry>(request.TimeEntryId);

                timeEntry.Remove(_dateTime.UtcNow);

                _store.Add(timeEntry);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 20
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var company = await _store.FindAsync <Company>(request.CompanyId);

                company.Remove(_dateTime.UtcNow);

                _store.Add(company);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 21
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var brand = await _store.FindAsync <Brand>(request.BrandId);

                brand.Remove(_dateTime.UtcNow);

                _store.Add(brand);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 22
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var referral = await _store.FindAsync <Referral>(request.ReferralId);

                referral.Remove(_dateTime.UtcNow);

                _store.Add(referral);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 23
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var editedPhoto = await _store.FindAsync <EditedPhoto>(request.EditedPhotoId);

                editedPhoto.Remove(_dateTime.UtcNow);

                _store.Add(editedPhoto);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 24
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var participant = await _store.FindAsync <Participant>(request.ParticipantId);

                participant.Remove(_dateTime.UtcNow);

                _store.Add(participant);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 25
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var familyPortrait = await _store.FindAsync <FamilyPortrait>(request.FamilyPortraitId);

                familyPortrait.Remove(_dateTime.UtcNow);

                _store.Add(familyPortrait);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 26
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var expense = await _store.FindAsync <Expense>(request.ExpenseId);

                expense.Remove(_dateTime.UtcNow);

                _store.Add(expense);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 27
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var shotList = await _store.FindAsync <ShotList>(request.ShotListId);

                shotList.Remove(_dateTime.UtcNow);

                _store.Add(shotList);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 28
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var venue = await _store.FindAsync <Venue>(request.VenueId);

                venue.Remove(_dateTime.UtcNow);

                _store.Add(venue);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 29
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var task = await _store.FindAsync <DblDip.Core.Models.Task>(request.TaskId);

                task.Remove(_dateTime.UtcNow);

                _store.Add(task);

                await _store.SaveChangesAsync(cancellationToken);

                return(new());
            }
Exemplo n.º 30
0
        /// <summary>
        /// Add multiple events to the stream
        /// </summary>
        /// <typeparam name="T">Type of the aggregate</typeparam>
        /// <param name="id">The id of the aggregate</param>
        /// <param name="events">The events to add</param>
        public async Task Add <T>(Guid id, IEnumerable <Event> events)
        {
            var streamId = StreamId <T>(id);

            using var aes = await GetAes(streamId, true);

            await _eventStore.Add(streamId, await Task.WhenAll(events.Select(async @event => await Encrypt(aes, @event))));

            if (events.Any(@event => @event is IProtectedDataDeletionEvent))
            {
                await _keyStore.Delete(streamId, DeleteAfter);
            }
        }