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