Silverlight PRISM Creating a custom module catalog - silverlight-4.0

I have created a silverlight application with PRISM and MEF.
Is there a way to populate the modules catalog through some web service or database call?
The example shown in the PRISM documentation gets the module information through XAP file which is included in the Shell project.
In my case i need to get this list from some service. I read some articles which suggested to create a custom ModuleCatalog which implements IModuleCatalog.
I am not able to find any example or code snippet on how to proceed.
Any suggestions on how to accomplish this?
Thanks,
Deepak

Got the solution for this requirement.
Inorder to do load the OnDemand Module in runtime, the Module Info object has to be added into the catalog
ModuleInfo moduleInfo = new ModuleInfo();
moduleInfo.ModuleName = item.Name;
moduleInfo.ModuleType = item.Type;
moduleInfo.Ref = item.Reference;
ModuleCatalog.AddModule(moduleInfo);
The item shown in the above code is populate using a webservice call, which hits the database and gets the name, type and reference (example.xap).
This successfully adds the module catalog, the module catalog can be referenced in any ViewModel by just importing that property like below
[Import(AllowRecomposition = false)]
public IModuleManager ModuleManager;
[Import(AllowRecomposition = false)]
public IModuleCatalog ModuleCatalog;
Inorder to Load the module during a button click or any event just call the ModuleManager.LoadModule(YourModuleName); and thats it, it will be available for use.

Related

Why can't i reference to a method/property? VB.NET

Please take a look at the 2 photos i attached, i wish to call the methods from one project to another. Both projects are in the same solution. I have already made the reference to the project containing the method in the project i want to call the method.
http://postimg.org/image/m42dlc28r/
http://postimg.org/image/w03gkz80r/
In your main project, go to
Project -> Add Reference
In that window, click browse and find the compiled version of your other project (Probably in the Release or Debug folder)
In your main projects window add this to the very top of your code (even above your class declaration)
Imports SecondProjectRootNamespace
That should give you enough information on how to do what your trying to do, but if anything was unclear, I am going to need all the details to provide a more precise answer.
Also, make sure your methods/functions are NOT declared as private.
Private = Method is only visible from within the same class
Friend = Method is only visible from any class within the same assembly (same .exe or .dll or etc)
Public = Method has no access restrictions
There are a few others but those are the basics
Try to find the dll file of the method that you want, then add it as reference in the properties of your application

How to get a module instance in PRISM

I have a PRISM desktop app which loads modules from a directory with the help of the DirectoryModuleCatalog.
Everything is fine, except that I cannot find a way to get the instance of a loaded module.
IModuleManager and IModuleCatalog don't have a method like getInstance(ModuleInfo) or similar.
See
moduleManager.LoadModule(moduleInfo.ModuleName);
This line loads the module properly(moduleManager is of type IModuleManager), but what do I have to do next to get the actual instance of this module?
The modules are loaded on demand of the user, so I cannot register all modules at startup within the bootstrapper.
If by Module instance you mean the class that implement IModule, then you must explicitly register the instance into the container to be able to get it.
Although the aforementioned will work, you should not take that approach at all. The idea is that the module classes are specific to a particular module and should only be used for module initialization purposes.
I would place each module's Start method in a separate component (IStartable), register each component in the container with a different Id and resolve/import an IEnumerable to get all instances that have the start method.
Hope this helps

MEF + SL4 question

I'm working on an app in the Silverlight 4 RC and i'm taking the oppertunity to learn MEF for handling plugin controls. I've got it working in a pretty basic manor, but it's not exactly tidy and I know there is a better way of importing multiple xap's.
Essentially, in the App.xaml of my host app, I've got the following telling MEF to load my xap's:
AggregateCatalog catalog = new AggregateCatalog();
DeploymentCatalog c1 = new DeploymentCatalog(new Uri("TestPlugInA.xap", UriKind.Relative));
DeploymentCatalog c2 = new DeploymentCatalog(new Uri("TestPlugInB.xap", UriKind.Relative));
catalog.Catalogs.Add(c1);
catalog.Catalogs.Add(c2);
CompositionHost.Initialize(catalog);
c1.DownloadAsync();
c2.DownloadAsync();
I'm sure I'm not using the AggregateCatalog fully here and I need to be able to load any xap's that might be in the directory, not just hardcoding Uri's obviously....
Also, in the MainPage.xaml.cs in the host I have the following collection which MEF puts the plugin's into:
[ImportMany(AllowRecomposition = true)]
public ObservableCollection<IPlugInApp> PlugIns { get; set; }
Again, this works, but I'm pretty sure I'm using ImportMany incorrectly....
Finally, the MainPage.xaml.cs file implements IPartImportsSatisfiedNotification and I have the following for handling the plugin's once loaded:
public void OnImportsSatisfied()
{
sp.Children.Clear();
foreach (IPlugInApp plugIn in PlugIns)
{
if (plugIn != null)
sp.Children.Add(plugIn.GetUserControl());
}
}
This works, but it seems filthy that it runs n times (n being the number of xap's to load). I'm having to call sp.Children.Clear() as if I don't, when loading the 2 plugin's, my stack panel is populated as follows:
TestPlugIn A
TestPlugIn A
TestPlugIn B
I'm clearly missing something here. Can anyone point out what I should be doing?
Thanks!
I think most of what you are doing is fine. Although ObservableCollections do support notifications of individual elements being added and removed, MEF doesn't take advantage of this. In your case it will simply clear the collection and then add all the plugins. Since you are using OnImportsSatisfied for the change notification, you don't even need an ObservableCollection. You could just use an IEnumerable for your import.
To add flexibility in downloading different xaps, I would expose a service in your container that can be imported and that provides the functionality to download a xap given a url. Then any component in your container can trigger a download, and the url to download can come from whatever source you deem appropriate.

Xwiki Create virtual wiki - problem adding a class

I'm trying to create a virtual wiki but I already struggle with
In your Class Editor, create a new class called "XWikiServerClass"
Further reading in the DevGuide / DataModel shows that I'm not alone. I understand the words saying but I don't get the how-to as there is no option in the class-editior of creating new classes. Navigating to class editor shows an info box
No class is defined in this wiki document. You can create one by adding properties from the panel on your right, or you can choose another class to edit from the list below.
Ok, I added 'XWikiServerClass' and would have expected to be able to add a type class but that's not possible. I've tried a few properties but nothing shows up as a class in class editor.
Can you give more info on how you set up your wiki ?
As far as I know, you should have installed xwiki-enterprise-manager-web-x.y.war and modify your setup to fit your needs.
Second, you should have imported "xwiki-enterprise-manager-wiki-administrator-x.y.xar into your empty instance.
This xar archive already contains the XWikiServerClass and a very handy set of pages to automate the creation of virtual wikis.

vb.net: Get to resources of a referenced project

I have a project which contains all custom controls and images; we'll call it projectBase. Now I have created a windows forms project (project1) that references projectBase. I need to access the embedded resource (images) of projectBase in project1. Any idea how i can pull this off?
In project properties, under Resources, you have the Access Modifier at the top, which you can set as Public. Now you can access resources from the other project like this:
Dim someResource = MyReferencedProject.My.Resources.SomeResource
One option would be to expose the images as readonly properties of your custom control classes.