Last active
December 23, 2015 15:09
-
-
Save AArnott/6653447 to your computer and use it in GitHub Desktop.
Allows calling Flickr.NET (http://flickrnet.codeplex.com/) async APIs using the C# 5 await syntax.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Task<T> DoAsync<T>(Action<Action<FlickrNet.FlickrResult<T>>> begin) { | |
var tcs = new TaskCompletionSource<T>(); | |
begin(result => { | |
if (result.HasError) { | |
tcs.SetException(result.Error); | |
} else { | |
tcs.SetResult(result.Result); | |
} | |
}); | |
return tcs.Task; | |
} | |
private async void ConnectFlickrButton_Click(object sender, RoutedEventArgs e) { | |
var requestToken = await DoAsync<FlickrNet.OAuthRequestToken>( | |
cb => flickr.OAuthGetRequestTokenAsync("oob", cb)); | |
string url = flickr.OAuthCalculateAuthorizationUrl(requestToken.Token, FlickrNet.AuthLevel.Write); | |
Process.Start(url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment