Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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");
        }