Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/14 16:36:10 (10 years ago)
Author:
ascheibe
Message:

#2117 merged r10130, r10150, r10154, r10170, r11079 into stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs

    r9886 r11083  
    2929  [StorableClass]
    3030  public class EngineTask : ItemTask {
     31    public override HiveTask CreateHiveTask() {
     32      //only used when deserializing, so no problem with parentscope
     33      return new EngineHiveTask(this, null);
     34    }
     35
    3136    [Storable]
    3237    protected IOperation initialOperation;
     
    5459      this.Item = engine;
    5560    }
     61
     62    public EngineTask(IEngine engine) : base(engine) { }
    5663
    5764    [StorableConstructor]
  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/ItemTask.cs

    r9456 r11083  
    2222using System;
    2323using System.Drawing;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Hive;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.PluginInfrastructure;
    2830
    2931namespace HeuristicLab.Clients.Hive {
     
    3133  [StorableClass]
    3234  public abstract class ItemTask : NamedItem, ITask {
     35    public virtual HiveTask CreateHiveTask() {
     36      return new HiveTask(this, true);
     37    }
     38
    3339    public virtual bool IsParallelizable {
    3440      get { return true; }
     41      set { }
    3542    }
    3643
     
    7178      this.Item = cloner.Clone(original.Item);
    7279    }
     80    public ItemTask(IItem item) {
     81      Item = item;
     82    }
    7383
    7484    [StorableHook(HookType.AfterDeserialization)]
     
    211221      return Name;
    212222    }
     223
     224    #region Helpers
     225    public static bool IsTypeSupported(Type itemType) {
     226      var supportedHiveTaskTypes = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     227          .Select(t => t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)).PropertyType);
     228      return supportedHiveTaskTypes.Any(x => x.IsAssignableFrom(itemType));
     229    }
     230
     231    public static Type GetHiveTaskType(Type itemType) {
     232      if (!IsTypeSupported(itemType)) throw new Exception("Item " + itemType + " is not supported for Hive.");
     233
     234      var typeHiveTaskMap = ApplicationManager.Manager.GetTypes(typeof(ItemTask))
     235          .Select(t => new Tuple<Type, Type>(t.GetProperties().Single(x => x.Name == "Item" && x.PropertyType != typeof(IItem)).PropertyType, t));
     236
     237      return typeHiveTaskMap.Single(x => x.Item1.IsAssignableFrom(itemType)).Item2;
     238    }
     239
     240    public static ItemTask GetItemTaskForItem(IItem item) {
     241      Type itemType = item.GetType();
     242      Type hiveTaskType = GetHiveTaskType(itemType);
     243      return Activator.CreateInstance(hiveTaskType, new object[] { item }) as ItemTask;
     244    }
     245    #endregion
    213246  }
    214247}
  • stable/HeuristicLab.Clients.Hive/3.3/Tasks/OptimizerTask.cs

    r9886 r11083  
    3030  [StorableClass]
    3131  public class OptimizerTask : ItemTask {
     32    public override HiveTask CreateHiveTask() {
     33      return new OptimizerHiveTask(this);
     34    }
     35
    3236    public override bool IsParallelizable {
    3337      get { return this.Item is Experiment || this.Item is BatchRun; }
     
    4650    }
    4751
    48     public OptimizerTask(IOptimizer optimizer) {
    49       this.Item = optimizer;
    50 
    51       if (optimizer is Experiment) {
     52    public OptimizerTask(IOptimizer optimizer)
     53      : base(optimizer) {
     54
     55      if (optimizer is Experiment || optimizer is BatchRun) {
    5256        this.ComputeInParallel = true;
    53       } else if (optimizer is BatchRun) {
    54         this.ComputeInParallel = false;
    5557      } else {
    5658        this.ComputeInParallel = false;
Note: See TracChangeset for help on using the changeset viewer.