Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/25/10 10:50:50 (15 years ago)
Author:
epitzer
Message:

statically initialize list of assemblies and plugins (#842)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperator.cs

    r2678 r2679  
    6666    private object syncRoot = new object();
    6767
     68    private static object initLock = new object();
     69    private static Dictionary<string, List<Assembly>> defaultPluginDict;
     70    private static Dictionary<Assembly, bool> defaultAssemblyDict;
     71
    6872    public readonly Dictionary<string, List<Assembly>> Plugins;
    6973
     
    130134
    131135    #region Construction & Initialization
    132 
     136   
    133137    public ProgrammableOperator() {
    134138      code = "";
    135139      description = "An operator that can be programmed for arbitrary needs.";
    136140      executeMethod = null;
    137       Assemblies = DiscoverAssemblies();
     141      ProgrammableOperator.StaticInitialize();
     142      Assemblies = defaultAssemblyDict;
     143      Plugins = defaultPluginDict;
    138144      namespaces = new HashSet<string>(DiscoverNamespaces());
    139       Plugins = GroupAssemblies();
    140     }
    141 
    142     private Dictionary<string, List<Assembly>> GroupAssemblies() {
     145    }
     146
     147    private static void StaticInitialize() {
     148      lock (initLock) {
     149        if (defaultPluginDict != null || defaultAssemblyDict != null) return;
     150        defaultAssemblyDict = DiscoverAssemblies();
     151        defaultPluginDict = GroupAssemblies(defaultAssemblyDict.Keys);
     152      }
     153    }
     154
     155    private static Dictionary<string, List<Assembly>> GroupAssemblies(IEnumerable<Assembly> assemblies) {
    143156      var plugins = new Dictionary<string, List<Assembly>>();
    144       var assemblyNames = Assemblies.ToDictionary(a => a.Key.Location, a => a.Key);
     157      var locationTable = assemblies.ToDictionary(a => a.Location, a => a);
    145158      foreach (var plugin in ApplicationManager.Manager.Plugins) {
    146159        var aList = new List<Assembly>();
    147160        foreach (var aName in plugin.Assemblies) {
    148161          Assembly a;
    149           assemblyNames.TryGetValue(aName, out a);
     162          locationTable.TryGetValue(aName, out a);
    150163          if (a != null) {
    151164            aList.Add(a);
    152             assemblyNames.Remove(aName);
     165            locationTable.Remove(aName);
    153166          }
    154167        }
    155168        plugins[plugin.Name] = aList;
    156169      }
    157       plugins["other"] = assemblyNames.Values.ToList();
     170      plugins["other"] = locationTable.Values.ToList();
    158171      return plugins;
    159172    }
Note: See TracChangeset for help on using the changeset viewer.