I have a simple app called “OnDemandApp”. This app uses an assembly “OnDemandLibrary”. This library has set of resources (in this sample that is a WMV file that is about 16 MBs). Application is pretty simple as all it does is pulls out the WMV out of the assembly and plays the video. Though there are other ways to solve the video problem, that seemed to be the easiest way for me to make the assembly big to make sense to use on-demand download.
I created a sample project and only things I have changed are as follows.
<UserControl x:Class="OnDemandApp.Page" xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <StackPanel x:Name="LayoutRoot" Background="White"> <Button Name="btndownload" Height="20" Content="Download" Click="Button_Click"/> </StackPanel> </UserControl>
This code is pretty straightforward…
- Application.GetResourceStream is the function, I can use to pull out streams for the resources from the assemblies, in this case that is vihan.wmv
- I set the source of the media element to be that stream.
- I add the media element on the stackpanel
- I call play so that video playes
Now to create on demand experience for the big DLLs here is what changed in the Page.xaml.cs
- In this case, this assembly is not part of the package but deployed as loose assembly on the webserver next to Xap (app package).
- On button Click, I created a WebClient to download the DLL
- On OpenReadCompleted Event, I load the stream that webclient returned into and assemblypart.
- Use AssemblyPart.Load method to load the assembly from stream.
- Now, PlayMedia method can use the video embedded in that assembly
you can also build actual progress UI using DownloadProgressChanged event on webclient.