sipgate on N95 using Fring

Tuesday, October 30th, 2007

http://www.allaboutsymbian.com/forum/showthread.php?t=62596

Searchable Google Map

Thursday, October 25th, 2007

http://www.thinkvitamin.com/features/ajax/create-a-searchable-google-map

FMBL - yes I know I have to learn fmbl

Wednesday, October 17th, 2007

http://wiki.developers.facebook.com/index.php/FBML

Bloody Facebook Applications

Wednesday, October 17th, 2007

I have got to build a facebook app and founds these:

http://www.softwaredeveloper.com/features/develop-facebook-app-072607/

http://services.tucows.com/developers/2007/07/25/getting-started-with-facebook-application-development/

http://developers.facebook.com/resources.php

Global.asax? Use HttpModules Instead!

Tuesday, October 16th, 2007

http://codebetter.com/blogs/karlseguin/archive/2006/06/12/146356.aspx

In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are probably more common than HttpHandlers, but could still stand to be advertised a bit more.

HttpModules are incredibly easy to explain, so this will hopefully be a short-ish post. Simply put, HttpModules are portable versions of the global.asax. So, in your HttpModule you’ll see things like BeginRequest, OnError, AuthenticateRequest, etc. Actually, since HttpModules implement IHttpModule, you actually only get Init (and Dispose if you have any cleanup to do). The Init method passes in the HttpApplication which lets you hook into all of those events. For example, I have an ErrorModule that I use on most projects:

using System;
using System.Web;
using log4net;

namespace Fuel.Web
{
 public class ErrorModule : IHttpModule
{
#region IHttpModule Members
public void Init(HttpApplication application)
{
application.Error += new EventHandler(application_Error);
}
public void Dispose() { }
#endregion

public void application_Error(object sender, EventArgs e)
{
//handle error
}
}
}

Now, the code in my error handler is pretty simple:

HttpContext ctx = HttpContext.Current;
//get the inner most exception
Exception exception;
for (exception = ctx.Server.GetLastError(); exception.InnerException != null; exception = exception.InnerException) { }
if (exception is HttpException && ((HttpException)exception).GetHttpCode() == 404)
{
logger.Warn(”A 404 occurred”, exception);
}
else
{
logger.Error(”ErrorModule caught an unhandled exception”, exception);
}

I’m just using a log4net logger to log the exception, if it’s a 404 I’m just logging it as a warning.

You can do this just as easily with a global.asax, but those things aren’t reusable across projects. That of course means that you’ll end up duplicating your code and making it hard to manage. With my ErrorModule class, I just put it in a DLL, drop it in my bin folder and add a couple lines to my web.config under <system.web>:

<httpModules>
<add name=”ErrorModule” type=”Fuel.Web.ErrorModule, Fuel.Web” />
</httpModules>

And voila, I have a global error in place.

In almost all cases, you should go with HttpModules over global.asax because they are simply more reusable. As another example, my localization stuff uses an HttpModule as the basis for adding a multilingual framework to any application. Simply drop the DLL in the bin and add the relevant line in your web.config and you’re on your way. Here’s the important code from that module:

public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
public void Dispose() {}
private void context_BeginRequest(object sender, EventArgs e)
{
HttpRequest request = ((HttpApplication) sender).Request;
HttpContext context = ((HttpApplication)sender).Context;
 string applicationPath = request.ApplicationPath;
 if(applicationPath == “/”)
{
applicationPath = string.Empty;
}
string requestPath = request.Url.AbsolutePath.Substring(applicationPath.Length);
//just a function that parses the path for a culture and sets the CurrentCulture and CurrentUICulture
LoadCulture(ref requestPath);
context.RewritePath(applicationPath + requestPath);
}

If you are developing a shrink-wrap product, you don’t have a choice but to use HttpModules, because the last thing you want is to ship a global.asax which the user must use, overwriting the code in his own global.asax.

The only time you want to use Global.asax is when using OutputCaching with the VaryByCustom property. As far as I know, the GetVaryByCustomString function _must_ be placed in the global.asax file.

Anyways, switching from Global.asax to HttpModules is pretty straightforward. So I encourage you to look at where it makes sense (ie, where you see the potential for reuse across applications) and make it so.

MVC in flash

Tuesday, October 16th, 2007

http://www.adobe.com/devnet/flash/articles/mv_controller.html

http://www.adobe.com/devnet/flash/actionscript.htmlÂ

My guide to building Flash & Flex with ANT

Tuesday, October 16th, 2007

Using ANT to build Flash and Flex applications
==============================================

Introduction
————
As the Flash and hopefully new Flex projects get more complicated the move away from the Flash IDE is becoming more desirable. As the non-IDE projects require MTASC (the open source flash compiler), it has been made apparent that some form of build process is required.

To simplify the build process for Flash and Flex some research has been conducted into the validity of using ANT. ANT is synonymous with building Java projects but it can be used to build any types of projects such as Flash.

This document will outline the steps involved into installing and using ANT to build and possibly deploy Flash projects.

Installing Java and ANT
———————–
ANT requires Java to run. If it is not already installed on your machine it can be downloaded from here:
http://www.java.com/en/download/manual.jsp#win

Now you will require ANT. ANT can be downloaded here:
http://ant.apache.org/

Unzip it. And put it in a sensible location. In my case I have put it here: C:\Program Files\ANT

Once unzipped you will need to add some environment variables. To do this go to start and then right click on my computer and select properties. Select the advanced tab and then click the Environment Variables button at the bottom of the panel.

In the system variables section (lower one) add a new one. Call it ‘ANT_HOME’ and give it a value of ‘C:\Program Files\ANT’ (no quotes for each of these). Obviously change the path if you have extracted ANT to a different location.

Now in the same section find the variable called ‘PATH’ and select edit. Here there will be a list of ‘;’ separated paths. Go to the end and add a new ‘;’ and then add ‘C:\Program Files\ANT\bin’ (again no quotes and change as required).

At this point you will need to restart for the changes to take affect.

To test that the paths have been set up correctly, open the command prompt by going to start, run and then typing ‘cmd’.

In the prompt window type ‘ant’. Depending on your Java installation you may get a warning ‘unable to locate tools.jar’. This is ok. You will also get a message that the build.xml does not exists. This again is expected as we have not created one yet.

If you have any other issues then get googling.

MTASC and the Flash Player
————————–
To compile the .as files the MTASC compiler is required and to play the outputted swf files the flash player is also required.

MTASC can be downloaded here:
http://www.mtasc.org/

Flash Player can be downloaded here:
http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash

In most cases the project folder will have a tools directory that will have both the MTASC and FlashPlayer in.

Creating a Project to Compile
—————————–
In this example we are going to create a simple flash movie that draws a triangle on the screen.

Open a text editor. You can use notepad or the like but I tend to use FlashDevelop.

Create a new class:

//=================== CODE ===================
class MyClass {

public function MyClass()
{
trace(”hello”);
_root.createEmptyMovieClip(”triangle_mc”, 1);
_root.triangle_mc.beginFill(0×0000FF, 30);
_root.triangle_mc.lineStyle(5, 0xFF00FF, 100);
_root.triangle_mc.moveTo(200, 200);
_root.triangle_mc.lineTo(300, 300);
_root.triangle_mc.lineTo(100, 300);
_root.triangle_mc.lineTo(200, 200);
_root.triangle_mc.endFill();
}

public static function main():Void {
var mc:MyClass = new MyClass();
}

}
//=================== END CODE ===============

In this case we have a class that in the constructor will draw a triangle on the stage. There is a public static main that just creates an instance of that class.

Thats our ActionScript done now all we have to do is create an ANT build XML file.

Creating a Build File For ANT
—————————–
Open notepad or similar and create a new file called ‘build.xml’

Save this file in the same location as the as file you created in the previous step.

In this file add the following:

<?xml version=”1.0″ ?>
<project default=”compile” basedir=”.”>
<description>simple build file for flash projects</description>

<property name=”targetswf” value=”MyClass.swf”/>
<property name=”mainclass” value=”MyClass.as” />

<property name=”classpath1″ value=”C:\Documents and Settings\backup\[[[REPLACE WITH YOUR USERNAME]]]\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Classes\mx”/>

<property name=”mtasc” location=”[[[REPLACE WITH THE LOCATION OF YOUR MTASC.exe]]]” />
<property name=”flashplayer” value=”[[[REPLACE WITH THE LOCATION OF YOUR FlashPlayer.exe]]]” />

<property name=”source” location=”.” />
<property name=”deploy” location=”.” />

<target name=”compile”>
<exec executable=”${mtasc}” failonerror=”true”>
<arg value=”-cp” />
<arg value=”${classpath1}” />
<arg value=”-cp” />
<arg value=”${source}” />
<arg value=”-swf” />
<arg value=”${deploy}/${targetswf}” />
<arg value=”-header” />
<arg value=”800:600:31″ />
<arg value=”-main” />
<arg value=”-v” />
<arg value=”-strict” />
<arg value=”${source}/${mainclass}” />
</exec>

<exec executable=”${flashplayer}” spawn=”true”>
<arg value=”${deploy}/${targetswf}” />
</exec>
</target>
</project>

The root node of the ANT build file is <project />. Most of the file is self explanatory. Some notable points are the failonerror=”true” means that the build script will not continue if the build fails and spawn=”true” in the second executable means that ANT can stop and close and doesn’t have to wait.

The arguments for MTASC can be found here:
http://www.mtasc.org/#usage

Running The Build
—————–
Open the command prompt and navigate to the folder containing the as file and the build.xml In this directory type ‘ant’ and then return to run this command.

ANT should then compile the as file and produce a swf. You should automatically see the swf playing in a Flash Player window. If not review the messages in the command window and resolve.

Building Flex Applications
==========================
Introduction
————
Pre-requisites - you already have ANT installed and working. If not please review the above first.

To build Flex applications there are a few other requirements. To start with the Flex SDK is required. You can download the Flex 2 SDK from here:
http://www.adobe.com/products/flex/downloads/

Install the Flex SDK.

Flex 3 is available at this point but we are using Flex 2 for now.

The Flex Ant Tasks are also required. These can be downloaded from here:
http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks

Installing Flex Ant Tasks
————————-
Once downloaded extract the Flex Ant Tasks to an appropriate place. Copy the ‘flexTasks.jar’ to your ANT lib directory. If you have followed the steps above this will be: ‘C:\Program Files\ANT\lib\’.

Creating a flex Application
—————————
Now you are ready to start but we will need something to compile. We are going to create a simple Flex app.

Open your favorite text editor and create a new file. Add the following:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”>
<mx:Panel x=”140″ y=”100″ width=”250″ height=”200″ layout=”absolute” title=”Company Leaders”>

</mx:Panel>
</mx:Application>

… and save as myApp/Main.mxml in a suitable directory.

This is a really simple Flex app but you get the idea.

Creating the ANT Build Script
—————————–
The ANT build script is similar to the previous build script as in it has a root element and runs the Flash Player but that is about it.

Firstly we have to add the Flex build tasks.

Open your favorite text editor and create a new xml file. Add the following:

<?xml version=”1.0″ encoding=”utf-8″?>
<project name=”My App Builder” basedir=”../tools”>
<taskdef resource=”flexTasks.tasks” classpath=”${basedir}/flexTasks/lib/flexTasks.jar” />
<property name=”FLEX_HOME” value=”C:\Program Files\Adobe\Flex Builder 2\Flex SDK 2″/>
<property name=”APP_ROOT” value=”C:\Documents and Settings\jhinton\My Documents\FlexTest\classes\myApp”/>
<property name=”flashplayer” value=”C:\Documents and Settings\jhinton\My Documents\FlexTest\tools\FlashPlayer.exe” />

<target name=”main”>
<mxmlc file=”${APP_ROOT}/Main.mxml” keep-generated-actionscript=”true”>
<load-config filename=”${FLEX_HOME}/frameworks/flex-config.xml”/>
<source-path path-element=”${FLEX_HOME}/frameworks”/>
</mxmlc>

<exec executable=”${flashplayer}” spawn=”true”>
<arg value=”${APP_ROOT}\Main.swf” />
</exec>
</target>

</project>

… save the file as build.xml in the directory above the myApp directory we created that holds the Main.mxml.

Open the command prompt and browse to the directory with the build.xml file for this project and run ‘ant main’. If main is left out the project will compile but there will be no output.

One interesting point is the attribute on the mxmlc node called ‘keep-generated-actionscript’. If this property is true a directory called ‘generated’ will be produced and will contain all of the action script classes created in the build.

If the build succeeds you should see a flash window open with a very simple Flex application in. If you browse to the myApp directory you will see a new swf file called Main.swf.

Conclusion
———-
It is possible to use notepad and open source compilers to create Flash and Flex files. ANT is not essential to this process but does help in the build process.

In these examples ANT has not been used to anywhere nears it’s full potential. A list of tasks that ANT can perform can be found here:
http://antdoclet.neuroning.com/html/index.all.html

To conclude - ANT will be useful.

Ant build tasks for Flex

Monday, October 15th, 2007

http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks

http://blog.pixelconsumption.com/index.php?p=31

setting up ant etc:

http://www.bit-101.com/blog/?p=627

Scheduling Backups for SQL Server 2005 Express

Saturday, October 13th, 2007

http://www.mssqltips.com/tip.asp?tip=1174

Problem
One problem with SQL Server 2005 Express is that it does not offer a way to schedule jobs. In a previous tip, Free Job Scheduling Tool for SQL Server Express and MSDE, we looked at a free tool that allows you to create scheduled jobs for SQL Server. The one issue people often face though is what to install and what not to install on their production servers and therefore these items go without resolution. One very important part of managing SQL Server is to ensure you run backups on a set schedule. I often hear about corrupt databases and no backups, so let’s take a look at another approach of scheduling backups using the included tools in both the operating system and SQL Server.

Solution
There are two components to this; the first is the backup command and the second is the scheduling needed to run the backups.

Backup Commands
There are a few things that we need to setup. The first is to create a stored procedure that allows us to dynamically generate the backup file name as well as what type of backup to run Full, Differential or Transaction Log backup. The default for this stored procedure is to create the backups in the “C:\Backup” folder. This can be changed to any folder you like.

The following stored procedure should be created in the master database. This is just one way of handling this. There are several other options and enhancements that can be made.

USEÂ [master]
GO
/****** Object:  StoredProcedure [dbo].[sp_BackupDatabase]    Script Date: 02/07/2007 11:40:47 ******/
SETÂ ANSI_NULLSÂ ON
GO
SETÂ QUOTED_IDENTIFIERÂ ON
GO

–Â =============================================
– Author: Edgewood Solutions
– Create date: 2007-02-07
– Description: Backup Database
–Â Parameter1:Â databaseName
– Parameter2: backupType F=full, D=differential, L=log
–Â =============================================
CREATEÂ PROCEDUREÂ [dbo].[sp_BackupDatabase]
@databaseName sysname@backupType CHAR(1)
AS
BEGIN
SETÂ
NOCOUNTÂ ON;

DECLARE @sqlCommand NVARCHAR(1000)
DECLARE @dateTime NVARCHAR(20)

SELECT @dateTime REPLACE(CONVERT(VARCHARGETDATE(),111),‘/’,) +
REPLACE(CONVERT(VARCHARGETDATE(),108),‘:’,)

IF @backupType ‘F’
SET @sqlCommand ‘BACKUP DATABASE ‘ @databaseName +
‘ TO DISK = ”C:\Backup\’ @databaseName ‘_Full_’ @dateTime ‘.BAK”’

IF @backupType ‘D’
SET @sqlCommand ‘BACKUP DATABASE ‘ @databaseName +
‘ TO DISK = ”C:\Backup\’ @databaseName ‘_Diff_’ @dateTime ‘.BAK” WITH DIFFERENTIAL’

IF @backupType ‘L’
SET @sqlCommand ‘BACKUP LOG ‘ @databaseName +
‘ TO DISK = ”C:\Backup\’ @databaseName ‘_Log_’ @dateTime ‘.TRN”’

EXECUTE sp_executesql @sqlCommand
END

The second part of this is to create a SQLCMD file to run the backup commands. Here is a simple SQLCMD file that backups databases master, model and msdb.

This file gets saved as backup.sql and for our purposes this is created in the “C:\Backup” folder, but again this could be put anywhere.

sp_BackupDatabase ‘master’, ‘F’
GO
sp_BackupDatabase ‘model’, ‘F’
GO
sp_BackupDatabase ‘msdb’, ‘F’
GO
QUIT


Scheduling
Included with the Windows operating system is a the ability to setup and run scheduled tasks. This is generally not used for SQL Server environments, because SQL Server Agent is so robust and gives you a lot more control and options for setting up re-occurring jobs. With SQL Server 2005 Express the only choice is to set a scheduled task at the operating system level or look for some third party tool.

To setup a scheduled task you need to open the folder where you can create a new scheduled task. This can be found under Accessories -> System Tools -> Scheduled Tasks or under Control Panel.

The first thing to do is to click on “Add Scheduled Task” and the following wizard will run.

Select the application that you want to run. For our purposes we will be using SQLCMD.EXE. In order to find SQLCMD.EXE you will need to click on the Browse… button.

You should be able to find this in the following directory “C:\Program Files\Microsoft SQL Server\90\Tools\Binn”.

Give the scheduled task a name and specify when to perform the task.

Specify the time that this should be run.

Provide the credentials for the account that will run this task.

Finish and save the task. One thing you want to do is click on the “Open advanced properties” so you can edit the command.

Below is the advanced properties screen. You will need to change the “Run” command to the following:

sqlcmd -S serverName -E -i C:\Backup\Backup.sql

This is broken down as follows:

  • sqlcmd
  • -S (this specifies the server\instance name for SQL Server)
  • serverName (this is the server\instance name for SQL Server)
  • -E (this allows you to make a trusted connection)
  • -i (this specifies the input command file)
  • C:\Backup\Backup.sql (this is the file that we created above with the command steps)

That should do it. The scheduled task should now be setup.

If you want to run the command now to make sure it works go back to the Scheduled Tasks view and right click on the task and select “Run”.

Next Steps

  • Although this is a pretty simple example this should allow you to backup your SQL Server databases pretty easily
  • Modify the process to handle errors and also to take other parameters
  • Also take a look at this tip,Free Job Scheduling Tool for SQL Server Express and MSDE, to see if this tool makes more sense for your environment

Missing some environment variables?

Monday, October 8th, 2007

Sometimes some environment variables are missing for some .NET commands such as msbuild.

To fix this find ‘vsvars32.bat’ and run it. You may then have to restart and it should be fine!