init
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using DTS.Common.Events;
|
||||
using DTS.Common.Core.PluginLib;
|
||||
using Microsoft.Practices.Prism.Events;
|
||||
using Microsoft.Practices.Prism.Modularity;
|
||||
using Microsoft.Practices.Prism.Regions;
|
||||
using Microsoft.Practices.ServiceLocation;
|
||||
using Microsoft.Practices.Unity;
|
||||
// ReSharper disable EmptyConstructor
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace DTS.Viewer.PSDReport
|
||||
{
|
||||
/// <summary>
|
||||
/// I think we need it...
|
||||
/// </summary>
|
||||
public class PSDReportSession
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom Bootstrapper
|
||||
/// </summary>
|
||||
///<remarks>
|
||||
/// Do not try to re-create the bootstrapper. Once modules are loaded, they will be be loaded into the DirectoryModuleCatalog and each
|
||||
/// Module initialization will not be called (thus no registered types).
|
||||
/// It appears that the current bootstrapper loads around 40 MB into memory.
|
||||
/// To completely unload the bootstrapper would take same research and effort.
|
||||
/// </remarks>
|
||||
private Bootstrapper _bootstrapper;
|
||||
|
||||
public IUnityContainer Container { get; private set; }
|
||||
public IServiceLocator _serviceLocator { get; private set; }
|
||||
public IEventAggregator _eventAggregator { get; private set; }
|
||||
public IRegionManager _regionManager { get; private set; }
|
||||
private string _customConfigPath = string.Empty;
|
||||
public string CustomConfigPath { get => _customConfigPath; set => _customConfigPath = value; }
|
||||
/// <summary>
|
||||
/// empty constructor
|
||||
/// </summary>
|
||||
public PSDReportSession()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void CreateSession(bool standalone, string customConfigPath = "")
|
||||
{
|
||||
CustomConfigPath = customConfigPath;
|
||||
CreateBootstrapper(standalone, customConfigPath);
|
||||
if (_bootstrapper == null) return;
|
||||
Container = _bootstrapper.Container;
|
||||
_eventAggregator = Container.Resolve<IEventAggregator>();
|
||||
_serviceLocator = Container.Resolve<IServiceLocator>();
|
||||
_regionManager = Container.Resolve<IRegionManager>();
|
||||
//TODO: review publishPlugins vs base.InitializeModules();
|
||||
publishPlugins(_eventAggregator, LoadPlugins());
|
||||
}
|
||||
|
||||
private List<Assembly> LoadPlugins()
|
||||
{
|
||||
var pluginManager = PluginManager.GetPluginManager(CustomConfigPath);
|
||||
return pluginManager.GetPluginList<IModule>();
|
||||
}
|
||||
|
||||
private void publishPlugins(IEventAggregator eventAggregator, List<Assembly> pluginList)
|
||||
{
|
||||
eventAggregator.GetEvent<AssemblyListNotificationViewer>().Publish(new AssemblyListInfo(pluginList));
|
||||
}
|
||||
/// <summary>
|
||||
/// Create bootstrapper for prism-based modules and views.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently, there is no course of action for destroying the bootstrapper.
|
||||
/// </remarks>
|
||||
private void CreateBootstrapper(bool standalone, string customConfigPath = "")
|
||||
{
|
||||
if (_bootstrapper == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_bootstrapper = new Bootstrapper(standalone, customConfigPath);
|
||||
_bootstrapper.Run();
|
||||
}
|
||||
catch (ApplicationException ex)
|
||||
{
|
||||
throw new Exception("Failed to create bootstrapper ", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (_bootstrapper == null)
|
||||
{
|
||||
throw new Exception("Failed to create Bootstrapper!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Terminate method is called only when JMPS is in the process of shutting down.
|
||||
/// If a component is just being closed, only the class destructor will be called.
|
||||
/// Part of IComponent implementation.
|
||||
/// </summary>
|
||||
public void Terminate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user