Example #1
0
        private Task StartWriteToAzure(CloudAppendBlob file, string chunkFilePath, CancellationToken token)
        {
            return(Task.Run(
                       async() =>
            {
                var context = new OperationContext();
                var options =
                    new BlobRequestOptions
                {
                    RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(5), 10),
                    SingleBlobUploadThresholdInBytes = AppendBlobBlockSize,
                    UseTransactionalMD5 = false,
                };
                var condition = AccessCondition.GenerateEmptyCondition();

                var prevChunk = 0;
                while (true)
                {
                    if (_chunkFilesCompleted == 0)
                    {
                        await Task.Delay(100);
                        continue;
                    }

                    await WriteCompletedFiles();

                    if (token.IsCancellationRequested)
                    {
                        await WriteCompletedFiles();
                        break;
                    }

                    await Task.Delay(100, token);
                }

                async Task WriteCompletedFiles()
                {
                    while (prevChunk < _chunkFilesCompleted)
                    {
                        var chunkPath = Path.Combine(chunkFilePath, (prevChunk + 1).ToString());
                        await file.AppendFromFileAsync(chunkPath, condition, options, context);
                        File.Delete(chunkPath);
                        prevChunk++;
                    }
                }
            }, token));
        }
Example #2
0
 public static void AppendFromFile(this CloudAppendBlob blob, string path)
 {
     blob.AppendFromFileAsync(path).Wait();
 }