Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13511


Ignore:
Timestamp:
01/15/16 12:13:51 (9 years ago)
Author:
abeham
Message:

#2560: Moved both get and set characteristic values functionality to run creation service

Location:
trunk/sources/HeuristicLab.Services.OKB/3.3
Files:
6 edited

Legend:

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

    r13501 r13511  
    8888      return new DT.ValueName() { Id = source.Id, Category = source.Category, Name = source.Name };
    8989    }
    90 
    91     public static DT.Value ToDto(DA.CharacteristicValue source) {
    92       if (source == null) return null;
    93       if (source.Characteristic.Type == DA.CharacteristicType.Bool) {
    94         return new DT.BoolValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.BoolValue.GetValueOrDefault() };
    95       } else if (source.Characteristic.Type == DA.CharacteristicType.Int) {
    96         return new DT.IntValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.IntValue.GetValueOrDefault() };
    97       } else if (source.Characteristic.Type == DA.CharacteristicType.TimeSpan) {
    98         return new DT.TimeSpanValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() };
    99       } else if (source.Characteristic.Type == DA.CharacteristicType.Long) {
    100         return new DT.LongValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() };
    101       } else if (source.Characteristic.Type == DA.CharacteristicType.Float) {
    102         return new DT.FloatValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.FloatValue.GetValueOrDefault() };
    103       } else if (source.Characteristic.Type == DA.CharacteristicType.Double) {
    104         return new DT.DoubleValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() };
    105       } else if (source.Characteristic.Type == DA.CharacteristicType.Percent) {
    106         return new DT.PercentValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() };
    107       } else if (source.Characteristic.Type == DA.CharacteristicType.String) {
    108         return new DT.StringValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.StringValue };
    109       } else {
    110         throw new ArgumentException("Unknown characteristic type.", "source");
    111       }
    112     }
    11390  }
    11491}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Query/IQueryService.cs

    r13501 r13511  
    4848    [OperationContract]
    4949    IEnumerable<ValueName> GetValueNames();
    50 
    51     [OperationContract]
    52     IEnumerable<Value> GetCharacteristics(long problemId);
    5350  }
    5451}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Query/QueryService.cs

    r13501 r13511  
    278278    }
    279279
    280 
    281     public IEnumerable<DataTransfer.Value> GetCharacteristics(long problemId) {
    282       using (OKBDataContext okb = new OKBDataContext()) {
    283         var prob = okb.Problems.SingleOrDefault(x => x.Id == problemId);
    284         if (prob == null) return Enumerable.Empty<DataTransfer.Value>();
    285         return prob.CharacteristicValues.Select(Convert.ToDto).ToArray();
    286       }
    287     }
    288 
    289280    private List<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter, OKBDataContext okb) {
    290281      IFilter f = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r13501 r13511  
    7070    }
    7171
    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();
     72    public static DT.Value ToDto(DA.CharacteristicValue source) {
     73      if (source == null) return null;
     74      if (source.Characteristic.Type == DA.CharacteristicType.Bool) {
     75        return new DT.BoolValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.BoolValue.GetValueOrDefault() };
     76      } else if (source.Characteristic.Type == DA.CharacteristicType.Int) {
     77        return new DT.IntValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.IntValue.GetValueOrDefault() };
     78      } else if (source.Characteristic.Type == DA.CharacteristicType.TimeSpan) {
     79        return new DT.TimeSpanValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() };
     80      } else if (source.Characteristic.Type == DA.CharacteristicType.Long) {
     81        return new DT.LongValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() };
     82      } else if (source.Characteristic.Type == DA.CharacteristicType.Float) {
     83        return new DT.FloatValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.FloatValue.GetValueOrDefault() };
     84      } else if (source.Characteristic.Type == DA.CharacteristicType.Double) {
     85        return new DT.DoubleValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() };
     86      } else if (source.Characteristic.Type == DA.CharacteristicType.Percent) {
     87        return new DT.PercentValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() };
     88      } else if (source.Characteristic.Type == DA.CharacteristicType.String) {
     89        return new DT.StringValue { Name = source.Characteristic.Name, DataType = Convert.ToDto(source.DataType), Value = source.StringValue };
     90      } else {
     91        throw new ArgumentException("Unknown characteristic type.", "source");
     92      }
     93    }
     94
     95    public static DA.CharacteristicValue ToEntity(DT.Value source, DA.OKBDataContext okb, DA.Problem problem, DA.CharacteristicType type) {
     96      if (okb == null || problem == null || source == null || string.IsNullOrEmpty(source.Name)) throw new ArgumentNullException();
    7497      var entity = new DA.CharacteristicValue();
    7598      entity.Problem = problem;
    7699      entity.DataType = Convert.ToEntity(source.DataType, okb);
    77       entity.Characteristic = Convert.ToEntity(characteristicName, type, okb);
     100      entity.Characteristic = Convert.ToEntity(source.Name, type, okb);
    78101      if (source is DT.BoolValue) {
    79102        entity.BoolValue = ((DT.BoolValue)source).Value;
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r13501 r13511  
    4747
    4848    [OperationContract]
     49    IEnumerable<Value> GetCharacteristicValues(long problemId);
     50
     51    [OperationContract]
    4952    [FaultContract(typeof(MissingProblem))]
    5053    [FaultContract(typeof(UnknownCharacteristicType))]
    51     void SetCharacteristicValue(long problemId, string characteristicName, Value value);
     54    void SetCharacteristicValue(long problemId, Value value);
     55
     56    [OperationContract]
     57    [FaultContract(typeof(MissingProblem))]
     58    [FaultContract(typeof(UnknownCharacteristicType))]
     59    void SetCharacteristicValues(long problemId, Value[] values);
    5260  }
    5361}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r13501 r13511  
    137137    }
    138138
    139 
    140     public void SetCharacteristicValue(long problemId, string characteristicName, DataTransfer.Value value) {
     139    public IEnumerable<DataTransfer.Value> GetCharacteristicValues(long problemId) {
     140      using (OKBDataContext okb = new OKBDataContext()) {
     141        var prob = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     142        if (prob == null) return Enumerable.Empty<DataTransfer.Value>();
     143        return prob.CharacteristicValues.Select(Convert.ToDto).ToArray();
     144      }
     145    }
     146
     147    public void SetCharacteristicValue(long problemId, DataTransfer.Value value) {
    141148      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
    142149
     
    144151        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
    145152        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId));
    146         CharacteristicType characteristicType;
    147         try {
    148           characteristicType = GetCharacteristicType(value);
    149         } catch (ArgumentException ex) {
    150           throw new FaultException<UnknownCharacteristicType>(new UnknownCharacteristicType(ex.Message));
    151         }
    152 
    153         var entity = okb.CharacteristicValues.SingleOrDefault(x => x.Characteristic.Name == characteristicName && x.Characteristic.Type == characteristicType);
    154         if (entity != null) {
    155           // Update
    156           switch (characteristicType) {
    157             case CharacteristicType.Bool: entity.BoolValue = ((DataTransfer.BoolValue)value).Value; break;
    158             case CharacteristicType.Int: entity.IntValue = ((DataTransfer.IntValue)value).Value; break;
    159             case CharacteristicType.Long: entity.LongValue = ((DataTransfer.LongValue)value).Value; break;
    160             case CharacteristicType.Float: entity.FloatValue = ((DataTransfer.FloatValue)value).Value; break;
    161             case CharacteristicType.Double: entity.DoubleValue = ((DataTransfer.DoubleValue)value).Value; break;
    162             case CharacteristicType.Percent: entity.DoubleValue = ((DataTransfer.PercentValue)value).Value; break;
    163             case CharacteristicType.String: entity.StringValue = ((DataTransfer.StringValue)value).Value; break;
    164             case CharacteristicType.TimeSpan: entity.LongValue = ((DataTransfer.TimeSpanValue)value).Value; break;
    165           }
    166         } else {
    167           // Insert
    168           entity = Convert.ToEntity(value, okb, problem, characteristicName, characteristicType);
    169           okb.CharacteristicValues.InsertOnSubmit(entity);
    170         }
     153
     154        DoSetCharacteristicValue(okb, problem, value);
    171155        okb.SubmitChanges();
    172156      }
     157    }
     158
     159    public void SetCharacteristicValues(long problemId, DataTransfer.Value[] values) {
     160      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     161
     162      using (OKBDataContext okb = new OKBDataContext()) {
     163        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     164        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId));
     165
     166        foreach (var v in values) {
     167          DoSetCharacteristicValue(okb, problem, v);
     168        }
     169        okb.SubmitChanges();
     170      }
     171    }
     172
     173    private void DoSetCharacteristicValue(OKBDataContext okb, Problem problem, DataTransfer.Value value) {
     174      CharacteristicType characteristicType;
     175      try {
     176        characteristicType = GetCharacteristicType(value);
     177      } catch (ArgumentException ex) {
     178        throw new FaultException<UnknownCharacteristicType>(new UnknownCharacteristicType(ex.Message));
     179      }
     180
     181      var entity = okb.CharacteristicValues.SingleOrDefault(x => x.Characteristic.Name == value.Name && x.Characteristic.Type == characteristicType);
     182      if (entity != null) {
     183        // Update
     184        switch (characteristicType) {
     185          case CharacteristicType.Bool: entity.BoolValue = ((DataTransfer.BoolValue)value).Value; break;
     186          case CharacteristicType.Int: entity.IntValue = ((DataTransfer.IntValue)value).Value; break;
     187          case CharacteristicType.Long: entity.LongValue = ((DataTransfer.LongValue)value).Value; break;
     188          case CharacteristicType.Float: entity.FloatValue = ((DataTransfer.FloatValue)value).Value; break;
     189          case CharacteristicType.Double: entity.DoubleValue = ((DataTransfer.DoubleValue)value).Value; break;
     190          case CharacteristicType.Percent: entity.DoubleValue = ((DataTransfer.PercentValue)value).Value; break;
     191          case CharacteristicType.String: entity.StringValue = ((DataTransfer.StringValue)value).Value; break;
     192          case CharacteristicType.TimeSpan: entity.LongValue = ((DataTransfer.TimeSpanValue)value).Value; break;
     193        }
     194      } else {
     195        // Insert
     196        entity = Convert.ToEntity(value, okb, problem, characteristicType);
     197        okb.CharacteristicValues.InsertOnSubmit(entity);
     198      }
     199
    173200    }
    174201
Note: See TracChangeset for help on using the changeset viewer.