Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/12 20:01:42 (12 years ago)
Author:
ascheibe
Message:

#1174

  • prevent uploading of double parameters/results that are NaN
  • when adding a run don't generate duplicate binary datas
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r7574 r7741  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Security.Cryptography;
     
    5859    public static DA.Run ToEntity(DT.Run source, DA.OKBDataContext okb) {
    5960      if (source == null) return null;
     61
     62      List<DA.BinaryData> binCache = new List<DA.BinaryData>();
     63
    6064      DA.Run entity = new DA.Run { Id = 0, AlgorithmId = source.AlgorithmId, ProblemId = source.ProblemId, CreatedDate = source.CreatedDate, UserId = source.UserId, ClientId = source.ClientId };
    6165      foreach (var value in source.ParameterValues)
    62         entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb));
     66        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb, binCache));
    6367      foreach (var value in source.ResultValues)
    64         entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb));
     68        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache));
    6569      return entity;
    6670    }
    6771
    68     private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb) {
     72    private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb, List<DA.BinaryData> binCache) {
    6973      if (source == null) return null;
    7074      var entity = new DA.Value();
     
    97101      } else if (source is DT.BinaryValue) {
    98102        entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Binary, okb);
    99         entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb);
     103        entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb, binCache);
    100104      } else {
    101105        throw new ArgumentException("Unknown value type.", "source");
     
    120124    }
    121125
    122     private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb) {
     126    private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb, List<DA.BinaryData> binCache) {
    123127      if (data == null) return null;
    124128      byte[] hash;
     
    126130        hash = sha1.ComputeHash(data);
    127131      }
     132
     133      var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();
     134      if (cachedBinaryData != null)
     135        return cachedBinaryData;
     136
    128137      var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
    129       if (entity == null)
     138      if (entity == null) {
    130139        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
     140        binCache.Add(entity);
     141      }
     142
    131143      return entity;
    132144    }
Note: See TracChangeset for help on using the changeset viewer.