Presenting OpenRasta in Aarhus, Denmark, 27th of August

The good chaps in Denmark have asked me to do a session on OpenRasta. You can imagine how excited I was, and I immediately said yes! You can go and register now for it.

Ads

What a difference a framework can make…

Rick Strahl, C# MVP extraordinaire, has released a very cool app at codepaste.net. Go and check it out, it’s quite cool.

One of the things Rick is doing is publishing a POD API that uses xml and json. And he posted on an unrelated entry an implementation of POD using MVC. For reference, here’s his snippet.

AcceptVerbs(HttpVerbs.Post | HttpVerbs.Put)]
public ActionResult PostNewCodeSnippetObject()
{
StreamReader sr = new StreamReader(Request.InputStream);
string data = sr.ReadToEnd();
sr.Close();

Snippet inputSnippet = null;

if (Request.ContentType == "text/javascript" || Request.ContentType == "application/json")
{
JSONSerializer ser = new JSONSerializer(SupportedJsonParserTypes.WestWindJsonSerializer);
inputSnippet = ser.Deserialize(data, typeof(Snippet)) as Snippet;
}
else if (Request.ContentType == "text/xml")
{
inputSnippet = SerializationUtils.DeSerializeObject(data, typeof(Snippet)) as Snippet;
}
else
return ExceptionResult("Unsuppported data input format. Please provide input content-type as text/javascript, application/json or text/xml.");


busCodeSnippet codeSnippet = new busCodeSnippet();
codeSnippet.NewEntity();

DataUtils.CopyObjectData(inputSnippet, codeSnippet.Entity, "Id", BindingFlags.Public | BindingFlags.Instance);

if (!codeSnippet.Validate())
return this.ExceptionResult("Code snippet validation failed: " + codeSnippet.ValidationErrors.ToString());

if (!codeSnippet.Save())
return this.ExceptionResult("Couldn't save new code snippet: " + codeSnippet.ValidationErrors.ToString());

return ApiResult(codeSnippet.Entity);
}

Ouch. Lot of fluff if I may say so. Let’s see what the equivalent implementation would be using OpenRasta.

The configuration:

using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has.ResourcesOfType<Snippet>().AtUri("/snippets")
.HandledBy<SnippetHandler>()
.AsJsonDataContract().And.AsXmlDataContract();
}

The handler:

public OperationResult Post(Snippet newSnippet)
{
var codeSnippet = new busCodeSnippet();
codeSnippet.NewEntity();

DataUtils.CopyObjectData(inputSnippet, codeSnippet.Entity, "Id", BindingFlags.Public | BindingFlags.Instance);

if (!codeSnippet.Validate())
return new OperationResult.BadRequest("Code snippet validation failed", codeSnippet.ValidationErrors.ToString());

if (!codeSnippet.Save())
return new OperationResult.InternalServerError("Couldn't save new code snippet", codeSnippet.ValidationErrors.ToString());

return new OperationResult.OK(codeSnippet.Entity);
}

I much prefer the latter. Don’t you?

Ads

NHibernate and OpenRasta frenzy in Aarhus, Denmark

On a very positive note, I’ll be delivering Skillsmatter’s NHibernate course in Aarhus, Denmark, from the 26th to the 28th of August.

I’m also discussing with some guys to get an OpenRasta presentation there so you can hear what the fuss is all about.

And I’ll take the Saturday to visit Copenhagen, as it would be a shame not to. If some people are available Saturday we can meet for a beer and a chat.

First time in Denmark, I’m quite excited!

Ads