Changeset 13683
- Timestamp:
- 03/10/16 16:01:23 (9 years ago)
- 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 46 46 ProblemId = source.ProblemId.Value, 47 47 RunId = source.RunId, 48 Quality = source.Quality 48 Quality = source.Quality, 49 DataType = ToDto(source.DataType) 49 50 }; 50 51 } … … 175 176 } 176 177 177 p rivatestatic 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)); 180 181 if (entity == null) 181 182 entity = new DA.DataType() { Id = 0, Name = source.Name, TypeName = source.TypeName }; … … 185 186 private static DA.ValueName ToEntity(string name, DA.ValueNameCategory category, DA.ValueNameType type, DA.OKBDataContext okb) { 186 187 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)); 188 189 if (entity == null) 189 190 entity = new DA.ValueName() { Id = 0, Name = name, Category = category, Type = type }; … … 198 199 } 199 200 200 var cachedBinaryData = binCache. Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();201 var cachedBinaryData = binCache.FirstOrDefault(x => x.Hash.SequenceEqual(hash)); 201 202 if (cachedBinaryData != null) 202 203 return cachedBinaryData; 203 204 204 var entity = okb.BinaryDatas. Where(x => x.Hash.Equals(hash)).FirstOrDefault();205 var entity = okb.BinaryDatas.FirstOrDefault(x => x.Hash.Equals(hash)); 205 206 if (entity == null) { 206 207 entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash }; … … 210 211 return entity; 211 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 } 212 235 #endregion 213 236 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/DataTransfer/Solution.cs
r13682 r13683 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using System.Runtime.Serialization; 26 using System.Text;27 using System.Threading.Tasks;28 23 29 24 namespace HeuristicLab.Services.OKB.RunCreation.DataTransfer { … … 37 32 [DataMember] 38 33 public long? RunId { get; set; } 34 [DataMember] 35 public DataType DataType { get; set; } 39 36 } 40 37 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/IRunCreationService.cs
r13682 r13683 20 20 #endregion 21 21 22 using HeuristicLab.Services.OKB.RunCreation.DataTransfer; 22 23 using System.Collections.Generic; 23 24 using System.Net.Security; 24 25 using System.ServiceModel; 25 using HeuristicLab.Services.OKB.RunCreation.DataTransfer;26 26 27 27 namespace HeuristicLab.Services.OKB.RunCreation { … … 52 52 53 53 [OperationContract] 54 [FaultContract(typeof(MissingProblem))] 55 void AddSolution(Solution solution, byte[] data); 56 57 [OperationContract] 54 58 void AddRun(Run run); 55 59 -
trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs
r13682 r13683 20 20 #endregion 21 21 22 using HeuristicLab.Services.Access; 23 using HeuristicLab.Services.OKB.DataAccess; 22 24 using System; 23 25 using System.Collections.Generic; … … 25 27 using System.Linq; 26 28 using System.ServiceModel; 27 using HeuristicLab.Services.Access;28 using HeuristicLab.Services.OKB.DataAccess;29 29 30 30 namespace HeuristicLab.Services.OKB.RunCreation { … … 165 165 return null; 166 166 } 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(); 167 180 } 168 181 }
Note: See TracChangeset
for help on using the changeset viewer.