- Timestamp:
- 06/28/17 22:14:18 (7 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13682-13684,13690-13693,13709,13746
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs
r15081 r15082 38 38 if (source == null) return null; 39 39 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 }; 40 51 } 41 52 … … 165 176 } 166 177 167 p rivatestatic 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)); 170 181 if (entity == null) 171 182 entity = new DA.DataType() { Id = 0, Name = source.Name, TypeName = source.TypeName }; … … 175 186 private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb) { 176 187 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)); 178 189 if (entity == null) 179 190 entity = new DA.ValueName() { Id = 0, Name = name, Category = category, Type = type }; … … 188 199 } 189 200 190 var cachedBinaryData = binCache. Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();201 var cachedBinaryData = binCache.FirstOrDefault(x => x.Hash.SequenceEqual(hash)); 191 202 if (cachedBinaryData != null) 192 203 return cachedBinaryData; 193 204 194 var entity = okb.BinaryDatas. Where(x => x.Hash.Equals(hash)).FirstOrDefault();205 var entity = okb.BinaryDatas.FirstOrDefault(x => x.Hash.Equals(hash)); 195 206 if (entity == null) { 196 207 entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash }; … … 200 211 return entity; 201 212 } 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 } 202 235 #endregion 203 236 }
Note: See TracChangeset
for help on using the changeset viewer.