Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/12/16 16:08:38 (8 years ago)
Author:
abeham
Message:

#2560: added service methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r12012 r13501  
    6868        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache));
    6969      return entity;
     70    }
     71
     72    public static DA.CharacteristicValue ToEntity(DT.Value source, DA.OKBDataContext okb, DA.Problem problem, string characteristicName, DA.CharacteristicType type) {
     73      if (okb == null || problem == null || string.IsNullOrEmpty(characteristicName) || source == null) throw new ArgumentNullException();
     74      var entity = new DA.CharacteristicValue();
     75      entity.Problem = problem;
     76      entity.DataType = Convert.ToEntity(source.DataType, okb);
     77      entity.Characteristic = Convert.ToEntity(characteristicName, type, okb);
     78      if (source is DT.BoolValue) {
     79        entity.BoolValue = ((DT.BoolValue)source).Value;
     80      } else if (source is DT.IntValue) {
     81        entity.IntValue = ((DT.IntValue)source).Value;
     82      } else if (source is DT.TimeSpanValue) {
     83        entity.LongValue = ((DT.TimeSpanValue)source).Value;
     84      } else if (source is DT.LongValue) {
     85        entity.LongValue = ((DT.LongValue)source).Value;
     86      } else if (source is DT.FloatValue) {
     87        entity.FloatValue = ((DT.FloatValue)source).Value;
     88      } else if (source is DT.DoubleValue) {
     89        entity.DoubleValue = ((DT.DoubleValue)source).Value;
     90      } else if (source is DT.PercentValue) {
     91        entity.DoubleValue = ((DT.PercentValue)source).Value;
     92      } else if (source is DT.StringValue) {
     93        entity.StringValue = ((DT.StringValue)source).Value;
     94      } else {
     95        throw new ArgumentException("Unknown characteristic type.", "source");
     96      }
     97      return entity;
     98    }
     99
     100    private static DA.Characteristic ToEntity(string name, DA.CharacteristicType type, DA.OKBDataContext okb) {
     101      if (string.IsNullOrEmpty(name)) return null;
     102      var entity = okb.Characteristics.FirstOrDefault(x => (x.Name == name) && (x.Type == type));
     103      return entity ?? new DA.Characteristic() { Id = 0, Name = name, Type = type };
    70104    }
    71105
Note: See TracChangeset for help on using the changeset viewer.