IsolatedStorage in Siverlight 2 Beta 1

Tue, April 15, 2008, 01:49 AM under Silverlight
Silverlight applications can store data (in files) onto the user's machine via the good old Isolated Storage mechanism. The API and restrictions of Isolated Storage are slightly tweaked in the Silverlight framework. Let's explore that.

Background Research
On both the full (aka desktop) framework and the Silverlight framework the implementation resides in mscorlib.dll and specifically the System.IO.IsolatedStorage namespace. On the desktop framework the classes in there are shown on the following class diagram (with the 2 most interesting classes collapsed for exploration later):

Note that in the Silverlight implementation there is no base abstract class IsolatedStorage as on the desktop or INormalizeForIsolatedStorage interface or IsolatedStorageScope enumeration. If you explore the desktop capabilities following the links above and relate them to Silverlight's restrictions you'll see why that is – I will not explore that in this post. Also note that the IsolatedStorageException class is available in Silverlight.

On the flip side, when looking in the namespace in the Silvelright version of mscorlib we additionally find the IsolatedStorageSecurityOptions enumeration that is only used by the other new type in the namespace: the IsolatedStorageSecurityState class which itself is not used or exposed publically by anything AFAICT! So basically, just ignore these two types for now as I can only presume that someone forgot to mark them as internal.

Using It
So back to looking at useful classes, and we are left with the 2 that exist in both variants (that are collapsed on the diagram further above): IsolatedStorageFile and IsolatedStorageFileStream. If you follow the links to the Silverlight documentation for those you'll find some differences compared to the desktop version and maybe the eagle-eyed among you can spot them in the following list of methods:

The IsolatedStorageFileStream class is the same as the desktop version but it omits 5 overloads of the constructor (the ones that have a bufferSize option and the ones that do not have the IsolatedStorageFile argument). The IsolatedStorageFile class has 12 static methods removed (the GetXXX methods except one) and also adds 10 members of its own (I have marked these with an asterisk * in the screenshot above).

OK, enough of API spelunking; how do you use this thing? That's the easiest part as you just follow the pattern of:

1. Obtaining an IsolatedStorageFile (e.g. via the static method GetUserStoreForApplication)
2. Creating an IsolatedStorageFileStream object passing it in the reference from step one
3. Creating a normal System.IO. StreamWriter or StreamReader passing it in the reference from step two
4. Using the Stream to read or write as per usual.

I have a basic SL app that uses iso storage here so have a play by entering some text/values and close/reopen the browser to see them remembered. To look at the code, follow the steps here. To browse on your local machine to the storage, paste this in your windows explorer (and drill in to find a moth file and a _LocalSettings):
%userprofile%\AppData\LocalLow\Microsoft\Silverlight\is

Wait, There Is More
What other things must you know? There is a default disc quota that Silverlight apps have and your app can request an increase (IncreaseQuotaTo) from the user, but only from the UI thread. There is a good explanation of that and more here. You may also be thinking what type of data you should be storing in iso storage (e.g. things that the browser caches anyway are not good candidates) and Chris has some opinions here (even if some of his facts are outdated).

In addition to all of the above, Silverlight adds a unique class (no equivalent on the desktop yet) that makes it easy to store application settings in isolated store: System.IO.IsolatedStorage.ApplicationSettings in System.Windows.dll. There are examples of its usage here and here (and I also use it in my basic sample above). If you are the decompiling type, look through reflector at the class's Save method to see how it uses the lower level APIs discussed further above combined with a MemoryStream ;-)

Silverlight 2 Beta 1 Assemblies and Namespaces – Part 1

Mon, April 14, 2008, 01:03 AM under Silverlight
One of the big things about Silverlight 2 is that it is "just .NET", but in the (cross)browser and cross-platform world. "Just .NET" means that we can use the same programming language (e.g. C# 3.0 or VB9), the same tool (i.e. Visual Studio 2008) and we can expect the same services from a runtime (i.e. the CLR). It also means that the libraries available should have some parity (e.g. compatible subset) with the .NET Framework 3.5 libraries that we are already familiar with. So I thought I'd explore the managed assemblies in Silverlight 2 Beta 1 from a high level.

First we browse to %ProgramFiles%\Microsoft Silverlight\2.0.30226.2\ and there is the full list of what is part of the runtime package that is installed on users' machines when they install the plugin (note the size of each assembly that gives an indication of the number of members in there):


In addition to those assemblies above, currently there are some additional ones that you can choose to reference and deploy with your Silverlight application (i.e. in the XAP). You currently get these when you download the Silverlight SDK:

Notable in the list above are the 3 highlighted assemblies that include controls. I would expect that some of the assemblies currently in the SDK folder would become part of the main list further up. Also note the interesting System.Xml.Linq.dll and all the support for dynamic languages.

In future posts, I will write a paragraph for each one of the assemblies comparing them to their desktop counterparts as applicable.

Introducing the ADO.NET Entity Framework

Sun, April 13, 2008, 02:55 AM under Links
Occasionally people will ask me why I don't blog about some of the new data technologies. The answer is simple: my colleague MikeT (aka internally as Data Boy) owns that space. So who better to ask to write a relevant article for the MSDN Flash that went out 10 days ago. Read his great 500-word introduction to the Entity Framework here (scroll down).

Tech Ed Israel – Best conference party ever?

Sun, April 13, 2008, 02:46 AM under Events
I am back from my travels, and if you attended my 2 talks at Tech Ed Israel 2008 you'll find resources for them here and here.

With that out of the way, let me say that I have never ever been to a conference/geek party that even came close to what we experienced in Eilat! After consuming great food (starting at 20:30-21:00), as the night progressed, it was indistinguishable from a high quality commercial club night or a rock gig (dependent on which live band was on stage). Everyone was drunk (open bar all night), everyone was dancing and... unlike most geek parties, there were as many women as men in attendance. I stayed until the end and it was still kicking (02:35 in the morning). If you live in Israel then you owe it to yourself to attend Tech Ed Israel 2010 and if you are on the international speaker circuit try to get invited. I will let the pictures from the party convince you or maybe the video footage ;-)

Spending my life in Airports and Planes

Tue, April 1, 2008, 02:15 PM under Random
On the day of my last 3 posts, I flew to Seattle (10 hours each way) for a quick 3 night trip. Upon my return to UK, it was only a day of catch up before travelling to my hometown in Thessaloniki (Greece). After a day of rest I took the internal flight to Athens for the Greek 2008 Launch. For anyone that attended my session, the videos I mentioned are here. There was also brief mention of Parallel LINQ on the day, and my related video(s) can be found here. After flying back to Thessaloniki for a day of rest, I fly tomorrow to the UK and then a day later I fly for a 5-day trip to Israel for Tech Ed 2008 (which also includes 2 internal flights between Tel Aviv and Eilat)...phew.

There will be more activity here after that – talk to you then.

Positioning the ASP.NET MVC Framework

Thu, March 20, 2008, 07:19 PM under Links
In the latest issue of the MSDN Flash, ScottHa wrote an article that, in my opinion, perfectly positions the ASP.NET MVC Framework. Read the 500 words here (scroll down).

UK 2008 Launch resources

Thu, March 20, 2008, 07:13 PM under Events | Orcas
On Wednesday we had the 1-day free multi-track event in the UK to celebrate the launch of Visual Studio 2008, Windows Server 2008 and SQL Server 2008.

The Windows and SQL tracks basically took the identical slides/demos from the US launch and found local speakers to deliver them. The benefit of that is that the content is not a million miles from the UK Virtual Launch site (which has the US recordings).

For the Visual Studio track I specified session titles and abstracts for 8 complementary developer sessions and "recruited" top speakers to deliver it. If you were there and need to contact the speakers for resources here are links for finding them: Guy Smith-Ferrier, David Gristwood, Andy Wigley, Michael McClary, James O'Neill, Amanda Silver, Mike Taulty, Mike Ormond and mine.

Five VS2008 Smart Client features

Thu, March 20, 2008, 07:10 PM under dotNET | Orcas | VisualStudio
I have created a Smart Client session that I am repeating at various events and it is basically 5 demos. If you attended that session and heard me refer to my blog for more detailed videos of the 5 things, then please find the list below:

1. WPF and WinForms Interop: blog, screencast.
2. Managed AddIn Framework: blog, screencast and code.
3. Client Application Services: blog, screencast and code.
4. ADO.NET Sync Services v1.0: blog, screencast and code.
5. VSTO v3.0: blog and screencasts.

In addition to those links, when people ask me about other Visual Studio 2008 resources I always point them to the Top 10 and they are happy so hope you are too :)

DDS: attend my Parallel Extensions talk

Mon, March 17, 2008, 04:02 AM under Events
There is a great agenda of sessions for the Scottish Developer Day (DDS) in May and I hope you'll choose to come to my session on Parallel Extensions. Register here.

Use of Silverlight at Tech Ed US site

Mon, March 17, 2008, 03:59 AM under Events
Tech Ed in Orlando is in June and I have a couple of sessions there (more on that nearer to the time). I like how they used Silverlight 2 to list the speakers (although the z-ordering is not as accurate as I was expecting it). Give it a go, have a play.