Silverlight Loader Getting Started Guide

Silverlight Loader Getting Started Guide

The Silverlight Loader framework is a simple and light Silverlight framework for creating managed code splash screens, pre-loaders and  loader projects.

It was designed to simplify the creation of such project types and avoid the need to use non managed code.

To use the Silverlight loader framework in your projects you will need to follow 3 simple steps:

Step 1  - Create a new Silverlight loader project or use an existing Silverlight project

The Silverlight Loader framework can be used in 2 ways:

1. Manually add the SilverlightLoader.cs file to your existing project.

    - Download SilverlightLoader.cs to your project's directory.

    - Open your project, choose add existing item and then select the file from step 1.

2. Use the SilverlightLoader template project to instruct Visual studio to create a new Silverlight loader project..

    - Download the Silverlight Loader template file.

    - Copy the file to your Visual studio template directory (Example: My Documents\Visual Studio 2008\ProjectTemplates\Visual C#\) this will add a new project type to your Visual studio project list.

    - Create a new project in Visual studio and choose the new Silverlight Loader template from the project type list.

Step 2 - Implement the ISilverlightLoader interface and set the target sources

A. implement the ISilverlightLoader interface

The Silverlight loader uses an interface called the ISilverlightLoader interface to notify your loader of different events in the loading cycle.

Your code should handle those events to learn of the progress and modify your user interface accordingly.

Below is the definition of the interface:

public interface ISilverlightLoader

{

// init with list of packages to download

void initCallback(List<Uri> packageSourceList);

// called when package download starts

void downloadStartCallback(Uri packageSource);

// called when package download progresses

void downloadProgressCallback(Uri packageSource, DownloadProgressEventArgs eventArgs);

// called when package download is complete

void downloadCompleteCallback(Uri packageSource, DownloadCompleteEventArgs eventArgs);

}

B. Create a starting point where the download is initiated (optional):

Note that this code is generated automatically for you if you use the project template (Step1.2).

private void Application_Startup(object sender, StartupEventArgs e)

{

// create a loader page

MyLoaderPage loader = new MyLoaderPage();

// set the visual root to loader page

this.RootVisual = loader;

// create package download manager and start the download process

PackageDownloadManager pdm = new PackageDownloadManager(loader, e.InitParams, 200);

}

Step 3 - Set your target sources by modifying your html file or your code

The Silverlight loader accepts a list of source Ur'i that will be loaded by the loader.

You can either specify the list in your code or accept it from the built in initParams type called LoaderSourceList.

A. Examples using Silverlight object html initParams to specify which files would be downloaded:

1. Plain html example (Self hosted files, not using streaming):

 <div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightLoader.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="LoaderSourceList=ClientBin/Beegger.xap" />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a></object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
 

2. ASP.NET Silverlight control example (Self hosted files, not using streaming):

 <form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="height:100%;">
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightLoader.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%"
initParameters="LoaderSourceList=ClientBin/Beegger.xap"/>
</div>
</form>
 

3. Microsoft Silverlight Streaming example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:devlive="http://dev.live.com" >
<head>
<title>Silverlight Project Test Page </title>
<script type="text/javascript" src="http://controls.services.live.com/scripts/base/v0.3/live.js"></script>
<script type="text/javascript" src="http://controls.services.live.com/scripts/base/v0.3/controls.js"></script>
</head>
<body>
<devlive:slscontrol
silverlightVersion="2.0"
src="/67180/SilverlightLoader/"
initParams="LoaderSourceList=streaming:/67180/MyTestApp/"

installationMode="popup">
</devlive:slscontrol>
</body>
</html>

B. If you do not wish to use the Silverlight object html initParams method you can manually set the list:

// create package download manager and start the download process

//PackageDownloadManager pdm = new PackageDownloadManager(loader, e.InitParams, 200);

List<Uri> myDownloadList = new List<Uri>();

myDownloadList.Add(new Uri("ClientBin/MyTestApp.xap", UriKind.RelativeOrAbsolute));

ParamUtil.fixRelativeLinks(
ref myDownloadList);

PackageDownloadManager pdm = new PackageDownloadManager(loader, myDownloadList, 200);

-----------------------------------------------------------------------------------------------------------------------------

Important Usage Notes:

-----------------------------------------------------------------------------------------------------------------------------

PackageDownloadManager  class accepts an optional parameter called maxTransferRateKB that will cause the download rate to be simulated and capped by that amount. This is useful for testing because other wise you will need to delete the cache file after each download and you would also find it hard to debug and test your loader. Setting this parameter to 0 would remove the simulation mode and create a real download experience.

Examples:

// create package download manager and start the download process at max of 100KB per sec

PackageDownloadManager pdm =
new PackageDownloadManager(loader, myDownloadList, 100);

// create package download manager and start the download process in real mode -> no cap or simulation

PackageDownloadManager pdm = new PackageDownloadManager(loader, myDownloadList, 0);

-----------------------------------------------------------------------------------------------------------------------------

When your loader is complete and ready to start the primary xap file remember to call XapUtil.setCurrentXapFile(source)

-----------------------------------------------------------------------------------------------------------------------------

This will unload the the loader from the page and cause the package source to become the active xap file on page.
This should be the last loader operation, after that it will start the unload process!

Example:

// called on download complete of each package/file

public void downloadCompleteCallback(Uri packageSource, DownloadCompleteEventArgs e)

{

  // this will unload the the loader from the page and cause the package source to become the active xap file on page

  XapUtil.setCurrentXapFile(packageSource);

}

 

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author

My name is Bacon…James Bacon.

I am an API wars veteran I was wounded by x86 assembly, recovered and moved on to C. I am currently stuck in C++ and sniffing .NET.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

E-mail me Send mail


Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments

Authors

Disclaimer

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

© Copyright 2009

Sign in