private async Task <SwiftResponse> ChunkedUpload(hubiCContext context, string objectId, Stream content, IProgress <ProgressValue> progress) { var readBuffer = new byte[MAX_CHUNK_SIZE]; var bytesTransferred = 0; var bytesTotal = (int)content.Length; progress?.Report(new ProgressValue(bytesTransferred, bytesTotal)); var chunks = (content.Length - 1) / MAX_CHUNK_SIZE + 1; var item = default(SwiftResponse); for (var i = 0; i < chunks; ++i) { var chunkSize = await content.ReadAsync(readBuffer, 0, MAX_CHUNK_SIZE); item = await context.Client.PutObjectChunk(context.Container, objectId, chunkSize == MAX_CHUNK_SIZE?readBuffer : readBuffer.Take(chunkSize).ToArray(), i); if (!item.IsSuccess) { throw new ApplicationException(item.Reason); } progress?.Report(new ProgressValue(bytesTransferred += chunkSize, bytesTotal)); } var manifest = await context.Client.PutManifest(context.Container, objectId); if (!manifest.IsSuccess) { throw new ApplicationException(manifest.Reason); } return(item); }
private async Task <hubiCContext> RequireContextAsync(RootName root, string apiKey = null, string container = DEFAULT_CONTAINER) { if (root == null) { throw new ArgumentNullException(nameof(root)); } var result = default(hubiCContext); if (!contextCache.TryGetValue(root, out result)) { var client = await OAuthAuthenticator.LoginAsync(root.UserName, apiKey, settingsPassPhrase); contextCache.Add(root, result = new hubiCContext(client, container)); } return(result); }