nbsp;
Pretty cool eh?
For more information Wikipedia as usual is our friend:
http://en.wikipedia.org/wiki/Genetic_algorithm
Currently .net and to some degree SQL services are available.
To play around with Azure you need to register so sign up at: http://www.microsoft.com/azure/register.mspx.
Microsoft will then send you a key (mine took about a week to arrive) allowing you to access the online facilities.
Until you get this key you can still play around to an extentby downloading the SDK: http://www.microsoft.com/downloads/details.aspx?FamilyId=BB893FB0-AD04-4FE8-BB04-0C5E4278D3E9amp;displaylang=en.
I suggest you also download the tools for visual studio from http://www.microsoft.com/downloads/details.aspx?FamilyId=63D0D248-1B08-4F7D-ABDE-62EB75CB1E69amp;displaylang=en. As this is beta software you probably want to be running it in virtual pc (although I didnt and everything seems fine still).
The first thing you should do is watch Steve Marx's presentation on developing an application in Azure at: http://channel9.msdn.com/pdc2008/ES01/
Steve is an excellent preseter, great to watch and will take you through the basics of Windows Azure.
After installing the Visual Studio tools you can create Web Cloud service ASP.net projects. Cloud projects are very similar to standard ASP.net projects but contain another project that has some additional files that describe where the service is hosted and configuration settings (.csdef and .cscfg).
If you look at the project name in Visual Studio you will see it is called something like CloudService1_webRole. Role is a term within Azure that seems to describe the type of service you are running. If you right click on the service project you can deploy it to the cloud (which they havent given me access to yet).
As it would be inconvenient to deploy your app every time you wanted to test it Microsoft provide an application called the development fabric which simulates how it will function in the cloud (below). If you open the cscfg in studio you will see its an XML file that contains the following:
lt;?xml version="1.0"?gt;
lt;ServiceConfiguration serviceName="CloudService3" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"gt;
lt;Role name="WebRole"gt;
lt;Instances count="1"/gt;
lt;ConfigurationSettingsgt;
lt;/ConfigurationSettingsgt;
lt;/Rolegt;
lt;/ServiceConfigurationgt;
If you alter the instances count element and run the app you will see more instances created in development fabric. This simulates adding capacity to your Azure application e.g. if you are expecting many visitors to hit the site.
Once you have your key and have activated it you can log into the Azure services platform. This will take you to an interface like the screen shot below. At present its a bit rough around the edges but you can see the direction they are going.
Currently within .net services you have access to 3 components:
The examples provided in the SDK take you through the basics of how these work. There is an example of a chat application that sends messages via the service broker. What is impressive is the speed of it, no noticable delay at all. There is also another example application to demonstrate the security features )(a calculator app). This threw an security exception when I tried to run it about token being valid 10 seconds after it was requested?!
Security is defined by an input claim e.g. a specific username which is then matched to Output claims (e.g. in the included example give the ability to multiply).
Some of the examples are a bit cryptic at present and I would suggest brush up on your WCF and Workflow as these concepts will certainly be used.
It all looks really promising so far and I cant wait to learn more about it.
Having said this it does look interesting from the point of view of:
DataContext objCon = new DataContext(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnStr"));
Tablelt;BlogEntryCommentgt; objBlogEntryCommentTable = objCon.GetTablelt;BlogEntryCommentgt;();
var query = from b in objBlogEntryCommentTable
orderby b.CommentDate
where b.BlogEntryID ==BlogEntryID
select b;
return query.ToList();
Perhaps the best option if you just want a single value back is to use a format called JSON in conjuction with JQuery.
JSON stands for Javascript object notation and is a very lightweight format to return a simple object. For example a stock quote result might look something like this:
{Symbol:"MSFT",Value:"4.4"}
I think we can all agree thats a lot less data than your average SOAP call and its pretty readable making JSON less heavy on bandwidth and probably quicker to process than XML (needs confirming!). Libraries such as JQuery understand JSON is an object which makes it very easy to work with e.g:
alert(objMyResult.Value);
Which is much preferable to processing XML from SOAP results etc...
But how do you use this with ASP.net?
Currently ASP.net and JSON support is pretty ropey (however nothing to stop you returning JSON formatted strings). In the MVC framework there is some nice inbuilt functionality for dealing with JSON posts in controllers. I decided to add the ability for users to comment on my blog posts and decided to implement this with MVC. The client side code is below and can be seen in action by commenting on any of the blog posts. Note you will need JQuery to use this code and currently the Json result class is only included in MVC projects (System.Web.MVC).
Client side code:
function submit()
{
nbsp;
var strName = $("#txtName").val(); $.ajax({
var strEmail = $("#txtEmail").val();
var strComment = $("#txtComment").val();
var strSpamCheck = $("#txtSpamCheck").val();
var rand1=window.rand1;
var rand2=window.rand2;
type:
nbsp;
"POST", });
dataType: "json",
url: "lt;%=Application["URLRoot"].ToString() + "BlogEntryComment/Submit?id=" + objBlogEntry.BlogEntryID.ToString() %gt;",
data: { Email: strEmail, Name: strName, Comment: strComment, SpamCheck: strSpamCheck, Rand1: rand1, Rand2: rand2},
success: function(result) {
$("#CommentEntry").fadeOut("slow");
setTimeout(redirect,2000);
},
error: function(error) {
alert('error ');
}
}
nbsp;
Then server side I use this code in my controller class for processing BlogEntryComments:
public JsonResult Submit(string Email, string Name, string Comment, int SpamCheck, int Rand1, int Rand2)
{
if (SpamCheck != (Rand1 + Rand2))
{
return Json(new { message = "SPAM" });
}
if (Comment == "")
{
return Json(new { message = "SUCCESS" });
}
if ("" + Name.Trim() == "")
{
Name = "Anon";
}
DataContext objCon = new DataContext(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnStr"));
Tablelt;BlogEntryCommentgt; objBlogEntryCommentTable = objCon.GetTablelt;BlogEntryCommentgt;();
BlogEntryComment objBlogEntryComment = new BlogEntryComment();
objBlogEntryComment.IP = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();
objBlogEntryComment.BlogEntryID=Convert.ToInt32(Request.QueryString["id"]);
objBlogEntryComment.CommentDate = System.DateTime.Now;
objBlogEntryComment.Name = "" + Name;
objBlogEntryComment.Email = "" + Email;
objBlogEntryComment.Comment = "" + Comment;
objBlogEntryComment.Approved = 0;
objBlogEntryCommentTable.InsertOnSubmit(objBlogEntryComment);
objCon.SubmitChanges();
return Json(new { message = "SUCCESS" });
}
If you want to adapt this for you own use couple of things to note:
]]>
let a=1 let b=(a+a) let c=(a+b*2)
http://weblogs.asp.net/scottgu/archive/2008/10/16/asp-net-mvc-beta-released.aspx
]]>A number of things come to mind:
It doesnt take too much imagination to see the problems with the above. The bozos who designed this system would do well to read a book called Dont Make me think by Steve Krug (http://www.amazon.co.uk/Dont-Make-Think-Usability-Circle-Com/dp/0789723107/ref=sr_1_2?ie=UTF8amp;s=booksamp;qid=1224192586amp;sr=8-2)
Steve considers when people make decisions they make not necessairly the smartest but the easiest decision possible (with no problems).
This has implications for user interface design the ideal being the user should make the decisions without having to think about them. I think you can see this with a well designed site like Amazon or StackOverflow where you just feel drawn to the right button etc. You can help or hinder this process by adhearing to well known standards and ui elements.
After covering basic concepts and web standards Steve takes a number of websites, shows the current design and alters them (some times very slightly to improve the usability). Every developer should be made to read this book. It took me about 2-3 hours to read cover from cover and it was an entertaining read. Every developer should read this book.
Belows the code I used to convert an imagr to greyscale. I have commented out brightness adjustment (just add to each value) and some other stuff I was playing with.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
public class Imaging
{
public string ExportDir = "";
public string ModifyImageProperties(string Mode, string FilePath, int RedModify, int GreenModify, int BlueModify, int Lighten, int Darken)
{
int intStride = 0;
int intBrightness = -150;
System.IntPtr Scan0;
Bitmap objBitmap = new Bitmap(FilePath);
string strNewFileName = "" + Guid.NewGuid().ToString() + ".jpg";
BitmapData objBitmapData = objBitmap.LockBits(new Rectangle(0, 0, objBitmap.Width, objBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
//For 24 bit formats (RGB) stride=imageWidth * 3 (note if this isnt a number divisible by 4 an offset will be added to make it so)
//For 32 bit formats (RGB) stride=imageWidth * 4
intStride = objBitmapData.Stride;
Scan0 = objBitmapData.Scan0;
unsafe
{
//Pointer to start of image
byte* p = (byte*)Scan0;
//Calculate offset
int nOffset = intStride - (objBitmap.Width * 3);
int nWidth = (objBitmap.Width * 3);
int intRed = 0;
int intGreen = 0;
int intBlue = 0;
for (int y = 0; y lt; objBitmap.Height; ++y)
{
for (int x = 0; x lt; objBitmap.Width; ++x)
{
intRed =p[2];
intGreen =p[1];
intBlue = p[0];
if (Mode == "RGB")
{
intRed = intRed + RedModify;
intGreen = intGreen + GreenModify;
intBlue = intBlue + BlueModify;
}
if(Mode=="INVERT")
{
intRed = 255 - p[2];
intGreen = 255 - p[1];
intBlue = 255 - p[0];
}
if (Mode == "GREY")
{
intRed = (byte) (.299 * intRed + .587 * intGreen + .114 * intRed);
intGreen = (byte) (.299 * intRed + .587 * intGreen + .114 * intRed);
intBlue = (byte)(.299 * intRed + .587 * intGreen + .114 * intRed);
}
if (Lighten gt; 0)
{
intRed = intRed + Lighten;
intGreen = intGreen + Lighten;
intBlue = intBlue + Lighten;
}
if (Darken gt; 0)
{
intRed = intRed - Darken;
intGreen = intGreen - Darken;
intBlue = intBlue - Darken;
}
if (intRedgt; 255) intRed = 255;
if (intGreen gt; 255) intGreen = 255;
if (intBlue gt; 255) intBlue = 255;
if (intRed lt; 0) intRed = 0;
if (intGreen lt; 0) intGreen = 0;
if (intBlue lt; 0) intBlue = 0;
p[2] = (byte) intRed;
p[1] = (byte) intGreen;
p[0] = (byte) intBlue;
//++p;
p += 3;
}
p += nOffset;
}
objBitmap.Save(ExportDir + strNewFileName, ImageFormat.Jpeg);
objBitmap.UnlockBits(objBitmapData);
return strNewFileName;
}
}
}
I found a few links which helped me put this together the codeproject was very helpful (although not the most readable):
http://www.bobpowell.net/lockingbits.htm
http://www2.sys-con.com/ITSG/virtualcd/Dotnet/archives/0104/brown/index.html
http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx
In relation to standard ASP.net
MVC doesnt make use of standard view state so some scenerios may be more difficult than classic ASP.net. The application uses the url and http verbs to map to the views e.g /products/GetList is automatically mapped to GetList view
The main advantage of using MVC are that:
After the MVC session we watched a talk on optimizing ASP.net performance from the front end.
The main conclusions were:
The other session I atteneded was given by Mike Taulty on how Silverlight can interact with the page.
This was very impressive:
After meeting up with Howard just outside the exhibition hall the day began with an excellent key note speech given by Bill Buxton ( usability and industrial design expert) Bill has written an interesting looking book called Sketching user experiences which I purchased.
Bill argued that in many places the design phase occurs after the product development and that it was a mistake to let non experts be too involved in design (e.g. the FD on a project being involved to the level of screen design). He argued that good design was dependent on many aspects citing Apples Ipod. Prior to this Apple had been in decline. At this time a number of key personnel Jonathan Ive had been at Apple some time but the Ipod wouldnt become a success until a combination of events such as:
After this we attnded 2 sessions by Scott Gu on Silverlight. I have spent some time with Silverlight lately and would highly recommend the video tutorials. Scott said that Silverlight 2 was due to be released shortly (somewhat non committal!). Other items that looked interesting were IE 8 which includes a javascript profiler and useful looking development tools, Visual studio intellisense support for javascript frameworks such as prototype, about 50 new silverlight controls including graphing components coming.
We then saw a session on Sql data services (astoria). Astoria is basically a REST api to query sql server. I am not sure what I would use this for but it may be useful for example in a silverlight situation to avoid writing a web service interface for every crud query.
The final session was on Visual Studio IDE tips given by Sara Ford. This was very interesting and contained several time saving tips. I suggest you look at her blog which has a tip a day http://blogs.msdn.com/saraford/default.aspx
After we left this session I managed to talk to Scott Gu. One of the great things about Remix was how accessible all the presenters were. To have the chance to talk to Microsoft's VP was pretty cool.

I asked Scott about whether we should be using Web sites or Web application projects (a contentious issue in our company). Scott suggested web application projects where the dll is built is the better way to go. This was due to better performance and the ability to produce unit tests as a dll is built.
After the main sessions I had a few beers with Howard and had a chance to look at Microsoft Surface. There was an excellent demonstration given which had a virtual earth map. You could rotate it at any angle and even zoom into and walk inside buildings. At $13000 per unit they dont come cheap through.
I am looking forward to the MVC session tomorrow (finding out what exactly it is!)
So always practice safe threading or refrain..
]]>
Public Class Ben
Public Sub AddTwoNumbers()
Assert.AreEqual(1 + 1, 2)
End Sub
Public Sub MakeTea()
Throw new system.exception("Ben doesnt make tea")
End Sub
End Class
lt;TestFixture()gt; _
Public Class Ben
lt; test()gt; _
Public Sub AddTwoNumbers()
Assert.AreEqual(1 + 1, 2)
End Sub
lt;test()gt; _
Public Sub MakeTea()
Throw new System.Exception(“Ben doesn’t make tea”)
End Sub
End Class
lt;test()gt;_
Public Sub IsGoogleWorking()
Dim objIE As New IE("http://www.google.com")
objIE.TextField(Find.ByName("q")).TypeText("Hicom")
objIE.Button(Find.ByName("btnG")).Click()
Assert.IsTrue(objIE.ContainsText("Hicom"))
End Sub

But the real killer is that when you change pages the entire screen flashes which is really irritating. Why with all the effort that has gone into the rest of it would you do this.
Nice try Sony but I dont think its there yet...
On the whole not a bad book and if you think you need to wise up to some of the non technical issues well worth a read.
]]>But why would you want to do this?
Perhaps the only problem with CruiseControl.net is the documentation which you are going to have to do a bit of searching around. However CruiseControl.net is a popular application so there are quite a few tutorials.
CruiseControl.net has 2 parts the application itself and a web front end. The web front end is okay however you can modify various bits yourself through XSL files.
Using CruiseControl.net
1) Download NUnit from: http://sourceforge.net/project/downloading.php?groupname=nunitamp;filename=NUnit-2.4.8-net-2.0.msiamp;use_mirror=osdn (not strictly necessary but this tutorial will be integrating NUnit tests in the build)
2) Download CruiseControl.net from: http://sourceforge.net/project/showfiles.php?group_id=71179amp;package_id=83198
3) Check you have IIS amp; .net 3.5 installed
4) Install NUnit amp; CruiseControl.net
5) This will create a short cut on your desktop click this to run it you should see a dos window with a load of messages similar to this:
Create Project to build
Now what we need to do is create a sample project for CruiseControl to build.
I have created a new blank solution called cctestapp and added a console application to it. My solution file is at E:\wwwroot\Testing\cctestapp\cctestapp.sln and the application is at E:\wwwroot\Testing\cctestapp\cctestapp\.
Once you have created your console application add a reference to Nunit.framework.dll (by default this is at: C:\Program Files\NUnit 2.4.8\bin)
Add the following code to your console application:
using System;
using NUnit.Framework;
namespace MonitoringApplication
{
[TestFixture]
public class Program
{
[Test]
public void AlexTest()
{
Assert.AreEqual(1, 1);
}
public static int Main(string[] args)
{
//My program
return 0;
}
}
}
Check the application compiles okay.
Now we need to tell CruiseControl.net we want to build this project. To do this we need to alter an xml configuration file. This XML configuration file contains all the projects that are to be built. The configuration file contains a reference to a program called MsBuild. When you compile a project in visual studio behind the scences MsBuild is used to create the final output.
1) Open ccnet.config in notepad (by default its at C:\Program Files\CruiseControl.NET\server).
2) Modify it so it looks like this config file. This config file automates a build on Mondays and Wednesdays at 18:00 and runs NUnit tests.
3) Remember to alter the various paths to where you have created your project. I think these are fairly self explanatory. e.g assembly, executable, working directory, project file and logger.
4) If you now open up a web browser and go to http://localhost/ccnet/ you should see the main build screen like below:
5) Click the Force button to run the build.
6) You can then click refresh status to see if it built correctly if it did under the build status it should say Success.
7) To look at more details about whether your project built properly click the project name you can then view the build report and see the results of any tests.
8) If the project didnt build properly check your file paths are correct in ccnet.config.
You will probably want to install the CruiseControl tray application this notifies you of failures and allows you to kick of builds etc. This you can install by opening the web application and clicking the download CCTray link on the left.
Further reading
These tutorials helped me to get this running:
http://johnnycoder.com/blog/2008/01/29/getting-started-with-cruisecontrolnet/
http://weblogs.asp.net/jdanforth/pages/How-to-Hook-Up-a-VS.NET-2005-Solution-With-CruiseControl.NET-in-a-Few-Minutes.aspx
