Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/20 16:28:53 (5 years ago)
Author:
dpiringe
Message:

#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
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/AlgorithmConverter.cs

    r17443 r17444  
    1616      base.Inject(item, data, root);
    1717      IAlgorithm algorithm = item as IAlgorithm;
    18       IJsonItem problemData = data.Children.Where(x => x.Name == algorithm.Problem.ItemName).First();
    19       root.Inject(algorithm.Problem, problemData, root);
    20 
     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      }
    2123    }
    2224   
     
    2729        item.AddChildren(new ResultItem() {
    2830          Name = res.Name,
    29           Description = res.Description,
    30           Value = true,
    31           Range = new object[] { true, false }
     31          Description = res.Description
    3232        });
    3333      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Interfaces/IJsonItem.cs

    r17433 r17444  
    3333
    3434    void AddChildren(IEnumerable<IJsonItem> childs);
     35
     36    /// <summary>
     37    /// This method fixates the path.
     38    /// After calling, the path cannot be changed by changing the name or parent.
     39    /// </summary>
     40    void FixatePath();
     41
     42    /// <summary>
     43    /// This method looses the path again after a call of FixatePath.
     44    /// After calling, the path is calculated by the position in item tree again.
     45    /// </summary>
     46    void LoosenPath();
    3547  }
    3648}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItem.cs

    r17435 r17444  
    4545    public virtual string Description { get; set; }
    4646
     47    private string fixedPath = "";
    4748    public virtual string Path {
    4849      get {
     50        if (!string.IsNullOrWhiteSpace(fixedPath))
     51          return fixedPath;
     52
    4953        IJsonItem tmp = Parent;
    5054        StringBuilder builder = new StringBuilder(this.Name);
     
    5761    }
    5862
     63    public virtual object Value { get; set; }
     64
     65    public virtual IEnumerable<object> Range { get; set; }
     66   
     67    public virtual string ActualName { get; set; }
     68
    5969    [JsonIgnore]
    6070    public virtual IList<IJsonItem> Children { get; protected set; }
     
    6272    [JsonIgnore]
    6373    public virtual IJsonItem Parent { get; set; }
    64 
    65     public virtual object Value { get; set; }
    66 
    67     public virtual IEnumerable<object> Range { get; set; }
    68    
    69     public virtual string ActualName { get; set; }
    7074
    7175    #region Constructors
     
    97101
    98102    public void AddChildren(IEnumerable<IJsonItem> childs) {
     103      if (childs == null) return;
    99104      if (Children == null)
    100105        Children = new List<IJsonItem>();
     
    106111
    107112    public virtual IJsonItemValidator GetValidator() => new JsonItemValidator(this);
     113
     114    public void FixatePath() => fixedPath = Path;
     115    public void LoosenPath() => fixedPath = "";
    108116    #endregion
    109117
    110118    #region Helper
    111     protected bool IsInRange() {
     119    protected virtual bool IsInRange() {
    112120      bool b1 = true, b2 = true;
    113121      if (Value is IEnumerable && !(Value is string)) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItems.cs

    r17420 r17444  
    99  public class IntArrayJsonItem: JsonItem<int[], int> { }
    1010  public class IntRangeJsonItem : JsonItem<int[], int> { }
    11   public class IntMatrixJsonItem : JsonItem<int[][], int> { }
     11  public class IntMatrixJsonItem : JsonItem<int[][], int> {
     12    protected override bool IsInRange() {
     13      for (int c = 0; c < Value.Length; ++c) {
     14        for (int r = 0; r < Value[c].Length; ++r) {
     15          if (Value[c][r] < Range.First() && Range.Last() < Value[c][r])
     16            return false;
     17        }
     18      }
     19      return true;
     20    }
     21  }
    1222
    1323  public class DoubleJsonItem: JsonItem<double> {}
    1424  public class DoubleArrayJsonItem: JsonItem<double[], double> { }
    1525  public class DoubleRangeJsonItem : JsonItem<double[], double> { }
    16   public class DoubleMatrixJsonItem : JsonItem<double[][], double> { }
     26  public class DoubleMatrixJsonItem : JsonItem<double[][], double> {
     27    protected override bool IsInRange() {
     28      for(int c = 0; c < Value.Length; ++c) {
     29        for(int r = 0; r < Value[c].Length; ++r) {
     30          if (Value[c][r] < Range.First() && Range.Last() < Value[c][r])
     31            return false;
     32        }
     33      }
     34      return true;
     35    }
     36  }
    1737
    1838  public class BoolJsonItem: JsonItem<bool> { }
Note: See TracChangeset for help on using the changeset viewer.