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.Collections.Generic;
|
---|
23 | using System.Linq;
|
---|
24 | using System.ServiceModel;
|
---|
25 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Services.OKB {
|
---|
28 | /// <summary>
|
---|
29 | /// Implementation of the OKB administration service (interface <see cref="IAdminService"/>).
|
---|
30 | /// </summary>
|
---|
31 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
32 | public class AdminService : IAdminService {
|
---|
33 | #region Platform Methods
|
---|
34 | public DataTransfer.Platform GetPlatform(long id) {
|
---|
35 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
36 | return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id));
|
---|
37 | }
|
---|
38 | }
|
---|
39 | public IEnumerable<DataTransfer.Platform> GetPlatforms() {
|
---|
40 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
41 | return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray();
|
---|
42 | }
|
---|
43 | }
|
---|
44 | public void StorePlatform(DataTransfer.Platform dto) {
|
---|
45 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
46 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
47 | if (entity == null) okb.Platforms.InsertOnSubmit(Convert.ToEntity(dto));
|
---|
48 | else Convert.ToEntity(dto, entity);
|
---|
49 | okb.SubmitChanges();
|
---|
50 | }
|
---|
51 | }
|
---|
52 | public void DeletePlatform(long id) {
|
---|
53 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
54 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id);
|
---|
55 | if (entity != null) okb.Platforms.DeleteOnSubmit(entity);
|
---|
56 | okb.SubmitChanges();
|
---|
57 | }
|
---|
58 | }
|
---|
59 | #endregion
|
---|
60 |
|
---|
61 | #region AlgorithmClass Methods
|
---|
62 | public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {
|
---|
63 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
64 | return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));
|
---|
65 | }
|
---|
66 | }
|
---|
67 | public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() {
|
---|
68 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
69 | return okb.AlgorithmClasses.Select(x => Convert.ToDto(x)).ToArray();
|
---|
70 | }
|
---|
71 | }
|
---|
72 | public void StoreAlgorithmClass(DataTransfer.AlgorithmClass dto) {
|
---|
73 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
74 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id);
|
---|
75 | if (entity == null) okb.AlgorithmClasses.InsertOnSubmit(Convert.ToEntity(dto));
|
---|
76 | else Convert.ToEntity(dto, entity);
|
---|
77 | okb.SubmitChanges();
|
---|
78 | }
|
---|
79 | }
|
---|
80 | public void DeleteAlgorithmClass(long id) {
|
---|
81 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
82 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id);
|
---|
83 | if (entity != null) okb.AlgorithmClasses.DeleteOnSubmit(entity);
|
---|
84 | okb.SubmitChanges();
|
---|
85 | }
|
---|
86 | }
|
---|
87 | #endregion
|
---|
88 |
|
---|
89 | #region Algorithm Methods
|
---|
90 | public DataTransfer.Algorithm GetAlgorithm(long id) {
|
---|
91 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
92 | return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id));
|
---|
93 | }
|
---|
94 | }
|
---|
95 | public IEnumerable<DataTransfer.Algorithm> GetAlgorithms() {
|
---|
96 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
97 | return okb.Algorithms.Select(x => Convert.ToDto(x)).ToArray();
|
---|
98 | }
|
---|
99 | }
|
---|
100 | public void StoreAlgorithm(DataTransfer.Algorithm dto) {
|
---|
101 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
102 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
103 | if (entity == null) okb.Algorithms.InsertOnSubmit(Convert.ToEntity(dto));
|
---|
104 | else Convert.ToEntity(dto, entity);
|
---|
105 | okb.SubmitChanges();
|
---|
106 | }
|
---|
107 | }
|
---|
108 | public void DeleteAlgorithm(long id) {
|
---|
109 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
110 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id);
|
---|
111 | if (entity != null) okb.Algorithms.DeleteOnSubmit(entity);
|
---|
112 | okb.SubmitChanges();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | #endregion
|
---|
116 |
|
---|
117 | /*
|
---|
118 |
|
---|
119 | /// <summary>
|
---|
120 | /// Gets the complete algorithm object graph up to the following entities:
|
---|
121 | /// <list type="bullet">
|
---|
122 | /// <item>Parameter</item>
|
---|
123 | /// <item>Algorithm_Paramters.Parameter.DataType</item>
|
---|
124 | /// <item>Algorithm_Results.Result.DataType</item>
|
---|
125 | /// </list>
|
---|
126 | /// </summary>
|
---|
127 | /// <param name="id">The algorithm id.</param>
|
---|
128 | /// <returns>An <see cref="Algorithm"/></returns>
|
---|
129 | public Algorithm GetCompleteAlgorithm(int id) {
|
---|
130 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
131 | var dlo = new DataLoadOptions();
|
---|
132 | dlo.LoadWith<Algorithm>(a => a.AlgorithmClass);
|
---|
133 | dlo.LoadWith<Algorithm>(a => a.Platform);
|
---|
134 | dlo.LoadWith<Algorithm>(a => a.AlgorithmUsers);
|
---|
135 | dlo.LoadWith<AlgorithmUser>(u => u.User);
|
---|
136 | okb.LoadOptions = dlo;
|
---|
137 | return okb.Algorithms.Single(a => a.Id == id);
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | /// <summary>
|
---|
142 | /// Gets the complete problem object graph up to the following entities:
|
---|
143 | /// <list type="bullet">
|
---|
144 | /// <item>Platform</item>
|
---|
145 | /// <item>SolutionRepresentation</item>
|
---|
146 | /// <item>Problem_Parameters.Parameter</item>
|
---|
147 | /// <item>IntProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
|
---|
148 | /// <item>FloatProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
|
---|
149 | /// <item>CharProblemCharacteristicValues.ProblemCharacteristic.DataType</item>
|
---|
150 | /// </list>
|
---|
151 | /// </summary>
|
---|
152 | /// <param name="id">The problem id.</param>
|
---|
153 | /// <returns>A <see cref="Problem"/></returns>
|
---|
154 | public Problem GetCompleteProblem(int id) {
|
---|
155 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
156 | var dlo = new DataLoadOptions();
|
---|
157 | dlo.LoadWith<Problem>(p => p.ProblemClass);
|
---|
158 | dlo.LoadWith<Problem>(p => p.Platform);
|
---|
159 | dlo.LoadWith<Problem>(p => p.ProblemUsers);
|
---|
160 | dlo.LoadWith<ProblemUser>(u => u.User);
|
---|
161 | okb.LoadOptions = dlo;
|
---|
162 | return okb.Problems.Single(p => p.Id == id);
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | /// <summary>
|
---|
167 | /// Updates the algorithm object graph including the following properties and linked entitites:
|
---|
168 | /// <list type="bullet">
|
---|
169 | /// <item>Name</item>
|
---|
170 | /// <item>Description</item>
|
---|
171 | /// <item>AlgorithmClassId</item>
|
---|
172 | /// <item>PlatformId</item>
|
---|
173 | /// <item>Algorithm_Parameters</item>
|
---|
174 | /// <item>Algorithm_Results</item>
|
---|
175 | /// </list>
|
---|
176 | /// <remarks>
|
---|
177 | /// New <see cref="Parameter"/>s or <see cref="Result"/>s will not be
|
---|
178 | /// created but have to be pre-existing.
|
---|
179 | /// </remarks>
|
---|
180 | /// </summary>
|
---|
181 | /// <param name="algorithm">The algorithm.</param>
|
---|
182 | public void UpdateCompleteAlgorithm(Algorithm algorithm) {
|
---|
183 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
184 | Algorithm original = okb.Algorithms.Single(a => a.Id == algorithm.Id);
|
---|
185 | UpdateAlgorithmData(algorithm, original, okb);
|
---|
186 | okb.SubmitChanges();
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | /// <summary>
|
---|
191 | /// Updates the problem object graph including the following properties and linked entities:
|
---|
192 | /// <list type="bullet">
|
---|
193 | /// <item>Name</item>
|
---|
194 | /// <item>Description</item>
|
---|
195 | /// <item>ProblemClassId</item>
|
---|
196 | /// <item>PlatformId</item>
|
---|
197 | /// <item>SolutionRepresentationId</item>
|
---|
198 | /// <item>IntProblemCharacteristicValues.Value</item>
|
---|
199 | /// <item>FloatProblemCharacteristicValues.Value</item>
|
---|
200 | /// <item>CharProblemCharacteristicValues.Value</item>
|
---|
201 | /// <item>Problem_Parameters</item>
|
---|
202 | /// </list>
|
---|
203 | /// <remarks>
|
---|
204 | /// New <see cref="ProblemCharacteristic"/>s or <see cref="Parameter"/>s will
|
---|
205 | /// not be created but have to be pre-existing.
|
---|
206 | /// </remarks>
|
---|
207 | /// </summary>
|
---|
208 | /// <param name="problem">The problem.</param>
|
---|
209 | public void UpdateCompleteProblem(Problem problem) {
|
---|
210 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
211 | Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id);
|
---|
212 | UpdateProblemData(problem, originalProblem, okb);
|
---|
213 | okb.SubmitChanges();
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | private static void UpdateAlgorithmData(Algorithm algorithm, Algorithm original, OKBDataContext okb) {
|
---|
218 | original.Name = algorithm.Name;
|
---|
219 | original.Description = algorithm.Description;
|
---|
220 | original.AlgorithmClassId = algorithm.AlgorithmClassId;
|
---|
221 | original.PlatformId = algorithm.PlatformId;
|
---|
222 | okb.AlgorithmUsers.DeleteAllOnSubmit(original.AlgorithmUsers);
|
---|
223 | original.AlgorithmUsers.Clear();
|
---|
224 | foreach (var u in algorithm.AlgorithmUsers) {
|
---|
225 | original.AlgorithmUsers.Add(new AlgorithmUser() {
|
---|
226 | AlgorithmId = original.Id,
|
---|
227 | UserId = u.UserId
|
---|
228 | });
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | private static void UpdateProblemData(Problem problem, Problem original, OKBDataContext okb) {
|
---|
233 | original.Name = problem.Name;
|
---|
234 | original.Description = problem.Description;
|
---|
235 | original.ProblemClassId = problem.ProblemClassId;
|
---|
236 | original.SolutionRepresentationId = problem.SolutionRepresentationId;
|
---|
237 | original.PlatformId = problem.PlatformId;
|
---|
238 | okb.ProblemUsers.DeleteAllOnSubmit(original.ProblemUsers);
|
---|
239 | original.ProblemUsers.Clear();
|
---|
240 | foreach (var u in problem.ProblemUsers) {
|
---|
241 | original.ProblemUsers.Add(new ProblemUser() {
|
---|
242 | ProblemId = original.Id,
|
---|
243 | UserId = u.UserId
|
---|
244 | });
|
---|
245 | }
|
---|
246 | }*/
|
---|
247 | }
|
---|
248 | }
|
---|