7
votes

I have a prism 4 application using an MEF bootstrapper. I have implemented a splash screen from the bootstrapper and want to provide the user with module info (as they are loaded) while the module manager is loading the app/modules.

I think I need to subscribe to the LoadModuleCompleted event in the module manager. I cannot do this because when I resolve the module manager with the container in the MEF bootstrapper the PRISM framework calls OnImportsSatisfied which loads all the modules. (This is too late since I want to listen for this).

How can I display a splash window with a progress bar displaying module info/progress?

Many thanks!

1
You can check out this project. It uses a Unity bootstrapper, but you may find it useful.Adi Lester

1 Answers

0
votes

If you control the composed parts that are imported into your project, you can implement IPartImportsSatisfiedNotification on each and have them report their own progress to some imported progress monitor class:

public interface IProgressMonitor
{
    void ReportComposed(Type type);
}

[Export(typeof(IProgressMonitor))]
public class ProgressMonitor : IProgressMonitor
{
    public ProgressMonitor()
    {
        var loadHeuristic = this.GetPreviousLoadProgress();
        if (loadHeuristic == null)
        {
            // Never been loaded before, so it's unclear how long it will take
            // Set indeterminate progress bar.
        }
        else
        {
            // Use previous load times to estimate progress.
            _loadHeuristic = loadHeuristic;
            _progress = 0;
        }
    }

    public void ReportComposed(Type type)
    {
        if (_loadHeuristic != null)
        {
            this.IncrementProgress();
        }
    }
}

[Export]
public class FooExport : IPartImportsSatisfiedNotification
{
    [Import]
    internal IProgressMonitor ProgressMonitor { get; set; }

    public void OnImportsSatisfied()
    {
        this.ProgressMonitor.ReportComposed(typeof(FooExport));
    }
}