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.Linq;
|
---|
25 | using System.ServiceModel;
|
---|
26 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Services.OKB.Administration {
|
---|
29 | /// <summary>
|
---|
30 | /// Implementation of the OKB administration service (interface <see cref="IAdministrationService"/>).
|
---|
31 | /// </summary>
|
---|
32 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
33 | public class AdministrationService : IAdministrationService {
|
---|
34 | #region Platform Methods
|
---|
35 | public IEnumerable<DataTransfer.Platform> GetPlatforms() {
|
---|
36 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
37 | return okb.Platforms.Select(x => Convert.ToDto(x)).ToArray();
|
---|
38 | }
|
---|
39 | }
|
---|
40 | public long AddPlatform(DataTransfer.Platform dto) {
|
---|
41 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
42 | DataAccess.Platform entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
43 | okb.Platforms.InsertOnSubmit(entity);
|
---|
44 | okb.SubmitChanges();
|
---|
45 | return entity.Id;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | public void UpdatePlatform(DataTransfer.Platform dto) {
|
---|
49 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
50 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
51 | Convert.ToEntity(dto, entity);
|
---|
52 | okb.SubmitChanges();
|
---|
53 | }
|
---|
54 | }
|
---|
55 | public void DeletePlatform(long id) {
|
---|
56 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
57 | DataAccess.Platform entity = okb.Platforms.FirstOrDefault(x => x.Id == id);
|
---|
58 | if (entity != null) okb.Platforms.DeleteOnSubmit(entity);
|
---|
59 | okb.SubmitChanges();
|
---|
60 | }
|
---|
61 | }
|
---|
62 | #endregion
|
---|
63 |
|
---|
64 | #region AlgorithmClass Methods
|
---|
65 | public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() {
|
---|
66 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
67 | return okb.AlgorithmClasses.Select(x => Convert.ToDto(x)).ToArray();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | public long AddAlgorithmClass(DataTransfer.AlgorithmClass dto) {
|
---|
71 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
72 | DataAccess.AlgorithmClass entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
73 | okb.AlgorithmClasses.InsertOnSubmit(entity);
|
---|
74 | okb.SubmitChanges();
|
---|
75 | return entity.Id;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | public void UpdateAlgorithmClass(DataTransfer.AlgorithmClass dto) {
|
---|
79 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
80 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == dto.Id);
|
---|
81 | Convert.ToEntity(dto, entity);
|
---|
82 | okb.SubmitChanges();
|
---|
83 | }
|
---|
84 | }
|
---|
85 | public void DeleteAlgorithmClass(long id) {
|
---|
86 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
87 | DataAccess.AlgorithmClass entity = okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id);
|
---|
88 | if (entity != null) okb.AlgorithmClasses.DeleteOnSubmit(entity);
|
---|
89 | okb.SubmitChanges();
|
---|
90 | }
|
---|
91 | }
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | #region Algorithm Methods
|
---|
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 long AddAlgorithm(DataTransfer.Algorithm dto) {
|
---|
101 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
102 | DataAccess.Algorithm entity = Convert.ToEntity(dto, okb); entity.Id = 0;
|
---|
103 | okb.Algorithms.InsertOnSubmit(entity);
|
---|
104 | okb.SubmitChanges();
|
---|
105 | return entity.Id;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | public void UpdateAlgorithm(DataTransfer.Algorithm dto) {
|
---|
109 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
110 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id);
|
---|
111 | Convert.ToEntity(dto, entity, okb);
|
---|
112 | okb.SubmitChanges();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | public void DeleteAlgorithm(long id) {
|
---|
116 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
117 | DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == id);
|
---|
118 | if (entity != null) okb.Algorithms.DeleteOnSubmit(entity);
|
---|
119 | okb.SubmitChanges();
|
---|
120 | }
|
---|
121 | }
|
---|
122 | public IEnumerable<Guid> GetAlgorithmUsers(long algorithmId) {
|
---|
123 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
124 | return okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserId).ToArray();
|
---|
125 | }
|
---|
126 | }
|
---|
127 | public void UpdateAlgorithmUsers(long algorithmId, IEnumerable<Guid> users) {
|
---|
128 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
129 | okb.AlgorithmUsers.DeleteAllOnSubmit(okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId));
|
---|
130 | okb.AlgorithmUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.AlgorithmUser { AlgorithmId = algorithmId, UserId = x }));
|
---|
131 | okb.SubmitChanges();
|
---|
132 | }
|
---|
133 | }
|
---|
134 | public byte[] GetAlgorithmData(long algorithmId) {
|
---|
135 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
136 | return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
|
---|
137 | }
|
---|
138 | }
|
---|
139 | public void UpdateAlgorithmData(long algorithmId, byte[] data) {
|
---|
140 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
141 | var entity = okb.Algorithms.Where(x => x.Id == algorithmId).FirstOrDefault();
|
---|
142 | if (entity != null)
|
---|
143 | entity.BinaryData = Convert.ToEntity(data, okb);
|
---|
144 | okb.SubmitChanges();
|
---|
145 | }
|
---|
146 | }
|
---|
147 | #endregion
|
---|
148 |
|
---|
149 | #region ProblemClass Methods
|
---|
150 | public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() {
|
---|
151 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
152 | return okb.ProblemClasses.Select(x => Convert.ToDto(x)).ToArray();
|
---|
153 | }
|
---|
154 | }
|
---|
155 | public long AddProblemClass(DataTransfer.ProblemClass dto) {
|
---|
156 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
157 | DataAccess.ProblemClass entity = Convert.ToEntity(dto); entity.Id = 0;
|
---|
158 | okb.ProblemClasses.InsertOnSubmit(entity);
|
---|
159 | okb.SubmitChanges();
|
---|
160 | return entity.Id;
|
---|
161 | }
|
---|
162 | }
|
---|
163 | public void UpdateProblemClass(DataTransfer.ProblemClass dto) {
|
---|
164 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
165 | DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == dto.Id);
|
---|
166 | Convert.ToEntity(dto, entity);
|
---|
167 | okb.SubmitChanges();
|
---|
168 | }
|
---|
169 | }
|
---|
170 | public void DeleteProblemClass(long id) {
|
---|
171 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
172 | DataAccess.ProblemClass entity = okb.ProblemClasses.FirstOrDefault(x => x.Id == id);
|
---|
173 | if (entity != null) okb.ProblemClasses.DeleteOnSubmit(entity);
|
---|
174 | okb.SubmitChanges();
|
---|
175 | }
|
---|
176 | }
|
---|
177 | #endregion
|
---|
178 |
|
---|
179 | #region Problem Methods
|
---|
180 | public IEnumerable<DataTransfer.Problem> GetProblems() {
|
---|
181 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
182 | return okb.Problems.Select(x => Convert.ToDto(x)).ToArray();
|
---|
183 | }
|
---|
184 | }
|
---|
185 | public long AddProblem(DataTransfer.Problem dto) {
|
---|
186 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
187 | DataAccess.Problem entity = Convert.ToEntity(dto, okb); entity.Id = 0;
|
---|
188 | okb.Problems.InsertOnSubmit(entity);
|
---|
189 | okb.SubmitChanges();
|
---|
190 | return entity.Id;
|
---|
191 | }
|
---|
192 | }
|
---|
193 | public void UpdateProblem(DataTransfer.Problem dto) {
|
---|
194 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
195 | DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id);
|
---|
196 | Convert.ToEntity(dto, entity, okb);
|
---|
197 | okb.SubmitChanges();
|
---|
198 | }
|
---|
199 | }
|
---|
200 | public void DeleteProblem(long id) {
|
---|
201 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
202 | DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == id);
|
---|
203 | if (entity != null) okb.Problems.DeleteOnSubmit(entity);
|
---|
204 | okb.SubmitChanges();
|
---|
205 | }
|
---|
206 | }
|
---|
207 | public IEnumerable<Guid> GetProblemUsers(long problemId) {
|
---|
208 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
209 | return okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserId).ToArray();
|
---|
210 | }
|
---|
211 | }
|
---|
212 | public void UpdateProblemUsers(long problemId, IEnumerable<Guid> users) {
|
---|
213 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
214 | okb.ProblemUsers.DeleteAllOnSubmit(okb.ProblemUsers.Where(x => x.ProblemId == problemId));
|
---|
215 | okb.ProblemUsers.InsertAllOnSubmit(users.Select(x => new DataAccess.ProblemUser { ProblemId = problemId, UserId = x }));
|
---|
216 | okb.SubmitChanges();
|
---|
217 | }
|
---|
218 | }
|
---|
219 | public byte[] GetProblemData(long problemId) {
|
---|
220 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
221 | return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault();
|
---|
222 | }
|
---|
223 | }
|
---|
224 | public void UpdateProblemData(long problemId, byte[] data) {
|
---|
225 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
226 | var entity = okb.Problems.Where(x => x.Id == problemId).FirstOrDefault();
|
---|
227 | if (entity != null)
|
---|
228 | entity.BinaryData = Convert.ToEntity(data, okb);
|
---|
229 | okb.SubmitChanges();
|
---|
230 | }
|
---|
231 | }
|
---|
232 | #endregion
|
---|
233 | }
|
---|
234 | }
|
---|