JavaScript appears to be disabled. We recommend you enable JavaScript while visiting this site.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

BlogEngine.NET 1.6 released

Promising a real comment moderation system, BE.NET 1.6 was released a few days ago.

Having just upgraded from 1.5.0.7, I wasn't without my issues, but overall the memory footprint doesn't seem too horrible (it's increased a bit again, but ...)

Actually, the memory footprint isn't a minor issue. I have 805 posts with 688 comments, and get between 9 to 10 thousand visits a month. BlogEngine.NET starts at around 150 MB of RAM and jumps up to 210 MB. It's not horrid, but I remember the days when it was nice and lean.

At one point Mads suggested he was going to switch over to IIS 7; maybe we'll see .NET 3.5 functionality first, which might tighten things up. Otherwise it may just mean I need to do a custom build ... or scrap it altogether for a lean system. I don't want to, but ...

Tags:

Categories: software

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Determine BlogEngine.NET comments that haven't been published - with LINQPad

At the beginning of the month I wrote a post on how to find BlogEngine.NET comments that had not yet been published/approved.

Having purchased a copy of LINQPad a short while ago (autocompletion costs, the program with all other functionality does not; give it a try if you develop in .NET - it's very cool), and having got slammed this morning with some spammer who had an hour to kill, I decided to adapt my code for LINQPad.

string postsDirectory = @"C:\posts";

string[] postFiles = System.IO.Directory.GetFiles(postsDirectory);

DataTable comments = new DataTable();
	comments.Columns.Add("Post");
	comments.Columns.Add("CommentApproved");
	comments.Columns.Add("FileId");
	comments.Columns.Add("IpAddress");

XDocument postXml;

foreach (string postFile in postFiles) {
	postXml = XDocument.Load(postFile);

	var posts = from postData in postXml.Descendants("post")
		select new {
			Title = postData.Element("title").Value,
			CommentItems = (from commentItems in postData.Element("comments").Elements("comment")
				select commentItems).ToList()
		};

	foreach (var post in posts) {
		if (post.CommentItems.Count > 0) {
			foreach (var commentItem in post.CommentItems) {
				if (commentItem.Attribute("approved") != null && commentItem.Attribute("approved").Value == "False") {
					DataRow comment = comments.NewRow();
					comment["Post"] = post.Title;
					comment["CommentApproved"] = commentItem.Attribute("approved").Value;
					comment["IpAddress"] = commentItem.Element("ip").Value;
					comment["FileId"] = "/post.aspx?id=" + System.IO.Path.GetFileNameWithoutExtension(postFile);
					comments.Rows.Add(comment);
				}
			}

		}
	}
}

postXml = null;

comments.Dump();

You'll want to change postsDirectory accordingly.

This will output all unapproved comments, the post they are associated with, the post GUID, and the commentor's IP address.

It's relatively easy to expand this to display more or less information, as desired. For example, website and author can be swapped in in place of ip in the last foreach.

Comments/questions/etcetera welcome and appreciated.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Determine BlogEngine.NET comments that haven't been published

Unfortunately, BlogEngine.NET doesn't currently have a very good way to determine, at a glance, all of the comments that haven't been approved. While this will certainly be coming in a future release, or as an extension, I figured writing something simple to do this would be a good LINQ to XML test for me.

You can download the built executable, or play with the code, which is included below.

Download the executable (7-Zip format). Requires .NET Framework 3.5.

The form I created consisted of a TextBox, Button, and a DataGridView, with the default names.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace TestBlogEngine {
	public partial class Form1 : Form {
		public Form1() {
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e) {
			OpenFileDialog sampleFile = new OpenFileDialog();
			sampleFile.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";

			if (sampleFile.ShowDialog() == DialogResult.OK) {
				textBox1.Text = sampleFile.FileName;

				string postsDirectory = System.IO.Path.GetDirectoryName(sampleFile.FileName);
				sampleFile.Dispose();

				string[] postFiles = System.IO.Directory.GetFiles(postsDirectory);

				DataTable comments = new DataTable();
				comments.Columns.Add("Post");
				comments.Columns.Add("CommentApproved");
				comments.Columns.Add("FileId");

				XDocument postXml;

				foreach (string postFile in postFiles) {
					postXml = XDocument.Load(postFile);

					var posts = from postData in postXml.Descendants("post")
						select new {
							Title = postData.Element("title").Value,
							CommentItems = (from commentItems in postData.Element("comments").Elements("comment")
								select commentItems).ToList()
						};

					foreach (var post in posts) {
						if (post.CommentItems.Count > 0) {
							foreach (var commentItem in post.CommentItems) {
								if (commentItem.Attribute("approved") != null && commentItem.Attribute("approved").Value == "False") {
									DataRow comment = comments.NewRow();
									comment["Post"] = post.Title;
									comment["CommentApproved"] = commentItem.Attribute("approved").Value;
									comment["FileId"] = "/post.aspx?id=" + System.IO.Path.GetFileNameWithoutExtension(postFile);
									comments.Rows.Add(comment);
								}
							}

						}
					}
				}

				postXml = null;

				dataGridView1.DataSource = comments;

			}
		}
	}
}

EDIT: Scott Guthrie's excellent Using LINQ to XML (and how to build a custom RSS Feed Reader with it) is the article that I keep going back to when I forget LINQ to XML basics.