- 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/RunCreationService.cs
r15081 r15082 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 { … … 127 127 } 128 128 129 public IEnumerable<DataTransfer.Solution> GetSolutions(long problemId) { 130 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 131 132 using (OKBDataContext okb = new OKBDataContext()) { 133 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 134 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId)); 135 // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems 136 var result = problem.SingleObjectiveSolutions.Select(x => Convert.ToDto(x)).ToList(); 137 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 138 return result; 139 } else { 140 var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId).ToList(); 141 if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) { 142 return result; 143 } else { 144 return null; 145 } 146 } 147 } 148 } 149 150 public DataTransfer.Solution GetSolution(long solutionId) { 151 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 152 153 using (OKBDataContext okb = new OKBDataContext()) { 154 // TODO: In case of multi-objective problems one has to check whether it contains single- or multi-objective problems 155 var result = Convert.ToDto(okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId)); 156 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 157 return result; 158 } else { 159 var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == result.ProblemId).ToList(); 160 if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) { 161 return result; 162 } else { 163 return null; 164 } 165 } 166 } 167 } 168 169 public byte[] GetSolutionData(long solutionId) { 170 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 171 172 using (OKBDataContext okb = new OKBDataContext()) { 173 var solution = okb.SingleObjectiveSolutions.SingleOrDefault(x => x.Id == solutionId); 174 if (solution == null) throw new FaultException<MissingSolution>(new MissingSolution(solutionId)); 175 176 var result = solution.BinaryData.Data.ToArray(); 177 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 178 return result; 179 } else { 180 var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == solution.ProblemId).ToList(); 181 if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) { 182 return result; 183 } else { 184 return null; 185 } 186 } 187 } 188 } 189 190 public long AddSolution(DataTransfer.Solution solution, byte[] data) { 191 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 192 193 using (OKBDataContext okb = new OKBDataContext()) { 194 var soSolution = solution as DataTransfer.SingleObjectiveSolution; 195 if (soSolution != null) { 196 DataAccess.SingleObjectiveSolution entity = Convert.ToEntity(soSolution, data, okb); 197 okb.SingleObjectiveSolutions.InsertOnSubmit(entity); 198 okb.SubmitChanges(); 199 return entity.Id; 200 } 201 } 202 throw new FaultException(new FaultReason("The solution could not be added.")); 203 } 204 205 public void DeleteSolution(DataTransfer.Solution solution) { 206 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 207 208 using (OKBDataContext okb = new OKBDataContext()) { 209 var soSolution = solution as DataTransfer.SingleObjectiveSolution; 210 if (soSolution != null) { 211 okb.SingleObjectiveSolutions.DeleteOnSubmit(okb.SingleObjectiveSolutions.Single(x => x.Id == soSolution.Id)); 212 okb.SubmitChanges(); 213 } 214 } 215 } 216 129 217 public void AddRun(DataTransfer.Run run) { 130 218 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); … … 150 238 using (OKBDataContext okb = new OKBDataContext()) { 151 239 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 152 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem( "Problem with id {0} cannot be found",problemId));240 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId)); 153 241 154 242 DoSetCharacteristicValue(okb, problem, value); … … 162 250 using (OKBDataContext okb = new OKBDataContext()) { 163 251 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 164 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem( "Problem with id {0} cannot be found",problemId));252 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem(problemId)); 165 253 166 254 foreach (var v in values) {
Note: See TracChangeset
for help on using the changeset viewer.