Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/17 22:10:45 (7 years ago)
Author:
gkronber
Message:

#2560 merged r13501, r13503, r13511, r13513, r13534, r13535, r13540, r13550, r13552, r13593, r13666 from trunk to stable

Location:
stable
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj

    r12564 r15081  
    295295    <Compile Include="RunCreation\DataTransfer\StringValue.cs" />
    296296    <Compile Include="RunCreation\DataTransfer\Value.cs" />
     297    <Compile Include="RunCreation\MissingProblem.cs" />
    297298    <Compile Include="RunCreation\RunCreationService.cs" />
    298299    <Compile Include="RunCreation\IRunCreationService.cs" />
     300    <Compile Include="RunCreation\UnknownCharacteristicType.cs" />
    299301  </ItemGroup>
    300302  <ItemGroup>
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r14186 r15081  
    6868        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache));
    6969      return entity;
     70    }
     71
     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();
     97      var entity = new DA.CharacteristicValue();
     98      entity.Problem = problem;
     99      entity.DataType = Convert.ToEntity(source.DataType, okb);
     100      entity.Characteristic = Convert.ToEntity(source.Name, type, okb);
     101      if (source is DT.BoolValue) {
     102        entity.BoolValue = ((DT.BoolValue)source).Value;
     103      } else if (source is DT.IntValue) {
     104        entity.IntValue = ((DT.IntValue)source).Value;
     105      } else if (source is DT.TimeSpanValue) {
     106        entity.LongValue = ((DT.TimeSpanValue)source).Value;
     107      } else if (source is DT.LongValue) {
     108        entity.LongValue = ((DT.LongValue)source).Value;
     109      } else if (source is DT.FloatValue) {
     110        entity.FloatValue = ((DT.FloatValue)source).Value;
     111      } else if (source is DT.DoubleValue) {
     112        entity.DoubleValue = ((DT.DoubleValue)source).Value;
     113      } else if (source is DT.PercentValue) {
     114        entity.DoubleValue = ((DT.PercentValue)source).Value;
     115      } else if (source is DT.StringValue) {
     116        entity.StringValue = ((DT.StringValue)source).Value;
     117      } else {
     118        throw new ArgumentException("Unknown characteristic type.", "source");
     119      }
     120      return entity;
     121    }
     122
     123    private static DA.Characteristic ToEntity(string name, DA.CharacteristicType type, DA.OKBDataContext okb) {
     124      if (string.IsNullOrEmpty(name)) return null;
     125      var entity = okb.Characteristics.FirstOrDefault(x => (x.Name == name) && (x.Type == type));
     126      return entity ?? new DA.Characteristic() { Id = 0, Name = name, Type = type };
    70127    }
    71128
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r14186 r15081  
    4545    [OperationContract]
    4646    void AddRun(Run run);
     47
     48    [OperationContract]
     49    IEnumerable<Value> GetCharacteristicValues(long problemId);
     50
     51    [OperationContract]
     52    [FaultContract(typeof(MissingProblem))]
     53    [FaultContract(typeof(UnknownCharacteristicType))]
     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);
    4760  }
    4861}
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r14186 r15081  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Data.Linq;
     
    135136      }
    136137    }
     138
     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) {
     148      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     149
     150      using (OKBDataContext okb = new OKBDataContext()) {
     151        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     152        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId));
     153
     154        DoSetCharacteristicValue(okb, problem, value);
     155        okb.SubmitChanges();
     156      }
     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 = problem.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
     200    }
     201
     202    private CharacteristicType GetCharacteristicType(DataTransfer.Value source) {
     203      if (source is DataTransfer.BoolValue) {
     204        return CharacteristicType.Bool;
     205      } else if (source is DataTransfer.IntValue) {
     206        return CharacteristicType.Int;
     207      } else if (source is DataTransfer.TimeSpanValue) {
     208        return CharacteristicType.TimeSpan;
     209      } else if (source is DataTransfer.LongValue) {
     210        return CharacteristicType.Long;
     211      } else if (source is DataTransfer.FloatValue) {
     212        return CharacteristicType.Float;
     213      } else if (source is DataTransfer.DoubleValue) {
     214        return CharacteristicType.Double;
     215      } else if (source is DataTransfer.PercentValue) {
     216        return CharacteristicType.Percent;
     217      } else if (source is DataTransfer.StringValue) {
     218        return CharacteristicType.String;
     219      } else {
     220        throw new ArgumentException("Unknown characteristic type.", "source");
     221      }
     222    }
    137223  }
    138224}
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/UnknownCharacteristicType.cs

    r13501 r15081  
    1 using System.Runtime.Serialization;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.Runtime.Serialization;
    223
    324namespace HeuristicLab.Services.OKB.RunCreation {
Note: See TracChangeset for help on using the changeset viewer.