Archive for the ‘Uncategorized’ Category

h1

Chrome browser is bad for Silverlight Development

April 26, 2009

Today I switched over from IE to Chrome for my Silverlight development. As I did so I realised I lost the ability to debug both my Silverlight project and web server project at the same time. The reason is because the debugging process needs to attach to your browser process. One of chromes great features is that each tab is its own process. This is a problem because it means you can no longer debug your Silverlight applications and web server projects at the same time.

 

Just a quick gotchya that I thought I’d mention..

Advertisements
h1

Silverlight 2.0 and WCF Duplex Service

January 20, 2009

Today I was doing a POC on Silverlight 2.0 and WCF Duplex Services. It seems to be a great alternative to using sockets because of the cleaner and easier programming model. It also has almost the same advantage as socket programming because under the head it uses a sort of ‘smart polling’ where the client sends a request to the server checking for any new events/messages that need to be passed back to the Silverlight client, the connection and hangs around until there is something to send back to the client and does so when the server queues any messages. The max time this connection can stay open before timing out is 90 seconds, at which point another ‘half pole’ if you will happens. Pretty good trade off I must say. There is only one problem with this current solution and that is there is no visual studio support to add service references via the GUI so basically you not only have to generate the proxy client code yourself but you even need to do all the serialization and de-serialization manually! Very tedious, I will be researching for any alternatives in the next few days.

h1

Silverlight 2.0 MVP Architecture

November 6, 2008

I have recently kicked off a new project at work and decided to use Silverlight 2.0 as the technology of choice. Why? Because web 2.0 is dead and RIA is the way of the future. I got the structure of Tim Ross’s blog, he wrote an excellent in depth article with source code. I thought I would also write an article about it but by introducing some of the extra projects that I found necessary and some of the design decisions involved. The rest of this article will give you an idea of how to structure a Silverlight 2.0 application in visual studio 2008 that uses Silverlight WCF enabled services over BasicHttpBinding (the only one currently supported) to communicate with the web server. The separation of concerns pattern that I will be using will be the MVP pattern. I chose this pattern over the MVVM pattern because of two reasons. 1) It has been officially documented on the MSDN site and MVVM at this time of writing hasn’t

2) It has been around for longer than MVVM which was invented by a team of Microsoft guys during the writing of blend and therefore the chances of people knowing it will be higher. Because I’m using an emerging technology, my concerns are that people will already have a big learning curve to conquer and I don’t want to introduce a new(ish) pattern on top of it.

Here is a snip of the solution structure

Client and Server

To start off, we create two solution folders, one named Client and one named Server.

Client

This folder contains 3 projects

SilverlightMvp.View <- The actual SilverlightApplication

SilverlightMvp.Core <- Silverlight Class Library

SilverlightMvp.Core.UnitTests <- Unit tests for the presenters.

The unit test project won’t actually reside on the client machine but it makes more sense to group it in the client folder as it is purely testing the presenters.

Server

This folder contains 5 projects.

Database <- The database

DataAccess <- the CRUD library

Common <- Entities folder (The Model) and ExtensionMethods

SilverlightApplication.Web <- Web Application that hosts the Silverlight application. This has a folder in it called WCFServices which contains the Silverlight enabled WCF services. To add a Silverlight enabled WCF service, select the WebApplication that is hosting your Silverlight project. Right click -> Add -> New File.

This is where you will find the WCF template:

Business <- Business logic that the WCF Services will expose to the Silverlight application (SilverlightMvp.Core)

Tests <- The reason why this project is called Tests is because it will be hosting both my Unit tests and Integration tests. I have created two folders in there named Unit Tests and Integration Tests. Using the dependency injection pattern we ensure mocking the DataAcess Layer will be easy. For my requirements I will not be testing the WCF Services inside the SilverlightApplicaiton.Web projects because they will just expose Business Library methods and have no logic in them at all.

Notes

  • The Client and Server folder structure help enforce the developer to be constantly aware of the fact that the Silverlight application is actually a tiny subset of the .net CLR and therefor is missing a lot of functionality.
  • Because you are using a separate CLR that’s on the clients machine, you cannot point WCF to your existing Model. They must be dynamically generated.
  • Make sure you do all your data retrieval on the web server and pass it down in one hit rather than putting loops in your client service proxy’s retrieving data multiple times and therefore opening pooled database connections. As a general rule of thumb, loops in the presenter or client service making single calls to the database can usually be avoided and can speed things up

Conclusion

Overall I’m happy with the final design of the solution and I’m convinced that it’s the simplest solution that has the right balance of complexity to provide functionality, separation of concerns and maintainability but at the same time, not overly architected to cause Shunting friction

If I wasn’t so busy, I would look into creating a Guidence Automation package for this structure.

I would be very interested to hear comments on the Tests and Unit Test structure and would also love to hear about any alternatives you may have come up with.

h1

Don’t use funny ASCII chars in Application names…

September 12, 2008

Today I found a reason not to be too clever when using application names. Personally, I use the search in vista’s start bar quite a lot. Today I thought it was strange when I attempted to open uTorrent and it wouldn’t come up in the results. The reason is because I typed “uTorrent” which is not that funny looking ASCII u (I don’t even know what alt # that is).

h1

Using T-SQL and the Registry to Retrieve a List of Countries

August 20, 2008

I was catching up on some blog reading tonight when I saw this post. For retrieval purposes, I have made a copy of the post and will keep it for when in use. Thanks Omar!

Using T-SQL and the Registry to Retrieve a List of Countries

So every time I create a SQL script to populate a countries table I end up losing it. So here is proc I decided to keep forever on my blog that retrieves the list of countries from the registry of the machine it’s sitting on. Remember to run it under elevated permissions.

1:
PRINT
‘Building dbo.ListCountryFromRegistry’

2:
IF
EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N‘dbo.ListCountryFromRegistry’) AND OBJECTPROPERTY(id, N‘IsProcedure’) = 1)

3:
BEGIN

4:
DROP
PROC dbo.ListCountryFromRegistry

5:
END

6:
GO

7:
CREATE
PROC dbo.ListCountryFromRegistry

8:
AS

9: –Root Key

10:
DECLARE @RootKey nvarchar(255)

11:
SET @RootKey = ‘HKEY_LOCAL_MACHINE’

12: 

13: –Registry Key
for country list

14:
DECLARE @CountryListKey nvarchar(255)

15:
SET @CountryListKey = ‘SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\Country List\’

16: 

17:Table
to store registry extracts

18:
CREATE
TABLE #RegistryOutput ( countryKey int)

19: 

20:Table
to store registry outputs with rownumbers.

21:
CREATE
TABLE #NumberedRegistryOutput ( rowNumber int, countryKey int)

22: 

23:Get the the list of country nodes under the cuntry list tree

24: INSERT INTO #RegistryOutput EXEC master..xp_regenumkeys @RootKey, @CountryListKey

25: 

26:Add RowNumbers to
use
as indexers later

27: INSERT INTO #NumberedRegistryOutput ( rowNumber, countryKey )

28: (SELECT ROW_NUMBER() OVER(ORDER
BY countryKey), countryKey

29:
FROM #RegistryOutput)

30: 

31: –Grab a counter to
use
in looping through country nodes

32:
DECLARE @Counter int;

33:
SET @Counter = (SELECT
MAX(rowNumber) FROM #NumberedRegistryOutput);

34: 

35:Current
index
to be used to
iterate the countr nodes.

36:
DECLARE @CurrentCountryKey int;

37: 

38:Current Country Registry Key

39:
DECLARE @CountryRegistryKey nvarchar(150)

40: 

41: –Country name returned form registry and
to be added to
output

42:
DECLARE @CountryName nvarchar(255)

43: 

44:Output
table
with Country Names

45:
Create
table #CountryNames ( CountryName nvarchar(255))

46: 

47: –Loop through country nodes

48:
WHILE (@Counter > 0)

49:
BEGIN

50:
SET @Counter = @Counter – 1

51:
SET @CurrentCountryKey = (SELECT countryKey FROM #NumberedRegistryOutput WHERE rowNumber = @Counter)

52:
SET @CountryRegistryKey = @CountryListKey + RTRIM(LTRIM(CAST( @CurrentCountryKey as nvarchar(20))))

53: 

54:
EXEC master..xp_regread

55: @RootKey,

56: @CountryRegistryKey,

57:
‘Name’,

58: @CountryName OUTPUT

59: 

60: Insert #CountryNames VALUES (@CountryName)

61:
END

62: 

63:Output

64:
Select * from #CountryNames ORDER
BY CountryName

65: 

66: –Cleanup

67:
drop
table #RegistryOutput

68:
drop
table #NumberedRegistryOutput

69:
drop
table #CountryNames

70: 

71:
GO

h1

Frustrated and Disappointed.

July 1, 2008

<frustrated rant>

So on Monday night, a project that I have been working on for 3 months goes live. The project it self was very exciting and fun but unfortunately, it was managed very poorly and as a result, had scope creep and was not finished in time. It was not ready to go live yet it was rushed and tightly managed by Business Analysts and IT General Managers to ensure it still went out and made the deadline. Towards the middle of the project I had raised my conerns many times to the relevant business sponsors but it was ignored. Now, the applications launch (although it was reasonably successful) has lost a lot of credability because it keeps erroring. There have been over 1 million hits to the website with about a 60% error rate/unacceptable user experience. They have had an enormous amount of purchases made through the online store but I don’t think they realise (or chose to care) about the fact that those numbers could have been doubled. It is a frustrating feeling when IT Managers don’t choose to accept the advise of IT Professionals around them. I believe it is called micro managing. I strongly believe an Agile environment would solve these issues I have been experiencing as of late.

</frustrated rant>

h1

My Windows Mobile App Idea!

June 18, 2008

So I lost my phone yesterday. I’m going to get a smart phone for my next phone with GPS and this time i’ll create an app so that when it receives a message it scans the content of the message for ‘find me password=xxxx’ and it will then send its gps co-ordinates to a predefined email address and phone number. once I have these I will then be able to track the phone down using another GPS device.

I am looking at getting an IPhone so I may have to learn some non .net language for this…