This project has moved and is read-only. For the latest updates, please go here.

Notify when download complete

May 9, 2011 at 1:35 PM

In my xaps I have some mef components that I need to use to recompose if/when a new xap is downloaded. My current solution was to put in an eventaggregator that passes the deploymentcatalog so when its called I recompose using the handy catalog. This works just fine, I was wondering if there was something already in place that I could/should be using instead.

If that wasn't clear...  Thanks.

        private IEnumerable<IWorkflow> DownloadWorkflow(string xapName, Action<Exception> xapLoaded)
            var xap = xapName.Trim().ToLower();            

            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, xapName);

            var uri = new Uri(xap, UriKind.Relative);

            if (_loaded.Contains(uri))
                if (xapLoaded != null)
                yield break;

            var deploymentCatalog = new DeploymentCatalog(uri);

            var downloadAction = new WorkflowEvent<AsyncCompletedEventArgs>(deploymentCatalog.DownloadAsync,
                                                   h => deploymentCatalog.DownloadCompleted += h,
                                                   h => deploymentCatalog.DownloadCompleted -= h);

            yield return downloadAction;


            EventAggregator.Publish<DeploymentCatalog>(deploymentCatalog); /* ADDED TO RECOMPOSE MY MEF */
            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, deploymentCatalog.Uri);

            var e = downloadAction.Result;

            if (e.Error != null)
                var exception = new DeploymentCatalogDownloadException(e.Error);

                Logger.Log(LogSeverity.Critical, string.Format("{0}::{1}", GetType().FullName,
                MethodBase.GetCurrentMethod().Name), exception);

                if (xapLoaded == null)
                    throw exception;
                Logger.LogFormat(LogSeverity.Verbose, string.Format("{0}::{1}", GetType().FullName,
                                 Resources.DeploymentService_DeploymentCatalogDownloadCompleted_Finished, deploymentCatalog.Uri);                

                if (xapLoaded != null)
May 9, 2011 at 1:45 PM

MEF should automatically recompose dependent parts when the XAP is loaded, not sure why you'd need to kick anything off - not sure I understand the full scope?

* If I have dependencies and set "AllowRecomposition=True" they are automatically fired when the XAP is loaded

* I can hook to IPartImportsSatisfiedNotification to know when imports are satisfied

* I can hook to the container exports changed to know when the exports are added

* Jounce supports exporting a IModuleInitializer to kick off any necessary actions within the module when it is loaded


May 9, 2011 at 1:56 PM

I am using a 3rd party tool that probes assemblies at launch and as our application downloads new xaps we need to tell it to recompose itself otherwise it will not know of the new types, etc. I had tried the InitModule but had problems handing it the parts it needed to recompose. I have to actually hand it a catalog, its not just telling it to refresh or recompose.