Пример #1
0
        /// <inheritdoc />
        public async Task <IReadOnlyCollection <IEvent> > GetAsync(string aggregateId, int fromVersion)
        {
            var query = new TableQuery <EventStoreEvent>()
                        .Where(TableQuery.GenerateFilterCondition(
                                   "PartitionKey",
                                   QueryComparisons.Equal,
                                   aggregateId));

            var results           = new List <IEvent>();
            var continuationToken = new TableContinuationToken();

            do
            {
                var queryResults = await tableProxy.ExecuteQuerySegmentedAsync(query, continuationToken);

                if (!queryResults.Results.Any())
                {
                    throw new KeyNotFoundException($"Aggregate Root with id = '{aggregateId}' hasn't been found");
                }

                continuationToken = queryResults.ContinuationToken;
                results.AddRange(queryResults.Results.Select(tableEntity => tableEntity.ToEvent()));
            }while (continuationToken != null);

            return(results.AsReadOnly());
        }
Пример #2
0
        /// <inheritdoc/>
        public async Task <IReadOnlyCollection <ProcessMessage> > GetMessagesAsync(string id)
        {
            var filterByPartition = TableQuery.GenerateFilterCondition(nameof(TableEntity.PartitionKey), QueryComparisons.Equal, id);

            var operation = new TableQuery <DynamicTableEntity>()
                            .Where(filterByPartition);

            var tableResult = await tableProxy.ExecuteQuerySegmentedAsync(operation, null);

            var processMessages = new List <ProcessMessage>();

            foreach (var entity in tableResult.Results)
            {
                var isPublished = entity.Properties.TryGetValue(IsPublishedColumnName, out var published) && published.BooleanValue.GetValueOrDefault();

                var message = (AbstractMessage)AzureTableSerializer.Deserialize(entity);

                processMessages.Add(new ProcessMessage(message, isPublished));
            }

            return(processMessages.ToArray());
        }