Ignore:
Timestamp:
06/28/17 22:14:18 (3 years ago)
Author:
gkronber
Message:

#2588 merged r13682, r13683, r13684, r13690:13693, r13709, r13746 from trunk to stable

Location:
stable
Files:
6 edited
3 copied

Legend:

Unmodified
Added
Removed
  • stable

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

    r15081 r15082  
    283283    <Compile Include="RunCreation\DataTransfer\BinaryValue.cs" />
    284284    <Compile Include="RunCreation\DataTransfer\BoolValue.cs" />
     285    <Compile Include="RunCreation\DataTransfer\SingleObjectiveSolution.cs" />
     286    <Compile Include="RunCreation\DataTransfer\Solution.cs" />
    285287    <Compile Include="RunCreation\DataTransfer\TimeSpanValue.cs" />
    286288    <Compile Include="RunCreation\DataTransfer\PercentValue.cs" />
     
    295297    <Compile Include="RunCreation\DataTransfer\StringValue.cs" />
    296298    <Compile Include="RunCreation\DataTransfer\Value.cs" />
     299    <Compile Include="RunCreation\MissingSolution.cs" />
    297300    <Compile Include="RunCreation\MissingProblem.cs" />
    298301    <Compile Include="RunCreation\RunCreationService.cs" />
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r15081 r15082  
    3838      if (source == null) return null;
    3939      return new DT.Problem { Id = source.Id, Name = source.Name, Description = source.Description, ProblemClass = Convert.ToDto(source.ProblemClass), DataType = Convert.ToDto(source.DataType) };
     40    }
     41
     42    public static DT.SingleObjectiveSolution ToDto(DA.SingleObjectiveSolution source) {
     43      if (source == null) return null;
     44      return new DT.SingleObjectiveSolution() {
     45        Id = source.Id,
     46        ProblemId = source.ProblemId.Value,
     47        RunId = source.RunId,
     48        Quality = source.Quality,
     49        DataType = ToDto(source.DataType)
     50      };
    4051    }
    4152
     
    165176    }
    166177
    167     private static DA.DataType ToEntity(DT.DataType source, DA.OKBDataContext okb) {
    168       if (source == null) return null;
    169       var entity = okb.DataTypes.Where(x => (x.Name == source.Name) && (x.TypeName == source.TypeName)).FirstOrDefault();
     178    public static DA.DataType ToEntity(DT.DataType source, DA.OKBDataContext okb) {
     179      if (source == null) return null;
     180      var entity = okb.DataTypes.FirstOrDefault(x => (x.Name == source.Name) && (x.TypeName == source.TypeName));
    170181      if (entity == null)
    171182        entity = new DA.DataType() { Id = 0, Name = source.Name, TypeName = source.TypeName };
     
    175186    private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb) {
    176187      if (string.IsNullOrEmpty(name)) return null;
    177       var entity = okb.ValueNames.Where(x => (x.Name == name) && (x.Category == category) && (x.Type == type)).FirstOrDefault();
     188      var entity = okb.ValueNames.FirstOrDefault(x => (x.Name == name) && (x.Category == category) && (x.Type == type));
    178189      if (entity == null)
    179190        entity = new DA.ValueName() { Id = 0, Name = name, Category = category, Type = type };
     
    188199      }
    189200
    190       var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();
     201      var cachedBinaryData = binCache.FirstOrDefault(x => x.Hash.SequenceEqual(hash));
    191202      if (cachedBinaryData != null)
    192203        return cachedBinaryData;
    193204
    194       var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
     205      var entity = okb.BinaryDatas.FirstOrDefault(x => x.Hash.Equals(hash));
    195206      if (entity == null) {
    196207        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
     
    200211      return entity;
    201212    }
     213
     214    public static DA.SingleObjectiveSolution ToEntity(DT.SingleObjectiveSolution source, byte[] data, DA.OKBDataContext okb) {
     215      var sol = okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == source.Id) ?? new DA.SingleObjectiveSolution() {
     216        ProblemId = source.ProblemId,
     217        RunId = source.RunId,
     218        Quality = source.Quality
     219      };
     220      if (source.DataType != null) {
     221        sol.DataType = ToEntity(source.DataType, okb);
     222      }
     223      if (data != null && data.Length > 0) {
     224        byte[] hash;
     225        using (var sha1 = SHA1.Create()) {
     226          hash = sha1.ComputeHash(data);
     227        }
     228        sol.BinaryData = new DA.BinaryData() {
     229          Data = data,
     230          Hash = hash
     231        };
     232      }
     233      return sol;
     234    }
    202235    #endregion
    203236  }
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r15081 r15082  
    2020#endregion
    2121
     22using HeuristicLab.Services.OKB.RunCreation.DataTransfer;
    2223using System.Collections.Generic;
    2324using System.Net.Security;
    2425using System.ServiceModel;
    25 using HeuristicLab.Services.OKB.RunCreation.DataTransfer;
    2626
    2727namespace HeuristicLab.Services.OKB.RunCreation {
     
    4444
    4545    [OperationContract]
     46    [FaultContract(typeof(MissingProblem))]
     47    IEnumerable<Solution> GetSolutions(long problemId);
     48
     49    [OperationContract]
     50    Solution GetSolution(long solutionId);
     51
     52    [OperationContract]
     53    [FaultContract(typeof(MissingSolution))]
     54    byte[] GetSolutionData(long solutionId);
     55
     56    [OperationContract]
     57    long AddSolution(Solution solution, byte[] data);
     58
     59    [OperationContract]
     60    void DeleteSolution(Solution solution);
     61
     62    [OperationContract]
    4663    void AddRun(Run run);
    4764
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/MissingProblem.cs

    r15081 r15082  
    2828    public string Message { get; set; }
    2929
    30     public MissingProblem(string message, params object[] c) {
    31       Message = string.Format(message, c);
     30    public MissingProblem(long problemId) {
     31      Message = string.Format("Problem with id {0} cannot be found", problemId);
    3232    }
    3333  }
  • stable/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r15081 r15082  
    2020#endregion
    2121
     22using HeuristicLab.Services.Access;
     23using HeuristicLab.Services.OKB.DataAccess;
    2224using System;
    2325using System.Collections.Generic;
     
    2527using System.Linq;
    2628using System.ServiceModel;
    27 using HeuristicLab.Services.Access;
    28 using HeuristicLab.Services.OKB.DataAccess;
    2929
    3030namespace HeuristicLab.Services.OKB.RunCreation {
     
    127127    }
    128128
     129    public IEnumerable<DataTransfer.Solution> GetSolutions(long problemId) {
     130      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     131
     132      using (OKBDataContext okb = new OKBDataContext()) {
     133        var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId);
     134        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
     135        // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems
     136        var result = problem.SingleObjectiveSolutions.Select(x => Convert.ToDto(x)).ToList();
     137        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     138          return result;
     139        } else {
     140          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId).ToList();
     141          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     142            return result;
     143          } else {
     144            return null;
     145          }
     146        }
     147      }
     148    }
     149
     150    public DataTransfer.Solution GetSolution(long solutionId) {
     151      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     152
     153      using (OKBDataContext okb = new OKBDataContext()) {
     154        // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems
     155        var result = Convert.ToDto(okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId));
     156        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     157          return result;
     158        } else {
     159          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == result.ProblemId).ToList();
     160          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     161            return result;
     162          } else {
     163            return null;
     164          }
     165        }
     166      }
     167    }
     168
     169    public byte[] GetSolutionData(long solutionId) {
     170      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     171
     172      using (OKBDataContext okb = new OKBDataContext()) {
     173        var solution = okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId);
     174        if (solution == null) throw new FaultException<MissingSolution>(new MissingSolution(solutionId));
     175
     176        var result = solution.BinaryData.Data.ToArray();
     177        if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) {
     178          return result;
     179        } else {
     180          var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == solution.ProblemId).ToList();
     181          if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) {
     182            return result;
     183          } else {
     184            return null;
     185          }
     186        }
     187      }
     188    }
     189
     190    public long AddSolution(DataTransfer.Solution solution, byte[] data) {
     191      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     192
     193      using (OKBDataContext okb = new OKBDataContext()) {
     194        var soSolution = solution as DataTransfer.SingleObjectiveSolution;
     195        if (soSolution != null) {
     196          DataAccess.SingleObjectiveSolution entity = Convert.ToEntity(soSolution, data, okb);
     197          okb.SingleObjectiveSolutions.InsertOnSubmit(entity);
     198          okb.SubmitChanges();
     199          return entity.Id;
     200        }
     201      }
     202      throw new FaultException(new FaultReason("The solution could not be added."));
     203    }
     204
     205    public void DeleteSolution(DataTransfer.Solution solution) {
     206      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     207
     208      using (OKBDataContext okb = new OKBDataContext()) {
     209        var soSolution = solution as DataTransfer.SingleObjectiveSolution;
     210        if (soSolution != null) {
     211          okb.SingleObjectiveSolutions.DeleteOnSubmit(okb.SingleObjectiveSolutions.Single(x => x.Id == soSolution.Id));
     212          okb.SubmitChanges();
     213        }
     214      }
     215    }
     216
    129217    public void AddRun(DataTransfer.Run run) {
    130218      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     
    150238      using (OKBDataContext okb = new OKBDataContext()) {
    151239        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));
     240        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
    153241
    154242        DoSetCharacteristicValue(okb, problem, value);
     
    162250      using (OKBDataContext okb = new OKBDataContext()) {
    163251        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));
     252        if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId));
    165253
    166254        foreach (var v in values) {
Note: See TracChangeset for help on using the changeset viewer.