Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs @ 5991

Last change on this file since 5991 was 5902, checked in by swagner, 14 years ago

Worked on OKB (#1174)

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System.Collections.Generic;
23using System.Data.Linq;
24using System.Linq;
25using System.ServiceModel;
26using HeuristicLab.Services.OKB.DataAccess;
27
28namespace HeuristicLab.Services.OKB.RunCreation {
29  /// <summary>
30  /// Implementation of the OKB run creation service (interface <see cref="IRunCreationService"/>).
31  /// </summary>
32  [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
33  public class RunCreationService : IRunCreationService {
34    public IEnumerable<DataTransfer.Algorithm> GetAlgorithms(string platformName) {
35      using (OKBDataContext okb = new OKBDataContext()) {
36        DataLoadOptions dlo = new DataLoadOptions();
37        dlo.LoadWith<Algorithm>(x => x.AlgorithmClass);
38        dlo.LoadWith<Algorithm>(x => x.DataType);
39        okb.LoadOptions = dlo;
40        return okb.Algorithms.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray();
41      }
42    }
43
44    public byte[] GetAlgorithmData(long algorithmId) {
45      using (OKBDataContext okb = new OKBDataContext()) {
46        return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
47      }
48    }
49
50    public IEnumerable<DataTransfer.Problem> GetProblems(string platformName) {
51      using (OKBDataContext okb = new OKBDataContext()) {
52        DataLoadOptions dlo = new DataLoadOptions();
53        dlo.LoadWith<Problem>(x => x.ProblemClass);
54        dlo.LoadWith<Problem>(x => x.DataType);
55        okb.LoadOptions = dlo;
56        return okb.Problems.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray();
57      }
58    }
59
60    public byte[] GetProblemData(long problemId) {
61      using (OKBDataContext okb = new OKBDataContext()) {
62        return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
63      }
64    }
65
66    public void AddRun(DataTransfer.Run run) {
67      using (OKBDataContext okb = new OKBDataContext()) {
68        DataAccess.Run entity = Convert.ToEntity(run, okb);
69        okb.Runs.InsertOnSubmit(entity);
70        okb.SubmitChanges();
71      }
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.