Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Services.OKB/3.3/OKBService.cs @ 6593

Last change on this file since 6593 was 5295, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 48.3 KB
RevLine 
[4279]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
[4467]22using System;
[4426]23using System.Collections.Generic;
[4591]24using System.Data.Linq;
[4279]25using System.Linq;
26using System.ServiceModel;
27using HeuristicLab.Services.OKB.DataAccess;
28
29namespace HeuristicLab.Services.OKB {
30  /// <summary>
[4548]31  /// Implementation of the OKB service (interface <see cref="IOKBService"/>).
[4279]32  /// </summary>
[4381]33  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[4548]34  public class OKBService : IOKBService {
[4442]35    #region Platform Methods
[4455]36    public DataTransfer.Platform GetPlatform(long id) {
[4442]37      using (OKBDataContext okb = new OKBDataContext()) {
[4455]38        return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id));
[4442]39      }
40    }
[4455]41    public IEnumerable<DataTransfer.Platform> GetPlatforms() {
[4442]42      using (OKBDataContext okb = new OKBDataContext()) {
[4455]43        return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray();
[4442]44      }
45    }
[4481]46    public long AddPlatform(DataTransfer.Platform dto) {
[4442]47      using (OKBDataContext okb = new OKBDataContext()) {
[4481]48        DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0;
49        okb.Platforms.InsertOnSubmit(entity);
50        okb.SubmitChanges();
51        return entity.Id;
52      }
53    }
54    public void UpdatePlatform(DataTransfer.Platform dto) {
55      using (OKBDataContext okb = new OKBDataContext()) {
[4455]56        DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
[4481]57        Convert.ToEntity(dto, entity);
[4442]58        okb.SubmitChanges();
59      }
60    }
[4455]61    public void DeletePlatform(long id) {
[4442]62      using (OKBDataContext okb = new OKBDataContext()) {
[4455]63        DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id);
64        if (entity != null) okb.Platforms.DeleteOnSubmit(entity);
65        okb.SubmitChanges();
[4442]66      }
67    }
68    #endregion
69
[4481]70    #region DataType Methods
71    public DataTransfer.DataType GetDataType(long id) {
72      using (OKBDataContext okb = new OKBDataContext()) {
73        return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));
74      }
75    }
76    public IEnumerable<DataTransfer.DataType> GetDataTypes() {
77      using (OKBDataContext okb = new OKBDataContext()) {
78        return okb.DataTypes.Select(x => Convert.ToDto(x)).ToArray();
79      }
80    }
81    public long AddDataType(DataTransfer.DataType dto) {
82      using (OKBDataContext okb = new OKBDataContext()) {
83        DataAccess.DataType entity = Convert.ToEntity(dto); entity.Id = 0;
84        okb.DataTypes.InsertOnSubmit(entity);
85        okb.SubmitChanges();
86        return entity.Id;
87      }
88    }
89    public void UpdateDataType(DataTransfer.DataType dto) {
90      using (OKBDataContext okb = new OKBDataContext()) {
91        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == dto.Id);
92        Convert.ToEntity(dto, entity);
93        okb.SubmitChanges();
94      }
95    }
96    public void DeleteDataType(long id) {
97      using (OKBDataContext okb = new OKBDataContext()) {
98        DataAccess.DataType entity = okb.DataTypes.FirstOrDefault(x => x.Id == id);
99        if (entity != null) okb.DataTypes.DeleteOnSubmit(entity);
100        okb.SubmitChanges();
101      }
102    }
103    #endregion
104
[4442]105    #region AlgorithmClass Methods
[4455]106    public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
[4407]107      using (OKBDataContext okb = new OKBDataContext()) {
[4455]108        return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));
[4407]109      }
110    }
[4455]111    public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() {
[4407]112      using (OKBDataContext okb = new OKBDataContext()) {
[4455]113        return okb.AlgorithmClasses.Select(x => Convert.ToDto(x)).ToArray();
[4407]114      }
115    }
[4481]116    public long AddAlgorithmClass(DataTransfer.AlgorithmClass dto) {
[4407]117      using (OKBDataContext okb = new OKBDataContext()) {
[4481]118        DataAccess.AlgorithmClass entity = Convert.ToEntity(dto); entity.Id = 0;
119        okb.AlgorithmClasses.InsertOnSubmit(entity);
120        okb.SubmitChanges();
121        return entity.Id;
122      }
123    }
124    public void UpdateAlgorithmClass(DataTransfer.AlgorithmClass dto) {
125      using (OKBDataContext okb = new OKBDataContext()) {
[4455]126        DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id);
[4481]127        Convert.ToEntity(dto, entity);
[4407]128        okb.SubmitChanges();
129      }
130    }
[4455]131    public void DeleteAlgorithmClass(long id) {
[4407]132      using (OKBDataContext okb = new OKBDataContext()) {
[4455]133        DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id);
134        if (entity != null) okb.AlgorithmClasses.DeleteOnSubmit(entity);
135        okb.SubmitChanges();
[4407]136      }
137    }
[4442]138    #endregion
[4407]139
[4442]140    #region Algorithm Methods
[4455]141    public DataTransfer.Algorithm GetAlgorithm(long id) {
[4407]142      using (OKBDataContext okb = new OKBDataContext()) {
[4455]143        return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id));
[4407]144      }
145    }
[4455]146    public IEnumerable<DataTransfer.Algorithm> GetAlgorithms() {
[4407]147      using (OKBDataContext okb = new OKBDataContext()) {
[4455]148        return okb.Algorithms.Select(x => Convert.ToDto(x)).ToArray();
[4407]149      }
150    }
[4481]151    public long AddAlgorithm(DataTransfer.Algorithm dto) {
[4407]152      using (OKBDataContext okb = new OKBDataContext()) {
[4481]153        DataAccess.Algorithm entity = Convert.ToEntity(dto); entity.Id = 0;
154        okb.Algorithms.InsertOnSubmit(entity);
155        okb.SubmitChanges();
156        return entity.Id;
157      }
158    }
159    public void UpdateAlgorithm(DataTransfer.Algorithm dto) {
160      using (OKBDataContext okb = new OKBDataContext()) {
[4455]161        DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
[4481]162        Convert.ToEntity(dto, entity);
[4407]163        okb.SubmitChanges();
164      }
165    }
[4455]166    public void DeleteAlgorithm(long id) {
[4407]167      using (OKBDataContext okb = new OKBDataContext()) {
[4455]168        DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id);
169        if (entity != null) okb.Algorithms.DeleteOnSubmit(entity);
170        okb.SubmitChanges();
[4407]171      }
172    }
[4467]173    public IEnumerable<Guid> GetAlgorithmUsers(long algorithmId) {
174      using (OKBDataContext okb = new OKBDataContext()) {
175        return okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserId).ToArray();
176      }
177    }
[4481]178    public void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
[4467]179      using (OKBDataContext okb = new OKBDataContext()) {
180        okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId));
181        okb.AlgorithmUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.AlgorithmUser { AlgorithmId = algorithmId, UserId = x }));
182        okb.SubmitChanges();
183      }
184    }
[4442]185    #endregion
[4407]186
[4467]187    #region AlgorithmData Methods
188    public DataTransfer.AlgorithmData GetAlgorithmData(long algorithmId) {
189      using (OKBDataContext okb = new OKBDataContext()) {
190        return Convert.ToDto(okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == algorithmId));
191      }
192    }
[4481]193    public void UpdateAlgorithmData(DataTransfer.AlgorithmData dto) {
[4467]194      using (OKBDataContext okb = new OKBDataContext()) {
195        DataAccess.AlgorithmData entity = okb.AlgorithmDatas.FirstOrDefault(x => x.AlgorithmId == dto.AlgorithmId);
196        if (entity == null) okb.AlgorithmDatas.InsertOnSubmit(Convert.ToEntity(dto));
197        else Convert.ToEntity(dto, entity);
198        okb.SubmitChanges();
199      }
200    }
201    #endregion
202
[4566]203    #region AlgorithmParameter Methods
204    public DataTransfer.AlgorithmParameter GetAlgorithmParameter(long id) {
205      using (OKBDataContext okb = new OKBDataContext()) {
206        return Convert.ToDto(okb.AlgorithmParameters.FirstOrDefault(x => x.Id == id));
207      }
208    }
209    public IEnumerable<DataTransfer.AlgorithmParameter> GetAlgorithmParameters(long algorithmId) {
210      using (OKBDataContext okb = new OKBDataContext()) {
211        return okb.AlgorithmParameters.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
212      }
213    }
214    public long AddAlgorithmParameter(DataTransfer.AlgorithmParameter dto) {
215      using (OKBDataContext okb = new OKBDataContext()) {
216        DataAccess.AlgorithmParameter entity = Convert.ToEntity(dto); entity.Id = 0;
217        okb.AlgorithmParameters.InsertOnSubmit(entity);
218        okb.SubmitChanges();
219        return entity.Id;
220      }
221    }
222    public void UpdateAlgorithmParameter(DataTransfer.AlgorithmParameter dto) {
223      using (OKBDataContext okb = new OKBDataContext()) {
224        DataAccess.AlgorithmParameter entity = okb.AlgorithmParameters.FirstOrDefault(x => x.Id == dto.Id);
225        Convert.ToEntity(dto, entity);
226        okb.SubmitChanges();
227      }
228    }
229    public void DeleteAlgorithmParameter(long id) {
230      using (OKBDataContext okb = new OKBDataContext()) {
231        DataAccess.AlgorithmParameter entity = okb.AlgorithmParameters.FirstOrDefault(x => x.Id == id);
232        if (entity != null) okb.AlgorithmParameters.DeleteOnSubmit(entity);
233        okb.SubmitChanges();
234      }
235    }
236    #endregion
237
[4481]238    #region ProblemClass Methods
239    public DataTransfer.ProblemClass GetProblemClass(long id) {
[4467]240      using (OKBDataContext okb = new OKBDataContext()) {
[4481]241        return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id));
[4467]242      }
243    }
[4481]244    public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() {
[4467]245      using (OKBDataContext okb = new OKBDataContext()) {
[4481]246        return okb.ProblemClasses.Select(x => Convert.ToDto(x)).ToArray();
[4467]247      }
248    }
[4481]249    public long AddProblemClass(DataTransfer.ProblemClass dto) {
[4467]250      using (OKBDataContext okb = new OKBDataContext()) {
[4481]251        DataAccess.ProblemClass entity = Convert.ToEntity(dto); entity.Id = 0;
252        okb.ProblemClasses.InsertOnSubmit(entity);
[4467]253        okb.SubmitChanges();
[4481]254        return entity.Id;
[4467]255      }
256    }
[4481]257    public void UpdateProblemClass(DataTransfer.ProblemClass dto) {
[4467]258      using (OKBDataContext okb = new OKBDataContext()) {
[4481]259        DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == dto.Id);
260        Convert.ToEntity(dto, entity);
[4467]261        okb.SubmitChanges();
262      }
263    }
[4481]264    public void DeleteProblemClass(long id) {
265      using (OKBDataContext okb = new OKBDataContext()) {
266        DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == id);
267        if (entity != null) okb.ProblemClasses.DeleteOnSubmit(entity);
268        okb.SubmitChanges();
269      }
270    }
[4467]271    #endregion
272
[4481]273    #region Problem Methods
274    public DataTransfer.Problem GetProblem(long id) {
275      using (OKBDataContext okb = new OKBDataContext()) {
276        return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id));
277      }
278    }
279    public IEnumerable<DataTransfer.Problem> GetProblems() {
280      using (OKBDataContext okb = new OKBDataContext()) {
281        return okb.Problems.Select(x => Convert.ToDto(x)).ToArray();
282      }
283    }
284    public long AddProblem(DataTransfer.Problem dto) {
285      using (OKBDataContext okb = new OKBDataContext()) {
286        DataAccess.Problem entity = Convert.ToEntity(dto); entity.Id = 0;
287        okb.Problems.InsertOnSubmit(entity);
288        okb.SubmitChanges();
289        return entity.Id;
290      }
291    }
292    public void UpdateProblem(DataTransfer.Problem dto) {
293      using (OKBDataContext okb = new OKBDataContext()) {
294        DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id);
295        Convert.ToEntity(dto, entity);
296        okb.SubmitChanges();
297      }
298    }
299    public void DeleteProblem(long id) {
300      using (OKBDataContext okb = new OKBDataContext()) {
301        DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == id);
302        if (entity != null) okb.Problems.DeleteOnSubmit(entity);
303        okb.SubmitChanges();
304      }
305    }
306    public IEnumerable<Guid> GetProblemUsers(long problemId) {
307      using (OKBDataContext okb = new OKBDataContext()) {
308        return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserId).ToArray();
309      }
310    }
311    public void UpdateProblemUsers(long problemId, IEnumerable<Guid> users) {
312      using (OKBDataContext okb = new OKBDataContext()) {
313        okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId));
314        okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserId = x }));
315        okb.SubmitChanges();
316      }
317    }
318    #endregion
319
320    #region ProblemData Methods
321    public DataTransfer.ProblemData GetProblemData(long problemId) {
322      using (OKBDataContext okb = new OKBDataContext()) {
323        return Convert.ToDto(okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == problemId));
324      }
325    }
326    public void UpdateProblemData(DataTransfer.ProblemData dto) {
327      using (OKBDataContext okb = new OKBDataContext()) {
328        DataAccess.ProblemData entity = okb.ProblemDatas.FirstOrDefault(x => x.ProblemId == dto.ProblemId);
329        if (entity == null) okb.ProblemDatas.InsertOnSubmit(Convert.ToEntity(dto));
330        else Convert.ToEntity(dto, entity);
331        okb.SubmitChanges();
332      }
333    }
334    #endregion
335
[4566]336    #region ProblemParameter Methods
337    public DataTransfer.ProblemParameter GetProblemParameter(long id) {
338      using (OKBDataContext okb = new OKBDataContext()) {
339        return Convert.ToDto(okb.ProblemParameters.FirstOrDefault(x => x.Id == id));
340      }
341    }
342    public IEnumerable<DataTransfer.ProblemParameter> GetProblemParameters(long problemId) {
343      using (OKBDataContext okb = new OKBDataContext()) {
344        return okb.ProblemParameters.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray();
345      }
346    }
347    public long AddProblemParameter(DataTransfer.ProblemParameter dto) {
348      using (OKBDataContext okb = new OKBDataContext()) {
349        DataAccess.ProblemParameter entity = Convert.ToEntity(dto); entity.Id = 0;
350        okb.ProblemParameters.InsertOnSubmit(entity);
351        okb.SubmitChanges();
352        return entity.Id;
353      }
354    }
355    public void UpdateProblemParameter(DataTransfer.ProblemParameter dto) {
356      using (OKBDataContext okb = new OKBDataContext()) {
357        DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == dto.Id);
358        Convert.ToEntity(dto, entity);
359        okb.SubmitChanges();
360      }
361    }
362    public void DeleteProblemParameter(long id) {
363      using (OKBDataContext okb = new OKBDataContext()) {
364        DataAccess.ProblemParameter entity = okb.ProblemParameters.FirstOrDefault(x => x.Id == id);
365        if (entity != null) okb.ProblemParameters.DeleteOnSubmit(entity);
366        okb.SubmitChanges();
367      }
368    }
369    #endregion
370
371    #region Result Methods
372    public DataTransfer.Result GetResult(long id) {
373      using (OKBDataContext okb = new OKBDataContext()) {
374        return Convert.ToDto(okb.Results.FirstOrDefault(x => x.Id == id));
375      }
376    }
377    public IEnumerable<DataTransfer.Result> GetResults(long algorithmId) {
378      using (OKBDataContext okb = new OKBDataContext()) {
379        return okb.Results.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
380      }
381    }
382    public long AddResult(DataTransfer.Result dto) {
383      using (OKBDataContext okb = new OKBDataContext()) {
384        DataAccess.Result entity = Convert.ToEntity(dto); entity.Id = 0;
385        okb.Results.InsertOnSubmit(entity);
386        okb.SubmitChanges();
387        return entity.Id;
388      }
389    }
390    public void UpdateResult(DataTransfer.Result dto) {
391      using (OKBDataContext okb = new OKBDataContext()) {
392        DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == dto.Id);
393        Convert.ToEntity(dto, entity);
394        okb.SubmitChanges();
395      }
396    }
397    public void DeleteResult(long id) {
398      using (OKBDataContext okb = new OKBDataContext()) {
399        DataAccess.Result entity = okb.Results.FirstOrDefault(x => x.Id == id);
400        if (entity != null) okb.Results.DeleteOnSubmit(entity);
401        okb.SubmitChanges();
402      }
403    }
404    #endregion
405
[4591]406    #region Experiment Methods
407    public DataTransfer.Experiment GetExperiment(long id) {
408      using (OKBDataContext okb = new OKBDataContext()) {
409        DataLoadOptions dlo = new DataLoadOptions();
410        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
411        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
412        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
413        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
414        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
415        dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
416        dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
417        dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
418        dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
419        dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
420        okb.LoadOptions = dlo;
421        return Convert.ToDto(okb.Experiments.FirstOrDefault(x => x.Id == id));
422      }
423    }
424    public IEnumerable<DataTransfer.Experiment> GetExperiments(long algorithmId, long problemId) {
425      using (OKBDataContext okb = new OKBDataContext()) {
426        DataLoadOptions dlo = new DataLoadOptions();
427        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
428        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
429        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
430        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
431        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
432        dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
433        dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
434        dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
435        dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
436        dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
437        okb.LoadOptions = dlo;
438        if ((algorithmId != 0) && (problemId != 0))
439          return okb.Experiments.Where(x => (x.AlgorithmId == algorithmId) && (x.ProblemId == problemId)).Select(x => Convert.ToDto(x)).ToArray();
440        else if (algorithmId != 0)
441          return okb.Experiments.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray();
442        else if (problemId != 0)
443          return okb.Experiments.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray();
444        else
445          return okb.Experiments.Select(x => Convert.ToDto(x)).ToArray();
446      }
447    }
448    public long AddExperiment(DataTransfer.Experiment dto) {
449      using (OKBDataContext okb = new OKBDataContext()) {
450        DataAccess.Experiment entity = Convert.ToEntity(dto); entity.Id = 0;
451
452        DataLoadOptions dlo = new DataLoadOptions();
453        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
454        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
455        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
456        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
457        dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
458        dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
459        dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
460        dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
461        dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
462        dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
463        okb.LoadOptions = dlo;
464
[4929]465        var experiments = okb.Experiments.Where(x => ((x.AlgorithmId == entity.AlgorithmId) && (x.ProblemId == entity.ProblemId))).ToArray();
[4591]466        ExperimentEqualityComparer comparer = new ExperimentEqualityComparer();
467        Experiment exp = experiments.FirstOrDefault(x => comparer.Equals(x, entity));
468        if (exp != null) {
469          return exp.Id;
470        } else {
471          okb.Experiments.InsertOnSubmit(entity);
472          okb.SubmitChanges();
473          return entity.Id;
474        }
475      }
476    }
477    public void DeleteExperiment(long id) {
[5071]478      foreach (DataTransfer.Run run in GetRuns(id))
479        DeleteRun(run.Id);
480
[4591]481      using (OKBDataContext okb = new OKBDataContext()) {
[5071]482        IEnumerable<DataAccess.AlgorithmParameterBlobValue> algorithmParameterBlobValues = okb.AlgorithmParameterBlobValues.Where(x => x.ExperimentId == id);
483        okb.AlgorithmParameterBlobValues.DeleteAllOnSubmit(algorithmParameterBlobValues);
484        IEnumerable<DataAccess.AlgorithmParameterBoolValue> algorithmParameterBoolValues = okb.AlgorithmParameterBoolValues.Where(x => x.ExperimentId == id);
485        okb.AlgorithmParameterBoolValues.DeleteAllOnSubmit(algorithmParameterBoolValues);
486        IEnumerable<DataAccess.AlgorithmParameterFloatValue> algorithmParameterFloatValues = okb.AlgorithmParameterFloatValues.Where(x => x.ExperimentId == id);
487        okb.AlgorithmParameterFloatValues.DeleteAllOnSubmit(algorithmParameterFloatValues);
488        IEnumerable<DataAccess.AlgorithmParameterIntValue> algorithmParameterIntValues = okb.AlgorithmParameterIntValues.Where(x => x.ExperimentId == id);
489        okb.AlgorithmParameterIntValues.DeleteAllOnSubmit(algorithmParameterIntValues);
490        IEnumerable<DataAccess.AlgorithmParameterStringValue> algorithmParameterStringValues = okb.AlgorithmParameterStringValues.Where(x => x.ExperimentId == id);
491        okb.AlgorithmParameterStringValues.DeleteAllOnSubmit(algorithmParameterStringValues);
492
493        IEnumerable<DataAccess.ProblemParameterBlobValue> problemParameterBlobValues = okb.ProblemParameterBlobValues.Where(x => x.ExperimentId == id);
494        okb.ProblemParameterBlobValues.DeleteAllOnSubmit(problemParameterBlobValues);
495        IEnumerable<DataAccess.ProblemParameterBoolValue> problemParameterBoolValues = okb.ProblemParameterBoolValues.Where(x => x.ExperimentId == id);
496        okb.ProblemParameterBoolValues.DeleteAllOnSubmit(problemParameterBoolValues);
497        IEnumerable<DataAccess.ProblemParameterFloatValue> problemParameterFloatValues = okb.ProblemParameterFloatValues.Where(x => x.ExperimentId == id);
498        okb.ProblemParameterFloatValues.DeleteAllOnSubmit(problemParameterFloatValues);
499        IEnumerable<DataAccess.ProblemParameterIntValue> problemParameterIntValues = okb.ProblemParameterIntValues.Where(x => x.ExperimentId == id);
500        okb.ProblemParameterIntValues.DeleteAllOnSubmit(problemParameterIntValues);
501        IEnumerable<DataAccess.ProblemParameterStringValue> problemParameterStringValues = okb.ProblemParameterStringValues.Where(x => x.ExperimentId == id);
502        okb.ProblemParameterStringValues.DeleteAllOnSubmit(problemParameterStringValues);
503
[4591]504        DataAccess.Experiment entity = okb.Experiments.FirstOrDefault(x => x.Id == id);
505        if (entity != null) okb.Experiments.DeleteOnSubmit(entity);
506        okb.SubmitChanges();
507      }
508    }
509    #endregion
510
511    #region Run Methods
512    public DataTransfer.Run GetRun(long id) {
513      using (OKBDataContext okb = new OKBDataContext()) {
514        DataLoadOptions dlo = new DataLoadOptions();
515        dlo.LoadWith<Run>(x => x.ResultBlobValues);
516        dlo.LoadWith<Run>(x => x.ResultBoolValues);
517        dlo.LoadWith<Run>(x => x.ResultFloatValues);
518        dlo.LoadWith<Run>(x => x.ResultIntValues);
519        dlo.LoadWith<Run>(x => x.ResultStringValues);
520        okb.LoadOptions = dlo;
521        return Convert.ToDto(okb.Runs.FirstOrDefault(x => x.Id == id));
522      }
523    }
524    public IEnumerable<DataTransfer.Run> GetRuns(long experimentId) {
525      using (OKBDataContext okb = new OKBDataContext()) {
526        DataLoadOptions dlo = new DataLoadOptions();
527        dlo.LoadWith<Run>(x => x.ResultBlobValues);
528        dlo.LoadWith<Run>(x => x.ResultBoolValues);
529        dlo.LoadWith<Run>(x => x.ResultFloatValues);
530        dlo.LoadWith<Run>(x => x.ResultIntValues);
531        dlo.LoadWith<Run>(x => x.ResultStringValues);
532        okb.LoadOptions = dlo;
533        return okb.Runs.Where(x => x.ExperimentId == experimentId).Select(x => Convert.ToDto(x)).ToArray();
534      }
535    }
[5269]536    public long AddRun(DataTransfer.Run dto) {
[5073]537      using (OKBDataContext okb = new OKBDataContext()) {
[5269]538        DataAccess.Run entity = Convert.ToEntity(dto); entity.Id = 0;
539        okb.Runs.InsertOnSubmit(entity);
540        okb.SubmitChanges();
541        return entity.Id;
542      }
543    }
544    public void DeleteRun(long id) {
545      using (OKBDataContext okb = new OKBDataContext()) {
546        IEnumerable<DataAccess.ResultBlobValue> resultBlobValues = okb.ResultBlobValues.Where(x => x.RunId == id);
547        okb.ResultBlobValues.DeleteAllOnSubmit(resultBlobValues);
548        IEnumerable<DataAccess.ResultBoolValue> resultBoolValues = okb.ResultBoolValues.Where(x => x.RunId == id);
549        okb.ResultBoolValues.DeleteAllOnSubmit(resultBoolValues);
550        IEnumerable<DataAccess.ResultFloatValue> resultFloatValues = okb.ResultFloatValues.Where(x => x.RunId == id);
551        okb.ResultFloatValues.DeleteAllOnSubmit(resultFloatValues);
552        IEnumerable<DataAccess.ResultIntValue> resultIntValues = okb.ResultIntValues.Where(x => x.RunId == id);
553        okb.ResultIntValues.DeleteAllOnSubmit(resultIntValues);
554        IEnumerable<DataAccess.ResultStringValue> resultStringValues = okb.ResultStringValues.Where(x => x.RunId == id);
555        okb.ResultStringValues.DeleteAllOnSubmit(resultStringValues);
556
557        DataAccess.Run entity = okb.Runs.FirstOrDefault(x => x.Id == id);
558        if (entity != null) okb.Runs.DeleteOnSubmit(entity);
559        okb.SubmitChanges();
560      }
561    }
562    #endregion
563
564    #region Query Methods
565    public IEnumerable<DataTransfer.Filter> GetFilters() {
566      List<DataTransfer.Filter> filters = new List<DataTransfer.Filter>();
567      using (OKBDataContext okb = new OKBDataContext()) {
[5286]568        //DataLoadOptions dlo = new DataLoadOptions();
569        //dlo.LoadWith<Algorithm>(x => x.AlgorithmData);
570        //dlo.LoadWith<AlgorithmData>(x => x.DataType);
571        //dlo.LoadWith<Problem>(x => x.ProblemData);
572        //dlo.LoadWith<ProblemData>(x => x.DataType);
573        //dlo.LoadWith<AlgorithmParameter>(x => x.DataType);
574        //dlo.LoadWith<ProblemParameter>(x => x.DataType);
575        //dlo.LoadWith<Result>(x => x.DataType);
576        //okb.LoadOptions = dlo;
[5269]577
578        // run filters
[5295]579        filters.Add(new DataTransfer.OrdinalComparisonLongFilter(typeof(RunRandomSeedFilter).AssemblyQualifiedName, "Run Random Seed"));
580        filters.Add(new DataTransfer.OrdinalComparisonDateTimeFilter(typeof(RunCreatedDateFilter).AssemblyQualifiedName, "Run Created Date"));
[5269]581        filters.Add(new DataTransfer.SetComparisonStringFilter(typeof(RunUserNameFilter).AssemblyQualifiedName, "Run User Name"));
582        filters.Add(new DataTransfer.SetComparisonStringFilter(typeof(RunClientNameFilter).AssemblyQualifiedName, "Run Client Name"));
583
584        // result filters
[5286]585        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ResultNameFilter).AssemblyQualifiedName, "Result Name", okb.Results.Select(x => x.Name).Distinct().ToArray()));
[5269]586        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
[5286]587          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(ResultBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value Data Type Name", entity.Name, okb.ResultBlobValues.Where(x => x.Result.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
[5269]588        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
589          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(ResultBlobValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
590        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
591          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(ResultBoolValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
592        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
593          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(ResultFloatValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
594        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
595          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(ResultIntValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
596        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
597          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(ResultStringValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
598
599        // algorithm parameter filters
[5286]600        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmParameterNameFilter).AssemblyQualifiedName, "Algorithm Parameter Name", okb.AlgorithmParameters.Select(x => x.Name).Distinct().ToArray()));
[5269]601        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
[5286]602          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(AlgorithmParameterBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value Data Type Name", entity.Name, okb.AlgorithmParameterBlobValues.Where(x => x.AlgorithmParameter.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
[5269]603        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
604          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(AlgorithmParameterBlobValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
605        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
606          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(AlgorithmParameterBoolValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
607        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
608          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(AlgorithmParameterFloatValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
609        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
610          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(AlgorithmParameterIntValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
611        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
612          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(AlgorithmParameterStringValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
613
614        // algorithm filters
[5286]615        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmNameFilter).AssemblyQualifiedName, "Algorithm Name", okb.Algorithms.Select(x => x.Name).Distinct().ToArray()));
616        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmClassNameFilter).AssemblyQualifiedName, "Algorithm Class Name", okb.AlgorithmClasses.Select(x => x.Name).Distinct().ToArray()));
617        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmPlatformNameFilter).AssemblyQualifiedName, "Algorithm Platform Name", okb.Platforms.Select(x => x.Name).Distinct().ToArray()));
618        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmDataDataTypeNameFilter).AssemblyQualifiedName, "Algorithm Data Type Name", okb.Algorithms.Select(x => x.AlgorithmData.DataType.Name).Distinct().ToArray()));
[5269]619
620        // problem parameter filters
[5286]621        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemParameterNameFilter).AssemblyQualifiedName, "Problem Parameter Name", okb.ProblemParameters.Select(x => x.Name).Distinct().ToArray()));
[5269]622        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
[5286]623          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(ProblemParameterBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value Data Type Name", entity.Name, okb.ProblemParameterBlobValues.Where(x => x.ProblemParameter.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
[5269]624        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
625          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(ProblemParameterBlobValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
626        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
627          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(ProblemParameterBoolValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
628        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
629          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(ProblemParameterFloatValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
630        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
631          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(ProblemParameterIntValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
632        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
633          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(ProblemParameterStringValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
634
635        // problem filters
[5286]636        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemNameFilter).AssemblyQualifiedName, "Problem Name", okb.Problems.Select(x => x.Name).Distinct().ToArray()));
637        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemClassNameFilter).AssemblyQualifiedName, "Problem Class Name", okb.ProblemClasses.Select(x => x.Name).Distinct().ToArray()));
638        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemPlatformNameFilter).AssemblyQualifiedName, "Problem Platform Name", okb.Platforms.Select(x => x.Name).Distinct().ToArray()));
639        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemDataDataTypeNameFilter).AssemblyQualifiedName, "Problem Data Type Name", okb.Problems.Select(x => x.ProblemData.DataType.Name).Distinct().ToArray()));
640
641        // and/or filters
642        filters.Add(new DataTransfer.AndFilter(typeof(AndFilter).AssemblyQualifiedName, "And"));
643        filters.Add(new DataTransfer.OrFilter(typeof(OrFilter).AssemblyQualifiedName, "Or"));
[5269]644      }
645      return filters.OrderBy(x => x.Label);
646    }
[5295]647    public long QueryNumberOfRuns(DataTransfer.Filter filter) {
648      using (OKBDataContext okb = new OKBDataContext()) {
649        IFilter convertedFilter = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);
650        return okb.Runs.Where(convertedFilter.Expression).LongCount();
651      }
652    }
[5286]653    public IEnumerable<DataTransfer.Run> QueryRuns(DataTransfer.Filter filter) {
[5269]654      using (OKBDataContext okb = new OKBDataContext()) {
[5286]655        //DataLoadOptions dlo = new DataLoadOptions();
656        //dlo.LoadWith<Run>(x => x.ResultBlobValues);
657        //dlo.LoadWith<Run>(x => x.ResultBoolValues);
658        //dlo.LoadWith<Run>(x => x.ResultFloatValues);
659        //dlo.LoadWith<Run>(x => x.ResultIntValues);
660        //dlo.LoadWith<Run>(x => x.ResultStringValues);
661        //dlo.LoadWith<Run>(x => x.Experiment);
662        //dlo.LoadWith<ResultBlobValue>(x => x.Result);
663        //dlo.LoadWith<ResultBlobValue>(x => x.DataType);
664        //dlo.LoadWith<ResultBoolValue>(x => x.Result);
665        //dlo.LoadWith<ResultBoolValue>(x => x.DataType);
666        //dlo.LoadWith<ResultFloatValue>(x => x.Result);
667        //dlo.LoadWith<ResultFloatValue>(x => x.DataType);
668        //dlo.LoadWith<ResultIntValue>(x => x.Result);
669        //dlo.LoadWith<ResultIntValue>(x => x.DataType);
670        //dlo.LoadWith<ResultStringValue>(x => x.Result);
671        //dlo.LoadWith<ResultStringValue>(x => x.DataType);
672        //dlo.LoadWith<Result>(x => x.Algorithm);
673        //dlo.LoadWith<Result>(x => x.DataType);
674        //dlo.LoadWith<Experiment>(x => x.Algorithm);
675        //dlo.LoadWith<Experiment>(x => x.Problem);
676        //dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBlobValues);
677        //dlo.LoadWith<Experiment>(x => x.AlgorithmParameterBoolValues);
678        //dlo.LoadWith<Experiment>(x => x.AlgorithmParameterFloatValues);
679        //dlo.LoadWith<Experiment>(x => x.AlgorithmParameterIntValues);
680        //dlo.LoadWith<Experiment>(x => x.AlgorithmParameterStringValues);
681        //dlo.LoadWith<Experiment>(x => x.ProblemParameterBlobValues);
682        //dlo.LoadWith<Experiment>(x => x.ProblemParameterBoolValues);
683        //dlo.LoadWith<Experiment>(x => x.ProblemParameterFloatValues);
684        //dlo.LoadWith<Experiment>(x => x.ProblemParameterIntValues);
685        //dlo.LoadWith<Experiment>(x => x.ProblemParameterStringValues);
686        //dlo.LoadWith<AlgorithmParameterBlobValue>(x => x.AlgorithmParameter);
687        //dlo.LoadWith<AlgorithmParameterBlobValue>(x => x.DataType);
688        //dlo.LoadWith<AlgorithmParameterBoolValue>(x => x.AlgorithmParameter);
689        //dlo.LoadWith<AlgorithmParameterBoolValue>(x => x.DataType);
690        //dlo.LoadWith<AlgorithmParameterFloatValue>(x => x.AlgorithmParameter);
691        //dlo.LoadWith<AlgorithmParameterFloatValue>(x => x.DataType);
692        //dlo.LoadWith<AlgorithmParameterIntValue>(x => x.AlgorithmParameter);
693        //dlo.LoadWith<AlgorithmParameterIntValue>(x => x.DataType);
694        //dlo.LoadWith<AlgorithmParameterStringValue>(x => x.AlgorithmParameter);
695        //dlo.LoadWith<AlgorithmParameterStringValue>(x => x.DataType);
696        //dlo.LoadWith<ProblemParameterBlobValue>(x => x.ProblemParameter);
697        //dlo.LoadWith<ProblemParameterBlobValue>(x => x.DataType);
698        //dlo.LoadWith<ProblemParameterBoolValue>(x => x.ProblemParameter);
699        //dlo.LoadWith<ProblemParameterBoolValue>(x => x.DataType);
700        //dlo.LoadWith<ProblemParameterFloatValue>(x => x.ProblemParameter);
701        //dlo.LoadWith<ProblemParameterFloatValue>(x => x.DataType);
702        //dlo.LoadWith<ProblemParameterIntValue>(x => x.ProblemParameter);
703        //dlo.LoadWith<ProblemParameterIntValue>(x => x.DataType);
704        //dlo.LoadWith<ProblemParameterStringValue>(x => x.ProblemParameter);
705        //dlo.LoadWith<ProblemParameterStringValue>(x => x.DataType);
706        //dlo.LoadWith<AlgorithmParameter>(x => x.Algorithm);
707        //dlo.LoadWith<AlgorithmParameter>(x => x.DataType);
708        //dlo.LoadWith<ProblemParameter>(x => x.Problem);
709        //dlo.LoadWith<ProblemParameter>(x => x.DataType);
710        //dlo.LoadWith<Algorithm>(x => x.AlgorithmClass);
711        //dlo.LoadWith<Algorithm>(x => x.Platform);
712        //dlo.LoadWith<Problem>(x => x.ProblemClass);
713        //dlo.LoadWith<Problem>(x => x.Platform);
714        //okb.LoadOptions = dlo;
[5269]715
[5295]716        DataLoadOptions dlo = new DataLoadOptions();
717        dlo.LoadWith<Run>(x => x.ResultBlobValues);
718        dlo.LoadWith<Run>(x => x.ResultBoolValues);
719        dlo.LoadWith<Run>(x => x.ResultFloatValues);
720        dlo.LoadWith<Run>(x => x.ResultIntValues);
721        dlo.LoadWith<Run>(x => x.ResultStringValues);
722        okb.LoadOptions = dlo;
723
[5286]724        IFilter convertedFilter = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);
[5295]725        var runs = okb.Runs.Where(convertedFilter.Expression).ToArray();
726        var result = runs.Select(x => Convert.ToDto(x)).ToArray();
727        return result;
[5073]728      }
729    }
[4591]730    #endregion
731
[4455]732    /*
733
[4279]734    /// <summary>
735    /// Gets the complete algorithm object graph up to the following entities:
736    /// <list type="bullet">
[4381]737    ///   <item>Parameter</item>
738    ///   <item>Algorithm_Paramters.Parameter.DataType</item>
739    ///   <item>Algorithm_Results.Result.DataType</item>
740    /// </list>
[4279]741    /// </summary>
742    /// <param name="id">The algorithm id.</param>
743    /// <returns>An <see cref="Algorithm"/></returns>
744    public Algorithm GetCompleteAlgorithm(int id) {
[4381]745      using (OKBDataContext okb = new OKBDataContext()) {
746        var dlo = new DataLoadOptions();
747        dlo.LoadWith<Algorithm>(a => a.AlgorithmClass);
748        dlo.LoadWith<Algorithm>(a => a.Platform);
749        dlo.LoadWith<Algorithm>(a => a.AlgorithmUsers);
750        dlo.LoadWith<AlgorithmUser>(u => u.User);
751        okb.LoadOptions = dlo;
752        return okb.Algorithms.Single(a => a.Id == id);
753      }
[4279]754    }
755
756    /// <summary>
757    /// Gets the complete problem object graph up to the following entities:
758    /// <list type="bullet">
[4381]759    ///   <item>Platform</item>
760    ///   <item>SolutionRepresentation</item>
761    ///   <item>Problem_Parameters.Parameter</item>
762    ///   <item>IntProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
763    ///   <item>FloatProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
764    ///   <item>CharProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
765    /// </list>
[4279]766    /// </summary>
767    /// <param name="id">The problem id.</param>
768    /// <returns>A <see cref="Problem"/></returns>
769    public Problem GetCompleteProblem(int id) {
[4381]770      using (OKBDataContext okb = new OKBDataContext()) {
771        var dlo = new DataLoadOptions();
772        dlo.LoadWith<Problem>(p => p.ProblemClass);
773        dlo.LoadWith<Problem>(p => p.Platform);
774        dlo.LoadWith<Problem>(p => p.ProblemUsers);
775        dlo.LoadWith<ProblemUser>(u => u.User);
776        okb.LoadOptions = dlo;
777        return okb.Problems.Single(p => p.Id == id);
778      }
[4279]779    }
780
781    /// <summary>
782    /// Updates the algorithm object graph including the following properties and linked entitites:
783    /// <list type="bullet">
[4381]784    ///   <item>Name</item>
785    ///   <item>Description</item>
786    ///   <item>AlgorithmClassId</item>
787    ///   <item>PlatformId</item>
788    ///   <item>Algorithm_Parameters</item>
789    ///   <item>Algorithm_Results</item>
790    /// </list>
791    /// <remarks>
[4279]792    /// New <see cref="Parameter"/>s or <see cref="Result"/>s will not be
793    /// created but have to be pre-existing.
794    /// </remarks>
795    /// </summary>
796    /// <param name="algorithm">The algorithm.</param>
797    public void UpdateCompleteAlgorithm(Algorithm algorithm) {
[4381]798      using (OKBDataContext okb = new OKBDataContext()) {
799        Algorithm original = okb.Algorithms.Single(a => a.Id == algorithm.Id);
800        UpdateAlgorithmData(algorithm, original, okb);
801        okb.SubmitChanges();
802      }
[4279]803    }
804
805    /// <summary>
806    /// Updates the problem object graph including the following properties and linked entities:
807    /// <list type="bullet">
[4381]808    ///   <item>Name</item>
809    ///   <item>Description</item>
810    ///   <item>ProblemClassId</item>
811    ///   <item>PlatformId</item>
812    ///   <item>SolutionRepresentationId</item>
813    ///   <item>IntProblemCharacteristicValues.Value</item>
814    ///   <item>FloatProblemCharacteristicValues.Value</item>
815    ///   <item>CharProblemCharacteristicValues.Value</item>
816    ///   <item>Problem_Parameters</item>
817    /// </list>
818    /// <remarks>
[4279]819    /// New <see cref="ProblemCharacteristic"/>s or <see cref="Parameter"/>s will
820    /// not be created but have to be pre-existing.
821    /// </remarks>
822    /// </summary>
823    /// <param name="problem">The problem.</param>
824    public void UpdateCompleteProblem(Problem problem) {
[4381]825      using (OKBDataContext okb = new OKBDataContext()) {
826        Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id);
827        UpdateProblemData(problem, originalProblem, okb);
828        okb.SubmitChanges();
829      }
[4279]830    }
831
[4381]832    private static void UpdateAlgorithmData(Algorithm algorithm, Algorithm original, OKBDataContext okb) {
833      original.Name = algorithm.Name;
834      original.Description = algorithm.Description;
835      original.AlgorithmClassId = algorithm.AlgorithmClassId;
836      original.PlatformId = algorithm.PlatformId;
837      okb.AlgorithmUsers.DeleteAllOnSubmit(original.AlgorithmUsers);
838      original.AlgorithmUsers.Clear();
839      foreach (var u in algorithm.AlgorithmUsers) {
840        original.AlgorithmUsers.Add(new AlgorithmUser() {
841          AlgorithmId = original.Id,
842          UserId = u.UserId
[4279]843        });
844      }
845    }
846
[4381]847    private static void UpdateProblemData(Problem problem, Problem original, OKBDataContext okb) {
848      original.Name = problem.Name;
849      original.Description = problem.Description;
850      original.ProblemClassId = problem.ProblemClassId;
851      original.SolutionRepresentationId = problem.SolutionRepresentationId;
852      original.PlatformId = problem.PlatformId;
853      okb.ProblemUsers.DeleteAllOnSubmit(original.ProblemUsers);
854      original.ProblemUsers.Clear();
855      foreach (var u in problem.ProblemUsers) {
856        original.ProblemUsers.Add(new ProblemUser() {
857          ProblemId = original.Id,
858          UserId = u.UserId
859        });
860      }
[4455]861    }*/
[4279]862  }
863}
Note: See TracBrowser for help on using the repository browser.