public void Publish(WpsConsoleCommandLineOptions options) { try { var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(options.BlogConfigPath); var postDal = new PostDal(new Dal(MySqlConnectionString)); PostOrder postOrder = PostOrder.NewestFirst; switch (options.Strategy) { case "newest": postOrder = PostOrder.NewestFirst; break; case "oldest": postOrder = PostOrder.OldestFirst; break; case "random": postOrder = PostOrder.Random; break; default: break; } IList<Post> posts = new List<Post>();// postDal.GetPosts(postOrder, options.NumberToPublish); if (options.Strategy == "selected") { posts = postDal.GetPosts(options.PostIdsInt); } else { posts = postDal.GetPosts(postOrder, options.NumberToPublish); } if (posts == null) { Console.WriteLine("No posts found to publish!"); return; } foreach (var post in posts) { try { Console.WriteLine(string.Format("Publishing '{0}'", post.Title)); postDal.PublishPost(post); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } } } catch (Exception exception) { Console.WriteLine(exception.ToString()); } Console.WriteLine("Publishing done."); }
private HashSet<string> GetPostIds() { var result = new HashSet<string>(); var postDal = new PostDal(_dal); var allMeta = postDal.GetAllPostMeta(); if (allMeta.Tables.Count == 0) return result; if (allMeta.Tables[0].Rows.Count == 0) return result; foreach (DataRow row in allMeta.Tables[0].Rows) { var foreignKeys = row["meta_value"].ToString(); var keys=foreignKeys.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries); foreach (var key in keys) { result.Add(key); } } return result; }
private HashSet<string> GetPostTitles() { var result = new HashSet<string>(); var postDal = new PostDal(_dal); var allTitles = postDal.GetAllTitles(); if (allTitles.Tables.Count == 0) return result; if (allTitles.Tables[0].Rows.Count == 0) return result; foreach (DataRow row in allTitles.Tables[0].Rows) { result.Add(row["post_title"].ToString()); } return result; }
private void fixFeatureImageErrorToolStripMenuItem_Click(object sender, EventArgs e) { if (!_blogSelected) { MessageBox.Show("First connect to blog from File>Connect!"); return; } var thumbnailMetaData = new Dictionary<int, string>(); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); using (var dal = new Dal(MySqlConnectionString)) { var postDal = new PostDal(dal); var allYoastMeta = postDal.GetAllPostMeta("_yoast_wpseo_focuskw_text_input"); if (allYoastMeta.Tables.Count == 0) return; if (allYoastMeta.Tables[0].Rows.Count == 0) return; var thumbnailMeta = postDal.GetAllPostMeta("_thumbnail_id"); if (thumbnailMeta.Tables.Count > 0) { if (thumbnailMeta.Tables[0].Rows.Count > 0) { foreach (DataRow row in thumbnailMeta.Tables[0].Rows) { var postId = Int32.Parse(row["post_id"].ToString()); var meta_value = row["meta_value"].ToString(); if (!thumbnailMetaData.ContainsKey(postId)) { thumbnailMetaData.Add(postId, meta_value); } } } } barStatus.Maximum = allYoastMeta.Tables[0].Rows.Count; barStatus.Visible = true; foreach (DataRow row in allYoastMeta.Tables[0].Rows) { barStatus.PerformStep(); var postId = Int32.Parse(row["post_id"].ToString()); var meta_value = row["meta_value"].ToString(); if (thumbnailMetaData.ContainsKey(postId) && !string.IsNullOrEmpty(thumbnailMetaData[postId])) { continue; } Application.DoEvents(); SetStatus(string.Format("Fixing {0} ", postId)); postDal.SetPostMetaData(postId, "_thumbnail_id", meta_value); } barStatus.Visible = false; } MessageBox.Show("Finished"); }
private void CreateVideos(IList<Post> posts) { _videosCreated = new Dictionary<string, List<Post>>(); var postDal = new PostDal(new Dal(MySqlConnectionString)); Application.DoEvents(); AddStatus("Creating temp directories..."); Application.DoEvents(); if (Directory.Exists(TempFolder)) { Directory.Delete(TempFolder, true); } if (Directory.Exists(OutputFolder)) { Directory.Delete(OutputFolder, true); } Directory.CreateDirectory(TempFolder); Directory.CreateDirectory(OutputFolder); Application.DoEvents(); AddStatus("Getting post images..."); Application.DoEvents(); var videoPerPost = (int)numVideoPerPost.Value; var imagePerPost = (int)numImagePerPost.Value; var pageCount = (int)Math.Ceiling((double)posts.Count / videoPerPost); for (int pageNo = 0; pageNo < pageCount; pageNo++) { if (Directory.Exists(InputFolder)) { Directory.Delete(InputFolder, true); } Directory.CreateDirectory(InputFolder); var postsToTake = posts.Skip(pageNo * videoPerPost).Take(videoPerPost); if (postsToTake.Count() == 0) break; var images = postDal.GetImagePostsForPosts(postsToTake.Select(p => Int32.Parse(p.Id)).ToList()); var imagesToTake = new List<Post>(); foreach (var imageGroup in images.GroupBy(i => i.ParentId)) { imagesToTake.AddRange(imageGroup.Take(imagePerPost)); } var counter = 1; foreach (var image in imagesToTake) { var url = image.Url; if (string.IsNullOrEmpty(url)) { continue; } Application.DoEvents(); AddStatus("Downloading " + url); Application.DoEvents(); var extension = Path.GetExtension(url); using (WebClient webClient = new WebClient()) { webClient.DownloadFile(url, Helper.AssemblyDirectory + "/" + InputFolder + "\\img" + counter + "." + extension); } counter++; } var videoFileName = OutputFolder + "/outputwaudio" + pageNo + ".mp4"; CreateVideo(videoFileName); _videosCreated.Add(Helper.AssemblyDirectory + "/" + videoFileName, postsToTake.ToList()); } Directory.Delete(InputFolder, true); Directory.Delete(TempFolder, true); }
private void btnPublish_Click(object sender, EventArgs e) { EnDis(false); txtStatus.Text = ""; var postDal = new PostDal(new Dal(MySqlConnectionString)); var posts = _posts; if (_posts == null) { posts = postDal.GetPosts((PostOrder)cbCriteria.SelectedIndex, (int)numNumberOfPosts.Value); } else { posts = postDal.GetPosts(_posts.Select(p => int.Parse(p.Id)).ToList()); } if (posts == null) { MessageBox.Show("No posts found to publish!"); EnDis(); return; } foreach (var post in posts) { AddStatus(string.Format("Publishing '{0}'", post.Title)); Application.DoEvents(); postDal.PublishPost(post); } if (chkCreateSlide.Checked) { CreateVideos(posts); if (chkYoutube.Checked) { UploadToYoutube(); } } AddStatus("Done"); EnDis(); }
private void FtpDirectoryDeletionFinished(object sender, EventArgs e) { if(btnCleanup.Enabled)//file deletion canceled, don't continue to mysql part before cleaning up files { return; } try { EnDis(false); using (var dal = new Dal(MySqlConnectionString)) { var postDal = new PostDal(dal); postDal.DeleteAll(); } } catch (Exception exception) { EnDis(true); MessageBox.Show(exception.ToString()); Logger.LogExceptions(exception); return; } EnDis(true); MessageBox.Show("Finished!"); }