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.ClientManagement {
|
---|
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 | }
|
---|
100 | #endregion
|
---|
101 |
|
---|
102 | #region ClientType
|
---|
103 | public static DT.ClientType ToDto(DA.ClientType source) {
|
---|
104 | return new DT.ClientType() {
|
---|
105 | Id = source.Id,
|
---|
106 | Name = source.Name
|
---|
107 | };
|
---|
108 | }
|
---|
109 |
|
---|
110 | public static DA.ClientType ToEntity(DT.ClientType source) {
|
---|
111 | return new DA.ClientType() {
|
---|
112 | Id = source.Id,
|
---|
113 | Name = source.Name,
|
---|
114 |
|
---|
115 | };
|
---|
116 | }
|
---|
117 | #endregion
|
---|
118 |
|
---|
119 | #region ClientConfiguration
|
---|
120 | public static DT.ClientConfiguration ToDto(DA.ClientConfiguration source) {
|
---|
121 | return new DT.ClientConfiguration() {
|
---|
122 | Id = source.Id,
|
---|
123 | Hash = source.Hash,
|
---|
124 | Description = source.Description
|
---|
125 | };
|
---|
126 | }
|
---|
127 |
|
---|
128 | public static DA.ClientConfiguration ToEntity(DT.ClientConfiguration source) {
|
---|
129 | return new DA.ClientConfiguration() {
|
---|
130 | Id = source.Id,
|
---|
131 | Hash = source.Hash,
|
---|
132 | Description = source.Description
|
---|
133 | };
|
---|
134 | }
|
---|
135 | #endregion
|
---|
136 |
|
---|
137 | #region Plugin
|
---|
138 | public static DT.Plugin ToDto(DA.Plugin source) {
|
---|
139 | return new DT.Plugin() {
|
---|
140 | Id = source.Id,
|
---|
141 | Name = source.Name,
|
---|
142 | StrongName = source.StrongName,
|
---|
143 | Version = source.Version
|
---|
144 | };
|
---|
145 | }
|
---|
146 |
|
---|
147 | public static DA.Plugin ToEntity(DT.Plugin source) {
|
---|
148 | return new DA.Plugin() {
|
---|
149 | Id = source.Id,
|
---|
150 | Name = source.Name,
|
---|
151 | StrongName = source.StrongName,
|
---|
152 | Version = source.Version
|
---|
153 | };
|
---|
154 | }
|
---|
155 | #endregion
|
---|
156 |
|
---|
157 | #region Client
|
---|
158 | public static DT.Client ToDto(DA.Client source) {
|
---|
159 | return new DT.Client() {
|
---|
160 | Id = source.Id,
|
---|
161 | Description = source.Description,
|
---|
162 | Name = source.Name,
|
---|
163 | ClientConfiguration = ToDto(source.ClientConfiguration),
|
---|
164 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
165 | Country = ToDto(source.Country),
|
---|
166 | OperatingSystem = ToDto(source.OperatingSystem),
|
---|
167 | MemorySize = source.MemorySize.GetValueOrDefault(),
|
---|
168 | Timestamp = source.Timestamp.GetValueOrDefault(),
|
---|
169 | NumberOfCores = source.NumberOfCores.GetValueOrDefault(),
|
---|
170 | ProcessorType = source.ProcessorType,
|
---|
171 | ClientType = ToDto(source.ClientType)
|
---|
172 | };
|
---|
173 | }
|
---|
174 |
|
---|
175 | public static DA.Client ToEntity(DT.Client source) {
|
---|
176 | return new DA.Client() {
|
---|
177 | Id = source.Id,
|
---|
178 | Description = source.Description,
|
---|
179 | Name = source.Name,
|
---|
180 | ClientConfiguration = ToEntity(source.ClientConfiguration),
|
---|
181 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
182 | Country = ToEntity(source.Country),
|
---|
183 | OperatingSystem = ToEntity(source.OperatingSystem),
|
---|
184 | MemorySize = source.MemorySize,
|
---|
185 | Timestamp = source.Timestamp,
|
---|
186 | NumberOfCores = source.NumberOfCores,
|
---|
187 | ProcessorType = source.ProcessorType,
|
---|
188 | ClientType = ToEntity(source.ClientType)
|
---|
189 | };
|
---|
190 | }
|
---|
191 | #endregion
|
---|
192 |
|
---|
193 | #region ClientLog
|
---|
194 | public static DT.ClientLog ToDto(DA.ClientLog source) {
|
---|
195 | return new DT.ClientLog() {
|
---|
196 | Timestamp = source.Timestamp,
|
---|
197 | ResourceId = source.ResourceId,
|
---|
198 | Message = source.Message
|
---|
199 | };
|
---|
200 | }
|
---|
201 |
|
---|
202 | public static DA.ClientLog ToEntity(DT.ClientLog source) {
|
---|
203 | return new DA.ClientLog() {
|
---|
204 | Timestamp = source.Timestamp,
|
---|
205 | ResourceId = source.ResourceId,
|
---|
206 | Message = source.Message
|
---|
207 | };
|
---|
208 | }
|
---|
209 | #endregion
|
---|
210 |
|
---|
211 | #region ClientError
|
---|
212 | public static DT.ClientError ToDto(DA.ClientError source) {
|
---|
213 | return new DT.ClientError() {
|
---|
214 | Id = source.Id,
|
---|
215 | Timestamp = source.Timestamp,
|
---|
216 | Exception = source.Exception,
|
---|
217 | UserComment = source.UserComment,
|
---|
218 | ConfigDump = source.ConfigDump,
|
---|
219 | ClientId = source.ClientId.GetValueOrDefault(),
|
---|
220 | UserId = source.UserId.GetValueOrDefault()
|
---|
221 | };
|
---|
222 | }
|
---|
223 |
|
---|
224 | public static DA.ClientError ToEntity(DT.ClientError source) {
|
---|
225 | return new DA.ClientError() {
|
---|
226 | Id = source.Id,
|
---|
227 | Timestamp = source.Timestamp,
|
---|
228 | Exception = source.Exception,
|
---|
229 | UserComment = source.UserComment,
|
---|
230 | ConfigDump = source.ConfigDump,
|
---|
231 | ClientId = source.ClientId,
|
---|
232 | UserId = source.UserId
|
---|
233 | };
|
---|
234 | }
|
---|
235 | #endregion
|
---|
236 |
|
---|
237 | #region UserGroup
|
---|
238 | public static DT.UserGroup ToDto(DA.UserGroup source) {
|
---|
239 | return new DT.UserGroup() {
|
---|
240 | Id = source.Id,
|
---|
241 | Name = source.Name
|
---|
242 | };
|
---|
243 | }
|
---|
244 |
|
---|
245 | public static DA.UserGroup ToEntity(DT.UserGroup source) {
|
---|
246 | return new DA.UserGroup() {
|
---|
247 | Id = source.Id,
|
---|
248 | Name = source.Name
|
---|
249 | };
|
---|
250 | }
|
---|
251 | #endregion
|
---|
252 |
|
---|
253 | #region User
|
---|
254 | public static DT.User ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource) {
|
---|
255 | return new DT.User() {
|
---|
256 | Id = source.Id,
|
---|
257 | FullName = source.FullName,
|
---|
258 | Comment = aspMembershipSource.Comment,
|
---|
259 | CreationDate = aspMembershipSource.CreateDate,
|
---|
260 | Email = aspMembershipSource.Email,
|
---|
261 | IsApproved = aspMembershipSource.IsApproved,
|
---|
262 | LastActivityDate = aspUserSource.LastActivityDate,
|
---|
263 | LastLoginDate = aspMembershipSource.LastLoginDate,
|
---|
264 | LastPasswordChangedDate = aspMembershipSource.LastPasswordChangedDate,
|
---|
265 | UserName = aspUserSource.UserName
|
---|
266 | };
|
---|
267 | }
|
---|
268 |
|
---|
269 | public static void ToEntity(DT.User source, out DA.User accessUser, out DA.aspnet_User aspUser, out DA.aspnet_Membership aspMembership, out bool userExistsInASP) {
|
---|
270 | userExistsInASP = false;
|
---|
271 | accessUser = new DA.User();
|
---|
272 | aspUser = new DA.aspnet_User();
|
---|
273 | aspMembership = new DA.aspnet_Membership();
|
---|
274 |
|
---|
275 | if (source.Id != Guid.Empty) {
|
---|
276 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
277 | var userCol = context.aspnet_Users.Where(s => s.UserId == source.Id);
|
---|
278 | var membershipCol = context.aspnet_Memberships.Where(s => s.UserId == source.Id);
|
---|
279 | if (userCol.Count() > 0 && membershipCol.Count() > 0) {
|
---|
280 | aspUser = userCol.First();
|
---|
281 | aspMembership = membershipCol.First();
|
---|
282 | userExistsInASP = true;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | accessUser.Id = source.Id;
|
---|
288 | accessUser.FullName = source.FullName;
|
---|
289 |
|
---|
290 | aspUser.UserId = source.Id;
|
---|
291 | aspUser.LastActivityDate = source.LastActivityDate;
|
---|
292 | aspUser.UserName = source.UserName;
|
---|
293 |
|
---|
294 | aspMembership.UserId = source.Id;
|
---|
295 | aspMembership.Comment = source.Comment;
|
---|
296 | aspMembership.CreateDate = source.CreationDate;
|
---|
297 | aspMembership.Email = source.Email;
|
---|
298 | aspMembership.IsApproved = source.IsApproved;
|
---|
299 | aspMembership.LastLoginDate = source.LastLoginDate;
|
---|
300 | aspMembership.LastPasswordChangedDate = source.LastPasswordChangedDate;
|
---|
301 | }
|
---|
302 | #endregion
|
---|
303 | }
|
---|
304 | }
|
---|