1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Data.Linq;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Security.Cryptography;
|
---|
27 | using System.ServiceModel;
|
---|
28 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Services.OKB {
|
---|
31 | /// <summary>
|
---|
32 | /// Implementation of the OKB administration service (interface <see cref="IAdministrationService"/>).
|
---|
33 | /// </summary>
|
---|
34 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
35 | public class AdministrationService : IAdministrationService {
|
---|
36 | #region Platform Methods
|
---|
37 | public DataTransfer.Platform GetPlatform(long id) {
|
---|
38 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
39 | return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id));
|
---|
40 | }
|
---|
41 | }
|
---|
42 | public IEnumerable<DataTransfer.Platform> GetPlatforms() {
|
---|
43 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
44 | return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray();
|
---|
45 | }
|
---|
46 | }
|
---|
47 | public long AddPlatform(DataTransfer.Platform dto) {
|
---|
48 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
49 | DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
50 | okb.Platforms.InsertOnSubmit(entity);
|
---|
51 | okb.SubmitChanges();
|
---|
52 | return entity.Id;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | public void UpdatePlatform(DataTransfer.Platform dto) {
|
---|
56 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
57 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
58 | Convert.ToEntity(dto, entity);
|
---|
59 | okb.SubmitChanges();
|
---|
60 | }
|
---|
61 | }
|
---|
62 | public void DeletePlatform(long id) {
|
---|
63 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
64 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id);
|
---|
65 | if (entity != null) okb.Platforms.DeleteOnSubmit(entity);
|
---|
66 | okb.SubmitChanges();
|
---|
67 | }
|
---|
68 | }
|
---|
69 | #endregion
|
---|
70 |
|
---|
71 | #region DataType Methods
|
---|
72 | public DataTransfer.DataType GetDataType(long id) {
|
---|
73 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
74 | return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
|
---|
75 | }
|
---|
76 | }
|
---|
77 | public IEnumerable<DataTransfer.DataType> GetDataTypes() {
|
---|
78 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
79 | return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray();
|
---|
80 | }
|
---|
81 | }
|
---|
82 | public long AddDataType(DataTransfer.DataType dto) {
|
---|
83 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
84 | DataAccess.DataType entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
85 | okb.DataTypes.InsertOnSubmit(entity);
|
---|
86 | okb.SubmitChanges();
|
---|
87 | return entity.Id;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | public void UpdateDataType(DataTransfer.DataType dto) {
|
---|
91 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
92 | DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id);
|
---|
93 | Convert.ToEntity(dto, entity);
|
---|
94 | okb.SubmitChanges();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | public void DeleteDataType(long id) {
|
---|
98 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
99 | DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id);
|
---|
100 | if (entity != null) okb.DataTypes.DeleteOnSubmit(entity);
|
---|
101 | okb.SubmitChanges();
|
---|
102 | }
|
---|
103 | }
|
---|
104 | #endregion
|
---|
105 |
|
---|
106 | #region BinaryData Methods
|
---|
107 | public long GetBinaryDataId(byte[] hash) {
|
---|
108 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
109 | var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();
|
---|
110 | if (id == 0) return -1;
|
---|
111 | else return id;
|
---|
112 | }
|
---|
113 | }
|
---|
114 | public long AddBinaryData(DataTransfer.BinaryData dto) {
|
---|
115 | byte[] hash;
|
---|
116 | using (SHA1 sha1 = SHA1.Create()) {
|
---|
117 | hash = sha1.ComputeHash(dto.Data);
|
---|
118 | }
|
---|
119 |
|
---|
120 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
121 | var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();
|
---|
122 | if (id != 0) {
|
---|
123 | return id;
|
---|
124 | } else {
|
---|
125 | DataAccess.BinaryData entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
126 | okb.BinaryDatas.InsertOnSubmit(entity);
|
---|
127 | okb.SubmitChanges();
|
---|
128 | return entity.Id;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | public void DeleteBinaryData(long id) {
|
---|
133 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
134 | DataAccess.BinaryData entity = okb.BinaryDatas.FirstOrDefault(x => x.Id == id);
|
---|
135 | if (entity != null) okb.BinaryDatas.DeleteOnSubmit(entity);
|
---|
136 | okb.SubmitChanges();
|
---|
137 | }
|
---|
138 | }
|
---|
139 | #endregion
|
---|
140 |
|
---|
141 | #region AlgorithmClass Methods
|
---|
142 | public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
|
---|
143 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
144 | return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));
|
---|
145 | }
|
---|
146 | }
|
---|
147 | public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() {
|
---|
148 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
149 | return okb.AlgorithmClasses.Select(x => Convert.ToDto(x)).ToArray();
|
---|
150 | }
|
---|
151 | }
|
---|
152 | public long AddAlgorithmClass(DataTransfer.AlgorithmClass dto) {
|
---|
153 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
154 | DataAccess.AlgorithmClass entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
155 | okb.AlgorithmClasses.InsertOnSubmit(entity);
|
---|
156 | okb.SubmitChanges();
|
---|
157 | return entity.Id;
|
---|
158 | }
|
---|
159 | }
|
---|
160 | public void UpdateAlgorithmClass(DataTransfer.AlgorithmClass dto) {
|
---|
161 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
162 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id);
|
---|
163 | Convert.ToEntity(dto, entity);
|
---|
164 | okb.SubmitChanges();
|
---|
165 | }
|
---|
166 | }
|
---|
167 | public void DeleteAlgorithmClass(long id) {
|
---|
168 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
169 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id);
|
---|
170 | if (entity != null) okb.AlgorithmClasses.DeleteOnSubmit(entity);
|
---|
171 | okb.SubmitChanges();
|
---|
172 | }
|
---|
173 | }
|
---|
174 | #endregion
|
---|
175 |
|
---|
176 | #region Algorithm Methods
|
---|
177 | public DataTransfer.Algorithm GetAlgorithm(long id) {
|
---|
178 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
179 | return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id));
|
---|
180 | }
|
---|
181 | }
|
---|
182 | public IEnumerable<DataTransfer.Algorithm> GetAlgorithms() {
|
---|
183 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
184 | return okb.Algorithms.Select(x => Convert.ToDto(x)).ToArray();
|
---|
185 | }
|
---|
186 | }
|
---|
187 | public long AddAlgorithm(DataTransfer.Algorithm dto) {
|
---|
188 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
189 | DataAccess.Algorithm entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
190 | okb.Algorithms.InsertOnSubmit(entity);
|
---|
191 | okb.SubmitChanges();
|
---|
192 | return entity.Id;
|
---|
193 | }
|
---|
194 | }
|
---|
195 | public void UpdateAlgorithm(DataTransfer.Algorithm dto) {
|
---|
196 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
197 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
198 | Convert.ToEntity(dto, entity);
|
---|
199 | okb.SubmitChanges();
|
---|
200 | }
|
---|
201 | }
|
---|
202 | public void DeleteAlgorithm(long id) {
|
---|
203 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
204 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id);
|
---|
205 | if (entity != null) okb.Algorithms.DeleteOnSubmit(entity);
|
---|
206 | okb.SubmitChanges();
|
---|
207 | }
|
---|
208 | }
|
---|
209 | public IEnumerable<Guid> GetAlgorithmUsers(long algorithmId) {
|
---|
210 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
211 | return okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserId).ToArray();
|
---|
212 | }
|
---|
213 | }
|
---|
214 | public void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
|
---|
215 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
216 | okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId));
|
---|
217 | okb.AlgorithmUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.AlgorithmUser { AlgorithmId = algorithmId, UserId = x }));
|
---|
218 | okb.SubmitChanges();
|
---|
219 | }
|
---|
220 | }
|
---|
221 | public DataTransfer.BinaryData GetAlgorithmData(long algorithmId) {
|
---|
222 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
223 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
224 | dlo.LoadWith<Algorithm>(x => x.BinaryData);
|
---|
225 | okb.LoadOptions = dlo;
|
---|
226 | return Convert.ToDto(okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData).FirstOrDefault());
|
---|
227 | }
|
---|
228 | }
|
---|
229 | #endregion
|
---|
230 |
|
---|
231 | #region ProblemClass Methods
|
---|
232 | public DataTransfer.ProblemClass GetProblemClass(long id) {
|
---|
233 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
234 | return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id));
|
---|
235 | }
|
---|
236 | }
|
---|
237 | public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() {
|
---|
238 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
239 | return okb.ProblemClasses.Select(x => Convert.ToDto(x)).ToArray();
|
---|
240 | }
|
---|
241 | }
|
---|
242 | public long AddProblemClass(DataTransfer.ProblemClass dto) {
|
---|
243 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
244 | DataAccess.ProblemClass entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
245 | okb.ProblemClasses.InsertOnSubmit(entity);
|
---|
246 | okb.SubmitChanges();
|
---|
247 | return entity.Id;
|
---|
248 | }
|
---|
249 | }
|
---|
250 | public void UpdateProblemClass(DataTransfer.ProblemClass dto) {
|
---|
251 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
252 | DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == dto.Id);
|
---|
253 | Convert.ToEntity(dto, entity);
|
---|
254 | okb.SubmitChanges();
|
---|
255 | }
|
---|
256 | }
|
---|
257 | public void DeleteProblemClass(long id) {
|
---|
258 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
259 | DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == id);
|
---|
260 | if (entity != null) okb.ProblemClasses.DeleteOnSubmit(entity);
|
---|
261 | okb.SubmitChanges();
|
---|
262 | }
|
---|
263 | }
|
---|
264 | #endregion
|
---|
265 |
|
---|
266 | #region Problem Methods
|
---|
267 | public DataTransfer.Problem GetProblem(long id) {
|
---|
268 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
269 | return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id));
|
---|
270 | }
|
---|
271 | }
|
---|
272 | public IEnumerable<DataTransfer.Problem> GetProblems() {
|
---|
273 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
274 | return okb.Problems.Select(x => Convert.ToDto(x)).ToArray();
|
---|
275 | }
|
---|
276 | }
|
---|
277 | public long AddProblem(DataTransfer.Problem dto) {
|
---|
278 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
279 | DataAccess.Problem entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
280 | okb.Problems.InsertOnSubmit(entity);
|
---|
281 | okb.SubmitChanges();
|
---|
282 | return entity.Id;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | public void UpdateProblem(DataTransfer.Problem dto) {
|
---|
286 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
287 | DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id);
|
---|
288 | Convert.ToEntity(dto, entity);
|
---|
289 | okb.SubmitChanges();
|
---|
290 | }
|
---|
291 | }
|
---|
292 | public void DeleteProblem(long id) {
|
---|
293 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
294 | DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == id);
|
---|
295 | if (entity != null) okb.Problems.DeleteOnSubmit(entity);
|
---|
296 | okb.SubmitChanges();
|
---|
297 | }
|
---|
298 | }
|
---|
299 | public IEnumerable<Guid> GetProblemUsers(long problemId) {
|
---|
300 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
301 | return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserId).ToArray();
|
---|
302 | }
|
---|
303 | }
|
---|
304 | public void UpdateProblemUsers(long problemId, IEnumerable<Guid> users) {
|
---|
305 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
306 | okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId));
|
---|
307 | okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserId = x }));
|
---|
308 | okb.SubmitChanges();
|
---|
309 | }
|
---|
310 | }
|
---|
311 | public DataTransfer.BinaryData GetProblemData(long problemId) {
|
---|
312 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
313 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
314 | dlo.LoadWith<Problem>(x => x.BinaryData);
|
---|
315 | okb.LoadOptions = dlo;
|
---|
316 | return Convert.ToDto(okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData).FirstOrDefault());
|
---|
317 | }
|
---|
318 | }
|
---|
319 | #endregion
|
---|
320 |
|
---|
321 | #region ProblemParameter Methods
|
---|
322 | public DataTransfer.ProblemParameter GetProblemParameter(long id) {
|
---|
323 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
324 | return Convert.ToDto(okb.ProblemParameters.FirstOrDefault(x => x.Id == id));
|
---|
325 | }
|
---|
326 | }
|
---|
327 | public IEnumerable<DataTransfer.ProblemParameter> GetProblemParameters(long problemId) {
|
---|
328 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
329 | return okb.ProblemParameters.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray();
|
---|
330 | }
|
---|
331 | }
|
---|
332 | public long AddProblemParameter(DataTransfer.ProblemParameter dto) {
|
---|
333 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
334 | DataAccess.ProblemParameter entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
335 | okb.ProblemParameters.InsertOnSubmit(entity);
|
---|
336 | okb.SubmitChanges();
|
---|
337 | return entity.Id;
|
---|
338 | }
|
---|
339 | }
|
---|
340 | public void UpdateProblemParameter(DataTransfer.ProblemParameter dto) {
|
---|
341 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
342 | DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == dto.Id);
|
---|
343 | Convert.ToEntity(dto, entity);
|
---|
344 | okb.SubmitChanges();
|
---|
345 | }
|
---|
346 | }
|
---|
347 | public void DeleteProblemParameter(long id) {
|
---|
348 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
349 | DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == id);
|
---|
350 | if (entity != null) okb.ProblemParameters.DeleteOnSubmit(entity);
|
---|
351 | okb.SubmitChanges();
|
---|
352 | }
|
---|
353 | }
|
---|
354 | #endregion
|
---|
355 |
|
---|
356 | #region Result Methods
|
---|
357 | public DataTransfer.Result GetResult(long id) {
|
---|
358 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
359 | return Convert.ToDto(okb.Results.FirstOrDefault(x => x.Id == id));
|
---|
360 | }
|
---|
361 | }
|
---|
362 | public IEnumerable<DataTransfer.Result> GetResults(long algorithmId) {
|
---|
363 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
364 | return okb.Results.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
|
---|
365 | }
|
---|
366 | }
|
---|
367 | public long AddResult(DataTransfer.Result dto) {
|
---|
368 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
369 | DataAccess.Result entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
370 | okb.Results.InsertOnSubmit(entity);
|
---|
371 | okb.SubmitChanges();
|
---|
372 | return entity.Id;
|
---|
373 | }
|
---|
374 | }
|
---|
375 | public void UpdateResult(DataTransfer.Result dto) {
|
---|
376 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
377 | DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == dto.Id);
|
---|
378 | Convert.ToEntity(dto, entity);
|
---|
379 | okb.SubmitChanges();
|
---|
380 | }
|
---|
381 | }
|
---|
382 | public void DeleteResult(long id) {
|
---|
383 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
384 | DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == id);
|
---|
385 | if (entity != null) okb.Results.DeleteOnSubmit(entity);
|
---|
386 | okb.SubmitChanges();
|
---|
387 | }
|
---|
388 | }
|
---|
389 | #endregion
|
---|
390 |
|
---|
391 | #region Experiment Methods
|
---|
392 | public DataTransfer.Experiment GetExperiment(long id) {
|
---|
393 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
394 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
395 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
|
---|
396 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
|
---|
397 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
|
---|
398 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
|
---|
399 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
|
---|
400 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
|
---|
401 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
|
---|
402 | dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
|
---|
403 | dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
|
---|
404 | dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
|
---|
405 | okb.LoadOptions = dlo;
|
---|
406 | return Convert.ToDto(okb.Experiments.FirstOrDefault(x => x.Id == id));
|
---|
407 | }
|
---|
408 | }
|
---|
409 | public IEnumerable<DataTransfer.Experiment> GetExperiments(long algorithmId, long problemId) {
|
---|
410 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
411 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
412 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
|
---|
413 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
|
---|
414 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
|
---|
415 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
|
---|
416 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
|
---|
417 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
|
---|
418 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
|
---|
419 | dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
|
---|
420 | dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
|
---|
421 | dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
|
---|
422 | okb.LoadOptions = dlo;
|
---|
423 | if ((algorithmId != 0) && (problemId != 0))
|
---|
424 | return okb.Experiments.Where(x => (x.AlgorithmId == algorithmId) && (x.ProblemId == problemId)).Select(x => Convert.ToDto(x)).ToArray();
|
---|
425 | else if (algorithmId != 0)
|
---|
426 | return okb.Experiments.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
|
---|
427 | else if (problemId != 0)
|
---|
428 | return okb.Experiments.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray();
|
---|
429 | else
|
---|
430 | return okb.Experiments.Select(x => Convert.ToDto(x)).ToArray();
|
---|
431 | }
|
---|
432 | }
|
---|
433 | public long AddExperiment(DataTransfer.Experiment dto) {
|
---|
434 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
435 | DataAccess.Experiment entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
436 |
|
---|
437 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
438 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
|
---|
439 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
|
---|
440 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
|
---|
441 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
|
---|
442 | dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
|
---|
443 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
|
---|
444 | dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
|
---|
445 | dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
|
---|
446 | dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
|
---|
447 | dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
|
---|
448 | okb.LoadOptions = dlo;
|
---|
449 |
|
---|
450 | var experiments = okb.Experiments.Where(x => ((x.AlgorithmId == entity.AlgorithmId) && (x.ProblemId == entity.ProblemId))).ToArray();
|
---|
451 | ExperimentEqualityComparer comparer = new ExperimentEqualityComparer();
|
---|
452 | Experiment exp = experiments.FirstOrDefault(x => comparer.Equals(x, entity));
|
---|
453 | if (exp != null) {
|
---|
454 | return exp.Id;
|
---|
455 | } else {
|
---|
456 | okb.Experiments.InsertOnSubmit(entity);
|
---|
457 | okb.SubmitChanges();
|
---|
458 | return entity.Id;
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
462 | public void DeleteExperiment(long id) {
|
---|
463 | foreach (DataTransfer.Run run in GetRuns(id))
|
---|
464 | DeleteRun(run.Id);
|
---|
465 |
|
---|
466 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
467 | IEnumerable<DataAccess.AlgorithmParameterBlobValue> algorithmParameterBlobValues = okb.AlgorithmParameterBlobValues.Where(x => x.ExperimentId == id);
|
---|
468 | okb.AlgorithmParameterBlobValues.DeleteAllOnSubmit(algorithmParameterBlobValues);
|
---|
469 | IEnumerable<DataAccess.AlgorithmParameterBoolValue> algorithmParameterBoolValues = okb.AlgorithmParameterBoolValues.Where(x => x.ExperimentId == id);
|
---|
470 | okb.AlgorithmParameterBoolValues.DeleteAllOnSubmit(algorithmParameterBoolValues);
|
---|
471 | IEnumerable<DataAccess.AlgorithmParameterFloatValue> algorithmParameterFloatValues = okb.AlgorithmParameterFloatValues.Where(x => x.ExperimentId == id);
|
---|
472 | okb.AlgorithmParameterFloatValues.DeleteAllOnSubmit(algorithmParameterFloatValues);
|
---|
473 | IEnumerable<DataAccess.AlgorithmParameterIntValue> algorithmParameterIntValues = okb.AlgorithmParameterIntValues.Where(x => x.ExperimentId == id);
|
---|
474 | okb.AlgorithmParameterIntValues.DeleteAllOnSubmit(algorithmParameterIntValues);
|
---|
475 | IEnumerable<DataAccess.AlgorithmParameterStringValue> algorithmParameterStringValues = okb.AlgorithmParameterStringValues.Where(x => x.ExperimentId == id);
|
---|
476 | okb.AlgorithmParameterStringValues.DeleteAllOnSubmit(algorithmParameterStringValues);
|
---|
477 |
|
---|
478 | IEnumerable<DataAccess.ProblemParameterBlobValue> problemParameterBlobValues = okb.ProblemParameterBlobValues.Where(x => x.ExperimentId == id);
|
---|
479 | okb.ProblemParameterBlobValues.DeleteAllOnSubmit(problemParameterBlobValues);
|
---|
480 | IEnumerable<DataAccess.ProblemParameterBoolValue> problemParameterBoolValues = okb.ProblemParameterBoolValues.Where(x => x.ExperimentId == id);
|
---|
481 | okb.ProblemParameterBoolValues.DeleteAllOnSubmit(problemParameterBoolValues);
|
---|
482 | IEnumerable<DataAccess.ProblemParameterFloatValue> problemParameterFloatValues = okb.ProblemParameterFloatValues.Where(x => x.ExperimentId == id);
|
---|
483 | okb.ProblemParameterFloatValues.DeleteAllOnSubmit(problemParameterFloatValues);
|
---|
484 | IEnumerable<DataAccess.ProblemParameterIntValue> problemParameterIntValues = okb.ProblemParameterIntValues.Where(x => x.ExperimentId == id);
|
---|
485 | okb.ProblemParameterIntValues.DeleteAllOnSubmit(problemParameterIntValues);
|
---|
486 | IEnumerable<DataAccess.ProblemParameterStringValue> problemParameterStringValues = okb.ProblemParameterStringValues.Where(x => x.ExperimentId == id);
|
---|
487 | okb.ProblemParameterStringValues.DeleteAllOnSubmit(problemParameterStringValues);
|
---|
488 |
|
---|
489 | DataAccess.Experiment entity = okb.Experiments.FirstOrDefault(x => x.Id == id);
|
---|
490 | if (entity != null) okb.Experiments.DeleteOnSubmit(entity);
|
---|
491 | okb.SubmitChanges();
|
---|
492 | }
|
---|
493 | }
|
---|
494 | #endregion
|
---|
495 |
|
---|
496 | #region Run Methods
|
---|
497 | public DataTransfer.Run GetRun(long id) {
|
---|
498 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
499 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
500 | dlo.LoadWith<Run>(x => x.ResultBlobValues);
|
---|
501 | dlo.LoadWith<Run>(x => x.ResultBoolValues);
|
---|
502 | dlo.LoadWith<Run>(x => x.ResultFloatValues);
|
---|
503 | dlo.LoadWith<Run>(x => x.ResultIntValues);
|
---|
504 | dlo.LoadWith<Run>(x => x.ResultStringValues);
|
---|
505 | okb.LoadOptions = dlo;
|
---|
506 | return Convert.ToDto(okb.Runs.FirstOrDefault(x => x.Id == id));
|
---|
507 | }
|
---|
508 | }
|
---|
509 | public IEnumerable<DataTransfer.Run> GetRuns(long experimentId) {
|
---|
510 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
511 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
512 | dlo.LoadWith<Run>(x => x.ResultBlobValues);
|
---|
513 | dlo.LoadWith<Run>(x => x.ResultBoolValues);
|
---|
514 | dlo.LoadWith<Run>(x => x.ResultFloatValues);
|
---|
515 | dlo.LoadWith<Run>(x => x.ResultIntValues);
|
---|
516 | dlo.LoadWith<Run>(x => x.ResultStringValues);
|
---|
517 | okb.LoadOptions = dlo;
|
---|
518 | return okb.Runs.Where(x => x.ExperimentId == experimentId).Select(x => Convert.ToDto(x)).ToArray();
|
---|
519 | }
|
---|
520 | }
|
---|
521 | public long AddRun(DataTransfer.Run dto) {
|
---|
522 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
523 | DataAccess.Run entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
524 | okb.Runs.InsertOnSubmit(entity);
|
---|
525 | okb.SubmitChanges();
|
---|
526 | return entity.Id;
|
---|
527 | }
|
---|
528 | }
|
---|
529 | public void DeleteRun(long id) {
|
---|
530 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
531 | IEnumerable<DataAccess.ResultBlobValue> resultBlobValues = okb.ResultBlobValues.Where(x => x.RunId == id);
|
---|
532 | okb.ResultBlobValues.DeleteAllOnSubmit(resultBlobValues);
|
---|
533 | IEnumerable<DataAccess.ResultBoolValue> resultBoolValues = okb.ResultBoolValues.Where(x => x.RunId == id);
|
---|
534 | okb.ResultBoolValues.DeleteAllOnSubmit(resultBoolValues);
|
---|
535 | IEnumerable<DataAccess.ResultFloatValue> resultFloatValues = okb.ResultFloatValues.Where(x => x.RunId == id);
|
---|
536 | okb.ResultFloatValues.DeleteAllOnSubmit(resultFloatValues);
|
---|
537 | IEnumerable<DataAccess.ResultIntValue> resultIntValues = okb.ResultIntValues.Where(x => x.RunId == id);
|
---|
538 | okb.ResultIntValues.DeleteAllOnSubmit(resultIntValues);
|
---|
539 | IEnumerable<DataAccess.ResultStringValue> resultStringValues = okb.ResultStringValues.Where(x => x.RunId == id);
|
---|
540 | okb.ResultStringValues.DeleteAllOnSubmit(resultStringValues);
|
---|
541 |
|
---|
542 | DataAccess.Run entity = okb.Runs.FirstOrDefault(x => x.Id == id);
|
---|
543 | if (entity != null) okb.Runs.DeleteOnSubmit(entity);
|
---|
544 | okb.SubmitChanges();
|
---|
545 | }
|
---|
546 | }
|
---|
547 | #endregion
|
---|
548 | }
|
---|
549 | }
|
---|