/// <inheritdoc/> public async Task DeleteTenantAsync(string tenantId) { ArgumentNullException.ThrowIfNull(tenantId); if (tenantId == this.Root.Id) { throw new InvalidOperationException("You can not delete the root tenant."); } try { (_, CloudBlobContainer container) = await this.GetContainerAndTenantForChildTenantsOf(TenantExtensions.GetRequiredParentId(tenantId)).ConfigureAwait(false); CloudBlockBlob blob = GetLiveTenantBlockBlobReference(tenantId, container); string blobText = await blob.DownloadTextAsync().ConfigureAwait(false); CloudBlockBlob deletedBlob = container.GetBlockBlobReference(DeletedTenantsPrefix + tenantId); await deletedBlob.UploadTextAsync(blobText).ConfigureAwait(false); await blob.DeleteIfExistsAsync().ConfigureAwait(false); } catch (FormatException fex) { throw new TenantNotFoundException("Unsupported tenant ID", fex); } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { throw new TenantNotFoundException(); } }
/// <inheritdoc/> public async Task <ITenant> GetTenantAsync(string tenantId, string?etag = null) { ArgumentNullException.ThrowIfNull(tenantId); if (tenantId == this.Root.Id) { return(this.Root); } try { (_, CloudBlobContainer container) = await this.GetContainerAndTenantForChildTenantsOf(TenantExtensions.GetRequiredParentId(tenantId)).ConfigureAwait(false); return(await this.GetTenantFromContainerAsync(tenantId, container, etag).ConfigureAwait(false)); } catch (FormatException fex) { throw new TenantNotFoundException("Unsupported tenant ID", fex); } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { throw new TenantNotFoundException(); } }
/// <inheritdoc/> public async Task <ITenant> UpdateTenantAsync( string tenantId, string?name, IEnumerable <KeyValuePair <string, object> >?propertiesToSetOrAdd, IEnumerable <string>?propertiesToRemove) { if (name is null && propertiesToSetOrAdd is null && propertiesToRemove is null) { throw new ArgumentNullException(nameof(propertiesToSetOrAdd), $"{nameof(name)}, {nameof(propertiesToSetOrAdd)}, and {nameof(propertiesToRemove)} cannot all be null"); } if (tenantId == this.Root.Id) { ((RootTenant)this.Root).UpdateProperties(propertiesToSetOrAdd, propertiesToRemove); return(this.Root); } try { (_, CloudBlobContainer container) = await this.GetContainerAndTenantForChildTenantsOf(TenantExtensions.GetRequiredParentId(tenantId)).ConfigureAwait(false); CloudBlockBlob blob = GetLiveTenantBlockBlobReference(tenantId, container); Tenant tenant = await this.GetTenantFromContainerAsync(tenantId, container, null).ConfigureAwait(false); IPropertyBag updatedProperties = this.propertyBagFactory.CreateModified( tenant.Properties, propertiesToSetOrAdd, propertiesToRemove); var updatedTenant = new Tenant( tenant.Id, name ?? tenant.Name, updatedProperties); string text = JsonConvert.SerializeObject(updatedTenant, this.serializerSettings); await blob.UploadTextAsync(text).ConfigureAwait(false); tenant.ETag = blob.Properties.ETag; return(updatedTenant); } catch (FormatException fex) { throw new TenantNotFoundException("Unsupported tenant ID", fex); } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) { throw new TenantNotFoundException(); } catch (StorageException ex) when(ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.Conflict) { throw new TenantConflictException(); } }