Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17444 was 17444, checked in by dpiringe, 4 years ago

#3026:

  • added two new methods in IJsonItem -> FixatePath and LoosenPath to fixate/loosen the path (to enable name changing without effects on path)
  • set IsInRange to virtual and made overrides for IntMatrixJsonItem and DoubleMatrixJsonItem (IsInRange is a bad name and needs to be renamed in future versions)
  • implemented basic validation feedback with ErrorProvider for some inputs (templateName, Name, Range)
  • now all items gets validated before export (validation errors are shown with ErrorHandling.ShowErrorDialog)
  • added a check in AlgorithmConverter to prevent an exception for accessing the first element of an empty IEnumerable
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 {
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      var collection = data.Children.Where(x => x.Name == algorithm.Problem.ItemName);
19      if(collection.Count() > 0) {
20        IJsonItem problemData = collection.First();
21        root.Inject(algorithm.Problem, problemData, root);
22      }
23    }
24   
25    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
26      IJsonItem item = base.Extract(value, root);
27      IAlgorithm algorithm = value as IAlgorithm;
28      foreach (var res in algorithm.Results) {
29        item.AddChildren(new ResultItem() {
30          Name = res.Name,
31          Description = res.Description
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.