Thursday 31 July 2008

Silverlight Assault Course Feedback

Thanks again to everyone who attended the assault course in poole last week.

I'm just looking at the feedback just now and myself and Rich are sitting now joint 5th in the all time www.nxtgenug.net top 10 rated sessions.

Thanks again for coming, for making it a great day, and thanks for the great feedback :)

I've pasted a sample below :)

(9)
Good solid sessions by Chris - great work!

(9)
Chris went into some advanced areas of Silverlight, there were great tips that will save me a great deal of time and effort in research and reading up. Chris was able to move around the whole subject area of Silverlight with ease and produced a number of great demos.

(9)
Chris has definitely improved since I first saw him. His now alot more confident, and definitely knows he's stuff. Excellent stuff Chris!

(9)
I had such a blast today :)

(9)
Went into just enough detail to make me want to learn more...

(9)
Hay spoke with great authority and energy. He delivered many 'golden nuggets'

(9)
Seen Chris a few times before and was as impressed as ever with his knowledge and enthusiasm for Silverlight as well as his hatred of Will Young!

(9)
Extremely useful Silverlight subjects, certainly have renewed enthusiasm to take my Silverlight development forward.

(8)
Great examples; good speed. Great to be able to access the code from the talks to look through it again

(8)

(8)

(8)
Chris seems in a rush always and reluctant to take questions...understandable when falling behind the schedule, though.

(8)
Chris is a good presenter, despite the loud shirt

Wednesday 30 July 2008

Silverlight Desktop Application Launcher

So I’ve done my first (very rough version) of my Silverlight Launcher.

This application allows you to run any silverlight application locally on your desktop.

You can download the application from my skydrive

The difference between this application (and running under the file system) is that you can make network calls. I’ve include a Digg Sample to prove my point.

At the moment the application is restricted port 1234 however I will expand this in the future. I will also talk about the source etc in the future.

If your silverlight application needs to talk back to your web server (then you should use an absolute http reference for your WCF call in your silverlight application, and have clientaccesspolicy.xml or crossdomain.xml server).

Usage

SilverlightLauncher.exe mysilverlightapplication.xap

You can download the application from my skydrive

In my sample application try searching for Apple i haven't put any exception handling

I’m gonna be taking this application a lot further in the future

P.S. If you run in Vista you need to run this as an administrator (in future i will do the prompt)

Monday 28 July 2008

Silverlight Assault Course Samples

Thanks to everyone who turned up to the Silverlight Assault Course on Saturday.  It was a total blast and I hope everyone had as much fun as I did.

I promised I would post up my code samples, so it is here for you to download

Thanks again for coming and making it a great day.

Wednesday 23 July 2008

Silverlight Desktop Applications (Part 2)

So in the previous article I discussed what you can do today to run your Silverlight application independent of your web server. These were running your Silverlight application from the file system, or running a Silverlight application Offline.

In this post I am going to talk about the crazy thinking I had when responding to a post today.

Simple Web Server

My idea is quite simple. Essentially if you can run your application locally on local web server then you will have full access to network capabilities (WebClient, WCF etc). This means you will be able to make cross domain calls to local or non local servers. You will also be able to make socket calls to local or non local servers.

As was pointed out in the web server you could run cassini on the local machine but this is a little over the top.

Mega Simple C# Web Server

All we really need is a very simple socket server, which will spew out some http from a web request from IE.

Therefore we could have a little application which we associated with the .XAP file extension, which launches a simple web server process and then calls IE pointing it to our simple web server. Once the html page has been served we can trash the simple web server process and your application now runs on the desktop.

Cross Domain Access

Because our application is essentially an online application (came from a web server you know), we can talk to any web server / (socket server) which allows us via cross domain policies. Lots of Digg clients can be made yay, or when Beta 2 can talk to the new crossdomain.xml format then Yahoo Search etc will be supported.

Local Services

Not only can we talk to internet services but we can talk to intranet WCF / Socket Services (using crossdomain). This means you could potentially have local print services, file services which expose the file system, talk to a time service, talk to your build server, TFS, SQL Server anything really. For sockets (you may need to create a virtual socket due to the port range supported).

Anyways that was my crazy thinking for the day. I haven't written any code to validate this but there is no reason why it wouldn't work in principal. May'be I will have time to play with it one day, or may'be you will.

Desktop Silverlight Applications (Part One)

I responded to a question in a forum today, which got me thinking about running Silverlight Applications on the desktop. So this got me thinking of the options available.

File System Silverlight Applications

Silverlight applications can run from the filesystem already without a backend web host.

The issue is that you don't have access to any networking functions. WebClient, WCF Services, Sockets etc.

Even then you are still restricted to the sandbox (no direct filesystem access), and no possible way of interacting directly with the filesystem (without use of ActiveX objects, Javascript etc).

So if you want to deploy a game, or a learning application on a CD you can do this with Silverlight (cross platform) using this method. However If you are not worried about cross platform, WPF is probably a better solution.

Offline Silverlight Applications

So, the second option we have is to run the application offline (or online if you are online). I can connect to my silverlight application and it run it offline.

The downside of this approach is that i need to be online to perform the first download. My application is also dependent on Browser Cache. So if my browser cache is cleared, i need to download my application.

Could be a pain at a critical time. However this is a great solution, if you want to have an online access which is available (not critically) when the user is offline.

Desktop Silverlight Application

So what other solution do I have for running my Silverlight Application locally?

Well this is where my crazy out the box thinking began.

And in my next post, I will discuss my thoughts.

Last Night in Cambridge

Big thanks to everyone who attended our NxtGenUG Cambridge event last night.

Thanks especially to Microsoft for the Venue, Ian Cooper for giving the talk on Enterprise Architecture and Ben Hall for his talk on Team City.

A copy of the slide for the event is below:

NXtgenugslidejuly

Thursday 17 July 2008

Interactive Video

This is simple Silverlight Video where if you click on the play button of my ipod when I tell you to (in the video), it will play the same video on my ipod screen.

I will post the source code for this soon, but for now if you want to see a live version of the video, click here.

It is a cheap effect, but it is cool

Wednesday 16 July 2008

SQL Bits 3 Logo Competition

The folks at SQL Bits are wanting a new logo and are holding a competition.

I thought it was about time, I submitted my own entry (I hope it wins).

Anyways my entry is below:

 

SqlBits Logo

Tuesday 15 July 2008

Dynamic XAML

I thought I'd post up a Silverlight Beta 2 dynamic XAML sample.  This is a pretty simple sample which consists of a textbox, a button and a grid.

All you simply do is paste some XAML into the textbox, click the button and the XAML will appear in the grid.

You can view an online demo here

This is a very simple implementation however this could be extended much further as an application.  Isolated Storage to store XAML, save it back to a WCF Service etc.

You could take the concept further even still and use a duplex WCF service (or sockets) to post XAML between different clients.

The key thing when dealing with dynamic XAML is using System.Windows.Markup.XamlReader.Load to load the XAML.

The code is below.

XAML

<Grid x:Name="LayoutRoot">
<
Grid.ColumnDefinitions>
<
ColumnDefinition/>
</
Grid.ColumnDefinitions>
<
Grid.RowDefinitions>
<
RowDefinition/>
<
RowDefinition/>
</
Grid.RowDefinitions>
<
Grid x:Name="gridDynamic"
Grid.Row="0"
Height="500" Width="500"/>
<
StackPanel Orientation="Horizontal" Grid.Row="1">
<
TextBox x:Name="myTextbox"
Text="Load Xaml"
AcceptsReturn="True" TextWrapping="Wrap"
Margin="5" Height="200" Width="500"/>
<
Button Content="Load Xaml"
Height="30" Width="100"
Click="Button_Click"/>
</
StackPanel>
</
Grid>


C#


public partial class DynamicXaml : UserControl
{
public DynamicXaml()
{
InitializeComponent();
myTextbox.Text = @"<Grid xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""><Ellipse Height=""100"" Width=""100"" Fill=""Red""/></Grid>";
}

private void Button_Click(object sender, RoutedEventArgs e)
{
UIElement xamlElement = (UIElement)System.Windows.Markup.XamlReader.Load(myTextbox.Text);
gridDynamic.Children.Clear();
gridDynamic.Children.Add(xamlElement);
}
}

Thursday 10 July 2008

Silverlight 2 Wee Mee

Sometimes it is fun to redo something you did a while back. I did a cool little application back in 1.1 days which I have decided to update to Silverlight 2.0. All it is an image with a couple of invisible buttons where the eyes are. If you click on the eyes it will play a media file.

Click on the eyes below to see it in action (switch on your speakers)

It's a fun little sample and it brings kind of interesting possibilities to Silverlight 2. This technique can be used to bring a rich image map type control to Web Pages. It can also be use to bring much richer UI's. Why not have a media player which is a photograph of your stereo?

The XAML

<Grid>
<
Canvas>
<
Image x:Name="myImage"
Source="/Assets/Images/WeeMee.JPG">
</
Image>
<
Button x:Name="leftEye"
Canvas.Left="42" Canvas.Top="49"
Height="12" Width="10"
Cursor="Hand"
Opacity="0"
Click="leftEye_Click"/>
<
Button x:Name="rightEye"
Canvas.Left="57" Canvas.Top="49"
Height="12" Width="10"
Cursor="Hand"
Opacity="0"
Click="rightEye_Click"/>
</
Canvas>

<!-- Media 1-->
<MediaElement x:Name="media1"
AutoPlay="False"
Source="/Assets/Audio/cutitout.wma">
</
MediaElement>

<!-- Media 2-->
<MediaElement x:Name="media2"
AutoPlay="False"
Source="/Assets/Audio/laugh.wma">
</
MediaElement>
</
Grid>




The C#



private void leftEye_Click(object sender, RoutedEventArgs e)
{
media1.Stop();
media2.Stop();
media1.Play();
}

private void rightEye_Click(object sender, RoutedEventArgs e)
{
media1.Stop();
media2.Stop();
media2.Play();
}

Wednesday 9 July 2008

SQL Server Clearing Cache

Clear Stored Procedure Cache

DBCC FREEPROCCACHE


Clear Data Cache



DBCC DROPCLEANBUFFERS

Open File Dialog and Local Media Files

I've been messing around with the Open File Dialog in Silverlight 2.0 Beta 2.

The open file dialog (OFD) is the only method that a user can access the local file system in a Silverlight Application (outside of Isolated Storage).

The cool thing about it is is that you can work with not just only text files but other types of files too.

 

Single or Multiple Files

The OFD supports both a single file select mode or multi file select via the (Multiselect) property.

OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;

 


Filtering to MP3 or WMA files

// Initialise
OpenFileDialog ofd = new OpenFileDialog();

// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;

// Show the open file dialog
ofd.ShowDialog();
 

Playing Local Media Files


The following bit of code will set the source of a medialement to the stream of the selected file.  In this case it allow you to play a local video or audio file.

// Initialise
OpenFileDialog ofd = new OpenFileDialog();

// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;

// Show the open file dialog
ofd.ShowDialog();

// Do we have a selected file
if (ofd.SelectedFile != null)
{
// Set the source as the local file
mediaPlayer.AutoPlay = true;
mediaPlayer.SetSource(ofd.SelectedFile.OpenRead());
}
 

Text Files


If you wanna be a little more traditional in your use of the open file dialog, you can use OpenText() rather than OpenRead() to allow you to interact with the text file.  An advantage of OpenText is that it gives you a StreamReader so you have access to ReadToEnd() etc.

private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// Initialise
OpenFileDialog ofd = new OpenFileDialog();

// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;

// Show the open file dialog
ofd.ShowDialog();

// Do we have a selected file
if (ofd.SelectedFile != null)
{
string myText = ofd.SelectedFile.OpenText().ReadToEnd();
}
}

 


 


Multiple Files


If you want to select files then you should use the SelectedFiles property rather than SelectedFile and you will be able to enumerate through all the selected files.


 


Uses of the Open File Dialog


In a normal web scenario using a Silverlight Control to perform uploading of files is a much richer experience than using the equivalent Html Control.  You have the ability to select, process and upload multiple files at once.


The ability to perform client side validation of a file (CSV validation, XML validation) is a great feature and should encourage great take up in web scenarios.


The only thing I really want now is a Save File Dialog.

Padding Zeroes in SQL

Building a little script in SQL to allow me to autogenerate mobile phone numbers.

I know I can do this with Red-Gate's Data Generator but it is nice to build the SQL yourself.

Anyways the SQL to pad the mobile phone number with zeroes is:

 

-- This ensures my number is 11 digits long 079 + 8 other digits (padded with zeroes at the beginning

'079' + REPLICATE('0', (8 - LEN(@number))) + @number)

Tuesday 1 July 2008

Normal People haven't heard of Live Search

Following on from my last post on "Why do normal people not use Live Search?", I think I might have found the answer. I'm not convinced "non techies" have heard of Live Search. I asked a couple of folks yesterday who don't work in IT. They have heard of Google, they have heard of Yahoo, they have never heard of Live Search.

Now I did surmise yesterday that for normal searches that Google, Yahoo and Live probably return a result set which are similar (or good enough), so these days it doesn't really matter so much which search engine you use (for normal searches). This of course was not always the case hence why most people moved to Google and stuck to it.

So If I was Microsoft how would I tackle Google? I think I might take a leaf out of Apple's book and go for the cool factor. However this requires lots of marketing, imaging and branding (probably still cheaper than buying Yahoo however).

Also I think the stuff that is really great is things like the near real time statistics as part of the results, e.g. if you search for a sports team you get the last result, next game etc. Try and save folks that extra click. I would maybe focus in on that stuff.

I would probably take a 2 prong approach try and convince Techies and Normal folks independently, as the reasons for using Google are very similar (historically) but very different (now). A cool brand is not going to convince techies that they should switch to Live for their technical searches (results matter in this case), just as much as good result sets (unless they are dramatically different i.e. basically a brand new way of doing things) are not going to convince non techies (as the results are generally good enough) so you need to give them something else. I personally think that something else is UX, Image and Brand.

One real opportunity is to make use of the work they did with Tafiti to look at different methods of search.

Silverlight provides a real opportunity to provide a UX that Google will find difficult to compete with. Isolated storage to store previous searches, different visualisations on searches, the list is endless.