Advertisment

Running Business Apps Offline

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: We've been looking at creating line of business applications with Silverlight 3 since the past few months. One of the cool new features of Silverlight 3 however is the ability to run an application without viewing it in a Web browser in an Out-of-Browser (OOB) environment. These applications can be 'installed' on the client machine and be run of a shortcut icon.

Advertisment

They open with a normal window rather than being embedded within a browser and have a bunch of other features as well. The advantage with such an approach is that you can go ahead and create a single application that runs both as a web-based application through a browser as well as a standalone application installed on the client machine. For example, you could be creating an LoB application that can be used by end-users (say like a tax form) for submitting their individual information. But the same application can be used in OOB mode to allow CAs to process tax forms.

Enabling OOB support

The first thing to do of course is to enable OOB for the application. In Visual Studio 2008, simply right click the Silverlight project (and not the solution that holds this and the Silverlight Web host application) and go to the properties page. Turn on the 'Enable running application out of the browser' option and click the button next to it. This will allow you to change settings like the window title, the shortcut name, description, icons and also help you use any GPU acceleration if available. Once you do all this, save, compile and run the application which will open in the browser.

You can now ?install? the application by simply right-clicking inside the Silverlight 3 application within the browser and selecting the install option. The window that comes up will allow the user to choose where to put the shortcut icon and also start up the application window. You can reverse the process by right clicking inside the application window and selecting to remove the application.

Advertisment
Turn on the out-of-browser option by checking the 'Enable running app out of browser' option.

 
Advertisment

Installing from interface

Performing the above task may be possible for users who know that this feature is available. However, in most cases you would probably like to inform the user and allow them to install the application through a user interface element like a button or link on the application window itself. For doing this, first add a control to the application ? for instance a HyperlinkButton control like this:

Advertisment

Add a line at the top of the XAML.cs page that declares a variable for the current application instance like this:

Application app = Application.Current;

And then add the event handler for the hyperlink to install the application:

Advertisment
The OOB options let you change settings for the offline application window.

You can also add a number of other validations and even go ahead and change the error message if you wish like these:

private void hlInstall_Click(object sender, RoutedEventArgs e)

Advertisment

{

try

{    app.Install();

Advertisment

}

catch (InvalidOperationException)

{

ChildWindow c = new ChildWindow();    c.Title = "Error!";    c.Content = "The application is already installed.";    c.Show();  }}

This code will try to install the application and give an error message if it's already installed. You can even add the following code to the beginning of the page load to show or hide the hyperlink based on whether the application is already installed or not:

hlInstall.Visibility =  (app.InstallState == InstallState.Installed ?  Visibility.Collapsed: Visibility.Visible);

Auto-updating 'client install'

 

Users can install the application by right clicking inside the browser window.

Here you can see the OOB application window (running outside the browser).

In the 'Install application' window you can choose the folder where you want to install shortcuts.

One of the other things that you can do is automatically update the installed application version on client machines the next time they start up. This can be done by checking the server from where the app was first installed for the version and then if a newer version is available, download and update the application. To do this, you need to use a async call handler. Declare the following code at the startup of the page::

app.CheckAndDownloadUpdateCompleted += new_CheckAndDownloadUpdateCompletedEventHandler(app_CheckAndDownloadUpdateCompleted);

app.CheckAndDownloadUpdateAsync();

The event handler will be this:

void app_CheckAndDownloadUpdateCompleted(  object sender, CheckAndDownloadUpdateCompletedEventArgs e)

 {

if (e.UpdateAvailable)

{

The application will check to see if it's already installed on the client machine.

ChildWindow c = new ChildWindow();

c.Title = "Update";    c.Content = "A new version of this application has been downloaded & installed. \n\nPlease restart the application to see the changes.";

c.Show();

} }

Now whenever the offline application is executed on any client machine, it will quickly check for a new version on the client and download and install that as well as inform the user to start the application again to get the new version.

The OOB application can automatically check and download updates.

There are many other things one can do with the offline client application as well. For instance you can detect the correct network connectivity status  - connected or disconnected ? and based on that either send the data to the server or store it offline in IsolatedStorage and when the network connectivity comes back up, send the data to the server ? all transparently to the user. You can use all of these to improve the LoB application to perform tasks even when the user is offline. Silverlight 3 has a ton of new and enhanced features. We've only taken a tour of the ones specific for creating LoB applications in this series.  So if you're looking at creating rich client experiences with network connectivity, great tools and a familiar programming environment, Silverlight 3 shall prove useful. Hopefully this series has been a good introduction to some of the cool new things you can do with this.

tech-news