Silverlight 2 Navigating Between Xaml Pages

One of the problems I've run across while playing around with the Beta is the lack of support for any easy way to navigate around you application by moving between Xaml pages. The problem really stems from this little piece of generated code in your App.xaml.cs file.

private void Application_Startup(object sender, StartupEventArgs e)

{

    // Load the main control

    this.RootVisual = new Page();

}

Looking at the docs for the RootVisual property of Application class, we're told that RootVisual can only be set once. My limited testing shows that this isn't actually true, and that it's possible to set LayoutRoot as many times as you'd like but only in the Application_Startup handler, which is obviously of very little use! More...

March 21, 2008 09:23 by Sean
E-mail | Permalink | Comments (9) | Comment RSSRSS comment feed

Blogengine.NET extension for embedding a Silverlight plugin

Silverlight 2 is here and with it's arrival there are going to be a whole load of Blogengine.NET using developers wanting to embed their sample Silverlight apps in their blog posts.

Presented here is a Blogengine.NET extension which makes all the necessary arrangements to embed your content. It works, like most others, by using a token that you type into your posts and in the most basic form looks like this:

[ silverlight:source=/ClientBin/MySilverlightApp.xap ] (without the spaces!) More...

March 7, 2008 22:19 by Sean
E-mail | Permalink | Comments (6) | Comment RSSRSS comment feed

Silverlight 2.0 Regular Expression Evaluator

I don't think I'm alone in saying that I've been waiting to get my hands on the Silverlight 2.0 bits for quite a while now. First impressions: it delivers!

I've been reading through the docs and playing around with the bits and my mind has been buzzing with loads of little samples and things to try, many of which will make it to these pages over the coming months I'm sure. I was actually reading though the API docs on MSDN before MIX08 even started and when I saw System.Text.RegularExpressions it just popped into my head I could make my first little baby steps with a Silverlight regex evaluator.

If you have read through all of Mr Guthrie's tutorials, which I highly recommend you do, then most of the code is very simple so I will only highlight a few interesting pieces, although as always the code will be available for download. The application cycles through all available matches for the suplied regular expression highlighting each in turn as you press the button. If no match is found or the last match has been reached a modal "MessageBox" type control is displayed. More...

March 7, 2008 09:26 by Sean
E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

Getting the icon for a given file extension

Background

In writing a pretty boring LOB app for my day job, I had the need to associate and store arbitrary files with records. I didn't want to just store the file in the actual database, so given that the application already sends audio and image data to an Ftp server on the network I figured I would store the files there also and just hold the file name in the database. 'm not storing the path, just the name and extension of the file and then the file is on the Ftp. Works very well and any client in the building can store pdf/doc/xls/etc files and anyone else can see and save them.  The problem I had was that I wanted to make a nice UI for the workflow and display the correct icon for each file. There is a handy static method for extracting icons from files, Icon.ExtractAssociatedIcon(filePath), which works great when you actually have the path to a file you want to find the icon for. Unfortunately there is no way built into the framework to get the default icon for a given file extension. More...

February 24, 2008 15:22 by Sean
E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Compiler keywords for primitive types? Why?

Having just read a pretty interesting post by some guy who gets quite emotional about "else" blocks, the way to spot that this is an emotional reaction is the use of "Never-ever-under-any-circumstances-for-any-reason-what-so-ever", I have to admit I really liked the post. It was fascinating for me to see and have explained some other developer’s little mental twitch reflex when he sees "else" used in (what he considers to be) an inappropriate way.

The truth is I liked it because secretly I have one of my own. Actually I think its way worse than his. Why oh why did Microsoft see fit to include compiler keywords for primitive types? What purpose does it serve?

We have "string" for String, "byte" for Byte, "int" for Int32... Why? Seriously, why? "float" and "double", what's that all about, what we're talking about is single and double precision floating point numbers, if you're at least going to have compiler keywords for these they should be "single" and "double". If you're going to do this kind of thing, we already have "smalint", "int" and "bigint" from Sql Server, why not stick to that instead of "short", "int" and "long"? Has the whole world gone to madness? More...

February 23, 2008 22:28 by Sean
E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

Enforcing single instance with argument passing

There are several implementations out there already for doing this, but for one reason or another they all did something I didn't like. Some use the registry, some can't pass parameters, some use P/Invoke, some use remoting and others use the VB libraries. Not quite high treason but even so, an all C# and very light implementation has got to be worth the effort. More...

February 11, 2008 13:06 by Sean
E-mail | Permalink | Comments (5) | Comment RSSRSS comment feed

Creating a Low Integrity named pipe in C#

Before I start, I'll give fair warning, this fits squarely into the category of post where the topic is going to be of very little interest to most readers, however it just might make one person out there a very very happy developer and save them some pain. 

I'm nearing the end of my adventures (I sure as hell hope there are no more problems, put it that way) writing a Winsock LSP and I have to say, it's been a gloriously excrusiating experience.

One of the problems I had when tinkering with this was with the new Windows Integrity Control stuff in Vista, in particular, how it all applies to IE7 Protected Mode. I'm sure it's all far more secure and that's a great thing, but it does put some obstacles in the road of people writing code which runs in the IE process, such as BHO's and toolbars... and also Winsock LSPs. More...

February 10, 2008 23:05 by Sean
E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Free copy of VS '08, SQL '08 & Server '08 for the UK too...

In addition to the post made here a few days ago, registrations were opened today for the UK launch event of all three products, and just like our friends over in the USA we also get a free copy of everything just for turning up!

You can register on the (cheesily named) Heroes Happen Here UK website, go get it while you can. See you there! More...

January 23, 2008 15:59 by Sean
E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Really simple Business Rule validation using lambdas

At some time or another we all have to code all the little rules, probably most of them already enforced in the database, into our business objects. FirstName cannot be null or empty, Age must be greater than 21, StartDate must be less than EndDate, etc etc... Wouldn't it be lovely if we could just declare these rules in one place and have them decoupled yet cross cutting the whole application, in the database, in the business layer, in the UI? Yeah it would, but I don't really have a solution for that and is it really possible/practical anyway? If it's possible it's sure not clean and easy, and if it's practical we'd all be doing it already!

What I have here is a very simple and lightweight way of validating these little rules, certainly not enterprise grade but certainly of some use in small scale scenarios. More...

January 7, 2008 20:29 by Sean
E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Socket Server with .NET 3.5 using pooled buffers and SocketAsyncEventArgs

In a previous post I talked about the System.Net.Sockets enhancements in .NET 3.5, and if you haven't read it I suggest you do before tucking in to this as some of that code is important to understand what's happening here. Before I start, in essence this is just a result of my experimentation and while it seems it does a pretty good job, I'm not going to claim it's bullerproof or that it's a good example of how to write a socket server all it does is demonstrate the techniques of working with the new classes and methods.

The sample solution you can see on the right there contains three projects. FlawlessCode contains all the classes we'll need to build ourselves a socket server. TestLoadGenerator is a console application which generates load for us by connecting lots of sockets to our server and sending it random data. TestSocketServer is a small socket server implementation using the classes in FlawlessCode.

TcpSocketListener

We'll begin by looking at the FlawlessCode project and in particular, the TcpSocketListener. It should be fairly obvious from the name what this class is meant to achieve, it sits in a loop listening for socket connections and lets us know when one arrives. The public interface is very simple and looks like this:

public void Start();

public void Stop();

public event EventHandler<SocketEventArgs> SocketConnected;

The only thing we'll take a closer look at here is the internal loop which accepts the client sockets. Here you can see the first usage of the new SocketAsyncEventArgs and we're calling AcceptAsync, in our callback we check the SocketError property to see if we had any errors. More...

January 3, 2008 10:15 by Sean
E-mail | Permalink | Comments (9) | Comment RSSRSS comment feed