private void btnVerify_Click(object sender, EventArgs e) { WordPressConnector.InitializeWordPress(txtUsername.Text, txtPassword.Text); lblStatus.Text = "Verifying..."; SetLoginControlsEnabledState(false); GetProfileResponse user = WordPressConnector.GetUserProfile(); if (user != null) { MessageBox.Show("Thanks " + user.FirstName + "!" + "\nYou're ready to upload."); btnUpload.Enabled = true; } else { MessageBox.Show("Connection failed", "Can't connect to RW Wordpress!"); SetLoginControlsEnabledState(true); lblStatus.Text = "Can't connect to RW WordPress, please try again."; return; } if (chkSaveCredentials.Checked) { // Save credentials Settings.Default.CredentialsSaved = true; Settings.Default.Username = txtUsername.Text; Settings.Default.Password = txtPassword.Text; Settings.Default.Save(); } }
private static GetProfileResponse AskForCredentials(GetProfileResponse user) { Console.WriteLine("Username:"******"Pasword:"); string password = Console.ReadLine(); WordPressConnector.InitializeWordPress(username, password); user = WordPressConnector.GetUserProfile(); if (user == null) { ColoredConsole.WriteLineWithColor("Incorrect credentials / can't connect to RW WordPress.", ConsoleColor.Red); Console.WriteLine("Please try again."); } return(user); }
private bool UploadImages(string markdownPath, string htmlPath, bool onlyUpdateHtml, string username, string password) { Console.WriteLine("Logging into RW WordPress.."); WordPressConnector.InitializeWordPress(username, password); GetProfileResponse user = WordPressConnector.GetUserProfile(); if (user == null) { ColoredConsole.WriteLineWithColor("Login failed. Please check your credentials and internet connection.", ConsoleColor.Red); } Console.WriteLine(""); Console.WriteLine("Login succesful! Thanks for using the app, " + user.FirstName + "!"); Console.WriteLine("Gathering files..."); // Get image paths List <string> fullImagePaths = new List <string>(); List <string> localImagePaths = new List <string>(); string markdownText = ""; string htmlText = ""; using (StreamReader sr = new StreamReader(markdownPath)) { markdownText = sr.ReadToEnd(); } using (StreamReader sr = new StreamReader(htmlPath)) { htmlText = sr.ReadToEnd(); } var links = Converter.FindAllImageLinksInHtml(htmlText, Path.GetDirectoryName(htmlPath)); if (links.Count == 0) { Console.WriteLine("No images found. Aborting upload"); return(false); } foreach (ImageLinkData link in links) { fullImagePaths.Add(link.FullImagePath); localImagePaths.Add(link.LocalImagePath); } Console.WriteLine(""); Console.WriteLine(fullImagePaths.Count + " image paths found:"); foreach (string path in fullImagePaths) { Console.WriteLine(path + " (" + new FileInfo(path).Length / 1024 + " kb)"); } List <string> imageUrls = new List <string>(); List <string> imageIDs = new List <string>(); // Upload images for (var i = 0; i < fullImagePaths.Count; i++) { string path = fullImagePaths[i]; Console.WriteLine("Uploading: " + " (" + (i + 1) + "/" + fullImagePaths.Count + ")" + path + "..."); var result = WordPressConnector.UploadFile(path); if (result != null) { imageUrls.Add(result.FileResponseStruct.Url); imageIDs.Add(result.FileResponseStruct.Id.ToString()); } else { Console.WriteLine("Image upload failed! Aborting upload and going into file cleanup mode..."); CoreConsoleShared.StartFileDeletion(imageIDs); return(false); } } // Update markdown & html Console.WriteLine("Starting link replacer..."); Converter.ReplaceLocalImageLinksWithUrls(markdownPath, markdownText, htmlPath, htmlText, onlyUpdateHtml, localImagePaths, imageUrls); return(true); }