.NET

Slides and code for the presentation “An Introduction to Silverlight”

On yesterday’s Scot Alt.NET meeting I held a presentation (An Introduction to Silverlight) that was aimed at providing an overview of Silverlight and looking at some of it’s most important features. Thanks to the about 30 people who’ve attended and given feedback, I hope you’ve found it useful. For those who have missed out I’ll be writing up some follow up blog posts on the same topic.

Slides & code

The slides and code of the talk are available for download:

Cool Silverlight applications

Some interesting links worth looking at (the ones I couldn’t show at the end of the presentation):

Brief summary of the talk

The structure of the talk was the following:
Read More…

My MIX 10K entry – SilverCooler

I’ve entered the MIX 10K competition where the goal is to write an application using no more than 10KBytes of source code in Silverlight. I’ve decided to implement a cocktail selector application – strictly listing alcohol free cocktails only – using the web services I’ve previously built for a popular cocktail site, iCocktail.co.uk.

ICocktail.co.uk was built with Flash using XML services and since Silverlight is indeed as powerful as Flash implementation was quite an ease – my only problem was squishing in the 10K limit (thanks for Colin’s post on some tips on minifying the code). The application I’ve developed is the following:

SilverCooler - Gergely Orosz's entry for MIX 10K

If you like it, please vote for it on its the MIX 10K entry site.

One thing all people noticed when looking at the application at first is the cool “bouncing” effect of the cocktail name. In the flash version this was done by using an EaseOutElastic transition. Not surprisingly Silverlight has similar animation effects as Flash, these are called easing functions. To achieve the bouncing effect I only had to add the following code to the animations changing the width and height of the shape:

DoubleAnimation animation; // The animation changing width or height of the shape popping up
animation.EasingFunction=new ElasticEase(){ Oscillations=3, Springiness=1, EasingMode=EasingMode.EaseOut };

Oh, and if you’re in for some more drinks, check out iCocktail.co.uk as well!

Behaviour Driven Development for .NET developers

On the Scot ALT.NET meeting held on 4th November Robert Lewis gave a talk on BDD explaining the basics, motivations and demonstrating the .NET tools available to support this methodology. I found the talk to be really interesting, mostly because Robert was focusing on the practical side of BDD – that is how .NET developers can use this methodology and at what projects might this be beneficial.

Based on this talk I’ve written a small article on what BDD is, what tools there are out there to use it in the .NET world and how it can help in software projects. Read the article on my ScottLogic blog: Behaviour Driven Development for .NET developers

File Upload in Silverlight – a Simple Solution

Recently I wanted to implement a very simple file upload component in Silverlight that uploads a single file and if possible shows upload progress. Having done some search I’ve found numerous examples but all of them seemed too complex for the simple task of uploading a file so I implemented a really lightweight solution. The source code can be downloaded from here: SimpleFileUpload_v2.zip

Uploading files in Silverlight

Uploading files is quite an easy one in Silverlight: it’s basically just a request made to another server and the file contents are passed in this request. A possible way of implementing this is by using the WebClient class:

private void UploadFile()
{
FileStream _data; // The file stream to be read
string uploadUri;
 
byte[] fileContent = new byte[_data.Length]; // Read the contents of the stream into a byte array
int bytesRead = _data.Read(fileContent, 0, CHUNK_SIZE);
 
WebClient wc = new WebClient();
wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
Uri u = new Uri(uploadUri);
wc.OpenWriteAsync(u, null, new object[] { fileContent, bytesRead }); // Upload the file to the server
}
 
void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) // The upload completed
{
if (e.Error == null)
{
  // Upload completed without error
}

Upload Progress Indicator

The above solution does the job of uploading the file well. However it does not indicate file upload progress at all: when uploading large files or when having slow internet connection this behaviour would be desirable.

Silverlight has no built-in way to monitor the number of bytes sent which means that the only way to indicate upload progress is sending the file to the server in multiple, smaller chunks. Of course this behaviour needs support from the server side as well.

The idea is that multiple calls are made to the server, every call submitting the next chunk of the file. On the server these chunks are appended to the file.

Read More…

NHibernate vs Entity Framework: a performance test

As part of my thesis I measured the performance of some .NET ORM frameworks including NHibernate and Entity Framework. Measuring was done by implementing two simple applications using the same table structure and doing the same operations on the same data.

Note: before reading this article please see my views on comparing ORM tools. Also see the follow up post to this comparison for revised results.

I measured the time it took for each framework to complete these operations:

  • store
  • read over relations
  • read by ID
  • update
  • delete

The results were somewhat interesting. Here is a short summary of what I’ve found out.

Operation \ Number of operations NHiberante – 4K Entity Framework – 4K NHiberante – 40K Entity Framework- 40K Winner
Store 37,37 9,19 1500 98 Entity Framework
Read over relations 1,01 0,54 10,13 4,18 Entity Framework
Read by ID 3,06 25,22 246 230 NHibernate with smaller amount of objects
Update 6,61 7,34 77 72 Both
Delete 3,35 16,76 58 1824 NHibernate

Read on if you’re interested in the details of the performance measurements.

Update: the source code of the program used to measure is now available for download.
Read More…

How to resample images – a simple algorithm

When working with images I sooner or later usually run into the problem of creating thumbnails. Resampling images is not really difficult in the major programming languages however I have not found built-in support for caclulating thumbnail dimensions neither in .NET nor in PHP. And it seems that this made me re-invent the wheel over and over again creating codes with various lengths just for this simple task.

In Sense/Net 6.0, the open source ECMS I am working on I came across the exact same problem: I wanted to resize images, this time on the fly. This time however I decided to do it a bit less complicated as in previous cases and create a clean and simple solution. After a good deal of googling, tutorial reading and planning I came up with a fairly simple and good code snipplet.

Read More…

 Scroll to top