/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Reflection;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
namespace Everest.Library.Assemblies{
/// <summary>
///
/// </summary>
public static class AssemblyResolver
{
public static AssemblyDirectory Modules = new AssemblyDirectory("Modules");
/// <summary>
///
/// </summary>
public static AssemblyDirectory Packages = new AssemblyDirectory("Bin");
/// <summary>
/// Initializes the <see cref="AssemblyResolver"/> class.
/// </summary>
static AssemblyResolver()
{
//Modules.GetAssemblies();
//Packages.GetAssemblies();
//AppDomain.CurrentDomain.SetupInformation.ShadowCopyDirectories = Packages.DirectoryPath;
//AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
/// <summary>
/// Handles the AssemblyResolve event of the CurrentDomain control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="args">The <see cref="System.ResolveEventArgs"/> instance containing the event data.</param>
/// <returns></returns>
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (Modules.GetAssemblies() != null && Modules.GetAssemblies().ContainsKey(args.Name))
{
return Modules.GetAssemblies()[args.Name];
}
if (Packages.GetAssemblies() != null && Packages.GetAssemblies().ContainsKey(args.Name))
{
return Packages.GetAssemblies()[args.Name];
}
return null;
}
public static void InitializeRouteTable()
{
}
/// <summary>
/// Opens the configuration.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
private static System.Configuration.Configuration OpenConfiguration(string fileName)
{
return ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = fileName }
, ConfigurationUserLevel.None);
}
/// <summary>
/// Resolves the assembly.
/// </summary>
/// <param name="assemblyName">Name of the assembly.</param>
/// <returns></returns>
public static Assembly ResolveAssembly(string assemblyName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == assemblyName)
{
return assembly;
}
}
return null;
}
}
}
|