![]() |
Web Development »
Silverlight »
HowTo
Intermediate
License: The Code Project Open License (CPOL)
Silverlight on Fly loading (RC0)By TecfieldThis article is about how to manage xap packages at runtime |
C# (C# 1.0, C# 2.0, C# 3.0), ASP.NET, XAML, LINQ, Silverlight, Dev, Design
|
||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
This article is about how to breakdown xap packages at runtime and manage to load them in the most beneficial way ignoring repetitious requests.
In case you are using one Silverlight application for your website, you may be interested in this article. The whole idea behind my code is if I have a huge SL app and all users won't go to all areas and/or not allowed to go some places, it is better to load SL on demand into client machine instead of do it once and in a HUGE XAP package.
I tried to keep usage as simple as possible. There is one key function plus some events and settings need to be done in order to use this code. If you wanted to find out how the system works, you may go through the code. There are some brief comments in code to help you understand it easier.
The followings are libraries need to be referenced:
There are two StringConnections need to be set in Web.Config file
<add name="SilverlightClientBinFolderPath" connectionString="~/ClientBin"/>
<add name="XapInformationManagerMainPagePath" connectionString="AppLoader"/>
The first line defines the relative path of Silverlight's client bin folder on server.
The second line defines the main silverlight application's name. Keep in mind that the main SL app is the main host to load the rest of apps.
In server-side there is an http handler which all requests from silverlight controls come to it.
This HttpHandler just pass all requests to the XapManager:
public const string AppParameter = "ApplicationName";
public const string LibParameter = "LibraryName";
public void ProcessRequest(HttpContext context)
{
string appName = context.Request.Params[AppParameter];
string libName = context.Request.Params[LibParameter];
context.Response.ContentType = "application/octet-stream";
string fileName = XapInformationManager.Current[appName, libName];
context.Response.WriteFile(fileName);
context.Response.Flush();
XapInformationManager.DeleteFileIfRequired(fileName);
}
In client-side, there are two objects you need to use them to get proper results.
AssemblyManager asmManager = new AssemblyManager(App.Current.Host.Source.AbsolutePath);
AssemblyManager's constructor needs an initial strings which is HttpHandler's address to communicate with and send requests to. Once you create a new instance of AssemblyManager, it loads currently loaded libraries into its managed list.
Next step is asking for a page to be rendered. The following is the sample code:
Request request = new Request(applicationName, childPath);
request.OnSucceed += new Request.RequestResponse(OnSucceed);
request.OnFailure +=new Request.RequestResponse(OnFailure);
asmManager.LoadApplication(request);
You will be notified through Request events as soon as request loading finished
OnSucceed: Fires when the request loaded successfully. OnFailure: Fires when the request failed to be completed. Request.Error will contain the reason. applicationName refers to Silverlight Application Name i.e. MyControlchildPath refers to the page path within the application to load i.e. MyControl.Page
Solution and files are changed to be compatible with Silverlight RC0.
There were two ways to get system to work:
I put some more ideas in code for you about how to manage your system and load everything on fly, call on fly, and live on fly :D
I would appreciate any incoming idea or suggestion to improve this system.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 30 Sep 2008 Editor: Chris Maunder |
Copyright 2008 by Tecfield Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |