public AccountSettingsPage() { InitializeComponent(); // Load user stuff from isolated storage if (this.storage.Contains("userCredentials")) { this.userCredentials = storage["userCredentials"] as TumblrCredentials; } else { this.userCredentials = new TumblrCredentials(); } // Update username and password stuff this.usernameTextBox.Text = this.userCredentials.Username; this.passwordTextBox.Password = this.userCredentials.Password; // If OAuth tokens are present, display the OAuth screen if (this.userCredentials.Type == TumblrCredentials.CredentialsType.OAuth) { // HACK: This is dumb but I don't want to use automation to perform a button click. Consider refactoring. this.OAuthOption_Click(null, null); this.oAuthClearButton.Visibility = System.Windows.Visibility.Visible; } }
public AccountSettingsPage() { InitializeComponent(); // Load user stuff from isolated storage if (this.storage.Contains("userCredentials")) { this.userCredentials = storage["userCredentials"] as TumblrCredentials; } else { this.userCredentials = new TumblrCredentials(); } // Update username and password stuff this.usernameTextBox.Text = this.userCredentials.Username; this.passwordTextBox.Password = this.userCredentials.Password; // If OAuth tokens are present, display the OAuth screen if (this.userCredentials.Type == TumblrCredentials.CredentialsType.OAuth) { // HACK: This is dumb but I don't want to use automation to perform a button click. Consider refactoring. this.OAuthOption_Click(null, null); this.oAuthClearButton.Visibility = System.Windows.Visibility.Visible; } }
/** * 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.")); } } }