New Posts New Posts RSS Feed: How do I know when composition of parts completed on Silverlight client?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How do I know when composition of parts completed on Silverlight client?

 Post Reply Post Reply
Author
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Topic: How do I know when composition of parts completed on Silverlight client?
    Posted: 06-Jul-2012 at 8:57am

I'm using PRISM for UI composition and PRISM itself have all hooks necessary to tell me when module loaded, etc.

 
One of the things I'm doing is loading certan views when module loaded. Everything worked fine until I added custom verifiers to my model. Now I get racing issue where module already composed but IdeaBlade still probing assemblies. My VM initialization fails with MEF error. I noticed that this call:
 
30 : 7/6/2012 10:51:37 AM :  : IdeaBlade.Core.Composition.CompositionHost:CheckMultiExport : CompositionContext: '-IbDefault-' - Probed for non-default 'IVerifierProvider' and found 'IDATT.Model.DSPDriver+VerifierProvider'.
 
is made too late. If I don't open my view on startup and open via menu - it works. So, I need to somehow know when IdeaBlade done composing parts and probing assemblies. Is there any events for that?


Edited by katit - 06-Jul-2012 at 8:58am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 10:57am
Probing and composition of the main Silverlight application is done synchronously and no events are raised, but I'm assuming your custom IVerifierProvider is in a dynamically loaded module.  If that's the case, you can listen on the CompositionHost.Recomposed event, which fires whenever dynamic content is added.
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 11:16am
No, my Model is referenced in main XAP. See output of debug. It shows that Model loaded, then PRISM loads XAP's and when one of those modules loads I want to do something that relies on IB and it fails because as you see probing still going on after XAP's loaded.
 
Which tells me that probing is not synchronous. OR PRISM loads modules on background or something.
 
I tried to subscribe for recomposed event but I'm not sure where I should do it.  I did it in Bootstrapper where I subscribe for trace (which I get) and no events raised
 
#region IdeaBlade trace hookup
        private void SubscribeToTracePublisher()
        {
            this.subscriber.Publish += this.NotificationHandler;
            this.subscriber.StartSubscription();
            CompositionHost.Recomposed += this.CompositionHostRecomposed;
        }
        private void CompositionHostRecomposed(object sender, RecomposedEventArgs e)
        {
            Debug.WriteLine("IdeaBlade.CompositionHostRecomposed");
        }
        private void NotificationHandler(object sender, PublishEventArgs e)
        {
            Debug.WriteLine(e.TraceMessage);
        }
        #endregion
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 11:43am
DevForce "probes" for interfaces when it needs them.  The initial probing done at startup loads assemblies into the CompositionContainer, while subsequent probing is asking the container for specific implementations, such as we see here for your IVerifierProvider implementations.
 
If you're loading modules via Prism then you also need to tell DevForce about them.   Once you do, DevForce will raise the Recomposed event when new content is added.  See http://drc.ideablade.com/xwiki/bin/view/Documentation/on-demand-discovery#HWithPrismmodularity for more information.
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 12:53pm
My modules use everything from Model.SL so I didn't think I need IdeaBlade to load this into catalogs. And it was working fine all the time. It works fine even now if I don't try to inject View when module initialized.
 
Anyway, I tried your suggestion and did specify that every module recomposed when loaded. I got output like this where one output is my Event Handler, and then it followed by IB output.
 
Yet all IVerifierProvider probed at the very end. So, I still have the same issue and have no way of telling when probing done..
 
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 1:04pm
OK, what is the MEF error you're getting when the VM initializes?
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 1:22pm
Here is code I added right after IB should recompose to illustrate what I'm seeing:
 
// Get manager and subscribe to recompose IdeaBlade
            var manager = this.Container.GetExportedValue<IModuleManager>();
            var regionManager = this.Container.GetExportedValue<IRegionManager>();
            manager.LoadModuleCompleted += (o, e) =>
            {
                var uri = new Uri(e.ModuleInfo.Ref, UriKind.Relative);
                CompositionHost.Add(uri);
                if (e.ModuleInfo.ModuleName.Equals("DispatchModule"))
                {
                    regionManager.RequestNavigate(RegionNames.Tabs, "MaintainDriverView");
                }
            };
 
This is view (MaintainDriverView) on which composition fails, but this is just example. This is view that exists in DispatchModule and I call it after Composition should happen on IB
 
This is stack trace I get, where IB doesn't even have a chance to do composition. If you look at code - CopositionHost.Add was called before I try to get my view. So, it definitely does async composing, otherwise I should see trace of probing events (just like above)
 
Error meaningless, it just says it can't compose view. But it was working before I introduced custom verifiers.
 
 
 


Edited by katit - 06-Jul-2012 at 1:26pm
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 6:50pm
When I said recomposition was synchronous, I meant for the main application XAP.  When dynamic content is loaded the composition can be done asynchronously, and will fire the Recomposed event when complete. 
 
If you don't do the regionManager.RequestNavigate until after the Recomposed event fires, does an error still occur?
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2012 at 7:37pm
Error doesn't occur if I don't call it at all (during start) and do it after IVerifierProvider composed from program menu.
 
Doing it after Recomposed event still gives the same issue - because it happens before IVerifierProvider composed. If I disable custom verifier on entity that's used on my VM - it works. So it definitely related to this..
 
When I said recomposition was synchronous, I meant for the main application XAP.
 
I'm still confused about this. None of the stuff needed for IB is in my modules. Model.SL contains all of the entities, verifiers, etc and it is in main XAP


Edited by katit - 06-Jul-2012 at 7:39pm
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jul-2012 at 1:16pm
If your dynamically downloaded xaps don't have DevForce content - either entities or implemented interfaces - then you are right that you do not need to register them with DevForce.
 
So your VM, MaintainDriverViewModel in this sample, uses an entity type which now contains IVerifierProviders, and will no longer compose after adding these verifiers.   Since DevForce uses a separate composition container than Prism, it's really unlikely that it's a race condition causing the issue.   DevForce's container has also already been composed; the probing messages for the IVerifierProvider are generated when DevForce looks in its container for verifier providers upon encountering a new entity type. 
 
When you added the verifiers did you also add any imports within the VM which could cause composition of the VM to fail? 
Back to Top
katit View Drop Down
Senior Member
Senior Member


Joined: 09-Sep-2011
Posts: 146
Post Options Post Options   Quote katit Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jul-2012 at 2:44pm
In my case it works like this:
 
V/VM imports Repository<T> where T is Entity.
In this case IVerifierProvider was added to MBLDriver entity and this entity not used in main XAP (but it contains there).
 
If I remove navigation to VM from code on startup (upon module load) I see that everything eventually composed (those logs on top). And I can open View via menu in my program. It just doesn't work if I try to open on startup.
 
Right now I decided not to use IVerifierProvider for other reasons so this problem is not causing any issues. However, if what I'm describing not how it should work - please take a look at this..
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down