Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Azure, PHP, OpenXML, VSTS, ...

About the author

Maarten Balliauw is an MVP ASP.NET and is currently employed as .NET Software Engineer at RealDolmen. His interests are mainly web applications developed in ASP.NET (C#) or PHP.
More about me More about me
Send mail E-mail me


Microsoft Most Valuable Professional - MVP - ASP.NET

Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn RealDolmen - Rock-solid passion for ICT
I'm a speaker at TechDays Belgium and TechDays Finland

Search

Latest Twitter

    Follow me on Twitter...

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

    © Copyright Maarten Balliauw 2010

    Microsoft Web Development Summit 2009

    PHP at Microsoft Being in the US for 2 times in a month (PDC09 and Web Development Summit) is fun, tiring and rewarding. The WDS09 was an invite-only event organized by Microsoft, focusing on interaction between Microsoft and the PHP community. I must say: the event has been helpful and interesting for both parties!

    • The Heathman Hotel in Kirkland is a nice hotel!
    • Traveling towards the US is far more productive than flying back: I did PHPMEF traveling westbound, I crashed (half sleep/half awake) on the eastbound flight…
    • If you just traveled over 26 hours: do NOT go shopping immediately when you arrive home! It’s really frustrating and tiring.
    • Did a session on Windows Azure SDK for PHP, PHPExcel and PHPLinq.
    • Did an interview for the Connected Show
    • Met a lot of people I knew from Twitter and e-mail, and met a lot of new people, both Microsoft and PHP community. Nice to meet you all!
    • Event focus was on feedback between Microsoft and PHP community, overall I think the dialogue was respectful and open and helpful to both parties.

    Standing at the Microsoft logo

    This was actually my first time at the WDS which has been around for 5 years already. The Interop team invited me there, and I want to thank them for doing that: it was a great trip, a great event and I got the chance to meet lots of new people.

    Attendees were mostly people from the PHP community, like Cal Evans, Rafael Doms, Chris Cornutt, Romain Bourdon (WAMP server anyone?), Alison “snipe” Gianotto, … Next to that, lots of Microsoft people came by during various sessions. Some of them even reserved the whole week and were attending all sessions to make sure they were in the feedback loop all the time.

    We’ve seen Microsoft sessions on IIS, Web Platform Installer, Silverlight, SQL Server, Bing, Powershell (sorry, Scott Hanselman, for disturbing your presentation with a tweet :-)). Interesting sessions with some info I did not know. PHP community sessions were also available: Wordpress, Joomla, Drupal, the PHP community perspective, feedback sessions, PHPLinq, PHPExcel, interoperability bridges, … A good mix of content with knowledgeable speakers and good communication between speakers, product groups and audience. Well done!


    Microsoft PDC09 day 2 keynote highlights

    Happiness, pure happiness!

    Day 2 keynote at Microsoft PDC 2009 was quite exciting. To sum things up: Silverlight 4 went beta, IE9 features were previewed, and we got an external hard disk, nicely fitted in a tablet-pc format case. How thoughtful!

    Here’s some of the novelties:

    Silverlight 4 Beta

    This was a good starter… It’s really incredibly feature packed! In my opinion, I think WCF can now be called obsolete as well, but no announcements on that :-) Anyway, here’s a list of new features: webcam access, multicast streaming, offline DRM and output protection, printing, clipboard support, out-of-browser and out-of-sandbox support, drag and drop, implicit styling, a HTML control, rich-text editing, breathe, ability to share assemblies with .NET 4, data binding improvements, udp multicast, REST enhancements, TCP channel support, …

    Also check Tim Heuer’s blog post over at http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx.

    IE9

    Yes, IE9 was announced. Running JavaScript lots faster, passing more of the ACID3 test (still not all), and the coolest part: Direct3D rendering of all graphic content. This was demoed and approved by the audience: everything is so muh faster and smoother!

    WCF RIA Services

    Check out Brad Abrams’ blog for this: http://blogs.msdn.com/brada/archive/2009/11/18/welcome-to-wcf-ria-services-beta.aspx

    Basically a rename of RIA services, and converted to run on top of WCF rather than an own transport layer implementation in previous versions.

    Overall: a great PDC09 day two!


    Categories: C# | Events | General | ICT | Internet | SilverLight

    PHP and Silverlight - DevDays session

    I just returned from The Hague where Kevin and I delivered a session on PHP and Silverlight. As promised, we are putting our slides and demos online. Download the demo code from here: PHP and Silverlight - DevDays.zip (1.00 mb)

    Abstract:

    "So you have an existing PHP application and would like to spice it up with a rich and attractive front-end. Next to Adobe Flex, you can also choose Silverlight as a solution. This session shows you around in Silverlight and shows that PHP and Silverlight can go together easily."

    We really enjoyed DevDays and want to thank everyone who was there (and was in our session while beer drinking seemed more appropriate that time of day).


    Creating an ASP.NET MVC application with Google Gears

    Offline web applications… This term really sounds like 2 different things: offline, no network, and web application, online. Maarten, you speak in riddles man! Let me explain the term…

    You probably have been working with Gmail or Google Docs. One of the features with those web applications is that they provide an “offline mode”, which allows you to access your e-mail and documents locally, when an Internet connection is not available. When a connection is available, those items are synchronized between your PC and the application server. This offline functionality is built using JavaScript and a Google product called Google Gears.

    In this blog post, I will be building a simple notebook application using the ASP.NET MVC framework, and afterwards make it available to be used offline.

    What is this Gears-thingy?

    According to the Google Gears website: Gears is an open source project that enables more powerful web applications, by adding new features to your web browser:

    • Let web applications interact naturally with your desktop
    • Store data locally in a fully-searchable database
    • Run JavaScript in the background to improve performance

    Sounds like a good thing. I always wanted to make a web application that I could use offline, too. After reading the tutorial on Google Gears, I learned some things. Google Gears consists of an offline JavaScript extension framework, installed on your PC, together with a SQLite database. Second, there are some different components built on this client side installation:

    • Factory – An object which enables access to all of the following bullets.
    • Blob – Blob storage, the ability to store anything on the client PC.
    • Database – Yes, a database! Running on the local PC and supporting SQL syntax. Cool!
    • Desktop – Interaction with the client PC’s desktop: you can add a shortcut to your application to the desktop and start menu.
    • Geolocation – Locate the physical position of the client’s PC, based on either GPS, Wifi, GSM or IP address location.
    • HttpRequest – Can be used to simulate AJAX calls to the local client PC.
    • LocalServer – A local web server, which can be used to cache certain pages and make them available offline.
    • Timer – A timer.
    • WorkerPool – A class that can be used to execute asynchronous tasks. Think "threading for JavaScript".

    Picking some components to work with…

    Choices for Google Gears and ASP.NET MVC Have a look at the list of components for Google Gears I listed… Those are a lot of options! I can make an ASP.NET MVC notebook application, and make things available offline in several manners:

    • Read-only offline access: I can use the LocalServer to simply cache all rendered pages for my notes and display these cached pages locally.
    • Synchronized offline access: I can use the Database component of Google Gears to create a local database containing notes and which I can synchronize with the ASP.NET MVC web application.

    Note: Also check the architecture page on Google Gears documentation. It covers some strategies on the latter option.

    Choices… But which to choose? Let’s not decide yet and first build the “online only” version of the application.

    Building the ASP.NET MVC application

    Not too many details, the application is pretty straightforward. It’s a simple ASP.NET MVC web application built on top of a SQL Server database using LINQ to SQL. I’ve used a repository pattern to access this data using a defined interface, so I can easily mock my data context when writing tests (which I will NOT for this blog post, but you know you should).

    The data model is easy: ASP.NET membership tables (aspnet_Users) linked to a table Note, containing title, body and timestamp of last change.

    On the ASP.NET MVC side, I’ve used this repository pattern and LINQ to SQL generated classes using the Add view… menu a lot (check ScottGu’s post on this to see the magic…). Here’s a screenshot of the application:

    image

    Feel free to download the source code of the ASP.NET MVC – only application: GearsForMvcDemo - MVC only.zip (4.12 mb)

    Next steps: deciding the road to follow and implementing it in the ASP.NET MVC application…

    Adding Google Gears support (“go offline”) – Read-only offline access

    Refer to the choices I listed: “I can use the LocalServer to simply cache all rendered pages for my notes and display these cached pages locally.” Let’s try this one!

    The tutorial on Google Gears’ LocalServer states we need a manifest.json file, containing all info related to which pages should be made available offline. Great, but I don’t really want to maintain this. On top of that, offline access will need different files for each user since every user has different notes and so on. Let’s create some helper logic for that!

    Autogenerating the manifest.json class

    Let’s add a new Controller: the GearsController. We will generate a list of urls to cache in here and disguise it as a manifest.json file. Here’s the disguise (to be added in your route table):

    routes.MapRoute(
        "GearsManifest",
        "manifest.json",
        new { controller = "Gears", action = "Index" }
    );

    And here’s (a real short snippet of) the controller, automatically adding a lot of URL’s that I want to be accessible offline. Make sure to download the example code (see further in this post) to view the complete GearsController class.

    List<object> urls = new List<object>();

    // … add urls …

    // Create manifest
    return Json(new
    {
        betaManifestVersion = 1,
        version = "GearsForMvcDemo_0_1_0",
        entries = urls
    });

    The goodness of ASP.NET MVC! A manifest is built using JSON, and ASP.NET MVC plays along returning that from an object tree.

    Going offline…

    Next step: going offline! The tutorial I mentioned before contains some example files on how to do this. We need gears_init.js to set up the Google Gears environment. Check! We also need a JavaScript file setting up the local instance, caching data. Some development and… here it is: demo_offline.js.

    This demo_offline.js script is built using jQuery and Google Gears code. Let’s step trough a small part, make sure to download the example code (see further in this post) to view the complete file contents.

    // Bootstrapper (page load)
    $(function() {
        // Check for Google Gears. If it is not present,
        // remove the "Go offline" link.
        if (!window.google || !google.gears) {
            // Google Gears not present...
            $("#goOffline").hide();
        } else {
            // Initialize Google Gears
            if (google.gears.factory.hasPermission)
                initGears();

            // Offline cache available?
            if (!google.gears.factory.hasPermission || (store != null && !store.currentVersion)) {
                // Wire up Google Gears
                $("#goOffline").click(function(e) {
                    // Create store
                    initGears();
                    createStore();

                    // Prevent default behaviour
                    e.preventDefault();
                });
            } else {
                // Check if we are online...
                checkOnline(function(isOnline) {
                    if (isOnline) {
                        // Refresh data!
                        updateStore();
                    } else {
                        // Make sure "Edit" and "Create" are disabled
                        $("a").each(function(index, item) {
                            if ($(item).text() == "Edit" || $(item).text() == "Create New") {
                                $(item).attr('disabled', true);
                                $(item).click(function(e) {
                                    e.preventDefault();
                                });
                            }
                        });
                    }
                });

                // Provide "Clear cache" function
                $("#goOffline").text("Clear offline cache...").click(function(e) {
                    // Remove store
                    removeStore();
                    window.location.reload();

                    // Prevent default behaviour
                    e.preventDefault();
                });
            }
        }
    });

    What we are doing here is checking if Google gears has permisison to store data from this site on the local PC. If so, it is initialized. Next, we check if we already have something cached. If not, we wire up some code for the “Go offline” link, which will trigger the creation of a local cache on click. If we already have a cache, let’s do things different…

    First, we call a simple method on the GearsController class (abstarcted in the checkOnline JavaScript function), checking if we can reach the server. If so, we assume we are online and ask Google Gears to check for updated contents. We always want the latest notes available! However, if this function says we are offline, we look for al links stating “Edit” or “Create New” on the current page and disable them. Read-only we said, so we are not caching “Edit” pages anyway. This is just cosmetics to make sure users will not see browser errors when clicking “Edit”.

     Going offline!

    Conlusion for this approach

    This approach is quite easy. It’s actually instructing Google Gears to cache some stuff periodically, backed up by an “is online” checker in the ASP.NET MVC application. This approach does feel cheap… I’m just creating local copies of all my rendered pages, probably consuming too much disk space and probably putting too much load on the server in the update checks.

    Want to download and play? Here it is: GearsForMvcDemo - Offline copy.zip (4.11 mb)

    Adding Google Gears support (“go offline”) – Synchronized offline access

    In the first approach, I concluded that I was consuming too much resources, both on client and server, to check for updates. Not good! Let’s try the second approach: “I can use the Database component of Google Gears to create a local database containing notes and which I can synchronize with the ASP.NET MVC web application.”

    What needs to be done:

    • Keep the approach described above: we will still have to download some files to the local client PC. The UI will have to be available. Not that we will have to download all note details pages, but we want the UI to be available locally.
    • Add some more JavaScript: we should be able to access all data using JSON (as an extra alternative to just providing web-based views that the user can work with).
    • The above JavaScript should be extended: we need offline copies of that data, preferably stored in the Google Gears local database.
    • And yet: more JavaScript: a synchronization should occur between the local database and the data on the application server.

    Ideally, this should look like the following, having a JavaScript based data layer available:

    Google Gears Reference Architecture

    Due to a lack of time, I will not be implementing this version currently. But hey, here's a nice blog post that should help you with this option: .NET on Gears: A Tutorial

    Conlusion for this approach

    The concept of this approach is still easy, but requires you to write a lot of JavaScript. However, due to the fact that you are only synchronizing some basic UI stuff and JSON data, local and server resources are utilized far less than in the first approach I took.

    Conclusion

    The concept of Google Gears is great! But I seriously think this kind of stuff should be available in EVERY browser, natively, and with the same API across different browsers. Storing data locally may bring more speed to your application, due to more advanced caching of UI elements as well as data. The fact that it also enables you to access your application offline makes it ideal for building web applications where connectivity is not always guaranteed. Think mobile workers, sales people, ..., all traveling with a local web application. Not to forget: Gears is currently also available for Windows Mobile 5 and 6, which means that ultra-mobile people can run your web application offline on their handheld device! No need for specific software for them!

    By the way, also check this: .NET on Gears: A Tutorial. Interested in Silverlight on Gears? It has been done!

    kick it on DotNetKicks.com


    CarTrackr - Sample ASP.NET MVC application

    CarTrackr - Sample ASP.NET MVC application Some people may have already noticed the link in my VISUG session blog post, but for those who didn't... I've released my sample application CarTrackr on CodePlex.

    CarTrackr is a sample application for the ASP.NET MVC framework using the repository pattern and dependency injection using the Unity application block. It was written for various demos in presentations done by Maarten Balliauw.

    CarTrackr is an online software application designed to help you understand and track your fuel usage and kilometers driven.

    You will have a record on when you filled up on fuel, how many kilometers you got in a given tank, how much you spent and how much liters of fuel you are using per 100 kilometer.

    CarTrackr will enable you to improve your fuel economy and save money as well as conserve fuel. Fuel economy and conservation is becoming an important way to control your finances with the current high price.

    Go get the source code for CarTrackr on CodePlex! (note that it has been updated for ASP.NET MVC beta 1)

    Technologies and techniques used

    Here's a list of technologies and techniques used:

    • CarTrackr uses the Unity application block to provide dependency injection
    • The repository design pattern is used for building a flexible data layer
    • Controllers are instantiated by using a custom ASP.NET MVC ControllerBuilder, which uses Unity for dependency resolving
    • The testing project makes use of Moq to mock out parts of the ASP.NET runtime
    • Form validation is included on most forms, leveraging the ViewData.ModelState class
    • It is possible to sign in using OpenID, for which the ASP.NET MVC Membership starter kit was used
    • LinqToSQL is used as the persistence layer
    • CarTrackr uses my ASP.NET MVC sitemap provider
    • Configuration Section Designer was used to create a custom configuration section
    • Extension methods are created for including Silverlight charts (rendered with Visifire)
    • Web 2.0 logo creator was used to generate a classy logo

    kick it on DotNetKicks.com


    Heroes happen here - Microsoft TechDays 2008 in Belgium

    Microsoft TechDays 2008

    Dolmen polo Just to inform you: together with a numer of colleagues from Dolmen, I'll be attending the Microsoft TechDays 2008 in Ghent, Belgium on 12 and 13 March 2008. Want to spot me, Joris, Jeroen, Danny, ... and meet in person? Search for one of the guys in a Dolmen shirt!

    Update 17/03/2008: Jeroen posted an overview of the inspiring sessions on his blog. 


    OpenXML + Silverlight 2.0 = cool!

    Mix '08 announced some nice things, among them the release of Silverlight 2.0 (beta), ASP.NET MVC framework (CTP 2). This morning, I saw one very cool thing in my RSS reader: TextGlow.

    TextGlow is James Newton-King's newest exciting project which basically combines Silverlight 2.0 and OpenXML into a fancy web-based Word 2007 document viewer. Think about combining this with my own Word 2007 document preview handler...

    TextGlow Silverlight OpenXML

    kick it on DotNetKicks.com


    Microsoft Tafiti just released

    I'm sure you have already heared of SilverLight before, right? If not: it's Microsoft's answer to Adobe Flash, providing the same features + XAML-like markup + easier databinding + ... Now you're up to date: the Redmond people have just released a new site, Microsoft Tafiti, which is basically Live Search combined with a rich SilverLight interface. Tafiti means "do research" in Swahili. Don't think I'm a native Swahili speaker though, I found this here 8-)

    The screenshot I made was first rendered in FireFox. No need to worry your SilverLight application not going to work on other systems than Windows + IE!

    If this is the way the web is evolving, I like it! Slick graphics, but not the "feeling" you are working in a browser plugin.