Ejemplo n.º 1
0
        public async Task <Domain.Domains.Domain> Get(Guid domainId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var context = await _ddpContextProvider.Get();

            var domainTable = await context.DomainTables.FindAsync(domainId);

            if (domainTable == null)
            {
                return(null);
            }

            var stream = await _eventStore.GetEventStreamFor <Domain.Domains.Domain>(domainId, cancellationToken : cancellationToken);

            var domain = new Domain.Domains.Domain(stream.DomainEvents, stream.StreamVersion);

            return(domain);
        }
Ejemplo n.º 2
0
        public async Task <EntityType> Get(Guid entityTypeId)
        {
            var context = await _ddpContextProvider.Get();

            var entityTypeTable = await context.EntityTypeTables.FindAsync(entityTypeId);

            if (entityTypeTable == null)
            {
                return(null);
            }

            var stream = await _eventStore.GetEventStreamFor <EntityType>(entityTypeId);

            var entityType = new EntityType(stream.DomainEvents, stream.StreamVersion);

            return(entityType);
        }
        public async Task <ConceptAttribute> Get(Guid conceptAttributeId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var context = await _ddpContextProvider.Get();

            var conceptAttributeTable = await context.ConceptAttributeTables.FindAsync(conceptAttributeId);

            if (conceptAttributeTable == null)
            {
                return(null);
            }

            var stream = await _eventStore.GetEventStreamFor <ConceptAttribute>(conceptAttributeId, cancellationToken : cancellationToken);

            var concept = new ConceptAttribute(stream.DomainEvents, stream.StreamVersion);

            return(concept);
        }
Ejemplo n.º 4
0
        private async Task <EventStream> GetEventsForInternal <T>(string entityId, int?version        = null,
                                                                  CancellationToken cancellationToken = default(CancellationToken))
            where T : EventSourcedEntity
        {
            var entityType = EventStoreMapping.GetEntityName <T>();

            if (entityType == null)
            {
                throw new Exception($"Unable to find event store mapping for entity type {typeof(T)}. Did you forget to add an entity binding to the event store mapping?");
            }

            var context = await _ddpContextProvider.Get();

            var query = context.EventTables.Where(x => x.EntityType == entityType && x.EntityId == entityId);

            if (version.HasValue)
            {
                query = query.Where(x => x.Version <= version);
            }

            var eventTables = await query.ToListAsync();

            var allEvents = new List <IDomainEvent>();

            foreach (var eventTable in eventTables)
            {
                var eventType = EventStoreMapping.GetEventType(eventTable.EventType);
                if (eventType == null)
                {
                    throw new Exception($"Unable to find event store mapping for event {eventTable.EventType}. Did you forget to add an event binding to the event store mapping?");
                }

                var materialized = (IDomainEvent)JsonConvert.DeserializeObject(eventTable.EventData, eventType);
                allEvents.Add(materialized);
            }

            return(new EventStream(allEvents, eventTables.Max(x => x.Version)));
        }
Ejemplo n.º 5
0
        public async Task <GetConceptsForDomainReadModel> Handle(GetConceptsForDomainQuery query,
                                                                 CancellationToken cancellationToken = default(CancellationToken))
        {
            var ddpContext = await _ddpContextProvider.Get();

            var readModel = new GetConceptsForDomainReadModel
            {
                Concepts = await ddpContext.ConceptTables.Where(x => x.DomainId == query.DomainId).Select(x =>
                                                                                                          new GetConceptsForDomainReadModelConcept
                {
                    ConceptId   = x.ConceptId,
                    Description = x.Description,
                    Name        = x.Name
                }).ToListAsync(cancellationToken: cancellationToken)
            };

            return(readModel);
        }