Raj on August 7th, 2008

Mono is the the open-source version of the Microsoft’s .NET runtime. Mono runs on Linux, Unix, BSD, Solaris, and Windows. Mod_mono and XSP are Mono components that bring ASP.NET functionality to non-Microsoft servers.  For an example of an ASP.NET page running, in Mono, check out Hello World, 2!

Getting Mono up and running in a Plesk system is suprisingly easy. I use CentOS, which is a Fedora-based system. Consequently, these instructions are geared toward CentOS Plesk systems. However, with the exception of steps 1 and 2, these instructions should work for any Linux-based Plesk system.

0) SSH into your server.

1) Add the Mono repository to your yum repositories.

In CentOS, yum stores a list of its repositories in /etc/yum.repos.d, so adding the Mono repository is as easy as downloading the mono.repo file to this directory.

cd /etc/yum.repos.d/
wget http://ftp.novell.com/pub/mono/download-stable/rhel-4-i386/mono.repo

2) Install Mono, XSP, and mod_mono.

yum install mono
yum install xsp
yum install mod_mono

3) Configure Apache to use mod_mono.

Switch to the httpd customized configuration directory. In most Plesk systems, this should be located at /etc/httpd/conf.d.

cd /etc/httpd/conf.d
vi mod_mono.conf

In vi, or your favorite command line editor, paste the following:

<IfModule !mod_mono.c>
LoadModule mono_module modules/mod_mono.so

AddType application/x-asp-net .aspx
AddType application/x-asp-net .asmx
AddType application/x-asp-net .ashx
AddType application/x-asp-net .asax
AddType application/x-asp-net .ascx
AddType application/x-asp-net .soap
AddType application/x-asp-net .rem
AddType application/x-asp-net .axd
AddType application/x-asp-net .cs
AddType application/x-asp-net .config
AddType application/x-asp-net .Config
AddType application/x-asp-net .dll
DirectoryIndex index.aspx
DirectoryIndex Default.aspx
DirectoryIndex default.aspx
</IfModule>

Save the file.

4) Restart Apache

From your Plesk control panel, go to the Server>Services page. Restart the Web Server (Apache). You can also restart Apache from the command line.

/usr/local/psa/admin/sbin/websrvmng -a
/usr/local/psa/admin/sbin/websrvmng –restart

5) Wait a few minutes.

Plesk doesn’t restart immediatly, despite what the Plesk control panel (or the command prompt) may tell you.

6) Create a test ASP.Net page

<%@ Page Language="C#" %>
<html>
<script language="C#" runat="server">
void Page_Load(object sender, EventArgs e)
{
    Response.Write("<br>Hello World! (Response.Write)<br>");
    lbHelloWorld.Text = "Hello World! (HTML element changed.)";
}
</script>
<body>
    <asp:label id="lbHelloWorld" runat="server" />
</body>
</html>

7) That’s it!

    Some caveats:

  • The default configuration for mod_mono uses the Mono binaries compatible with .Net 1.1. These binaries don’t support VB.
  • Mod_mono is slow. It does not yet support pre-compiled binaries.

Tags: , , , , , ,

Raj on July 30th, 2008

I’ve just posted a tutorial on creating a 2D camera for XNA. The XNA2dCamera class provides a clean, simple interface to camera functionality in 2-D games. It handles translation, rotation, and scaling/zoom with ease. Most importantly, the class is graphics-engine agnostic, so it can be used for platformer engines, puzzle game engines, and isometric engines.

The full contents of the XNA2dCamera class are on the last page of the tutorial.

Read the XNA 2D Camera tutorial.

Tags: , , , , , , ,

Raj on July 22nd, 2008

Word’s font selection combobox displays a preview of each font. It’s a great feature which makes it much easier for a user to select a font. Instead of going through each font one-by-one to see what the font looks like, the user can see the results for all installed fonts in one fell swoop.

Accomplishing this feat using C# in .NET 1.0 and 1.1 was no easy feat. The length of many older code samples easily reached into the hundreds of lines. .NET 2.0 introduced new controls and features that made the job much easier.

The C# .NET 2.0 solution only requires one class and less than 40 lines of code. All we need to do is handle several of the events thrown by the ToolStripComboBox’s underlying ComboBox control. My solution extends the ToolStripComboBox, but you can accomplish the same thing without extending the control.
Read the rest of this entry »

Tags: , , , , ,