New Posts New Posts RSS Feed: Moving to dynamic module loading
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Moving to dynamic module loading

 Post Reply Post Reply
Author
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Topic: Moving to dynamic module loading
    Posted: 26-Jun-2012 at 2:20am
Hello,
sorry to disturb you again, i've got a SL 5 application that's composed of modules but currently they're all loaded when the application starts (I've added them as reference to my sl application).

I've read this post on the wiki but I've no clear idea on where to put this... another client requisite (if possible) is to load the module only if the user is allowed to (I've  a core module that will be loaded (and referenced) by different projects), considering that I know if a user can/can't load that module if it's defined a role for it (asp.net role) what 's the best approach for my needs?

I've also checked the TempHire demo but it doesn't use Composition.AddXap...  can someone help me on this?
Thanks
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 9:00am
There are generally two approaches. You can eager load the Xap files during the bootstrapping of the application or in your case after the login, since you need the user's roles, or lazy loading the Xap file when the user first tries to enter a certain module.
 
It sounds like the best approach for you is to load them after the login. Similarly to TempHire, where it pre-loads some data using the PreLoader, you can have a coroutine at that point with a number of Compositon.AddXap calls that load the appropriate modules based on the user's roles. You can use a parallel coroutine to load them in parallel.
 
On a side-note I'm going to rename Composition.AddXap to Composition.AddXapAsync. Just noticed that I forgot to add the Async postfix to this method.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 9:12am
Hello Marcel,
I was of the same mind of you, after the login I've created a
 

[Export(typeof(IPartFactory<MenuViewModel>))]

   public class MenuViewModelFactory : PartFactoryBase<MenuViewModel>

   {

   }

and on the Execute method I do
 

public void Execute(ActionExecutionContext context)

      {

          IList<string> rolesList = userService.CurrentUser.Roles;

 

          var filtered = rolesList.Where(o1 => o1.StartsWith("module"));

 

          if (filtered.Any())

          {

             // Here I have to download the modules  

          }

       //   GetMenuItems();

      }

I think I'll need to store some information on the DB for telling my app to download for module_admin the full path to the admin's module... what you think about this?
 
Or if there was a DirectoryCatalog equivent I would have download the list index and parsed it ...
Is this approach ok?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 9:20am
Yes, that's correct. You need to store some metadata about your modules somewhere, either in the DB or an XML file on the server that you can download. 

Your code won't quite work. Keep in mind AddXap is an asynchronous operation. You need to wait for it to finish before you can access anything from the downloaded Xap file.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 12:26pm
I know I know.... I'll use a Coroutine.BeginExecute to wait the data...or am I wrong?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 1:03pm
Yes, that works.
Back to Top
pponzano View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Apr-2011
Location: Italy
Posts: 165
Post Options Post Options   Quote pponzano Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 11:47pm
It's morning in Italy and I've a question for you.........currently my solution's module are .dll, since I have to load XAP file, have I to re-create my projects as Silverlight Application? what about their own bootstrapper? should I implement them?
 
Thanks
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 26-Jun-2012 at 11:56pm
Yes, in order to get a XAP file you need to create them as Silverlight Applications, but they don't need a bootstrapper.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down