Changeset 13683


Ignore:
Timestamp:
03/10/16 16:01:23 (18 months ago)
Author:
abeham
Message:

#2588:

  • Added service method to add solutions
Location:
trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation
Files:
4 edited

Legend:

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

    r13682 r13683  
    4646        ProblemId = source.ProblemId.Value,
    4747        RunId = source.RunId,
    48         Quality = source.Quality
     48        Quality = source.Quality,
     49        DataType = ToDto(source.DataType)
    4950      };
    5051    }
     
    175176    }
    176177
    177     private static DA.DataType ToEntity(DT.DataType source, DA.OKBDataContext okb) {
    178       if (source == null) return null;
    179       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));
    180181      if (entity == null)
    181182        entity = new DA.DataType() { Id = 0, Name = source.Name, TypeName = source.TypeName };
     
    185186    private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb) {
    186187      if (string.IsNullOrEmpty(name)) return null;
    187       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));
    188189      if (entity == null)
    189190        entity = new DA.ValueName() { Id = 0, Name = name, Category = category, Type = type };
     
    198199      }
    199200
    200       var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();
     201      var cachedBinaryData = binCache.FirstOrDefault(x => x.Hash.SequenceEqual(hash));
    201202      if (cachedBinaryData != null)
    202203        return cachedBinaryData;
    203204
    204       var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
     205      var entity = okb.BinaryDatas.FirstOrDefault(x => x.Hash.Equals(hash));
    205206      if (entity == null) {
    206207        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
     
    210211      return entity;
    211212    }
     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    }
    212235    #endregion
    213236  }
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/DataTransfer/Solution.cs

    r13682 r13683  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2522using System.Runtime.Serialization;
    26 using System.Text;
    27 using System.Threading.Tasks;
    2823
    2924namespace HeuristicLab.Services.OKB.RunCreation.DataTransfer {
     
    3732    [DataMember]
    3833    public long? RunId { get; set; }
     34    [DataMember]
     35    public DataType DataType { get; set; }
    3936  }
    4037}
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs

    r13682 r13683  
    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 {
     
    5252
    5353    [OperationContract]
     54    [FaultContract(typeof(MissingProblem))]
     55    void AddSolution(Solution solution, byte[] data);
     56
     57    [OperationContract]
    5458    void AddRun(Run run);
    5559
  • trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r13682 r13683  
    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 {
     
    165165            return null;
    166166          }
     167        }
     168      }
     169    }
     170
     171    public void AddSolution(DataTransfer.Solution solution, byte[] data) {
     172      roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser);
     173
     174      using (OKBDataContext okb = new OKBDataContext()) {
     175        var soSolution = solution as DataTransfer.SingleObjectiveSolution;
     176        if (soSolution != null) {
     177          DataAccess.SingleObjectiveSolution entity = Convert.ToEntity(soSolution, data, okb);
     178          okb.SingleObjectiveSolutions.InsertOnSubmit(entity);
     179          okb.SubmitChanges();
    167180        }
    168181      }
Note: See TracChangeset for help on using the changeset viewer.