public Task <DBMetadata> LoadFileTask(string path, string destPath, CancellationToken token = default(CancellationToken)) { var tcs = new TaskCompletionSource <DBMetadata> (); if (token.IsCancellationRequested) { tcs.TrySetCanceled(); return(tcs.Task); } // workaround: loadedFile selector is always defined in autogenerated delegate, hence using custom delegate BeginInvokeOnMainThread(() => { if (token.IsCancellationRequested) { tcs.TrySetCanceled(); return; } Delegate = new DBLoadFileRestClientDelegate { OnFileMetadataLoaded = (_destPath, _contentType, _metadata) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled(); return; } tcs.TrySetResult(_metadata); }, OnLoadFileFailed = (_error) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled(); return; } tcs.TrySetException(new DropboxException(_error)); }, OnLoadProgress = (_progress, _destPath) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled(); return; } if (this.OnLoadProgress != null) { this.OnLoadProgress(_progress, _destPath); } } }; LoadFile(path, destPath); }); return(tcs.Task); }
public Task<DBMetadata> LoadFileTask(string path, string destPath, CancellationToken token = default (CancellationToken)) { var tcs = new TaskCompletionSource<DBMetadata> (); if (token.IsCancellationRequested) { tcs.TrySetCanceled (); return tcs.Task; } // workaround: loadedFile selector is always defined in autogenerated delegate, hence using custom delegate BeginInvokeOnMainThread (() => { if (token.IsCancellationRequested) { tcs.TrySetCanceled (); return; } Delegate = new DBLoadFileRestClientDelegate { OnFileMetadataLoaded = (_destPath, _contentType, _metadata) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled (); return; } tcs.TrySetResult (_metadata); }, OnLoadFileFailed = (_error) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled (); return; } tcs.TrySetException (new DropboxException (_error)); }, OnLoadProgress = (_progress, _destPath) => { if (token.IsCancellationRequested) { tcs.TrySetCanceled (); return; } if (this.OnLoadProgress != null) this.OnLoadProgress (_progress, _destPath); } }; LoadFile (path, destPath); }); return tcs.Task; }