Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17828 was 17828, checked in by dpiringe, 3 years 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.4 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 {
10  public class AlgorithmConverter : ParameterizedItemConverter {
11    public override int Priority => 30;
12
13    public override Type ConvertableType => typeof(IAlgorithm);
14
15    public override bool CanConvertType(Type t) =>
16      t.GetInterfaces().Any(x => x == ConvertableType);
17
18    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
19      base.Inject(item, data, root);
20      IAlgorithm algorithm = item as IAlgorithm;
21      var collection = data.Children.Where(x => x.Name == algorithm.Problem.ItemName);
22      if(collection.Count() > 0) {
23        IJsonItem problemData = collection.First();
24        root.Inject(algorithm.Problem, problemData, root);
25      }
26    }
27   
28    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
29      IJsonItem item = base.Extract(value, root);
30      IAlgorithm algorithm = value as IAlgorithm;
31      foreach (var res in algorithm.Results) {
32        item.AddChildren(new ResultJsonItem() {
33          Name = res.Name,
34          Description = res.Description
35        });
36      }
37      item.AddChildren(root.Extract(algorithm.Problem, root));
38      return item;
39    }
40  }
41}
Note: See TracBrowser for help on using the repository browser.