source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs @ 17433

Last change on this file since 17433 was 17433, checked in by dpiringe, 2 years ago

#3026:

  • added property Description in IJsonItem and updated all construction calls
  • updated UnsupportedJsonItem with unsupported property Description
  • updated JsonItemBaseControl and JsonItemVMBase for new property Description
File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HeuristicLab.Optimization;
8
9namespace HeuristicLab.JsonInterface.Converters {
10  public class AlgorithmConverter : ParameterizedItemConverter {
11    public override int Priority => 30;
12
13    public override Type ConvertableType => typeof(IAlgorithm);
14
15    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
16      base.Inject(item, data, root);
17      IAlgorithm algorithm = item as IAlgorithm;
18      IJsonItem problemData = data.Children.Where(x => x.Name == algorithm.Problem.Name).First();
19      root.Inject(algorithm.Problem, problemData, root);
20
21    }
22   
23    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
24      IJsonItem item = base.Extract(value, root);
25      IAlgorithm algorithm = value as IAlgorithm;
26      foreach (var res in algorithm.Results) {
27        item.AddChildren(new ResultItem() {
28          Name = res.Name,
29          Description = value.ItemDescription,
30          Value = true,
31          Range = new object[] { true, false }
32        });
33      }
34      item.AddChildren(root.Extract(algorithm.Problem, root));
35      return item;
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.