Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • 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  }
Note: See TracChangeset for help on using the changeset viewer.