/// <inheritdoc/> public async Task <bool> DeleteDataBlobs(Instance instance) { BlobContainerClient container = await CreateBlobClient(instance.Org); if (container == null) { _logger.LogError($"BlobSerivce // DeleteDataBlobs // Could not connect to blob container."); return(false); } try { await foreach (BlobItem item in container.GetBlobsAsync(BlobTraits.None, BlobStates.None, $"{instance.AppId}/{instance.Id}", CancellationToken.None)) { container.DeleteBlobIfExists(item.Name, DeleteSnapshotsOption.IncludeSnapshots); } } catch (Exception e) { _sasTokenProvider.InvalidateSasToken(instance.Org); _logger.LogError(e, $"BlobSerivce // DeleteDataBlobs // Org: {instance.Org} // Exeption: {e.Message}"); return(false); } return(true); }
/// <inheritdoc/> public async Task <long> WriteDataToStorage(string org, Stream stream, string blobStoragePath) { try { return(await UploadFromStreamAsync(org, stream, blobStoragePath)); } catch (Exception storageException) { _logger.LogWarning($"StorageException when accessing blob storage for {org}: {Environment.NewLine}{storageException}"); _logger.LogWarning("Invalidating SAS token and retrying upload operation."); _sasTokenProvider.InvalidateSasToken(org); return(await UploadFromStreamAsync(org, stream, blobStoragePath)); } }
/// <inheritdoc/> public async Task <long> WriteDataToStorage(string org, Stream stream, string blobStoragePath) { try { return(await UploadFromStreamAsync(org, stream, blobStoragePath)); } catch (RequestFailedException requestFailedException) { switch (requestFailedException.ErrorCode) { case "AuthenticationFailed": _logger.LogWarning("Authentication failed. Invalidating SAS token."); _sasTokenProvider.InvalidateSasToken(org); // No use retrying upload as the original stream can't be reset back to start. throw; default: throw; } } }