public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query, CancellationToken cancellationToken)
        {
            var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <ElasticsearchThingyMessageReadModel>();
            var indexName            = readModelDescription.IndexName.Value;

            // Never do this
            await _elasticClient.FlushAsync(
                indexName,
                d => d
                .RequestConfiguration(c => c
                                      .AllowedStatusCodes((int)HttpStatusCode.NotFound)),
                cancellationToken)
            .ConfigureAwait(false);

            await _elasticClient.RefreshAsync(
                indexName,
                d => d
                .RequestConfiguration(c => c
                                      .AllowedStatusCodes((int)HttpStatusCode.NotFound)),
                cancellationToken)
            .ConfigureAwait(false);

            var searchResponse = await _elasticClient.SearchAsync <ElasticsearchThingyMessageReadModel>(d => d
                                                                                                        .RequestConfiguration(c => c
                                                                                                                              .AllowedStatusCodes((int)HttpStatusCode.NotFound))
                                                                                                        .Index(indexName)
                                                                                                        .Query(q => q.Term(m => m.ThingyId.Suffix("keyword"), query.ThingyId.Value)),
                                                                                                        cancellationToken)
                                 .ConfigureAwait(false);

            return(searchResponse.Documents
                   .Select(d => d.ToThingyMessage())
                   .ToList());
        }
Exemple #2
0
        public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query, CancellationToken cancellationToken)
        {
            var readModels = await _readStore.FindAsync(rm => rm.ThingyId == query.ThingyId, cancellationToken).ConfigureAwait(false);

            return(readModels
                   .Select(rm => rm.ToThingyMessage())
                   .ToList());
        }
Exemple #3
0
        public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query, CancellationToken cancellationToken)
        {
            var thingyId    = query.ThingyId.ToString();
            var asyncCursor = await _readStore.FindAsync(f => string.Equals(f.ThingyId, thingyId), cancellationToken : cancellationToken).ConfigureAwait(false);

            var thingyMessageReadModels = await asyncCursor.ToListAsync(cancellationToken : cancellationToken).ConfigureAwait(false);

            return(thingyMessageReadModels.Select(b => b.ToThingyMessage()).ToList());
        }
Exemple #4
0
        public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query, CancellationToken cancellationToken)
        {
            var readModels = await _postgreSqlConnection.QueryAsync <PostgreSqlThingyMessageReadModel>(
                Label.Named("postgresql-fetch-thingy-message-read-model"),
                cancellationToken,
                "SELECT * FROM \"ReadModel-ThingyMessage\" WHERE ThingyId = @ThingyId;",
                new { ThingyId = query.ThingyId.Value })
                             .ConfigureAwait(false);

            return(readModels
                   .Select(rm => rm.ToThingyMessage())
                   .ToList());
        }
        public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query,
                                                                                   CancellationToken cancellationToken)
        {
            using (var context = _dbContextProvider.CreateContext())
            {
                var entities = await context.ThingyMessages
                               .Where(m => m.ThingyId == query.ThingyId.Value)
                               .Select(m => m.ToThingyMessage())
                               .ToArrayAsync(cancellationToken);

                return(entities);
            }
        }
        public async Task <IReadOnlyCollection <ThingyMessage> > ExecuteQueryAsync(ThingyGetMessagesQuery query, CancellationToken cancellationToken)
        {
            var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <ElasticsearchThingyMessageReadModel>();
            var indexName            = readModelDescription.IndexName.Value;

            // Never do this
            await _elasticClient.FlushAsync(d => d.Index(indexName)).ConfigureAwait(false);

            await _elasticClient.RefreshAsync(d => d.Index(indexName)).ConfigureAwait(false);

            var searchResponse = await _elasticClient.SearchAsync <ElasticsearchThingyMessageReadModel>(d => d
                                                                                                        .Index(indexName)
                                                                                                        .Query(q => q.Term(m => m.ThingyId, query.ThingyId.Value)))
                                 .ConfigureAwait(false);

            return(searchResponse.Documents
                   .Select(d => d.ToThingyMessage())
                   .ToList());
        }