Showing posts with label PRISM. Show all posts
Showing posts with label PRISM. Show all posts

Monday, 3 December 2012

Application Library Caching with PRISM

Your main Shell project xap file will reference all your application dependencies with Copy Local = true, which ensures your application has the DLL available.

For each referenced library, if it has been signed and a *.extmap.xml file is found in the same directory as the DLL then a zip file will be created for it in the Web Server ClientBin folder.  If not then the DLL will be be copied directly into the Shell.xap.

All your “Module” project / xap files should reference their dependencies with Copy Local = false.  This will let Visual Studio build each module project xap files but not copy the referenced libraries into the xap.

imageFor example this is the Prism extmap.xml file:

extmap

<?xml version="1.0"?>
<manifest>
<assembly>
<name>Microsoft.Practices.Prism</name>
<version>4.1.0.0</version>
<publickeytoken>31bf3856ad364e35</publickeytoken>
<relpath>Microsoft.Practices.Prism.dll</relpath>
<extension downloadUri="Microsoft.Practices.Prism.zip" />
</assembly>
</manifest>

AppManifest.xaml


This file is contained within each xap file and lets Silverlight know whether dependencies can be found within the xap or externally.


  • The “Deployment.Parts” section contains the libraries with Copy to Local = true.

  • The “Deployment.ExternalParts” section contains libraries with Copy to Local = false.

Note:  When PRISM loads modules it does not automatically download ExternalParts, see here. Here is an example of an AppManifest.xaml file:

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="PivotViewerDemo" EntryPointType="PivotViewerDemo.App" RuntimeVersion="5.0.61118.0">
<Deployment.Parts>
<AssemblyPart x:Name="PivotViewerDemo" Source="PivotViewerDemo.dll" />
<AssemblyPart x:Name="System.Xml.Serialization" Source="System.Xml.Serialization.dll" />
<AssemblyPart x:Name="System.Xml.Linq" Source="System.Xml.Linq.dll" />
</Deployment.Parts>
<Deployment.ExternalParts>
<ExtensionPart Source="System.Windows.Controls.zip" />
<ExtensionPart Source="System.Windows.Controls.Pivot.zip" />
</Deployment.ExternalParts>
</Deployment>

Configuring Silverlight application projects (Xap files)


Don’t forget to switch on application library caching for all your Silverlight applications (Shell and module projects).

image

How to cache your own Silverlight libraries


Simply sign the library (Project > Properties > Signing) by creating a new key file which requires a password then manually create an extmap.xml file:


image


Where to find the extmap.xml files


If you don’t have access to the extmap.xml files just create them yourself. 


You’ll need to know the assembly version number, right click on the file in Windows Explorer, select properties then click the Details tab.


assembly version


To find out the public key token use the sn.exe (strong name) application that comes with Visual Studio:


sn


See earlier in this blog post for an example of an *.extmap.dll file.


I want to store copies of each of my references within my code base, where can I find the DLLs


While many people use Nuget nowadays you may still wish to store the DLLs files yourself.  Here is a quick lust of locations so you can find them.


The Silverlight “core” libraries do not have to be included in either xap or zip files and can always be set to Copy Local False and do not need to be stored within your code base.


image


Other Microsoft and third party libraries can be added to a libraries (libs) folder within your solution, don’t forget to include the extmap.xml files.  Once the files are installed the Microsoft SDK files can be found here:


image


PRISM libraries can be downloaded from CodePlex:  http://compositewpf.codeplex.com/


Expression libraries can be downloaded from Blend SDK, Blend Service Pack, Silverlight Tools SP1, VS 2010 SP1.

Wednesday, 31 August 2011

StackPanelRegionAdapter

Extend Prism to make use of a stackpanel with this simple solution:

You can use the same technique with a gird or other container control, simply register your adapter(s) in the bootstrapper.

Saturday, 18 June 2011

Composite apps with Prism

In this example I have used Prism to dynamically load xap files in the background after the initial landing page has loaded.

ScreenShot015

Here’s the same page with the Prism xap loader log switched on and configured to output to the screen.  You can see messages updating the developer on the sequence of operations such as the creation of the Unity container and tracking for each of the separate xap modules throughout their download and initialisation.

ScreenShot014

The application shell or display is broken down into three areas: 

The header

Containing the Company/Product name along with some user buttons for comments, settings, user details, log out and help.  This header is initially collapsed for the login screen and is made visible once the user successfully logs in.

Main content pane

In the example below the charts section has been selected from the main menu and displayed.

The footer

The footer contains the main menu to allow the user to load the content pane with various areas of functionality.  This section is also initially collapsed until the user has logged in.

Note in the screenshot below the logger output to screen has been switched off.

ScreenShot017

The XAPs

Each of the menu options is broken out into it’s own Xap file (separate Silverlight project) and can have their entry point / initial view loaded into the content pane via the messaging architecture.  Event the menu itself is a xap file that is loaded asynchronously whilst the user is preparing to login.

You can download the source for this code here:

http://stevenhollidge.com/blog-source-code/Silverblade-Prism.7z

Friday, 20 May 2011

Silverlight MEF modularity loading

When designing an architecture for Silverlight applications it’s important to break down your application into loosely coupled modules, which can then be composed to create your system.

ScreenShot028

In this example you can see our solution contains our main Silverlight application, the web hosting project and a further six loadable modules named A - F.  There is also a ninth project called ModuleTracking which tracks the state of the loadable modules e.g. ModuleE 39% downloaded.

vs

The main application project can discover these modules through either direct project references or, more importantly, through a configuration file or directory sweep. When using the configuration file (ModulesCatalog.xaml in the example code) you can define dependencies so that a working module is always provided.

 

To download the source code please visit the PRISM website and select active releases v4:

http://msdn.microsoft.com/en-us/library/ff648465.aspx

Wednesday, 18 May 2011

MVVMLight Messenger for Loosely Coupled Events

The Messenger class within MVVMLight gives developers the ability to publish an application wide event using messages that allow a subscriber to react without either the publisher or subscriber knowing anything about each other.

As always with MVVMLight it’s really simple to do.

In this example, I wanted a user to be able to click on the main menu of my application, shown on the left hand side of the screenshot below, which would update the content pane on the right hand side.

image

The main menu is a user control whilst the content pane is a navigation frame located within the MainPage.xaml.

To allow two pieces of code to communicate with each other, without knowing anything about each other, I will use the Messenger class in 3 simple steps.

1 Create a strongly typed message

 

2 Register a subscriber to the message type

Register the MainPage as the subscriber so that when the message is received the Uri within the message will be passed to the NavigateTo method to update the content pane.

 

3 Lastly, publish the message

 

When the TreeView menu is clicked the code behind checks for a Uri within the selected TreeViewItem then creates a message containing the Uri and publishes it to your application.

Summary

Using messages within your application can be a great way for your components to communicate whilst maintaining a loosely coupled architecture. This is important because you don’t have any nasty hard coded dependencies. Hard coded dependencies result in brittle, inflexible systems that can be hard to extend in the future.

The Messenger class in MVVMLight provides similar functionality to the EventAggregator class in PRISM.

You can download the WCF RIA sample application here:

http://www.stevenhollidge.com/blog-source-code/Silverblade5-WCF-RIA-MVVMLight-Messenger.zip

Please note that for demo purposes only menu options “Home > Search” and “Client > Details” have views that can be displayed within the content pane.  All other menu options will return an error.