Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/22/11 16:45:46 (14 years ago)
Author:
mkommend
Message:

#1418: Merged trunk changes into branch.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/DefaultApplicationManager.cs

    r5445 r5796  
    100100      foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
    101101        foreach (string fileName in desc.AssemblyLocations) {
    102           var asm = Assembly.LoadFrom(fileName);
     102          // load assembly reflection only first to get the full assembly name
     103          var reflectionOnlyAssembly = Assembly.ReflectionOnlyLoadFrom(fileName);
     104          // load the assembly into execution context using full assembly name
     105          var asm = Assembly.Load(reflectionOnlyAssembly.FullName);
    103106          RegisterLoadedAssembly(asm);
    104107          // instantiate and load all plugins in this assembly
     
    255258      return from t in assembly.GetTypes()
    256259             where CheckTypeCompatibility(type, t)
    257              where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
     260             where onlyInstantiable == false ||
     261                (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
     262             where !IsNonDiscoverableType(t)
    258263             select BuildType(t, type);
     264    }
     265
     266    private static bool IsNonDiscoverableType(Type t) {
     267      return t.GetCustomAttributes(typeof(NonDiscoverableTypeAttribute), false).Any();
    259268    }
    260269
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj

    r5163 r5796  
    2121    </UpgradeBackupLocation>
    2222    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    23     <TargetFrameworkProfile></TargetFrameworkProfile>
     23    <TargetFrameworkProfile>
     24    </TargetFrameworkProfile>
    2425    <PublishUrl>publish\</PublishUrl>
    2526    <Install>true</Install>
     
    213214    <Compile Include="Attributes\ApplicationAttribute.cs" />
    214215    <Compile Include="Attributes\ContactInformationAttribute.cs" />
     216    <Compile Include="Attributes\NonDiscoverableTypeAttribute.cs" />
    215217    <Compile Include="Attributes\PluginAttribute.cs" />
    216218    <Compile Include="Attributes\PluginDependencyAttribute.cs" />
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs

    r5445 r5796  
    122122               where CheckTypeCompatibility(type, t)
    123123               where onlyInstantiable == false || (!t.IsAbstract && !t.IsInterface && !t.HasElementType)
     124               where !IsNonDiscoverableType(t)
    124125               select BuildType(t, type);
    125126      }
     
    130131        return Enumerable.Empty<Type>();
    131132      }
     133    }
     134
     135    private static bool IsNonDiscoverableType(Type t) {
     136      return t.GetCustomAttributes(typeof(NonDiscoverableTypeAttribute), false).Any();
    132137    }
    133138
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/ApplicationDescription.cs

    r5445 r5796  
    2727  /// </summary>
    2828  [Serializable]
    29   internal sealed class ApplicationDescription : IApplicationDescription {
     29  public sealed class ApplicationDescription : IApplicationDescription {
    3030    private string name;
    3131
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginManager.cs

    r5445 r5796  
    5454    /// Gets all installed applications.
    5555    /// </summary>
    56     internal IEnumerable<ApplicationDescription> Applications {
     56    public IEnumerable<ApplicationDescription> Applications {
    5757      get { return applications; }
    5858    }
     
    7575      AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
    7676      setup.PrivateBinPath = pluginDir;
     77      // probing should only occur in PrivateBinPath (not in ApplicationBase). This is enforced by the value string.Empty
     78      setup.PrivateBinPathProbe = string.Empty;
    7779      AppDomain pluginDomain = null;
    7880      try {
    7981        pluginDomain = AppDomain.CreateDomain("plugin domain", null, setup);
    8082        Type pluginValidatorType = typeof(PluginValidator);
    81         PluginValidator remoteValidator = (PluginValidator)pluginDomain.CreateInstanceAndUnwrap(pluginValidatorType.Assembly.FullName, pluginValidatorType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
     83        PluginValidator remoteValidator = (PluginValidator)pluginDomain.CreateInstanceAndUnwrap(pluginValidatorType.Assembly.FullName, pluginValidatorType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);
    8284        remoteValidator.PluginDir = pluginDir;
    8385        // forward all events from the remoteValidator to listeners
     
    110112    /// </summary>
    111113    /// <param name="appInfo">application to run</param>
    112     internal void Run(ApplicationDescription appInfo) {
     114    public void Run(ApplicationDescription appInfo) {
    113115      if (!initialized) throw new InvalidOperationException("PluginManager is not initialized. DiscoverAndCheckPlugins() must be called before Run()");
    114116      // create a separate AppDomain for the application
     
    124126        Type applicationManagerType = typeof(DefaultApplicationManager);
    125127        DefaultApplicationManager applicationManager =
    126           (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
     128          (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);
    127129        applicationManager.PluginLoaded += applicationManager_PluginLoaded;
    128130        applicationManager.PluginUnloaded += applicationManager_PluginUnloaded;
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginValidator.cs

    r5445 r5796  
    117117      CheckPluginDependencyCycles(pluginDescriptions);
    118118
    119       // recursively check if all necessary plugins are available and not disabled
    120       // disable plugins with missing or disabled dependencies
     119      // 1st time recursively check if all necessary plugins are available and not disabled
     120      // disable plugins with missing or disabled dependencies
     121      // to prevent that plugins with missing dependencies are loaded into the execution context
     122      // in the next step
    121123      CheckPluginDependencies(pluginDescriptions);
    122124
     
    124126      // disables plugins that are not loaded correctly
    125127      CheckExecutionContextLoad(pluginDescriptions);
     128
     129      // 2nd time recursively check if all necessary plugins have been loaded successfully and not disabled
     130      // disable plugins with for which dependencies could not be loaded successfully
     131      CheckPluginDependencies(pluginDescriptions);
    126132
    127133      // mark all plugins as enabled that were not disabled in CheckPluginFiles, CheckPluginAssemblies,
     
    135141
    136142      plugins = pluginDescriptions;
    137       DiscoverApplications();
    138     }
    139 
    140     private void DiscoverApplications() {
     143      DiscoverApplications(pluginDescriptions);
     144    }
     145
     146    private void DiscoverApplications(IEnumerable<PluginDescription> pluginDescriptions) {
    141147      applications = new List<ApplicationDescription>();
    142 
    143       foreach (IApplication application in GetApplications()) {
     148      foreach (IApplication application in GetApplications(pluginDescriptions)) {
    144149        Type appType = application.GetType();
    145150        ApplicationAttribute attr = (from x in appType.GetCustomAttributes(typeof(ApplicationAttribute), false)
    146151                                     select (ApplicationAttribute)x).Single();
    147         var declaringPlugin = GetDeclaringPlugin(appType, plugins);
    148152        ApplicationDescription info = new ApplicationDescription();
     153        PluginDescription declaringPlugin = GetDeclaringPlugin(appType, pluginDescriptions);
    149154        info.Name = application.Name;
    150155        info.Version = declaringPlugin.Version;
     
    158163    }
    159164
    160     private static IEnumerable<IApplication> GetApplications() {
     165    private static IEnumerable<IApplication> GetApplications(IEnumerable<PluginDescription> pluginDescriptions) {
    161166      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    162167             from t in asm.GetTypes()
    163168             where typeof(IApplication).IsAssignableFrom(t) &&
    164169               !t.IsAbstract && !t.IsInterface && !t.HasElementType
     170             where GetDeclaringPlugin(t, pluginDescriptions).PluginState != PluginState.Disabled
    165171             select (IApplication)Activator.CreateInstance(t);
    166172    }
     
    173179      }
    174180      // try to load each .dll file in the plugin directory into the reflection only context
    175       foreach (string filename in Directory.GetFiles(baseDir, "*.dll")) {
     181      foreach (string filename in Directory.GetFiles(baseDir, "*.dll").Union(Directory.GetFiles(baseDir, "*.exe"))) {
    176182        try {
    177183          Assembly asm = Assembly.ReflectionOnlyLoadFrom(filename);
     
    500506                                                                                .Where(x => x.PluginState != PluginState.Disabled))) {
    501507        foreach (string assemblyLocation in desc.AssemblyLocations) {
    502           try {
    503             // now load the assemblies into the execution context 
    504             // this can still lead to an exception
    505             // even when the assembly was successfully loaded into the reflection only context before
    506             var asm = Assembly.LoadFrom(assemblyLocation);
    507           }
    508           catch (BadImageFormatException) {
    509             desc.Disable(Path.GetFileName(assemblyLocation) + " is not a valid assembly.");
    510           }
    511           catch (FileLoadException) {
    512             desc.Disable("Can't load file " + Path.GetFileName(assemblyLocation));
    513           }
    514           catch (FileNotFoundException) {
    515             desc.Disable("File " + Path.GetFileName(assemblyLocation) + " is missing.");
    516           }
    517           catch (SecurityException) {
    518             desc.Disable("File " + Path.GetFileName(assemblyLocation) + " can't be loaded because of security constraints.");
     508          if (desc.PluginState != PluginState.Disabled) {
     509            try {
     510              string assemblyName = (from assembly in AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
     511                                     where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
     512                                     select assembly.FullName).Single();
     513              // now load the assemblies into the execution context 
     514              // this can still lead to an exception
     515              // even when the assemby was successfully loaded into the reflection only context before
     516              var asm = Assembly.Load(assemblyName);
     517            }
     518            catch (BadImageFormatException) {
     519              desc.Disable(Path.GetFileName(assemblyLocation) + " is not a valid assembly.");
     520            }
     521            catch (FileLoadException) {
     522              desc.Disable("Can't load file " + Path.GetFileName(assemblyLocation));
     523            }
     524            catch (FileNotFoundException) {
     525              desc.Disable("File " + Path.GetFileName(assemblyLocation) + " is missing.");
     526            }
     527            catch (SecurityException) {
     528              desc.Disable("File " + Path.GetFileName(assemblyLocation) + " can't be loaded because of security constraints.");
     529            }
     530            catch (NotSupportedException ex) {
     531              // disable the plugin
     532              desc.Disable("Problem while loading plugin assemblies:" + Environment.NewLine + "NotSupportedException: " + ex.Message);
     533            }
    519534          }
    520535        }
     
    533548          foreach (string assemblyLocation in desc.AssemblyLocations) {
    534549            var asm = (from assembly in assemblies
    535                       where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
    536                       select assembly)
     550                       where string.Equals(Path.GetFullPath(assembly.Location), Path.GetFullPath(assemblyLocation), StringComparison.CurrentCultureIgnoreCase)
     551                       select assembly)
    537552                      .Single();
    538553
     
    582597    }
    583598
    584     private PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) {
     599    private static PluginDescription GetDeclaringPlugin(Type appType, IEnumerable<PluginDescription> plugins) {
    585600      return (from p in plugins
    586601              from asmLocation in p.AssemblyLocations
  • branches/DataAnalysis Refactoring/HeuristicLab.PluginInfrastructure/3.3/Sandboxing/SandboxManager.cs

    r5445 r5796  
    8585      Type applicationManagerType = typeof(DefaultApplicationManager);
    8686      DefaultApplicationManager applicationManager =
    87         (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null, null);
     87        (DefaultApplicationManager)applicationDomain.CreateInstanceAndUnwrap(applicationManagerType.Assembly.FullName, applicationManagerType.FullName, true, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null);
    8888      PluginManager pm = new PluginManager(applicationBase);
    8989      pm.DiscoverAndCheckPlugins();
Note: See TracChangeset for help on using the changeset viewer.