source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BatchRunConverter.cs @ 17828

Last change on this file since 17828 was 17828, checked in by dpiringe, 2 months ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7
8namespace HeuristicLab.JsonInterface {
9  public class BatchRunConverter : BaseConverter {
10    public override int Priority => 10;
11    public override Type ConvertableType => HEAL.Attic.Mapper.StaticCache.GetType(new Guid("E85407E0-18EC-4198-8321-9CF030FDF6D7"));
12
13    public override bool CanConvertType(Type t) => ConvertableType.IsAssignableFrom(t);
14
15    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
16      dynamic batchRun = (dynamic)value;
17      EmptyJsonItem batchRunJI = new EmptyJsonItem() {
18        Name = batchRun.Name,
19        Description = value.ItemDescription
20      };
21
22      var optimizerJI = root.Extract((IItem)batchRun.Optimizer, root);
23      if(!(optimizerJI is UnsupportedJsonItem)) {
24        batchRunJI.AddChildren(optimizerJI);
25      }
26
27      int reps = (int)batchRun.Repetitions;
28      batchRunJI.AddChildren(new IntJsonItem() {
29        Name = "Repetitions",
30        Description = "The repetitions for this batch run.",
31        Value = reps,
32        Minimum = 0,
33        Maximum = int.MaxValue
34      });
35      return batchRunJI;
36    }
37
38    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
39      dynamic batchRun = (dynamic)item;
40      if(data.Children != null) {
41        foreach(var i in data.Children) {
42          if(i.Path.EndsWith("Repetitions") && i is IntJsonItem reps ) {
43            batchRun.Repetitions = reps.Value;
44          } else {
45            root.Inject((IItem)batchRun.Optimizer, i, root);
46          }
47        }
48      }
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.