diff options
Diffstat (limited to 'samples/OAuthConsumer/Twitter.aspx.cs')
-rw-r--r-- | samples/OAuthConsumer/Twitter.aspx.cs | 98 |
1 files changed, 55 insertions, 43 deletions
diff --git a/samples/OAuthConsumer/Twitter.aspx.cs b/samples/OAuthConsumer/Twitter.aspx.cs index 6b298cc..42ffa6e 100644 --- a/samples/OAuthConsumer/Twitter.aspx.cs +++ b/samples/OAuthConsumer/Twitter.aspx.cs @@ -20,58 +20,70 @@ set { Session["TwitterAccessToken"] = value; } } - protected async void Page_Load(object sender, EventArgs e) { - var twitter = new TwitterConsumer(); - if (twitter.ConsumerKey != null) { - this.MultiView1.ActiveViewIndex = 1; + protected void Page_Load(object sender, EventArgs e) { + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + var twitter = new TwitterConsumer(); + if (twitter.ConsumerKey != null) { + this.MultiView1.ActiveViewIndex = 1; - if (!IsPostBack) { - // Is Twitter calling back with authorization? - var accessTokenResponse = await twitter.ProcessUserAuthorizationAsync(this.Request.Url); - if (accessTokenResponse != null) { - this.AccessToken = accessTokenResponse.AccessToken; - } else { - // If we don't yet have access, immediately request it. - Uri redirectUri = await twitter.RequestUserAuthorizationAsync(MessagingUtilities.GetPublicFacingUrl()); - this.Response.Redirect(redirectUri.AbsoluteUri); - } - } - } + if (!IsPostBack) { + // Is Twitter calling back with authorization? + var accessTokenResponse = await twitter.ProcessUserAuthorizationAsync(this.Request.Url); + if (accessTokenResponse != null) { + this.AccessToken = accessTokenResponse.AccessToken; + } else { + // If we don't yet have access, immediately request it. + Uri redirectUri = await twitter.RequestUserAuthorizationAsync(MessagingUtilities.GetPublicFacingUrl()); + this.Response.Redirect(redirectUri.AbsoluteUri); + } + } + } + })); } - protected async void downloadUpdates_Click(object sender, EventArgs e) { - var twitter = new TwitterConsumer(); - var statusesJson = await twitter.GetUpdatesAsync(this.AccessToken); + protected void downloadUpdates_Click(object sender, EventArgs e) { + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + var twitter = new TwitterConsumer(); + var statusesJson = await twitter.GetUpdatesAsync(this.AccessToken); - StringBuilder tableBuilder = new StringBuilder(); - tableBuilder.Append("<table><tr><td>Name</td><td>Update</td></tr>"); + StringBuilder tableBuilder = new StringBuilder(); + tableBuilder.Append("<table><tr><td>Name</td><td>Update</td></tr>"); - foreach (dynamic update in statusesJson) { - if (!update.user.@protected.Value) { - tableBuilder.AppendFormat( - "<tr><td>{0}</td><td>{1}</td></tr>", - HttpUtility.HtmlEncode(update.user.screen_name), - HttpUtility.HtmlEncode(update.text)); - } - } + foreach (dynamic update in statusesJson) { + if (!update.user.@protected.Value) { + tableBuilder.AppendFormat( + "<tr><td>{0}</td><td>{1}</td></tr>", + HttpUtility.HtmlEncode(update.user.screen_name), + HttpUtility.HtmlEncode(update.text)); + } + } - tableBuilder.Append("</table>"); - this.resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); + tableBuilder.Append("</table>"); + this.resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); + })); } - protected async void uploadProfilePhotoButton_Click(object sender, EventArgs e) { - if (this.profilePhoto.PostedFile.ContentType == null) { - this.photoUploadedLabel.Visible = true; - this.photoUploadedLabel.Text = "Select a file first."; - return; - } + protected void uploadProfilePhotoButton_Click(object sender, EventArgs e) { + this.RegisterAsyncTask( + new PageAsyncTask( + async ct => { + if (this.profilePhoto.PostedFile.ContentType == null) { + this.photoUploadedLabel.Visible = true; + this.photoUploadedLabel.Text = "Select a file first."; + return; + } - var twitter = new TwitterConsumer(); - XDocument imageResult = await twitter.UpdateProfileImageAsync( - this.AccessToken, - this.profilePhoto.PostedFile.InputStream, - this.profilePhoto.PostedFile.ContentType); - this.photoUploadedLabel.Visible = true; + var twitter = new TwitterConsumer(); + XDocument imageResult = + await + twitter.UpdateProfileImageAsync( + this.AccessToken, this.profilePhoto.PostedFile.InputStream, this.profilePhoto.PostedFile.ContentType); + this.photoUploadedLabel.Visible = true; + })); } } }
\ No newline at end of file |