Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.JobBase/3.3/PluginUtil.cs @ 4368

Last change on this file since 4368 was 4368, checked in by cneumuel, 14 years ago
  • created HiveClient which shows an overview over all submitted HiveExperiments
  • its possible to download all submitted HiveExperiments including results
  • Experiments are now sent as a whole to the Hive and the Hive-Slaves take care of creating child-jobs (if necessary). The parent job is then paused and will be reactivated when all child-jobs are finished
  • WcfService-Clients are now consistently managed by WcfServicePool which allows to use IDisposable-Pattern and always keeps exactly one proxy-object until all callers disposed them.
  • created ProgressView which is able to lock a View and display progress of an action. It also allows to simulate progress if no progress-information is available so that users don't get too nervous while waiting.
File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Reflection;
6using HeuristicLab.PluginInfrastructure;
7
8namespace HeuristicLab.Hive.JobBase {
9  public static class PluginUtil {
10    #region Required Plugin Search
11   
12    /// <summary>
13    /// Returns a list of plugins in which the type itself and all members
14    /// of the type are declared. Objectgraph is searched recursively.
15    /// </summary>
16    public static IEnumerable<IPluginDescription> GetDeclaringPlugins(Type type) {
17      HashSet<Type> types = new HashSet<Type>();
18      FindTypes(type, types, "HeuristicLab.");
19      return GetDeclaringPlugins(types);
20    }
21
22    /// <summary>
23    /// Returns the plugins (including dependencies) in which the given types are declared
24    /// </summary>
25    public static IEnumerable<IPluginDescription> GetDeclaringPlugins(IEnumerable<Type> types) {
26      HashSet<IPluginDescription> plugins = new HashSet<IPluginDescription>();
27      foreach (Type t in types) {
28        FindDeclaringPlugins(ApplicationManager.Manager.GetDeclaringPlugin(t), plugins);
29      }
30      return plugins;
31    }
32
33    /// <summary>
34    /// Finds the dependencies of the given plugin and adds it to the plugins hashset.
35    /// Also searches the dependencies recursively.
36    /// </summary>
37    public static void FindDeclaringPlugins(IPluginDescription plugin, HashSet<IPluginDescription> plugins) {
38      if (!plugins.Contains(plugin)) {
39        plugins.Add(plugin);
40        foreach (IPluginDescription dependency in plugin.Dependencies) {
41          FindDeclaringPlugins(dependency, plugins);
42        }
43      }
44    }
45
46    /// <summary>
47    /// Recursively finds all types used in type which are in a namespace which starts with namespaceStart
48    /// Be aware that search is not performed on attributes
49    /// </summary>
50    /// <param name="type">the type to be searched</param>
51    /// <param name="types">found types will be stored there, needed in order to avoid duplicates</param>
52    /// <param name="namespaceStart">only types from namespaces which start with this will be searched and added</param>
53    public static void FindTypes(Type type, HashSet<Type> types, string namespaceStart) {
54      if (!types.Contains(type) && type.Namespace.StartsWith(namespaceStart)) {
55        types.Add(type);
56
57        // constructors
58        foreach (ConstructorInfo info in type.GetConstructors()) {
59          foreach (ParameterInfo paramInfo in info.GetParameters()) {
60            FindTypes(paramInfo.ParameterType, types, namespaceStart);
61          }
62        }
63
64        // interfaces
65        foreach (Type t in type.GetInterfaces()) {
66          FindTypes(t, types, namespaceStart);
67        }
68
69        // events
70        foreach (EventInfo info in type.GetEvents()) {
71          FindTypes(info.EventHandlerType, types, namespaceStart);
72          FindTypes(info.DeclaringType, types, namespaceStart);
73        }
74
75        // properties
76        foreach (PropertyInfo info in type.GetProperties()) {
77          FindTypes(info.PropertyType, types, namespaceStart);
78        }
79
80        // fields
81        foreach (FieldInfo info in type.GetFields()) {
82          FindTypes(info.FieldType, types, namespaceStart);
83        }
84
85        // methods
86        foreach (MethodInfo info in type.GetMethods()) {
87          foreach (ParameterInfo paramInfo in info.GetParameters()) {
88            FindTypes(paramInfo.ParameterType, types, namespaceStart);
89          }
90          FindTypes(info.ReturnType, types, namespaceStart);
91        }
92      }
93    }
94    #endregion
95  }
96}
Note: See TracBrowser for help on using the repository browser.