1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.JsonInterface {
|
---|
9 | public class BatchRunConverter : BaseConverter {
|
---|
10 | public override int Priority => 10;
|
---|
11 |
|
---|
12 | public override bool CanConvertType(Type t) =>
|
---|
13 | HEAL.Attic.Mapper.StaticCache.GetType(new Guid("E85407E0-18EC-4198-8321-9CF030FDF6D7")).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 | }
|
---|