Silverlight + Google Gears = Awesome! at least in Firefox

I spent most of the week prototyping some things in Silverlight. I figured during the holiday week most people out there goofed off on their jobs a lot this week, so rather than work on my roadmap priorities, I decided to have some fun and play with Silverlight.

Some of you who have followed my blog for a while may remember some posts I made in the past about my plans for Site Office as a second plug in model for mojoPortal more geared to line of business apps that need a consistent look and feel rather than the web site kind of look, they need to look like applications. I originally protyped the UI using Dojo and then later re-did it with ExtJs. You can see the ExtJs version if you login to this site (or http://demo.mojoportal.com using admin@admin.com and password admin), then click the Site Office link at the top. You'll see the drag resizable panes that give the idea of where I wanted to go with Site Office as a UI for LOB applications. This prototype has just been sitting there without much attention because of other priorities and also partly because my enthusiasm for ExtJs disappeared when they changed the license from LGPL to GPL. Anyway, even back then I implemented a google gears query tool. Its really the only functioning app in the old Site Office prototype, you can find it by clicking the My Stuff in the left accordian menu in Site Office and then click SQL. For those who don't know, google gears is a client side SQL database built on SQLite and having this database available opens a lot of possibilities in web development for very rich and responsive applications.

Well, now my plan is to scrap the old ExtJs based Site Office prototype and build a better one with Silverlight. I've already got the Google Gears Query Tool re-implemented in Silverlight as shown below:

silverlight google gears query tool ascreenshot

I wrote a nice managed code wrapper around the javscript calls for gears. The only problem is, it doesn't work well in IE 7 for some reason, it works great in Firefox. I've sent an email off to Scott Guthrie at Microsoft in hopes of some help looking into the problem, but for now you can try it out online at http://demo.mojoportal.com/Index.aspx, you can see that I've got the basic layout of Site Office again implemented in Silverlight with the drag re-sizable panes. I plan to build a plug in model that allows you to plugin your own Silverlight applets and let the framework provide stuff thats common across applications. If I can get google gears working well across browsers with Silverlight its really going to be sweet. The code for this is in my svn sandbox and will probably land in trunk sometime next week.

Now using the managed gears wrapper can be seen in this client side business/data class, it looks very much like a server side class but its a client side object populated from a client side database in a very similar fashion to what it would look like in server side code. Notice the parametrized queries to prevent sql injection attacks. This class represents a saved query but it could represent anything.

using System;


namespace mojoPortal.Silverlight.Helpers.Gears
{
   
    public class SavedQuery
    {
        public SavedQuery()
        {}

        private int id = -1;
        private string name = string.Empty;
        private string query = string.Empty;

        public int Id
        {
            get { return id; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public string Query
        {
            get { return query; }
            set { query = value; }
        }

        public void Save(GearsDb gearsDb)
        {
            if (id == -1) { Create(gearsDb); return; }

            Update(gearsDb);
        }

        private void Create(GearsDb gearsDb)
        {
            if (gearsDb == null) { return; }

            string sqlCommand = "insert into savedqueries (name, query) values (?, ?)";
            object[] parameters = new object[2];
            parameters.SetValue(name, 0);
            parameters.SetValue(query, 1);
            gearsDb.Execute(sqlCommand, parameters);
            id = gearsDb.LastInsertRowId();

        }

        private bool Update(GearsDb gearsDb)
        {
            if (gearsDb == null) { return false; }

            string sqlCommand = "update savedqueries set name = ?, query = ? where id = ?";
            object[] parameters = new object[3];
            parameters.SetValue(name, 0);
            parameters.SetValue(query, 1);
            parameters.SetValue(id, 2);
            gearsDb.Execute(sqlCommand, parameters);
            int rowsAffected = gearsDb.RowsAffected();
            return (rowsAffected > 0);
        }

        public static SavedQuery GetQuery(GearsDb gearsDb, int id)
        {
            if (gearsDb == null) { return null; }
            string sqlCommand = "select * from savedqueries where id = ?";
            object[] parameters = new object[1];
            parameters.SetValue(id, 0);
            GearsResultSet rs = new GearsResultSet(gearsDb.Execute(sqlCommand, parameters));

            SavedQuery query = null;
            if (rs.IsValidRow())
            {
                query = new SavedQuery();
                query.id = Convert.ToInt32(rs.GetFieldValue("id"));
                query.name = rs.GetFieldValue("name").ToString();
                query.query = rs.GetFieldValue("query").ToString();
            }
            rs.Close();

            return query;
        }

        public static SavedQuery GetQuery(GearsDb gearsDb, string name)
        {
            if (gearsDb == null) { return null; }

            string sqlCommand = "select * from savedqueries where name = ?";
            object[] parameters = new object[1];
            parameters.SetValue(name, 0);
            GearsResultSet rs = new GearsResultSet(gearsDb.Execute(sqlCommand, parameters));

            SavedQuery query = null;
            if (rs.IsValidRow())
            {
                query = new SavedQuery();
                query.id = Convert.ToInt32(rs.GetFieldValue("id"));
                query.name = rs.GetFieldValue("name").ToString();
                query.query = rs.GetFieldValue("query").ToString();
            }
            rs.Close();

            return query;
        }

        public static bool Delete(GearsDb gearsDb, int id)
        {
            if (gearsDb == null) { return false; }
            string sqlCommand = "delete from savedqueries where id = ?";
            object[] parameters = new object[1];
            parameters.SetValue(id, 0);
            gearsDb.Execute(sqlCommand, parameters);
            int rowsAffected = gearsDb.RowsAffected();
            return (rowsAffected > 0);

        }

    }
}

Update 2008-12-23

I have narrowed down the problem with IE and use of Google Gears in Silverlight. All the Gears functionality works except for 2 methods. The 2 methods broken in IE are GearsResultSet.GetFieldName(int fieldIndex) and GearsResultSet.GetFieldValue(int fieldIndex). I can get the field value if I know the field name ahead of time using GearsResultSet.GetFieldValue(string fieldName), so for most applications I should still be able to use Gears even in IE because my field names will be known ahead of time. Unfortunately for the query tool we have no way of knowing what fields will be in the result of ad hoc queries. So the query tool will only be useful in Firefox, but for other features I should be able to use gears without any trouble and this is very good news. I also have got a few web services talking to Silverlight, so I'm able to authenticate and get user roles. These services are actually built into the framework so I didn't have to implement them. I am working on some RESTful web services using the WCF REST Starter Kit.
 

Gravatar Joe Audette is the founder of the mojoPortal project and was the primary developer until February 2017.

Comments

bob

re: Silverlight + Google Gears = Awesome! at least in Firefox

Friday, November 28, 2008 5:20:23 PM

Possibly, ou need to use JQuery instead of ExtJs, the  MIT licence is not a winner in the case?They say it will be used in next MS VS.

Silverlight is in Mac now. So Safari should be compatable too.

But, I don't understand why there's a need to use Silverlight in very features?

 

unknown

re: Silverlight + Google Gears = Awesome! at least in Firefox

Friday, November 28, 2008 5:21:40 PM

But, I don't understand why there's a need to use Silverlight in very simple features?

re: Silverlight + Google Gears = Awesome! at least in Firefox

Saturday, November 29, 2008 12:01:20 AM

Why use .NET/Mono to write applications?  Why not stick with C?  Or Assembly?  You use these higher level tools because they are easier and provide more productivity.  Even with jQuery, you still have to deal with CSS differences.  Most Silverlight controls that I've written just work in IE, FireFox, and Safari (both Mac and Win).  The last major HTML app that I wrote, it took 3 weeks to tweak the CSS to be just right on every browser.  I'd rather spend those 3 weeks actually writing real code.

re: Silverlight + Google Gears = Awesome! at least in Firefox

Saturday, November 29, 2008 5:34:26 AM

I agree with Justin, at least for LOB type applications. Silverlight is an awesome development platform. Its will be cross platform because of Moonlight. I've only been playing with Silverlight for a week and I'm in love with it as a platform.

I think there is a difference between the public facing part of the site and LOB application framework. For the public facing things, I'm more concerned about the ubiquity of the plugin than I am on the LOB side of the house. For LOB apps I think generally we have more ability to require the plugin. For strangers that visit the front door, (ie the public facing site) I won't assume the have the Silverlight plugin and for now will limit use of Silverlight as additive to exisiting html/ajax functionality. Whereas in LOB aapplications I want to build full screen apps that look and feel like desktops apps.

Silverlight gives amazing power for that and its much easier to create very rich experiences without having to do the cross browser voodoo dance with javascript and CSS. I've been interested in Flash UI for years but its just never been something I could grok very well so its never really come together. Silverlight makes me feel at home, there are things to learn but there is a lot that I already know because I know .NET well. I think Silverlight will be the RIA framework of the future and I would rather invest my time building tomorrow's applications than tomorrow's legacy applications. I'm betting with Microsoft that this plugin will become ubiquitous, by making compelling apps with Silverlight I will do my part to help that happen, and I have a feeling that a lot of ASP.NET developers will do the same. But, I acknowledge its not ubiquitous yet and for this reason I would use it judiciously on public facing web where I'm trying to connect with strangers. I mean I'd love to have the power of Silverlight in the mojoPortal WebStore feature, but I'm not going to take the risk of lost sales by requiring this plugin to complete a purchase.

I agree with Bob, that for anything where I would use ExtJs in the past I will probably try and use jQuery UI or YUI in the future.

Best,

Joe

re: Silverlight + Google Gears = Awesome! at least in Firefox

Saturday, November 29, 2008 10:23:58 AM

Did you use Visual Studio or write the XAML by hand?  I'm interested in Silverlight, but really can't imagine doing it without a XAML designer;  which so far I haven't been able to find.  I do most of my development with Monodevelop (Gtk# apps).

re: Silverlight + Google Gears = Awesome! at least in Firefox

Saturday, November 29, 2008 10:33:34 AM

Hi Adam,

Yes, of course I have VS 2008 and couldn't yet live without it for productivity. I am not trying Silverlight development on Mono yet. I can build the main mojoPortal projects on linux using MonoDevelop, but I don't do that for day to day development because its more productinve to use VS 2008.

I do look forward to the day when MonoDevelop can do all these things and especially when you can step through the code.

Best,

Joe

bob

re: Silverlight + Google Gears = Awesome! at least in Firefox

Sunday, November 30, 2008 7:59:45 PM

I don't attack Silverlight ;-) I've written:  to use Silverlight in very simple features. Are there any plans to turn mojoPortal into a sort of flash-portal? :-) But as for an e-commerce feature, I think it will be very useful as a superb presentation medium. It's possibly wise to move in the direction right now. But at the moment I can see finicky build system in current Mono 2.0.1 and a lot of bugs in it. I can't even compile it with moonlight flag - it leads to unexpected bugs.   

re: Silverlight + Google Gears = Awesome! at least in Firefox

Tuesday, December 2, 2008 5:06:08 AM

Hi Bob,

There are no plans to turn mojoPortal into a Flash portal or a Silverlight portal. The main content management system will remain ASP.NET producing html. It is possible now to use Silverlight within custom modules or controls, but I won't be doing much of that in the near term.

SiteOffice will be implemented as Silverlight UI against RESTful web services and leveraging the mojoportal web infratructure. It will have its own plug-in system for developers to plugin custom silverlight features. It will be ideal for LOB applications. I think it will be more clear once I have implemented the framework and a few features in it.

My concerns for the moment about Mono is just not breaking existing functionality in the main web features of mojoPortal, so my strategy is just to leave out things that don't work from the MonoDevelop solution. As these things become available in Mono we will update to include them. I would not expect to be able to develop Silverlight 2.0 apps efficiently on Mono for a while yet, but those of us working on Windows with VS can moe forward.

Best,

Joe

re: Silverlight + Google Gears = Awesome! at least in Firefox

Thursday, February 12, 2009 9:58:09 AM

ty man nice homepage,

Why use .NET/Mono to write applications? Why not stick with C? Or Assembly? You use these higher level tools because they are easier and provide more productivity. Even with jQuery, you still have to deal with CSS differences. Most Silverlight controls that I've written just work in IE, FireFox, and Safari (both Mac and Win). The last major HTML app that I wrote, it took 3 weeks to tweak the CSS to be just right on every browser. I'd rather spend those 3 weeks actually writing real code.

re: Silverlight + Google Gears = Awesome! at least in Firefox

Thursday, February 12, 2009 9:59:11 AM

ty man nice homepage,

Why use .NET/Mono to write applications? Why not stick with C? Or Assembly? You use these higher level tools because they are easier and provide more productivity. Even with jQuery, you still have to deal with CSS differences.

Comments are closed on this post.