public Task <T> GetItemAsync <T>(IDataStoreReadById aggregateQueriedById) where T : class, IAggregate, new()
        {
            var aggregate = Aggregates.Where(x => x.schema == typeof(T).FullName).Cast <T>().SingleOrDefault(a => a.id == aggregateQueriedById.Id);

            //clone otherwise its to easy to change the referenced object in test code affecting results
            return(Task.FromResult(aggregate?.Clone()));
        }
        public async Task <dynamic> GetItemAsync(IDataStoreReadById aggregateQueriedById)
        {
            try
            {
                if (aggregateQueriedById.Id == Guid.Empty)
                {
                    return(null);                                       //createdocumentselflink will fail otherwise
                }
                var result = await this.documentClient.ReadDocumentAsync(CreateDocumentSelfLinkFromId(aggregateQueriedById.Id)).ConfigureAwait(false);

                if (result == null)
                {
                    throw new DatabaseRecordNotFoundException(aggregateQueriedById.Id.ToString());
                }

                aggregateQueriedById.StateOperationCost = result.RequestCharge;

                return(result.Resource);
            }
            catch (DocumentClientException de)
            {
                if (de.StatusCode == HttpStatusCode.NotFound) //handle when it doesn't exists and return null
                {
                    return(null);
                }
                throw new DatabaseException($"Failed to retrieve record with id {aggregateQueriedById.Id}: {de.Message}", de);
            }
            catch (Exception e)
            {
                throw new DatabaseException($"Failed to retrieve record with id {aggregateQueriedById.Id}: {e.Message}", e);
            }
        }
Exemplo n.º 3
0
        public async Task <bool> Exists(IDataStoreReadById aggregateQueriedById)
        {
            Raven.Abstractions.Data.JsonDocumentMetadata documentMetadata =
                await store.AsyncDatabaseCommands.HeadAsync(aggregateQueriedById.Id.ToString()).ConfigureAwait(false);

            return(documentMetadata != null);
        }
Exemplo n.º 4
0
 public Task <T> GetItemAsync <T>(IDataStoreReadById aggregateQueriedById) where T : class, IAggregate, new()
 {
     using (IAsyncDocumentSession session = store.OpenAsyncSession())
     {
         T result = session.LoadAsync <T>(aggregateQueriedById.Id.ToString()).Result;
         return(Task.FromResult(result));
     }
 }
Exemplo n.º 5
0
        public Task <T> GetItemAsync <T>(IDataStoreReadById aggregateQueriedById) where T : class, IAggregate, new()
        {
            // NOTE: SqlCommand.ExecuteScalarAsync() has severe performance issues when
            //       retrieving large recordsets, therefore we use the sync implementation.

            var result = GetItem <T>(aggregateQueriedById);

            return(Task.FromResult(result));
        }
        public async Task <bool> Exists(IDataStoreReadById aggregateQueriedById)
        {
            var query = this.documentClient.CreateDocumentQuery(this.config.CollectionSelfLink()).Where(item => item.Id == aggregateQueriedById.Id.ToString())
                        .AsDocumentQuery();

            var results = await query.ExecuteNextAsync().ConfigureAwait(false);

            aggregateQueriedById.StateOperationCost = results.RequestCharge;

            return(results.Count > 0);
        }
Exemplo n.º 7
0
        private T GetItem <T>(IDataStoreReadById aggregateQueriedById) where T : class, IAggregate, new()
        {
            var id = aggregateQueriedById.Id;

            T result;

            using (var connection = this.clientFactory.OpenClient())
            {
                using (var command = new SqlCommand($"SELECT Json FROM {this.settings.TableName} WHERE AggregateId = CONVERT(uniqueidentifier, '{id}') AND [Schema] = '{typeof(T).FullName}'", connection))
                {
                    var response = command.ExecuteScalar() as string;

                    result = response == null ? null : JsonConvert.DeserializeObject <T>(response);
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        public async Task <bool> Exists(IDataStoreReadById aggregateQueriedById)
        {
            var id = aggregateQueriedById.Id;

            string result;

            using (var connection = this.clientFactory.OpenClient())
            {
                using (var command = new SqlCommand(
                           $"SELECT AggregateId FROM {this.settings.TableName} WHERE AggregateId = CONVERT(uniqueidentifier, '{id}')",
                           connection))
                {
                    result = (await command.ExecuteScalarAsync().ConfigureAwait(false))?.ToString();
                }
            }

            return(result != null);
        }
        public async Task <T> GetItemAsync <T>(IDataStoreReadById aggregateQueriedById) where T : class, IAggregate, new()
        {
            var result = await GetItemAsync(aggregateQueriedById).ConfigureAwait(false);

            return((T)result);
        }
 public Task <bool> Exists(IDataStoreReadById aggregateQueriedById)
 {
     return(Task.FromResult(Aggregates.Exists(a => a.id == aggregateQueriedById.Id)));
 }