133 lines
5.0 KiB
C#
133 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using DTS.Common;
|
|
using DTS.Common.Base;
|
|
using DTS.Common.Classes;
|
|
using DTS.Common.Core.PluginLib;
|
|
using DTS.Common.Interface;
|
|
using Microsoft.Practices.Prism.Events;
|
|
using Microsoft.Practices.Prism.Modularity;
|
|
using Microsoft.Practices.Prism.Regions;
|
|
using Microsoft.Practices.ServiceLocation;
|
|
using Microsoft.Practices.Unity;
|
|
using System.IO;
|
|
|
|
namespace DTS.Viewer.Loader
|
|
{
|
|
/// <summary>
|
|
/// I think we need it...
|
|
/// </summary>
|
|
public class ViewerLoaderSession
|
|
{
|
|
/// <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 _unityContainer { get; private set; }
|
|
public IServiceLocator ServiceLocator { get; private set; }
|
|
public IEventAggregator EventAggregator { get; private set; }
|
|
public IRegionManager RegionManager { get; private set; }
|
|
|
|
public ViewerLoaderSession()
|
|
{
|
|
|
|
}
|
|
|
|
public void CreateSession()
|
|
{
|
|
CreateBootstrapper();
|
|
if (_bootstrapper == null) return;
|
|
_unityContainer = _bootstrapper.Container;
|
|
EventAggregator = _unityContainer.Resolve<IEventAggregator>();
|
|
ServiceLocator = _unityContainer.Resolve<IServiceLocator>();
|
|
RegionManager = _unityContainer.Resolve<IRegionManager>();
|
|
|
|
var shellVviewmodel = _unityContainer.Resolve<IShellViewModel>();
|
|
var viewerModule = _unityContainer.Resolve<IViewerModule>();
|
|
viewerModule.StartSession(true, @"C:\devDTS\RunTimeModules\DTS.Viewer.dll.config");
|
|
var viewModel = _unityContainer.Resolve<IViewerMainViewModel>();
|
|
|
|
shellVviewmodel.ContextMainRegion = viewModel.View;
|
|
|
|
//var assemblyList = LoadPlugins();
|
|
//if (assemblyList.Count == 1)
|
|
//{
|
|
// var assembly = assemblyList[0];
|
|
// if (assembly.ManifestModule.Name.StartsWith("DTS.Viewer"))
|
|
// {
|
|
|
|
|
|
// }
|
|
//}
|
|
|
|
|
|
//var viewDefinition = new ViewDefinition(RegionNames.MainRegion, typeof(IMainView), typeof(IMainViewModel));
|
|
//var viewModel = (IBaseViewModel)Container.Resolve(viewDefinition.ViewModelInterfaceType);
|
|
//var view = (IBaseView)Container.Resolve(viewDefinition.ViewInterfaceType);
|
|
//view.DataContext = viewModel;
|
|
//RegionManager.Regions[RegionNames.MainRegion].Add(view);
|
|
//RegionManager.ActivateViewIfExists(viewDefinition.RegionName, viewDefinition.ViewInterfaceType);
|
|
}
|
|
/// <summary>
|
|
/// Return type of View/ViewModel registered with Unity Container
|
|
/// </summary>
|
|
/// <param name="name">Name of the selected assembly (plug-in)</param>
|
|
/// <returns>interface type</returns>
|
|
private Type GetRegisteredViewType(string name)
|
|
{
|
|
return (from v in _unityContainer.Registrations where v.RegisteredType.Name.EndsWith(name) select v.RegisteredType).FirstOrDefault();
|
|
}
|
|
private List<Assembly> LoadPlugins()
|
|
{
|
|
var pluginManager = PluginManager.GetPluginManager(Path.Combine(Environment.CurrentDirectory, @"DTS.Viewer.Loader.exe.config"));
|
|
return pluginManager.GetPluginList<IModule>();
|
|
}
|
|
|
|
/// <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()
|
|
{
|
|
if (_bootstrapper == null)
|
|
{
|
|
try
|
|
{
|
|
_bootstrapper = new Bootstrapper();
|
|
_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()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|