private Task Upload(UploadTask uploadTask, IProgress <IUploadState>?progress = null, CancellationToken cancellationToken = default, PauseToken pauseToken = default) { var tcs = new TaskCompletionSource <bool>(); uploadTask.AddOnCompleteListener(new OnCompleteHandlerListener(task => { if (task.IsSuccessful) { tcs.SetResult(true); } else { tcs.SetException(ExceptionMapper.Map(task.Exception)); } })); if (progress != null) { uploadTask.AddOnProgressListener(new OnProgressHandlerListener(snapshot => { var uploadTaskSnapshot = snapshot.JavaCast <UploadTask.TaskSnapshot>(); progress.Report(new UploadTaskSnapshotWrapper(uploadTaskSnapshot !)); })); } if (cancellationToken != default) { cancellationToken.Register(() => uploadTask.Cancel()); } if (pauseToken != default) { pauseToken.SetStorageTask(new StorageTaskWrapper(uploadTask)); } return(tcs.Task); }