/** * Actually post the image... finally. **/ private void Post_Click(object sender, EventArgs e) { // Check if we have credentials IsolatedStorageSettings storage = IsolatedStorageSettings.ApplicationSettings; // If we have no credentials, force the user to enter their info in account settings. if (!storage.Contains("userCredentials")) { NavigationService.Navigate(new Uri("/AccountSettingsPage.xaml", UriKind.Relative)); } else { // Get the credentials TumblrCredentials userCredentials = storage["userCredentials"] as TumblrCredentials; // We have credentials, do we have a photo? if (photo != null) { // Now here comes the POST! // Create a RestClient RestClient client = new RestClient(); client.Authority = MainPage.TUMBLR_AUTHORITY; client.HasElevatedPermissions = true; client.Path = MainPage.TUMBLR_POST_PATH; client.Method = Hammock.Web.WebMethod.Post; // Set the correct credentials on the client or request depending on auth method if (userCredentials.Type == TumblrCredentials.CredentialsType.OAuth) { OAuthCredentials oAuthCred = new OAuthCredentials(); oAuthCred.ConsumerKey = Common.OAUTH_CONSUMER_KEY; oAuthCred.ConsumerSecret = Common.OAUTH_CONSUMER_SECRET; oAuthCred.Token = userCredentials.OAuthToken; oAuthCred.TokenSecret = userCredentials.OAuthTokenSecret; oAuthCred.ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader; oAuthCred.SignatureMethod = OAuthSignatureMethod.HmacSha1; oAuthCred.Type = OAuthType.ProtectedResource; client.Credentials = oAuthCred; } else { client.AddField("email", userCredentials.Username); client.AddField("password", userCredentials.Password); } // Add metadata fields client.AddField("type", "photo"); //client.AddField("state", "draft"); // Debug line for testing client.AddField("send-to-twitter", "auto"); // Debug line because I'm paranoid // Add caption but check for an empty field if (!this.hasDefaultText) { client.AddField("caption", this.captionTextbox.Text); } client.AddFile("data", "upload.jpg", new MemoryStream(photo)); // Send the request of to la-la-land client.BeginRequest(new RestCallback(PostCompleted)); this.isPosting = true; // HACK: Well this is hacky... Dispatcher.BeginInvoke(() => ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false); Dispatcher.BeginInvoke(() => { this.postProgress.Visibility = System.Windows.Visibility.Visible; this.captionTextbox.IsEnabled = false; this.postProgress.Focus(); }); } else { Dispatcher.BeginInvoke(() => MessageBox.Show("Please Select a Photo.")); } } }