示例#1
0
        /// <summary>
        /// Get all <see cref="IEvent{TAuthenticationToken}"/> instances for the given <paramref name="correlationId"/>.
        /// </summary>
        /// <param name="correlationId">The <see cref="IMessage.CorrelationId"/> of the <see cref="IEvent{TAuthenticationToken}"/> instances to retrieve.</param>
        public override IEnumerable <EventData> Get(Guid correlationId)
        {
            // Create the table query.
            var rangeQuery = new TableQuery <DynamicTableEntity>().Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(correlationId.ToString("N")))
                             );

            var operationContext          = new OperationContext();
            IEnumerable <EventData> query = CorrelationIdTableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
#pragma warning disable 0436
                                            .Select(eventData => EntityPropertyConverter.ConvertBack <EventData>(eventData.Properties, operationContext))
#pragma warning restore 0436
                                            .OrderBy(eventData => eventData.Timestamp);

            return(query.ToList());
        }
示例#2
0
        public override IEnumerable <EventData> Get(Guid correlationId)
        {
            // Create the table query.
            var rangeQuery = new TableQuery <EventDataTableEntity <EventData> >().Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(correlationId.ToString("N")))
                             );

            IEnumerable <EventData> query = CorrelationIdTableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
                                            .Select(eventData => eventData.EventData)
                                            .OrderBy(eventData => eventData.Timestamp);

            return(query.ToList());
        }
示例#3
0
        /// <summary>
        /// Gets a collection of <see cref="IEvent{TAuthenticationToken}"/> for the <see cref="IAggregateRoot{TAuthenticationToken}"/> of type <paramref name="aggregateRootType"/> with the ID matching the provided <paramref name="aggregateId"/>.
        /// </summary>
        /// <param name="aggregateRootType"> <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</param>
        /// <param name="aggregateId">The <see cref="IAggregateRoot{TAuthenticationToken}.Id"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/>.</param>
        /// <param name="useLastEventOnly">Loads only the last event<see cref="IEvent{TAuthenticationToken}"/>.</param>
        /// <param name="fromVersion">Load events starting from this version</param>
        public override IEnumerable <IEvent <TAuthenticationToken> > Get(Type aggregateRootType, Guid aggregateId, bool useLastEventOnly = false, int fromVersion = -1)
        {
            string streamName = GenerateStreamName(aggregateRootType, aggregateId);

            // Create the table query.
            var rangeQuery = new TableQuery <DynamicTableEntity>().Where
                             (
                TableQuery.CombineFilters
                (
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(streamName)),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("AggregateId", QueryComparisons.Equal, streamName)
                )
                             );

            var operationContext          = new OperationContext();
            IEnumerable <EventData> query = TableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
#pragma warning disable 0436
                                            .Select(eventData => EntityPropertyConverter.ConvertBack <EventData>(eventData.Properties, operationContext))
#pragma warning restore 0436
                                            .Where(eventData => eventData.AggregateId == streamName && eventData.Version > fromVersion)
                                            .OrderByDescending(eventData => eventData.Version);

            if (useLastEventOnly)
            {
                query = query.AsQueryable().Take(1);
            }

            return(query
                   .Select(eventData => EventDeserialiser.Deserialise(eventData))
                   .ToList());
        }
示例#4
0
        public override IEnumerable <IEvent <TAuthenticationToken> > Get(Type aggregateRootType, Guid aggregateId, bool useLastEventOnly = false, int fromVersion = -1)
        {
            string streamName = GenerateStreamName(aggregateRootType, aggregateId);

            // Create the table query.
            var rangeQuery = new TableQuery <EventDataTableEntity <EventData> >().Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(streamName))
                             );

            IEnumerable <EventData> query = TableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
                                            .Select(eventData => eventData.EventData)
                                            .Where(eventData => eventData.AggregateId == streamName && eventData.Version > fromVersion)
                                            .OrderByDescending(eventData => eventData.Version);

            if (useLastEventOnly)
            {
                query = query.AsQueryable().Take(1);
            }

            return(query
                   .Select(eventData => EventDeserialiser.Deserialise(eventData))
                   .ToList());
        }
        /// <summary>
        /// Get the latest <see cref="Snapshot"/> from storage.
        /// </summary>
        /// <returns>The most recent <see cref="Snapshot"/> of</returns>
        protected override Snapshot Get(Type aggregateRootType, string streamName)
        {
            // Create the table query.
            var rangeQuery = new TableQuery <DynamicTableEntity>().Where
                             (
                TableQuery.CombineFilters
                (
                    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(streamName)),
                    TableOperators.And,
                    TableQuery.GenerateFilterCondition("AggregateId", QueryComparisons.Equal, streamName)
                )
                             );

            var      operationContext = new OperationContext();
            Snapshot result           = TableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
#pragma warning disable 0436
                                        .Select(eventData => EntityPropertyConverter.ConvertBack <EventData>(eventData.Properties, operationContext))
#pragma warning restore 0436
                                        .Where(eventData => eventData.AggregateId == streamName)
                                        .OrderByDescending(eventData => eventData.Version)
                                        .Take(1)
                                        .Select(EventDeserialiser.Deserialise)
                                        .SingleOrDefault();

            return(result);
        }
        /// <summary>
        /// Gets a collection of <see cref="IEvent{TAuthenticationToken}"/> for the <see cref="IAggregateRoot{TAuthenticationToken}"/> of type <paramref name="aggregateRootType"/> with the ID matching the provided <paramref name="aggregateId"/> from and including the provided <paramref name="fromVersionedDate"/> up to and including the provided <paramref name="toVersionedDate"/>.
        /// </summary>
        /// <param name="aggregateRootType"> <see cref="Type"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/> the <see cref="IEvent{TAuthenticationToken}"/> was raised in.</param>
        /// <param name="aggregateId">The <see cref="IAggregateRoot{TAuthenticationToken}.Id"/> of the <see cref="IAggregateRoot{TAuthenticationToken}"/>.</param>
        /// <param name="fromVersionedDate">Load events from and including from this <see cref="DateTime"/></param>
        /// <param name="toVersionedDate">Load events up-to and including from this <see cref="DateTime"/></param>
        public override IEnumerable <IEvent <TAuthenticationToken> > GetBetweenDates(Type aggregateRootType, Guid aggregateId, DateTime fromVersionedDate, DateTime toVersionedDate)
        {
            string streamName = GenerateStreamName(aggregateRootType, aggregateId);

            // Create the table query.
            var rangeQuery = new TableQuery <EventDataTableEntity <EventData> >().Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(streamName))
                             );

            IEnumerable <EventData> query = TableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
                                            .Select(eventData => eventData.EventData)
                                            .Where(eventData => eventData.AggregateId == streamName && eventData.Timestamp >= fromVersionedDate && eventData.Timestamp <= toVersionedDate)
                                            .OrderByDescending(eventData => eventData.Version);

            return(query
                   .Select(eventData => EventDeserialiser.Deserialise(eventData))
                   .ToList());
        }
        /// <summary>
        /// Get the latest <see cref="Snapshot"/> from storage.
        /// </summary>
        /// <returns>The most recent <see cref="Snapshot"/> of</returns>
        protected override Snapshot Get(Type aggregateRootType, string streamName)
        {
            // Create the table query.
            var rangeQuery = new TableQuery <EventDataTableEntity <EventData> >().Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(streamName))
                             );

            Snapshot result = TableStorageStore.ReadableSource.ExecuteQuery(rangeQuery)
                              .Select(eventData => eventData.EventData)
                              .Where(eventData => eventData.AggregateId == streamName)
                              .OrderByDescending(eventData => eventData.Version)
                              .Take(1)
                              .Select(EventDeserialiser.Deserialise)
                              .SingleOrDefault();

            return(result);
        }
        /// <summary>
        /// Retrieves the data from Azure Storage using <see cref="TableStorageStore{TData,TCollectionItemData}.Collection"/>.
        /// </summary>
        public override IEnumerable <EntityTableEntity <TData> > GetByKey()
        {
            // Create the table query.
            var rangeQuery = Collection.Where
                             (
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, StorageStore <object, object> .GetSafeStorageKey(typeof(TData).FullName))
                             );

            IEnumerable <EntityTableEntity <TData> > results = ReadableSource.ExecuteQuery(rangeQuery);

            return(results);
        }