Changeset 13501


Ignore:
Timestamp:
01/12/16 16:08:38 (19 months ago)
Author:
abeham
Message:

#2560: added service methods

Location:
trunk/sources
Files:
2 added
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.OKB.DataAccess/3.3/CharacteristicType.cs

    r13484 r13501  
    2121
    2222namespace HeuristicLab.Services.OKB.DataAccess {
    23   public enum ValueNameType {
     23  public enum CharacteristicType {
    2424    Bool = 0,
    2525    Int = 1,
     
    2828    Double = 4,
    2929    String = 5,
    30     Binary = 6,
    31     Percent = 7,
    32     TimeSpan = 8
     30    Percent = 6,
     31    TimeSpan = 7
    3332  }
    3433}
  • trunk/sources/HeuristicLab.Services.OKB.DataAccess/3.3/HeuristicLab.Services.OKB.DataAccess-3.3.csproj

    r11623 r13501  
    128128  </ItemGroup>
    129129  <ItemGroup>
     130    <Compile Include="CharacteristicType.cs" />
    130131    <Compile Include="ValueNameType.cs" />
    131132    <Compile Include="ValueNameCategory.cs" />
  • trunk/sources/HeuristicLab.Services.OKB.DataAccess/3.3/OKB.dbml

    r8049 r13501  
    141141      <Column Name="Id" Type="System.Int64" DbType="BigInt NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    142142      <Column Name="Name" Type="System.String" DbType="NVarChar(200) NOT NULL" CanBeNull="false" />
    143       <Column Name="Type" Type="System.Byte" DbType="TinyInt NOT NULL" CanBeNull="false" />
     143      <Column Name="Type" Type="CharacteristicType" DbType="TinyInt NOT NULL" CanBeNull="false" />
    144144      <Association Name="Characteristic_CharacteristicValue" Member="CharacteristicValues" ThisKey="Id" OtherKey="CharacteristicId" Type="CharacteristicValue" />
    145145    </Type>
  • trunk/sources/HeuristicLab.Services.OKB.DataAccess/3.3/OKB.dbml.layout

    r8049 r13501  
    139139      </nestedChildShapes>
    140140    </classShape>
    141     <associationConnector edgePoints="[(3.24167093356531 : 2.65549967447917); (3.24167093356531 : 8.23159912109375); (5.75 : 8.23159912109375)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     141    <associationConnector edgePoints="[(3.24167093356531 : 2.65549967447917); (3.24167093356531 : 8.23159912109375); (5.75 : 8.23159912109375)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    142142      <AssociationMoniker Name="/OKBDataContext/Algorithm/Algorithm_Run" />
    143143      <nodes>
     
    146146      </nodes>
    147147    </associationConnector>
    148     <associationConnector edgePoints="[(12.7565713753709 : 2.65549967447917); (12.7565713753709 : 8.23159912109375); (8.13243692318721 : 8.23159912109375 : JumpStart); (7.96577025652055 : 8.23159912109375 : JumpEnd); (7.75 : 8.23159912109375)]" fixedFrom="Algorithm" fixedTo="Algorithm">
     148    <associationConnector edgePoints="[(12.7565713753709 : 2.65549967447917); (12.7565713753709 : 8.23159912109375); (8.13243692318721 : 8.23159912109375 : JumpStart); (7.96577025652055 : 8.23159912109375 : JumpEnd); (7.75 : 8.23159912109375)]" fixedFrom="NotFixed" fixedTo="NotFixed">
    149149      <AssociationMoniker Name="/OKBDataContext/Problem/Problem_Run" />
    150150      <nodes>
  • trunk/sources/HeuristicLab.Services.OKB.DataAccess/3.3/OKB.designer.cs

    r11623 r13501  
    33// <auto-generated>
    44//     This code was generated by a tool.
    5 //     Runtime Version:4.0.30319.34014
     5//     Runtime Version:4.0.30319.34209
    66//
    77//     Changes to this file may cause incorrect behavior and will be lost if
     
    31403140    private string _Name;
    31413141   
    3142     private byte _Type;
     3142    private CharacteristicType _Type;
    31433143   
    31443144    private EntitySet<CharacteristicValue> _CharacteristicValues;
     
    31523152    partial void OnNameChanging(string value);
    31533153    partial void OnNameChanged();
    3154     partial void OnTypeChanging(byte value);
     3154    partial void OnTypeChanging(CharacteristicType value);
    31553155    partial void OnTypeChanged();
    31563156    #endregion
     
    32023202    }
    32033203   
    3204     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Type", DbType="TinyInt NOT NULL")]
    3205     public byte Type
     3204    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Type", DbType="TinyInt NOT NULL", CanBeNull=false)]
     3205    public CharacteristicType Type
    32063206    {
    32073207      get
  • trunk/sources/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj

    r12479 r13501  
    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>
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Query/Convert.cs

    r13473 r13501  
    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    }
    90113  }
    91114}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/Query/IQueryService.cs

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

    r12012 r13501  
    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
    280289    private List<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter, OKBDataContext okb) {
    281290      IFilter f = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);
  • 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
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r12012 r13501  
    4545    [OperationContract]
    4646    void AddRun(Run run);
     47
     48    [OperationContract]
     49    [FaultContract(typeof(MissingProblem))]
     50    [FaultContract(typeof(UnknownCharacteristicType))]
     51    void SetCharacteristicValue(long problemId, string characteristicName, Value value);
    4752  }
    4853}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r12012 r13501  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Data.Linq;
     
    135136      }
    136137    }
     138
     139
     140    public void SetCharacteristicValue(long problemId, string characteristicName, DataTransfer.Value value) {
     141      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     142
     143      using (OKBDataContext okb = new OKBDataContext()) {
     144        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     145        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        }
     171        okb.SubmitChanges();
     172      }
     173    }
     174
     175    private CharacteristicType GetCharacteristicType(DataTransfer.Value source) {
     176      if (source is DataTransfer.BoolValue) {
     177        return CharacteristicType.Bool;
     178      } else if (source is DataTransfer.IntValue) {
     179        return CharacteristicType.Int;
     180      } else if (source is DataTransfer.TimeSpanValue) {
     181        return CharacteristicType.TimeSpan;
     182      } else if (source is DataTransfer.LongValue) {
     183        return CharacteristicType.Long;
     184      } else if (source is DataTransfer.FloatValue) {
     185        return CharacteristicType.Float;
     186      } else if (source is DataTransfer.DoubleValue) {
     187        return CharacteristicType.Double;
     188      } else if (source is DataTransfer.PercentValue) {
     189        return CharacteristicType.Percent;
     190      } else if (source is DataTransfer.StringValue) {
     191        return CharacteristicType.String;
     192      } else {
     193        throw new ArgumentException("Unknown characteristic type.", "source");
     194      }
     195    }
    137196  }
    138197}
Note: See TracChangeset for help on using the changeset viewer.