Changeset 5850


Ignore:
Timestamp:
03/28/11 19:12:31 (11 years ago)
Author:
mkommend
Message:

#1454: Implemented TypeDiscovery with multiple base types and adapted TypeSelector and CrossValidation.

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.cs

    r5837 r5850  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    252253            if (error != null) throw error;
    253254            IAlgorithm algorithm = content as IAlgorithm;
    254             if (algorithm == null || !(algorithm.Problem is IDataAnalysisProblem<IDataAnalysisProblemData>))
     255            if (algorithm == null || !(algorithm.Problem is IDataAnalysisProblem))
    255256              MessageBox.Show(this, "The selected file does not contain an algorithm or the problem of the algorithm is not a DataAnalysisProblem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    256257            else
     
    274275        problemTypeSelectorDialog.Caption = "Select Problem";
    275276        problemTypeSelectorDialog.TypeSelector.Caption = "Available Problems";
    276         problemTypeSelectorDialog.TypeSelector.Configure(Content.ProblemType, false, true);
    277       }
     277      }
     278      problemTypeSelectorDialog.TypeSelector.Configure(new List<Type>() { Content.ProblemType, Content.Algorithm.ProblemType }, false, true);
    278279      if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    279         try {
    280           Content.Problem = (IDataAnalysisProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    281         }
    282         catch (Exception ex) {
    283           ErrorHandling.ShowErrorDialog(this, ex);
    284         }
     280        Content.Problem = (IDataAnalysisProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    285281      }
    286282    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs

    r5848 r5850  
    3535    protected TypeSelectorDialog typeSelectorDialog;
    3636
    37     protected Type baseType;
    38     public Type BaseType {
    39       get { return baseType; }
     37    protected IEnumerable<Type> baseTypes;
     38    public IEnumerable<Type> BaseTypes {
     39      get { return baseTypes; }
    4040    }
    4141    protected bool showNotInstantiableTypes;
     
    8686
    8787    public virtual void Configure(Type baseType, bool showNotInstantiableTypes, bool showGenericTypes) {
    88       if (baseType == null) throw new ArgumentNullException();
     88      Configure(new List<Type>() { baseType }, showNotInstantiableTypes, showGenericTypes);
     89    }
     90
     91    public virtual void Configure(IEnumerable<Type> baseTypes, bool showNotInstantiableTypes, bool showGenericTypes) {
     92      if (baseTypes == null) throw new ArgumentNullException();
    8993      if (InvokeRequired)
    90         Invoke(new Action<Type, bool, bool>(Configure), baseType, showNotInstantiableTypes, showGenericTypes);
     94        Invoke(new Action<IEnumerable<Type>, bool, bool>(Configure), baseTypes, showNotInstantiableTypes, showGenericTypes);
    9195      else {
    92         this.baseType = baseType;
     96        this.baseTypes = baseTypes;
    9397        this.showNotInstantiableTypes = showNotInstantiableTypes;
    9498        this.showGenericTypes = showGenericTypes;
     
    115119          pluginNode.Tag = plugin;
    116120
    117           var types = from t in ApplicationManager.Manager.GetTypes(BaseType, plugin, ShowNotInstantiableTypes)
     121          var types = from t in ApplicationManager.Manager.GetTypes(BaseTypes, plugin, ShowNotInstantiableTypes)
    118122                      orderby t.Name ascending
    119123                      select t;
     
    252256      }
    253257      Type param = typeParametersListView.SelectedItems[0].Tag as Type;
    254       Type[] contraints = param.GetGenericParameterConstraints();
     258      Type[] constraints = param.GetGenericParameterConstraints();
    255259      bool showNotInstantiableTypes = !param.GenericParameterAttributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint);
    256       typeSelectorDialog.TypeSelector.Configure(typeof(IItem), showNotInstantiableTypes, true);
     260      typeSelectorDialog.TypeSelector.Configure(constraints, showNotInstantiableTypes, true);
    257261
    258262      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/DefaultApplicationManager.cs

    r5741 r5850  
    225225    }
    226226
     227    internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool allTypes) {
     228      IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable);
     229      foreach (Type type in types.Skip(1)) {
     230        IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable);
     231        if (allTypes) result = result.Intersect(discoveredTypes);
     232        else result = result.Union(discoveredTypes);
     233      }
     234
     235      if (!allTypes) return result.Distinct();
     236      return result;
     237    }
     238
    227239    /// <summary>
    228240    /// Finds all types that are subtypes or equal to the specified type if they are part of the given
     
    243255    }
    244256
     257    internal static IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription pluginDescription, bool onlyInstantiable, bool allTypes) {
     258      IEnumerable<Type> result = GetTypes(types.First(), pluginDescription, onlyInstantiable);
     259      foreach (Type type in types.Skip(1)) {
     260        IEnumerable<Type> discoveredTypes = GetTypes(type, pluginDescription, onlyInstantiable);
     261        if (allTypes) result = result.Intersect(discoveredTypes);
     262        else result = result.Union(discoveredTypes);
     263      }
     264
     265      if (!allTypes) return result.Distinct();
     266      return result;
     267    }
     268
    245269    private static bool IsDynamicAssembly(Assembly asm) {
    246270      return (asm is System.Reflection.Emit.AssemblyBuilder) || string.IsNullOrEmpty(asm.Location);
     
    314338    }
    315339
    316     IEnumerable<Type> IApplicationManager.GetTypes(Type type) {
    317       return GetTypes(type, true);
    318     }
    319 
    320340    IEnumerable<Type> IApplicationManager.GetTypes(Type type, bool onlyInstantiable) {
    321341      return GetTypes(type, onlyInstantiable);
    322342    }
    323 
    324     IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin) {
    325       return GetTypes(type, plugin, true);
     343    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, bool onlyInstantiable, bool allTypes) {
     344      return GetTypes(types, onlyInstantiable, allTypes);
    326345    }
    327346
    328347    IEnumerable<Type> IApplicationManager.GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
    329348      return GetTypes(type, plugin, onlyInstantiable);
     349    }
     350    IEnumerable<Type> IApplicationManager.GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable, bool allTypes) {
     351      return GetTypes(types, plugin, onlyInstantiable, allTypes);
    330352    }
    331353
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Interfaces/IApplicationManager.cs

    r5445 r5850  
    5656    /// </summary>
    5757    /// <param name="type">The type to discover.</param>
     58    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
    5859    /// <returns>An enumerable of discovered types.</returns>
    59     IEnumerable<Type> GetTypes(Type type);
     60    IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true);
    6061
    6162    /// <summary>
    62     /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly).
     63    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly).
    6364    /// </summary>
    64     /// <param name="type">The type to discover.</param>
     65    /// <param name="types">The types to discover.</param>
    6566    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     67    /// <param name="allTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
    6668    /// <returns>An enumerable of discovered types.</returns>
    67     IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable);
    68 
    69     /// <summary>
    70     /// Discovers all types implementing or inheriting <paramref name="type"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
    71     /// </summary>
    72     /// <param name="type">The type to discover.</param>
    73     /// <param name="plugin">The declaring plugin.</param>
    74     /// <returns>An enumerable of discovered types.</returns>
    75     IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin);
     69    IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool allTypes = true);
    7670
    7771    /// <summary>
     
    8276    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
    8377    /// <returns>An enumerable of discovered types.</returns>
    84     IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable);
     78    IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true);
     79
     80    /// <summary>
     81    /// Discovers all types implementing or inheriting all or any type in <paramref name="types"/> (directly and indirectly) that are declaed in any assembly of <paramref name="plugin"/>.
     82    /// </summary>
     83    /// <param name="types">The types to discover.</param>
     84    /// <param name="plugin">The declaring plugin.</param>
     85    /// <param name="onlyInstantiable">Return only types that are instantiable (instance, abstract... are not returned)</param>
     86    /// /// <param name="allTypes">Specifies if discovered types must implement or inherit all given <paramref name="types"/>.</param>
     87    /// <returns>An enumerable of discovered types.</returns>
     88    IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool allTypes = true);
    8589
    8690    /// <summary>
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/LightweightApplicationManager.cs

    r5741 r5850  
    8282    }
    8383
    84 
    85     /// <summary>
    86     /// Finds all instantiable types that are subtypes or equal to the specified type.
    87     /// </summary>
    88     /// <param name="type">Most general type for which to find matching types.</param>
     84    /// <summary>
     85    /// Finds all instantiable types that are subtypes or equal to the specified types.
     86    /// </summary>
     87    /// <param name="types">Most general types for which to find matching types.</param>
    8988    /// <remarks>Return only types that are instantiable
    9089    /// (interfaces, abstract classes... are not returned)</remarks>
    9190    /// <returns>Enumerable of the discovered types.</returns>
    92     public IEnumerable<Type> GetTypes(Type type) {
    93       return GetTypes(type, true);
     91    public IEnumerable<Type> GetTypes(IEnumerable<Type> types, bool onlyInstantiable = true, bool allTypes = true) {
     92      IEnumerable<Type> result = GetTypes(types.First(), onlyInstantiable);
     93      foreach (Type type in types.Skip(1)) {
     94        IEnumerable<Type> discoveredTypes = GetTypes(type, onlyInstantiable);
     95        if (allTypes) result = result.Intersect(discoveredTypes);
     96        else result = result.Union(discoveredTypes);
     97      }
     98
     99      if (!allTypes) return result.Distinct();
     100      return result;
    94101    }
    95102
     
    101108    /// (interfaces, abstract classes... are not returned)</param>
    102109    /// <returns>Enumerable of the discovered types.</returns>
    103     public IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable) {
     110    public IEnumerable<Type> GetTypes(Type type, bool onlyInstantiable = true) {
    104111      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    105112             from t in GetTypes(type, asm, onlyInstantiable)
     
    115122    /// (interfaces, abstract classes...  are not returned)</param>
    116123    /// <returns>Enumerable of the discovered types.</returns>
    117     private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable) {
     124    private static IEnumerable<Type> GetTypes(Type type, Assembly assembly, bool onlyInstantiable = true) {
    118125      try {
    119126        var assemblyTypes = assembly.GetTypes();
     
    175182    /// <returns></returns>
    176183    /// <throws>NotSupportedException</throws>
    177     public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable) {
     184    public IEnumerable<Type> GetTypes(Type type, IPluginDescription plugin, bool onlyInstantiable = true) {
     185      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
     186    }
     187
     188    /// <summary>
     189    /// Not supported by the LightweightApplicationManager
     190    /// </summary>
     191    /// <param name="type"></param>
     192    /// <param name="plugin"></param>
     193    /// <param name="onlyInstantiable"></param>
     194    /// <returns></returns>
     195    /// <throws>NotSupportedException</throws>
     196    public IEnumerable<Type> GetTypes(IEnumerable<Type> types, IPluginDescription plugin, bool onlyInstantiable = true, bool allTypes = true) {
    178197      throw new NotSupportedException("LightweightApplicationManager doesn't support type discovery for plugins.");
    179198    }
Note: See TracChangeset for help on using the changeset viewer.