public async Task <LicensePlateRegistration> GetByTypeAndNumberAsync(
            string registrationType,
            string licensePlateNumber)
        {
            var table = GetCloudTable();
            LicensePlateRegistration result = null;

            var retrieveOperation = TableOperation.Retrieve <LicensePlateRegistrationEntity>(
                registrationType,
                licensePlateNumber);

            try
            {
                var retrievedResult = await table.ExecuteAsync(retrieveOperation);

                if (retrievedResult.Result != null)
                {
                    result = LicensePlateRegistrationMapper.ToLicensePlateRegistration(
                        (LicensePlateRegistrationEntity)retrievedResult.Result);
                }
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForTableOperation(
                          registrationType, licensePlateNumber, table, retrieveOperation, e);
            }

            return(result);
        }
コード例 #2
0
        private async Task CreateDatabaseAndCollection()
        {
            var database = new Database
            {
                Id = DatabaseId
            };
            var databaseUri = GetDatabaseUri();

            try
            {
                await _documentClient.CreateDatabaseIfNotExistsAsync(database);

                var collection = new DocumentCollection
                {
                    Id = CollectionId
                };
                collection.PartitionKey.Paths.Add("/owner");
                collection.IndexingPolicy.Automatic    = true;
                collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent;
                collection.IndexingPolicy.IncludedPaths.Clear();

                await _documentClient.CreateDocumentCollectionIfNotExistsAsync(
                    databaseUri,
                    collection,
                    new RequestOptions { OfferThroughput = 400 });
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForCollectionCreation(databaseUri, CollectionId, e);
            }
        }
コード例 #3
0
 public async Task AddAsync(ParkingGarage parkingGarage)
 {
     try
     {
         await _documentClient.CreateDocumentAsync(GetDocumentCollectionUri(), parkingGarage, GetRequestOptions());
     }
     catch (Exception e)
     {
         throw RepositoryExceptionBuilder.CreateExceptionForDocumentCreation(parkingGarage, e);
     }
 }
コード例 #4
0
        public async Task RemoveAsync(string parkingGarageId)
        {
            var documentUri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, parkingGarageId);

            try
            {
                await _documentClient.DeleteDocumentAsync(documentUri);
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForDocumentDelete(documentUri, e);
            }
        }
コード例 #5
0
        public async Task UpdateAsync(ParkingGarage parkingGarage)
        {
            var documentUri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, parkingGarage.Id);

            try
            {
                await _documentClient.UpsertDocumentAsync(documentUri, parkingGarage, GetRequestOptions());
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForDocumentUpdate(documentUri, e);
            }
        }
        private CloudTable GetCloudTable()
        {
            var cloudTable = _cloudTableClient.GetTableReference(TableName);

            try
            {
                cloudTable.CreateIfNotExists();
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForTableCreation(cloudTable, e);
            }

            return(cloudTable);
        }
コード例 #7
0
        public async Task <ParkingGarage> GetByNameAsync(string name)
        {
            ParkingGarage result;

            try
            {
                var parkingGarage = _documentClient.CreateDocumentQuery <ParkingGarage>(GetDocumentCollectionUri())
                                    .Where(parking => parking.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                                    .AsEnumerable()
                                    .FirstOrDefault();

                result = await Task.FromResult(parkingGarage);
            }
            catch (Exception e)
            {
                throw RepositoryExceptionBuilder.CreateExceptionForDocumentQuery(nameof(name), name, e);
            }

            return(result);
        }