public ProgramOptions Get(string configPath) { var html = new HtmlAgilityPack.HtmlDocument(); html.Load(configPath); var options = new ProgramOptions(); options.BlogUrl = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/blogurl", "", true); options.BlogUser = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/bloguser", "", true); options.BlogPassword = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/blogpassword", "", true); options.DatabaseUrl = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/databaseurl", "", true); options.DatabaseName = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/databasename", "", true); options.DatabaseUser = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/databaseuser", "", true); options.DatabasePassword = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/databasepassword", "", true); options.FtpUrl = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/ftpurl", "", true); options.FtpUser = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/ftpuser", "", true); options.FtpPassword = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/ftppassword", "", true); options.ProxyAddress = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/proxyaddress", "", true); options.ProxyPort = XmlParse.GetIntegerNodeValue(html.DocumentNode, "/programoptions/proxyport", 0); options.UseProxy = XmlParse.GetBooleanNodeValue(html.DocumentNode, "/programoptions/useproxy", false); options.YoutubeClient = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/youtubeclient", "", true); options.YoutubeClientSecret = XmlParse.GetStringNodeValue(html.DocumentNode, "/programoptions/youtubeclientsecret", "", true); return options; }
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."); }
public static ProgramOptions ProgramOptionsForBlog(string blog) { var fileName = BlogsSettings.ProgramSettingsFolder + "/" + blog + ".xml"; var programOptionsFactory= new ProgramOptionsFactory(); var programOptions = new ProgramOptions(); if (File.Exists(fileName)) { programOptions = programOptionsFactory.Get(fileName); } return programOptions; }
public ProgramOptions Get() { var options = new ProgramOptions() { MakeFirstImageAsFeature = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["MakeFirstImageAsFeature"]), MergeBlockSize = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["MergeBlockSize"]), ThumbnailSize = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["ThumbnailSize"]), ResizeImages = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ResizeImages"]), ResizeSize = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["ResizeSize"]), UseFtp = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["UseFtp"]), UseCache = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["UseCache"]), ShowMessageBoxes = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowMessageBoxes"]), BlogUrl = System.Configuration.ConfigurationManager.AppSettings["BlogUrl"], BlogUser = System.Configuration.ConfigurationManager.AppSettings["BlogUser"], BlogPassword = System.Configuration.ConfigurationManager.AppSettings["BlogPassword"], DatabaseUrl = System.Configuration.ConfigurationManager.AppSettings["DatabaseUrl"], DatabaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"], DatabaseUser = System.Configuration.ConfigurationManager.AppSettings["DatabaseUser"], DatabasePassword = System.Configuration.ConfigurationManager.AppSettings["DatabasePassword"], FtpUrl = System.Configuration.ConfigurationManager.AppSettings["FtpUrl"], FtpUser = System.Configuration.ConfigurationManager.AppSettings["FtpUser"], FtpPassword = System.Configuration.ConfigurationManager.AppSettings["FtpPassword"], ScrambleLeadPosts = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ScrambleLeadPosts"]), TagsAsText = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["TagsAsText"]), TitleContainsKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["TitleContainsKeywordScore"]), TitleStartsWithKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["TitleStartsWithKeywordScore"]), ContentContainsKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["ContentContainsKeywordScore"]), ContentFirst100ContainsKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["ContentFirst100ContainsKeywordScore"]), KeywordRatioScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["KeywordRatioScore"]), NonExactTitleContainsKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["NonExactTitleContainsKeywordScore"]), NonExactContentContainsKeywordScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["NonExactContentContainsKeywordScore"]), NonExactKeywordRatioScore = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["NonExactKeywordRatioScore"]), ProxyPort = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["ProxyPort"]), ProxyAddress = System.Configuration.ConfigurationManager.AppSettings["ProxyAddress"], UseProxy = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["UseProxy"]), UseRemoteDownloading = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["UseRemoteDownloading"]), YoutubeClient = System.Configuration.ConfigurationManager.AppSettings["YoutubeClient"], YoutubeClientSecret = System.Configuration.ConfigurationManager.AppSettings["YoutubeClientSecret"], SkipSearchingPosted = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["SkipSearchingPosted"]), PriceSign = System.Configuration.ConfigurationManager.AppSettings["PriceSign"] }; return options; }
private void btnCleanup_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show("Are you sure to want to delete ALL POSTS and UPLOADS, including IMAGES from the blog?", "Confirm Delete!!", MessageBoxButtons.YesNo); if (confirmResult != DialogResult.Yes) return; var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); if (string.IsNullOrEmpty(_options.FtpUrl)) { MessageBox.Show("In order to delete images, please set up FTP account from settings."); return; } _ftp = new Ftp.Ftp(FtpConfiguration); if (!string.IsNullOrEmpty(_ftp.TestConnection())) { MessageBox.Show("Cannot connect to FTP, please check your settings."); return; } try { _ftp.DirectoryListingProgressing += FtpDirectoryListingProgressing; _ftp.DirectoryListingFetchFinished += FtpDirectoryListingFetchFinished; _ftp.DirectoryDeletionProgressing += FtpDirectoryDeletionProgress; _ftp.DirectoryDeletionFinished += FtpDirectoryDeletionFinished; EnDis(false); _ftp.DeleteDirectory("wp-content/uploads/"); } catch (Exception exception) { EnDis(true); MessageBox.Show(exception.ToString()); Logger.LogExceptions(exception); } }
public RelevanceCalculator() { var programOptionsFactory = new ProgramOptionsFactory(); _programOptions = programOptionsFactory.Get(); }
private void btnGo_Click(object sender, EventArgs e) { if (!_blogSelected) { MessageBox.Show("First connect to blog from File>Connect!"); return; } if (lvItems.SelectedItems.Count == 0) { MessageBox.Show("Select items to transfer!"); return; } var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); _stopWatch = new Stopwatch(); _stopWatch.Start(); EnDisItems(false); lblDateTime.Text = "Started at " + DateTime.Now.ToLongTimeString(); using (var dal = new Dal(MySqlConnectionString)) { _blogCache = new BlogCache(dal); if (_options.UseCache) { SetStatus("Loading present posts and tags in the blog(this may take some time)..."); Application.DoEvents(); _blogCache.Start(_options.BlogUrl); Application.DoEvents(); } SetStatus("Ready"); ResetBarStatus(true); barStatus.Maximum = lvItems.SelectedItems.Count; _postFactory = new PostFactory( SiteConfig, new Ftp(FtpConfiguration), _blogCache, dal, _options); var items = ItemsFromListView(lvItems.SelectedItems); _postFactory.PostCreated += PostCreated; _postFactory.PostBeingCreated += PostBeingCreated; _postFactory.PostsCreated += PostsCreated; _postFactory.PostCreationStopped += PostCreationStopped; _postFactory.Create(items); } }
private void frmAuthors_Load(object sender, EventArgs e) { var optionsFactory = new ProgramOptionsFactory(); _options = optionsFactory.Get(); }
private void FillValues(ProgramOptions options) { txtBlogUrl.Text = options.BlogUrl; txtUserName.Text = options.BlogUser; txtPassword.Text = options.BlogPassword; txtMysqlUser.Text = options.DatabaseUser; txtMySqlIp.Text = options.DatabaseUrl; txtMySqlDatabase.Text = options.DatabaseName; txtMySqlPass.Text = options.DatabasePassword; txtFtpUrl.Text = options.FtpUrl; txtFtpUserName.Text = options.FtpUser; txtFtpPassword.Text = options.FtpPassword; txtProxyIp.Text = options.ProxyAddress; FixEmptyNumericUpDown(numProxyPort); numProxyPort.Value = options.ProxyPort; chkUseProxy.Checked = options.UseProxy; txtYoutubeClientId.Text = options.YoutubeClient; txtYoutubeClientSecret.Text = options.YoutubeClientSecret; }
private void GettingSourceItemsFinished(object sender, EventArgs e) { ResetBarStatus(); EnDis(true); btnGo.Enabled = lvItems.Items.Count > 0; Cursor.Current = Cursors.Default; SetStatus("Getting source items finished"); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); if (_options.ShowMessageBoxes) { MessageBox.Show("Getting source items finished"); } _stopWatch.Stop(); var timeTook = _stopWatch.Elapsed.TotalMinutes.ToString("0.00"); lblDateTime.Text = string.Format("Took {0} mins", timeTook); _sourceItemFactory.NoSourceFound -= NoSourceFound; _sourceItemFactory.GettingSourceItemsStopped -= GettingSourceItemsStopped; _sourceItemFactory.ProcessFinished -= GettingSourceItemsFinished; _sourceItemFactory.SourceItemGot -= SourceItemGot; _sourceItemFactory.TotalResultsFound -= TotalResultsFound; _sourceItemFactory.SourceItemsGot -= SourceItemsGot; _sourceItemFactory = null; }
private void NoSourceFound(object sender, string e) { SetStatus(e); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); if (_options.ShowMessageBoxes) { MessageBox.Show(e); } }
private void btnStart_Click(object sender, EventArgs e) { if (txtUrl.Text == "") { MessageBox.Show("Enter Keyword!"); return; } var sitesCount = chkSites.CheckedItems.Count; if (sitesCount == 0) { MessageBox.Show("Select sites!"); return; } EnDis(false); numPage_ValueChanged(null, null); Cursor.Current = Cursors.WaitCursor; ResetBarStatus(true); btnGo.Enabled = false; lblTotalResults.Text = ""; var pageStart = (int)numPage.Value; var pageEnd = chkAllPages.Checked ? (int)numPageTo.Maximum : (int)numPageTo.Value; ///barStatus.Maximum = pageEnd - pageStart; barStatus.Maximum = 0; lblDateTime.Text = ""; _stopWatch = new Stopwatch(); _stopWatch.Start(); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); HashSet<string> existingIds = null; if (_options.SkipSearchingPosted) { using (var dal = new Dal(MySqlConnectionString)) { _blogCache = new BlogCache(dal); if (_options.UseCache) { SetStatus("Loading present posts and tags in the blog(this may take some time)..."); Application.DoEvents(); existingIds = _blogCache.IdsPresent(_options.BlogUrl); Application.DoEvents(); } } } _sourceItemFactory = new SourceItemFactory(); _sourceItemFactory.NoSourceFound += NoSourceFound; _sourceItemFactory.GettingSourceItemsStopped += GettingSourceItemsStopped; _sourceItemFactory.ProcessFinished += GettingSourceItemsFinished; _sourceItemFactory.SourceItemGot += SourceItemGot; _sourceItemFactory.TotalResultsFound += TotalResultsFound; _sourceItemFactory.SourceItemsGot += SourceItemsGot; _sourceItemFactory.ExceptionOccured += ExceptionOccuredWhileGettingItems; var checkedSites = (from object checkedItem in chkSites.CheckedItems select checkedItem.ToString()).ToList(); _sourceItemFactory.GetSourceItems(checkedSites, txtUrl.Text, pageStart, pageEnd, lvItems.Items.Count + 1, existingIds); }
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 frmPublish_Load(object sender, EventArgs e) { cbCriteria.Items.Clear(); cbCriteria.Items.AddRange(new object[] { "Newest", "Oldest", "Random" }); cbCriteria.SelectedIndex = 0; txtStatus.Text = ""; if (_posts != null) { cbCriteria.Items.Add("Selected Items"); cbCriteria.Enabled = false; cbCriteria.SelectedIndex = 3; numNumberOfPosts.Enabled = false; numNumberOfPosts.Value = _posts.Count; } var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); #if DEBUG btnGetGoogleToken.Visible = true; txtRefreshToken.Visible = true; #endif txtYoutubeDescription.Text = string.Format("See more on {0}\nMusic by http://www.bensound.com/ royalty free license", _options.BlogUrl); }
private void PrepareTemplates() { var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); if (string.IsNullOrEmpty(_options.FtpUrl)) { MessageBox.Show("In order to update wp files, please set up FTP account from settings."); return; } var ftp = new Ftp(FtpConfiguration); if (!string.IsNullOrEmpty(ftp.TestConnection())) { MessageBox.Show("Cannot connect to FTP, please check your settings."); return; } var frmPrepareTemplate = new frmPrepareTemplate(); frmPrepareTemplate.ShowDialog(); }
private void SetPluginData() { var checkedSites = (from object checkedItem in lstPlugins.CheckedItems select checkedItem.ToString()).ToList(); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); using (var dal = new Dal(MySqlConnectionString)) { var optionsDal = new OptionsDal(dal); var currentActivePluginsValue = optionsDal.GetValue("active_plugins"); var currentActivePlugins = new HashSet<string>(PhpSerializer.Deserialize(currentActivePluginsValue)); var pluginsToPut = new HashSet<string>(); var pluginPaths = GetPluginFiles(); var pluginNames = GetPluginNames(); for (int i = 0; i < pluginNames.Count; i++) { if (checkedSites.Contains(pluginNames[i])) { pluginsToPut.Add(pluginPaths[i]); } } currentActivePlugins.UnionWith(pluginsToPut); var newActivePluginData = PhpSerializer.Serialize(currentActivePlugins.ToList()); optionsDal.SetValue("active_plugins", newActivePluginData); var optionFiles = Directory.EnumerateFiles("blog", "*.bosf", SearchOption.AllDirectories); foreach (var optionFile in optionFiles) { var optionFileInfo = new FileInfo(optionFile); if (optionFileInfo.Directory.Name == "plugins") { var fileName = Path.GetFileNameWithoutExtension(optionFile); if (!checkedSites.Contains(fileName)) { continue; } } var contentLines = File.ReadAllLines(optionFileInfo.FullName); foreach (var content in contentLines) { var splitted = content.Split('\t'); if (splitted.Length > 0) { optionsDal.SetValue(splitted[0], splitted[1]); } else { optionsDal.SetValue(content, ""); } } } } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { var checkedSites = (from object checkedItem in lstPlugins.CheckedItems select checkedItem.ToString()).ToList(); var directoriesCreated = new HashSet<string>(); var programOptionsFactory = new ProgramOptionsFactory(); _options = programOptionsFactory.Get(); DeleteLocallyExtractedPlugins(); if (!chkRemoteUnzip.Checked) { UnzipPluginsLocally(checkedSites); } var ftp = new Ftp.Ftp(FtpConfiguration); var fileUploaded = 0; foreach (var file in _files) { fileUploaded++; if ((bw.CancellationPending)) { e.Cancel = true; break; } var fileInfo = new FileInfo(file); var dir = fileInfo.Directory; if (dir == null) { continue; } var ftpDir = dir.FullName.Replace(Helper.AssemblyDirectory + "\\blog", "").Replace("\\", "/"); if (ftpDir.StartsWith("/")) { ftpDir = ftpDir.Substring(1); } try { if (!directoriesCreated.Contains(ftpDir)) { ftp.MakeFtpDir(ftpDir); bw.ReportProgress(fileUploaded, "Creating Ftp Directory " + ftpDir); directoriesCreated.Add(ftpDir); } } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } try { var uploadFile = true; //upload ewww folder only if ewww-image-optimizer selected if (!checkedSites.Contains("ewww-image-optimizer") && fileInfo.Directory.Name == "ewww") { continue; } var fileName = Path.GetFileNameWithoutExtension(file); if (IsPluginFile(fileInfo)) { if (chkRemoteUnzip.Checked) //if remotely unzipping, then upload only zip files for checked plugins { if (!checkedSites.Contains(fileName) || Path.GetExtension(file) != ".zip") { uploadFile = false; } } else//if locally unzipping, then upload only extracted files for checked plugins { if (fileInfo.Directory.Name == "plugins") { uploadFile = false; } } } else { uploadFile = chkUploadAllExceptPlugin.Checked; } if (!uploadFile) continue; ftp.UploadFileFtp(file, ftpDir); bw.ReportProgress(fileUploaded, "Uploading " + file); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } if (chkRemoteUnzip.Checked) { try { UnzipPluginsRemotely(fileUploaded); } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } } try { SetPluginData(); } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } }
private ProgramOptions GetOptionsFromControls() { var options = new ProgramOptions() { BlogUrl = txtBlogUrl.Text, BlogUser = txtUserName.Text, BlogPassword = txtPassword.Text, DatabaseUrl = txtMySqlIp.Text, DatabaseName = txtMySqlDatabase.Text, DatabaseUser = txtMysqlUser.Text, DatabasePassword = txtMySqlPass.Text, FtpUrl = txtFtpUrl.Text, FtpUser = txtFtpUserName.Text, FtpPassword = txtFtpPassword.Text, ProxyAddress = txtProxyIp.Text, ProxyPort = (int)numProxyPort.Value, UseProxy = chkUseProxy.Checked, YoutubeClient = txtYoutubeClientId.Text, YoutubeClientSecret = txtYoutubeClientSecret.Text }; return options; }