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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using DA = HeuristicLab.Services.Access.DataAccess;
|
---|
25 | using DT = HeuristicLab.Services.Access.DataTransfer;
|
---|
26 |
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Services.Access {
|
---|
29 | public static class Convert {
|
---|
30 |
|
---|
31 | #region Resource
|
---|
32 | public static DT.Resource ToDto(DA.Resource source) {
|
---|
33 | return new DT.Resource() {
|
---|
34 | Id = source.Id,
|
---|
35 | Description = source.Description,
|
---|
36 | Name = source.Name
|
---|
37 | };
|
---|
38 | }
|
---|
39 |
|
---|
40 | public static DA.Resource ToEntity(DT.Resource source) {
|
---|
41 | return new DA.Resource() {
|
---|
42 | Id = source.Id,
|
---|
43 | Description = source.Description,
|
---|
44 | Name = source.Name
|
---|
45 | };
|
---|
46 | }
|
---|
47 | #endregion
|
---|
48 |
|
---|
49 | #region ClientGroup
|
---|
50 | public static DT.ClientGroup ToDto(DA.ClientGroup source) {
|
---|
51 | return new DT.ClientGroup() {
|
---|
52 | Id = source.Id,
|
---|
53 | Description = source.Description,
|
---|
54 | Name = source.Name
|
---|
55 | };
|
---|
56 | }
|
---|
57 |
|
---|
58 | public static DA.ClientGroup ToEntity(DT.ClientGroup source) {
|
---|
59 | return new DA.ClientGroup() {
|
---|
60 | Id = source.Id,
|
---|
61 | Description = source.Description,
|
---|
62 | Name = source.Name,
|
---|
63 |
|
---|
64 | };
|
---|
65 | }
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | #region Country
|
---|
69 | public static DT.Country ToDto(DA.Country source) {
|
---|
70 | return new DT.Country() {
|
---|
71 | Id = source.Id,
|
---|
72 | Name = source.Name
|
---|
73 | };
|
---|
74 | }
|
---|
75 |
|
---|
76 | public static DA.Country ToEntity(DT.Country source) {
|
---|
77 | return new DA.Country() {
|
---|
78 | Id = source.Id,
|
---|
79 | Name = source.Name,
|
---|
80 |
|
---|
81 | };
|
---|
82 | }
|
---|
83 | #endregion
|
---|
84 |
|
---|
85 | #region OperatingSystem
|
---|
86 | public static DT.OperatingSystem ToDto(DA.OperatingSystem source) {
|
---|
87 | return new DT.OperatingSystem() {
|
---|
88 | Id = source.Id,
|
---|
89 | Name = source.Name
|
---|
90 | };
|
---|
91 | }
|
---|
92 |
|
---|
93 | public static DA.OperatingSystem ToEntity(DT.OperatingSystem source) {
|
---|
94 | return new DA.OperatingSystem() {
|
---|
95 | Id = source.Id,
|
---|
96 | Name = source.Name,
|
---|
97 | };
|
---|
98 | }
|
---|
99 | #endregion
|
---|
100 |
|
---|
101 | #region ClientType
|
---|
102 | public static DT.ClientType ToDto(DA.ClientType source) {
|
---|
103 | return new DT.ClientType() {
|
---|
104 | Id = source.Id,
|
---|
105 | Name = source.Name
|
---|
106 | };
|
---|
107 | }
|
---|
108 |
|
---|
109 | public static DA.ClientType ToEntity(DT.ClientType source) {
|
---|
110 | return new DA.ClientType() {
|
---|
111 | Id = source.Id,
|
---|
112 | Name = source.Name,
|
---|
113 |
|
---|
114 | };
|
---|
115 | }
|
---|
116 | #endregion
|
---|
117 |
|
---|
118 | #region ClientConfiguration
|
---|
119 | public static DT.ClientConfiguration ToDto(DA.ClientConfiguration source) {
|
---|
120 | return new DT.ClientConfiguration() {
|
---|
121 | Id = source.Id,
|
---|
122 | Hash = source.Hash,
|
---|
123 | Description = source.Description
|
---|
124 | };
|
---|
125 | }
|
---|
126 |
|
---|
127 | public static DA.ClientConfiguration ToEntity(DT.ClientConfiguration source) {
|
---|
128 | return new DA.ClientConfiguration() {
|
---|
129 | Id = source.Id,
|
---|
130 | Hash = source.Hash,
|
---|
131 | Description = source.Description
|
---|
132 | };
|
---|
133 | }
|
---|
134 | #endregion
|
---|
135 |
|
---|
136 | #region Plugin
|
---|
137 | public static DT.Plugin ToDto(DA.Plugin source) {
|
---|
138 | return new DT.Plugin() {
|
---|
139 | Id = source.Id,
|
---|
140 | Name = source.Name,
|
---|
141 | StrongName = source.StrongName,
|
---|
142 | Version = source.Version
|
---|
143 | };
|
---|
144 | }
|
---|
145 |
|
---|
146 | public static DA.Plugin ToEntity(DT.Plugin source) {
|
---|
147 | return new DA.Plugin() {
|
---|
148 | Id = source.Id,
|
---|
149 | Name = source.Name,
|
---|
150 | StrongName = source.StrongName,
|
---|
151 | Version = source.Version
|
---|
152 | };
|
---|
153 | }
|
---|
154 | #endregion
|
---|
155 |
|
---|
156 | #region Client
|
---|
157 | public static DT.Client ToDto(DA.Client source) {
|
---|
158 | return new DT.Client() {
|
---|
159 | Id = source.Id,
|
---|
160 | Description = source.Description,
|
---|
161 | Name = source.Name,
|
---|
162 | ClientConfiguration = ToDto(source.ClientConfiguration),
|
---|
163 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
164 | Country = ToDto(source.Country),
|
---|
165 | OperatingSystem = ToDto(source.OperatingSystem),
|
---|
166 | MemorySize = source.MemorySize.GetValueOrDefault(),
|
---|
167 | Timestamp = source.Timestamp.GetValueOrDefault(),
|
---|
168 | NumberOfCores = source.NumberOfCores.GetValueOrDefault(),
|
---|
169 | ProcessorType = source.ProcessorType,
|
---|
170 | ClientType = ToDto(source.ClientType)
|
---|
171 | };
|
---|
172 | }
|
---|
173 |
|
---|
174 | public static DA.Client ToEntity(DT.Client source) {
|
---|
175 | return new DA.Client() {
|
---|
176 | Id = source.Id,
|
---|
177 | Description = source.Description,
|
---|
178 | Name = source.Name,
|
---|
179 | ClientConfiguration = ToEntity(source.ClientConfiguration),
|
---|
180 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
181 | Country = ToEntity(source.Country),
|
---|
182 | OperatingSystem = ToEntity(source.OperatingSystem),
|
---|
183 | MemorySize = source.MemorySize,
|
---|
184 | Timestamp = source.Timestamp,
|
---|
185 | NumberOfCores = source.NumberOfCores,
|
---|
186 | ProcessorType = source.ProcessorType,
|
---|
187 | ClientType = ToEntity(source.ClientType)
|
---|
188 | };
|
---|
189 | }
|
---|
190 | #endregion
|
---|
191 |
|
---|
192 | #region ClientLog
|
---|
193 | public static DT.ClientLog ToDto(DA.ClientLog source) {
|
---|
194 | return new DT.ClientLog() {
|
---|
195 | Timestamp = source.Timestamp,
|
---|
196 | ResourceId = source.ResourceId,
|
---|
197 | Message = source.Message
|
---|
198 | };
|
---|
199 | }
|
---|
200 |
|
---|
201 | public static DA.ClientLog ToEntity(DT.ClientLog source) {
|
---|
202 | return new DA.ClientLog() {
|
---|
203 | Timestamp = source.Timestamp,
|
---|
204 | ResourceId = source.ResourceId,
|
---|
205 | Message = source.Message
|
---|
206 | };
|
---|
207 | }
|
---|
208 | #endregion
|
---|
209 |
|
---|
210 | #region ClientError
|
---|
211 | public static DT.ClientError ToDto(DA.ClientError source) {
|
---|
212 | return new DT.ClientError() {
|
---|
213 | Id = source.Id,
|
---|
214 | Timestamp = source.Timestamp,
|
---|
215 | Exception = source.Exception,
|
---|
216 | UserComment = source.UserComment,
|
---|
217 | ConfigDump = source.ConfigDump,
|
---|
218 | ClientId = source.ClientId.GetValueOrDefault(),
|
---|
219 | UserId = source.UserId.GetValueOrDefault()
|
---|
220 | };
|
---|
221 | }
|
---|
222 |
|
---|
223 | public static DA.ClientError ToEntity(DT.ClientError source) {
|
---|
224 | return new DA.ClientError() {
|
---|
225 | Id = source.Id,
|
---|
226 | Timestamp = source.Timestamp,
|
---|
227 | Exception = source.Exception,
|
---|
228 | UserComment = source.UserComment,
|
---|
229 | ConfigDump = source.ConfigDump,
|
---|
230 | ClientId = source.ClientId,
|
---|
231 | UserId = source.UserId
|
---|
232 | };
|
---|
233 | }
|
---|
234 | #endregion
|
---|
235 |
|
---|
236 | #region UserGroup
|
---|
237 | public static DT.UserGroup ToDto(DA.UserGroup source) {
|
---|
238 | return new DT.UserGroup() {
|
---|
239 | Id = source.Id,
|
---|
240 | Name = source.Name
|
---|
241 | };
|
---|
242 | }
|
---|
243 |
|
---|
244 | public static DA.UserGroup ToEntity(DT.UserGroup source) {
|
---|
245 | return new DA.UserGroup() {
|
---|
246 | Id = source.Id,
|
---|
247 | Name = source.Name
|
---|
248 | };
|
---|
249 | }
|
---|
250 | #endregion
|
---|
251 |
|
---|
252 | #region User
|
---|
253 | public static DT.User ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource) {
|
---|
254 | return new DT.User() {
|
---|
255 | Id = source.Id,
|
---|
256 | FullName = source.FullName,
|
---|
257 | Comment = aspMembershipSource.Comment,
|
---|
258 | CreationDate = aspMembershipSource.CreateDate,
|
---|
259 | Email = aspMembershipSource.Email,
|
---|
260 | IsApproved = aspMembershipSource.IsApproved,
|
---|
261 | LastActivityDate = aspUserSource.LastActivityDate,
|
---|
262 | LastLoginDate = aspMembershipSource.LastLoginDate,
|
---|
263 | LastPasswordChangedDate = aspMembershipSource.LastPasswordChangedDate,
|
---|
264 | UserName = aspUserSource.UserName
|
---|
265 | };
|
---|
266 | }
|
---|
267 |
|
---|
268 | public static void ToEntity(DT.User source, out DA.User accessUser, out DA.aspnet_User aspUser, out DA.aspnet_Membership aspMembership, out bool userExistsInASP) {
|
---|
269 | userExistsInASP = false;
|
---|
270 | accessUser = new DA.User();
|
---|
271 | aspUser = new DA.aspnet_User();
|
---|
272 | aspMembership = new DA.aspnet_Membership();
|
---|
273 |
|
---|
274 | if (source.Id != Guid.Empty) {
|
---|
275 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
276 | var userCol = context.aspnet_Users.Where(s => s.UserId == source.Id);
|
---|
277 | var membershipCol = context.aspnet_Memberships.Where(s => s.UserId == source.Id);
|
---|
278 | if (userCol.Count() > 0 && membershipCol.Count() > 0) {
|
---|
279 | aspUser = userCol.First();
|
---|
280 | aspMembership = membershipCol.First();
|
---|
281 | userExistsInASP = true;
|
---|
282 | }
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | accessUser.Id = source.Id;
|
---|
287 | accessUser.FullName = source.FullName;
|
---|
288 |
|
---|
289 | aspUser.UserId = source.Id;
|
---|
290 | aspUser.LastActivityDate = source.LastActivityDate;
|
---|
291 | aspUser.UserName = source.UserName;
|
---|
292 |
|
---|
293 | aspMembership.UserId = source.Id;
|
---|
294 | aspMembership.Comment = source.Comment;
|
---|
295 | aspMembership.CreateDate = source.CreationDate;
|
---|
296 | aspMembership.Email = source.Email;
|
---|
297 | aspMembership.IsApproved = source.IsApproved;
|
---|
298 | aspMembership.LastLoginDate = source.LastLoginDate;
|
---|
299 | aspMembership.LastPasswordChangedDate = source.LastPasswordChangedDate;
|
---|
300 | }
|
---|
301 | #endregion
|
---|
302 |
|
---|
303 | #region ClientGroupMapping
|
---|
304 | public static DT.ClientGroupMapping ToDto(DA.ResourceResourceGroup c) {
|
---|
305 | return new DT.ClientGroupMapping() {
|
---|
306 | Child = c.ResourceId, Parent = c.ResourceGroupId
|
---|
307 | };
|
---|
308 | }
|
---|
309 | #endregion
|
---|
310 |
|
---|
311 |
|
---|
312 | }
|
---|
313 | }
|
---|