zaterdag 30 april 2011

Moved and some other stuff

As you may or may not have noticed, I’ve moved the site from blogspot to my own domain name.  This doesn’t change anything accept the fact that the page ranking in google (/ bing? Naaaaah) will drop.  Hopefully I’ll get my ranking up again in a couple of weeks.  I might be adding new content to this site to.  Some examples might include an online Silverlight 5 version or ASP.NET MVC 3 application of the KCalculator we are developing at QFrame.  Not sure which technology to use though and when I’ll have time to invest into the project.

I also promised a small update when I got any news from the Windows Phone 7 Developer account.  Well, it’s not quite there yet.  Qframe is going to talk with Microsoft to see if there are any advantages they can get as a Microsoft Partner.  I hope that I’ll get my hands on a WP7 developer license within the next two or three weeks.

 I’m currently reading a book called ‘the pragmatic programmer’. I picked up reading this after reading some promising reviews about it.  I’m only at the middle but even for being over 10 years old it still very up to date to current software development trends.  A real recommendation for all passionate developers!

Well that was it.  I haven’t posted a technical topic for a few weeks but that will change with the next few post ;)  Till then!

vrijdag 29 april 2011

Save File Dialog has a Filename setter in silverlight 5

In response to an earlier post I made about alternative ways for saving a file in silverlight, I'm glad to announce that Silverlight 5 will have a setter for the SaveFileDialog.

Techdays belgium

This week I went to techdays in Belgium and here is a small wrap-up:

The content was in my opinion less advertising then last year.  This could be because there are fewer technologies in the pipeline this year, but I found it a nice change then the usual: ‘this is our product and it’s the best’ – talks.  The main topics / technologies this year were NuGet, ASP.NET MVC 3, Silverlight, Windows Phone 7 and Windows Azure.  Off course there were also some other talks about the trend of programming languages and sharepoint, but the majority of the talks involved the previous mentioned technologies.

Some of the memorable talks were:

The keynote:
The keynote was given by Scott Hanselman.  I’m normally a big fan off Scott, but I didn’t like the keynote very much.  Normally, they talk about what’s in store in general, but this time it was more off a NuGet and ASP.NET MVC talk which he was going to show in another talk anyway... 

Silverlight, WP7 and some other stuff stirred not blended or whatever…:
The next talk I followed was the ‘Silverlight, windows Phone 7, windows azure, JQuery,… shaken, not stirred’ session.  It was a nice showcase of an existing application but nothing more.  I did not learn anything new, nor was there anything to learn.  The speaker showed us an application in which they’ve used RIA services in combination with Windows Phone 7.  It was nice to see how they’ve also managed to create an ASP.NET MVC frontend and a web UI using JQuery Mobile.

Silverlight 5:
Afterwards I followed the Silverlight 5 talk by Jeff Prosise.  I enjoyed his talk.  Not only is Jeff Prosise a very good speaker, the content he delivered was nice to.  Silverlight 5 seems to contain some very promising features like Markup Extensions, Text Improvements, Databinding enhancements (finally we can use relative binding to ancestortype!)  and some very impressive 3D rendering abilities.  He also demoed how the composition thread works and how it is used.  In all, I enjoyed his talk.

ASP.NET MVC 3 – Deep Dive:
Very nice talk by Hadi Hariri.  It was a bit out of my league because I’m not really that experienced with ASP.NET MVC but still he explained it well.  I laughed out loud when he made the remark: Partial classes is blasphemy …  and so is regions =D. 

NuGet in depth:
Scott Hanselman presented this talk in his usual comical way.  He showed us how to create your own NuGet package in a very original way.  He coded up a class and compiled it using nothing else but a dos prompt.  Immediately the day after I installed NuGet to get to play with it.  I really recommend everyone to use this tool.

Demystifying the .NET asynchronous Programming Landscape:
A talk given by Bart De Smet, a very clever man.  He showed how event driven async operations tend to lead to programmer faulths and showed us how to program asynchronously without the need to radically change your code.  He did this by explaining the new Async and Wait keywords.  I found it a real shame I did not see his Linq to everything talk, but I’m sure to watch it online later.  I encourage people to got to his VISUG talk next week.

Tips and Tricks and Techniques for Building Killer Silverlight Applications:
Another talk by Jeff Proise.  I learned quit a bit in this talk and I’m certain I’ll be able to apply half of it in the project I’m currently assigned to.  The talk was mainly about how to split up your XAP and download assemblies and load them in the appdomain on the fly.  He also showed some pitfalls when doing this (for example the compiler inlining short methods).  I enjoyed the talk and I found it for me to be one of the most educative talks on techdays (mainly because I’m a SL developer).

The other talks I did not follow or weren’t interesting enough to mention.   
Until next time ;)


dinsdag 19 april 2011

Windows Phone 7, I've got one! Yaaaaay me!

I recently got a Windows Phone 7 and wanted to share my thoughts with you on the OS and the phone.  The phone I got is the Samsung Omnia 7.  At first I was thinking of getting the LG optimus 7 but boy am I glad I went for the Samsung.  

The screen is truly superb.  The colors are vivid and even when using the phone in full sunlight the screen is more than readable.  I believe that Samsung uses a special manufacturing process in their Super AMOLED screens to make them more readable in the outdoors.  

Also performance wise this phone is truly amazing.  The 1 GHz processor is more than capable of running the WP7 operating system.  Even when browsing heavy sites, I have yet to see this phone flinch.
The build of the device is also very solid.  The back is made out of aluminum, so the phone feels expensive.  The slider on top of the phone to cover the micro usb port is also good instead of the cheap plug that some devices use.  One negative point this phone has is the power button that is positioned on the side of the screen.  Especially when making a phone call this can be truly irritating.  I only have the phone for five days but I’ve managed to turn it off by accident more than enough.  Also the battery life is pretty disappointing.  When the phone is in use for a full day while using 3g and wifi turned off, the battery is dead empty at the end of the day.

Overall I think Samsung has delivered a really neat device, so what about the OS?

The Samsung Omnia 7 runs the Windows Phone 7 operating system, hence the 7 in Samsu…  never mind. At the beginning it’s a real change from what I was used to (mainly Symbian and Android).  The design is basic but very clean.  I was very skeptic about the tiles on the home screen and I thought all the fuss about it was nothing more than a hype.  Yet I must say that it really is very fun to use and very innovative.  They give you a sense of personalization and interaction.  What does disappoint me is the main menu.  The main menu in Windows Phone 7 is nothing more than a listbox with the datatemplate set to a stackpanel with an image on the left and a textblock on the right.  Ok… I get it, you want to keep it basic, but damn that’s reaaaaaaallyy basic.  Maybe it’s a good thing they kept the games you’ve installed under the Xbox live hub, so the list doesn’t get to long. 

This brings us to the hubs.  Hubs are groupings of data / application.  One good example of this is the peoples hub.  Not only can you view people you know from Windows Live, Facebook, ect.  You can also see their status updated, make phone calles, see their profile, write on their wall, email them.  In essence everything you want to do with a person, you can do in the peoples hub.  Using this concept, I think Microsoft makes WP7 very accessible to users and allows them to distinguish themselves from the competition.  I let my girlfriend play with the phone for 10 minutes (under strict supervision surrounded by white pillows while glued to the chair) and she had no problem navigating and using it.

For business users this OS offers a nice integration with Exchange.  One can synchronize everything from contact to tasks to meetings, but that is more of a requirement than a feature these days.  PDF and office documents are viewable by using either the office hub or adobe pdf reader.
Other applications are available for download using the marketplace.  It is apparent that the marketplace for Windows Phone 7 contains allot less apps than on the IPhone of for Android.  The most obvious apps are their like adobe, youtube, facebook, ect.  But you can’t help it but feel the market place is still a bit empty.  It also strikes me that there are allot of applications available for programmers like a mini ‘C# in the cloud compiler’ or a programmers guide to .NET.  Could this mean that the majority of the WP7 users are .NET developers at this time?   The good thing about a less crowdy marketplace is that the applications that are available are of pretty good quality and you have to filter out less nonsense.  It is also the perfect moment for developers to start Windows Phone 7 development because the competition is less fears then oooh let’s say the app store where It’s a struggle to get you app noticed. 

Conclusion

I’m really glad I’ve got this phone.  I respect the competition but I wouldn’t trade my WP7 phone for any android or apple device out there.  The device and OS is lighting fast and rock solid.  Hopefully this Thursday I get to play with the WP7 developer license and start deploying custom apps to the phone. 
I’ll keep you posted!

donderdag 14 april 2011

Extracting the URI of a page in silverlight

This blogpost that I’m writing is a prequel to another blogpost about best practices in navigation in MVVM.  
I came upon the idea the other day by extracting the URI of a page by its location in the assembly.  This seemed easier than I thought and if anyone knows of a simpeler solution then I implore you to post it.

I searched for any quick fixes like some magic property on the page that would tell me where the XAML is stored inside the assembly, but no luck.  I even decompiled a few pages to see what’s in the InitialiseComponent  and I was deeply surprised that MS has opted for such a weak implementation.  This is what I found:

  Application.LoadComponent(this, new Uri("/MyAssembly;component/Views/MyPage.xaml", UriKind.Relative));

So by judging at how the XAML page is loaded, there is no property or wrapper class that will tell me where the page is stored.

Then while I was browsing the assembly, I noticed that in the assembly.g.resources file is a listing of all the resources in the assembly (hence the name…).   I saw that not only embedded resources are there but also the XAML of your pages.  It is structured by a dictionary that contains a key/value pair of string / memorystream.  So I thought, this should be easy then, I can just read the resourcemanifest and deserialize it …   Microsoft wouldn’t be Microsoft if they didn’t make all the classes you need to do this internal.  So I had to manually get out the pages from the binary data.  Enough gibberish, here is the code:

public class PageUriLocator
{
    public static string GetUri<T>() where T : Page
    {
        var typeName = typeof(T).Name;

        var allXamlFiles = ReadAssemblyResource();

        var fileName = new Regex(@"[[\w]*/]?" + typeName.ToLower() + @"\.xaml");
        return (allXamlFiles.Where(xamlFile => fileName.IsMatch(xamlFile.ToLower()))
                            .Select(xamlFile => xamlFile))
                            .FirstOrDefault();
    }

    private static List<string> ReadAssemblyResource()
    {
        byte[] binaryData = GetResourceInByteArray();
        var fileNames = new List<string>();

        // the first x bytes of the resource stream we are not interested in
        bool start = false;
        for (int i = 0; i < binaryData.Length; i++)
        {
            if (i < binaryData.Length - 255 && i > 0)
            {
                // the first file in the resource stream is app.xaml => it is 00 00 10 in size
                start = start | (binaryData[i] == 0x00 && binaryData[i + 1] == 0x00 && binaryData[i + 2] == 0x10);
                if (start)
                {
                    int length = binaryData[i + 1] + binaryData[i + 2]; // the length is described in the two latter bytes of the 5 stopbytes
                    if (length > 255) return fileNames; // name cannot be longer then 255 characters

                    // assemble the filename
                    string fileName = "";

                    for (int j = 0; j < length; j += 2)
                    {
                        fileName += Convert.ToChar(binaryData[j + i + 3]);
                    }

                    fileNames.Add(fileName);
                    i += length + 4;
                }
            }
        }

        return fileNames;
    }

    private static byte[] GetResourceInByteArray()
    {
        // get the assembly name
        var assemblyName = Assembly.GetExecutingAssembly().FullName.Split(',')[0];

        // a list of resources is saved in an embedded resource file called [AssemblyName].g.resources
        var resourceName = assemblyName + ".g.resources";

        // read binary data from the stream
        var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
        var streamReader = new BinaryReader(resourceStream);
        return streamReader.ReadBytes((int)resourceStream.Length);
    }
}

And the usage:


string whereIsThatDamnPage = PageUriLocator.GetUri<MainPage>();

Have fun with it and till next time.