Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/27/10 11:11:52 (15 years ago)
Author:
gkronber
Message:

Implemented an enumerable to iterate through all PluginFiles as suggested by swagner, replaced the Assemblies enumerable with an AssemblyName enumerable for internal usage in the plugin infrastructure and replaced Assembly.LoadFrom calls with Assembly.Load() to prevent loading from GAC as far as possible.

#850 (PluginInfrastructure should provide a way to get assemblies associated with a plug-in)

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/Manager
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs

    r2666 r2688  
    2424using System.Text;
    2525using System.Linq;
     26using System.Reflection;
    2627
    2728namespace HeuristicLab.PluginInfrastructure.Manager {
     
    7778
    7879
    79     private List<string> files = new List<string>();
     80    private List<PluginFile> files = new List<PluginFile>();
    8081    /// <summary>
    8182    /// Gets the names of all files that belong to this plugin.
    8283    /// These files are deleted when the plugin is removed or updated.
    8384    /// </summary>
    84     public IEnumerable<string> Files {
    85       get { return files; }
     85    public IEnumerable<IPluginFile> Files {
     86      get { return files.Cast<IPluginFile>(); }
    8687    }
    8788
    88     internal void AddFiles(IEnumerable<string> fileNames) {
     89    internal void AddFiles(IEnumerable<PluginFile> fileNames) {
    8990      files.AddRange(fileNames);
    9091    }
     
    105106    }
    106107
    107     private List<string> assemblies = new List<string>();
     108    private List<AssemblyName> assemblyNames = new List<AssemblyName>();
    108109    /// <summary>
    109110    /// Gets the names of the assemblies that belong to this plugin.
    110111    /// </summary>
    111     public IEnumerable<string> Assemblies {
    112       get { return assemblies; }
    113       // set { assemblies = value; }
     112    public IEnumerable<AssemblyName> AssemblyNames {
     113      get { return assemblyNames; }
    114114    }
    115115
    116     internal void AddAssemblies(IEnumerable<string> assemblyNames) {
    117       assemblies.AddRange(assemblyNames);
     116    internal void AddAssemblyNames(IEnumerable<AssemblyName> assemblyNames) {
     117      this.assemblyNames.AddRange(assemblyNames);
    118118    }
    119119
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs

    r2648 r2688  
    172172      foreach (var desc in pluginDescriptions.Where(x => x.PluginState != PluginState.Disabled)) {
    173173        try {
    174           foreach (var asm in desc.Assemblies) {
    175             Assembly.ReflectionOnlyLoadFrom(asm);
     174          foreach (var asmName in desc.AssemblyNames) {
     175            Assembly.ReflectionOnlyLoad(asmName.FullName);
    176176          }
    177177        }
     
    237237      // get all attributes of that type
    238238      IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(pluginType);
    239       List<string> pluginAssemblies = new List<string>();
     239      List<AssemblyName> pluginAssemblyNames = new List<AssemblyName>();
    240240      List<string> pluginDependencies = new List<string>();
    241       List<string> pluginFiles = new List<string>();
     241      List<PluginFile> pluginFiles = new List<PluginFile>();
    242242      string pluginName = null;
    243243      string pluginDescription = null;
     
    254254          string pluginFileName = (string)attributeData.ConstructorArguments[0].Value;
    255255          PluginFileType fileType = (PluginFileType)attributeData.ConstructorArguments[1].Value;
    256           pluginFiles.Add(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)));
     256          pluginFiles.Add(new PluginFile(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)), fileType));
    257257          if (fileType == PluginFileType.Assembly) {
    258             pluginAssemblies.Add(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)));
     258            pluginAssemblyNames.Add(AssemblyName.GetAssemblyName(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName))));
    259259          }
    260260        }
     
    268268      if (!string.IsNullOrEmpty(pluginName) &&
    269269          pluginFiles.Count > 0 &&
    270           pluginAssemblies.Count > 0 &&
     270          pluginAssemblyNames.Count > 0 &&
    271271          buildDates.Count() == 1) {
    272272        // create a temporary PluginDescription that contains the attribute values
     
    276276        info.Version = pluginType.Assembly.GetName().Version;
    277277        info.BuildDate = DateTime.Parse(buildDates.Single(), System.Globalization.CultureInfo.InvariantCulture);
    278         info.AddAssemblies(pluginAssemblies);
     278        info.AddAssemblyNames(pluginAssemblyNames);
    279279        info.AddFiles(pluginFiles);
    280280
     
    349349                                                                                .Where(x => x.PluginState != PluginState.Disabled))) {
    350350        List<Type> types = new List<Type>();
    351         foreach (string assembly in desc.Assemblies) {
    352           var asm = Assembly.LoadFrom(assembly);
     351        foreach (AssemblyName assemblyName in desc.AssemblyNames) {
     352          var asm = Assembly.Load(assemblyName);
    353353          foreach (Type t in asm.GetTypes()) {
    354354            if (typeof(IPlugin).IsAssignableFrom(t)) {
     
    379379
    380380    private bool CheckPluginFiles(PluginDescription pluginDescription) {
    381       foreach (string filename in pluginDescription.Files) {
     381      foreach (string filename in pluginDescription.Files.Select(x => x.Name)) {
    382382        if (!FileLiesInDirectory(PluginDir, filename) ||
    383383          !File.Exists(filename)) {
Note: See TracChangeset for help on using the changeset viewer.