[6815] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7355] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6815] | 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 |
|
---|
[6825] | 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
[6815] | 24 | using DA = HeuristicLab.Services.Access.DataAccess;
|
---|
| 25 | using DT = HeuristicLab.Services.Access.DataTransfer;
|
---|
| 26 |
|
---|
[6825] | 27 |
|
---|
[6840] | 28 | namespace HeuristicLab.Services.Access {
|
---|
[6815] | 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,
|
---|
[6825] | 36 | Name = source.Name
|
---|
[6815] | 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,
|
---|
[6825] | 44 | Name = source.Name
|
---|
[6815] | 45 | };
|
---|
| 46 | }
|
---|
| 47 | #endregion
|
---|
| 48 |
|
---|
[6825] | 49 | #region ClientGroup
|
---|
| 50 | public static DT.ClientGroup ToDto(DA.ClientGroup source) {
|
---|
[6815] | 51 | return new DT.ClientGroup() {
|
---|
| 52 | Id = source.Id,
|
---|
| 53 | Description = source.Description,
|
---|
[6825] | 54 | Name = source.Name
|
---|
[6815] | 55 | };
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[6825] | 58 | public static DA.ClientGroup ToEntity(DT.ClientGroup source) {
|
---|
| 59 | return new DA.ClientGroup() {
|
---|
[6815] | 60 | Id = source.Id,
|
---|
| 61 | Description = source.Description,
|
---|
| 62 | Name = source.Name,
|
---|
[6825] | 63 |
|
---|
[6815] | 64 | };
|
---|
| 65 | }
|
---|
| 66 | #endregion
|
---|
| 67 |
|
---|
[6825] | 68 | #region Country
|
---|
| 69 | public static DT.Country ToDto(DA.Country source) {
|
---|
[6852] | 70 | if (source == null) {
|
---|
| 71 | return null;
|
---|
| 72 | } else {
|
---|
| 73 | return new DT.Country() {
|
---|
| 74 | Id = source.Id,
|
---|
| 75 | Name = source.Name
|
---|
| 76 | };
|
---|
| 77 | }
|
---|
[6825] | 78 | }
|
---|
| 79 |
|
---|
| 80 | public static DA.Country ToEntity(DT.Country source) {
|
---|
[6852] | 81 | if (source == null) {
|
---|
| 82 | return null;
|
---|
| 83 | } else {
|
---|
| 84 | return new DA.Country() {
|
---|
| 85 | Id = source.Id,
|
---|
| 86 | Name = source.Name,
|
---|
[6825] | 87 |
|
---|
[6852] | 88 | };
|
---|
| 89 | }
|
---|
[6825] | 90 | }
|
---|
| 91 | #endregion
|
---|
| 92 |
|
---|
| 93 | #region OperatingSystem
|
---|
| 94 | public static DT.OperatingSystem ToDto(DA.OperatingSystem source) {
|
---|
[6852] | 95 | if (source == null) {
|
---|
| 96 | return null;
|
---|
| 97 | } else {
|
---|
| 98 | return new DT.OperatingSystem() {
|
---|
| 99 | Id = source.Id,
|
---|
| 100 | Name = source.Name
|
---|
| 101 | };
|
---|
| 102 | }
|
---|
[6825] | 103 | }
|
---|
| 104 |
|
---|
| 105 | public static DA.OperatingSystem ToEntity(DT.OperatingSystem source) {
|
---|
[6852] | 106 | if (source == null) {
|
---|
| 107 | return null;
|
---|
| 108 | } else {
|
---|
| 109 | return new DA.OperatingSystem() {
|
---|
| 110 | Id = source.Id,
|
---|
| 111 | Name = source.Name,
|
---|
| 112 | };
|
---|
| 113 | }
|
---|
[6825] | 114 | }
|
---|
| 115 | #endregion
|
---|
| 116 |
|
---|
| 117 | #region ClientType
|
---|
| 118 | public static DT.ClientType ToDto(DA.ClientType source) {
|
---|
[6852] | 119 | if (source == null) {
|
---|
| 120 | return null;
|
---|
| 121 | } else {
|
---|
| 122 | return new DT.ClientType() {
|
---|
| 123 | Id = source.Id,
|
---|
| 124 | Name = source.Name
|
---|
| 125 | };
|
---|
| 126 | }
|
---|
[6825] | 127 | }
|
---|
| 128 |
|
---|
| 129 | public static DA.ClientType ToEntity(DT.ClientType source) {
|
---|
[6852] | 130 | if (source == null) {
|
---|
| 131 | return null;
|
---|
| 132 | } else {
|
---|
| 133 | return new DA.ClientType() {
|
---|
| 134 | Id = source.Id,
|
---|
| 135 | Name = source.Name,
|
---|
[6825] | 136 |
|
---|
[6852] | 137 | };
|
---|
| 138 | }
|
---|
[6825] | 139 | }
|
---|
| 140 | #endregion
|
---|
| 141 |
|
---|
| 142 | #region ClientConfiguration
|
---|
| 143 | public static DT.ClientConfiguration ToDto(DA.ClientConfiguration source) {
|
---|
[6852] | 144 | if (source == null) {
|
---|
| 145 | return null;
|
---|
| 146 | } else {
|
---|
| 147 | return new DT.ClientConfiguration() {
|
---|
| 148 | Id = source.Id,
|
---|
| 149 | Hash = source.Hash,
|
---|
| 150 | Description = source.Description
|
---|
| 151 | };
|
---|
| 152 | }
|
---|
[6825] | 153 | }
|
---|
| 154 |
|
---|
| 155 | public static DA.ClientConfiguration ToEntity(DT.ClientConfiguration source) {
|
---|
[6852] | 156 | if (source == null) {
|
---|
| 157 | return null;
|
---|
| 158 | } else {
|
---|
| 159 | return new DA.ClientConfiguration() {
|
---|
| 160 | Id = source.Id,
|
---|
| 161 | Hash = source.Hash,
|
---|
| 162 | Description = source.Description
|
---|
| 163 | };
|
---|
| 164 | }
|
---|
[6825] | 165 | }
|
---|
| 166 | #endregion
|
---|
| 167 |
|
---|
| 168 | #region Plugin
|
---|
| 169 | public static DT.Plugin ToDto(DA.Plugin source) {
|
---|
| 170 | return new DT.Plugin() {
|
---|
| 171 | Id = source.Id,
|
---|
| 172 | Name = source.Name,
|
---|
| 173 | StrongName = source.StrongName,
|
---|
| 174 | Version = source.Version
|
---|
| 175 | };
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | public static DA.Plugin ToEntity(DT.Plugin source) {
|
---|
| 179 | return new DA.Plugin() {
|
---|
| 180 | Id = source.Id,
|
---|
| 181 | Name = source.Name,
|
---|
| 182 | StrongName = source.StrongName,
|
---|
| 183 | Version = source.Version
|
---|
| 184 | };
|
---|
| 185 | }
|
---|
| 186 | #endregion
|
---|
| 187 |
|
---|
[6815] | 188 | #region Client
|
---|
| 189 | public static DT.Client ToDto(DA.Client source) {
|
---|
| 190 | return new DT.Client() {
|
---|
| 191 | Id = source.Id,
|
---|
| 192 | Description = source.Description,
|
---|
| 193 | Name = source.Name,
|
---|
[6825] | 194 | ClientConfiguration = ToDto(source.ClientConfiguration),
|
---|
[6815] | 195 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
[6825] | 196 | Country = ToDto(source.Country),
|
---|
| 197 | OperatingSystem = ToDto(source.OperatingSystem),
|
---|
| 198 | MemorySize = source.MemorySize.GetValueOrDefault(),
|
---|
| 199 | Timestamp = source.Timestamp.GetValueOrDefault(),
|
---|
| 200 | NumberOfCores = source.NumberOfCores.GetValueOrDefault(),
|
---|
[6820] | 201 | ProcessorType = source.ProcessorType,
|
---|
[6825] | 202 | ClientType = ToDto(source.ClientType)
|
---|
[6815] | 203 | };
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | public static DA.Client ToEntity(DT.Client source) {
|
---|
| 207 | return new DA.Client() {
|
---|
| 208 | Id = source.Id,
|
---|
| 209 | Description = source.Description,
|
---|
| 210 | Name = source.Name,
|
---|
[6825] | 211 | ClientConfiguration = ToEntity(source.ClientConfiguration),
|
---|
[6815] | 212 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
[6825] | 213 | Country = ToEntity(source.Country),
|
---|
| 214 | OperatingSystem = ToEntity(source.OperatingSystem),
|
---|
[6815] | 215 | MemorySize = source.MemorySize,
|
---|
[6825] | 216 | Timestamp = source.Timestamp,
|
---|
[6815] | 217 | NumberOfCores = source.NumberOfCores,
|
---|
[6820] | 218 | ProcessorType = source.ProcessorType,
|
---|
[6825] | 219 | ClientType = ToEntity(source.ClientType)
|
---|
[6815] | 220 | };
|
---|
| 221 | }
|
---|
| 222 | #endregion
|
---|
| 223 |
|
---|
| 224 | #region ClientLog
|
---|
| 225 | public static DT.ClientLog ToDto(DA.ClientLog source) {
|
---|
| 226 | return new DT.ClientLog() {
|
---|
| 227 | Timestamp = source.Timestamp,
|
---|
| 228 | ResourceId = source.ResourceId,
|
---|
| 229 | Message = source.Message
|
---|
| 230 | };
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | public static DA.ClientLog ToEntity(DT.ClientLog source) {
|
---|
| 234 | return new DA.ClientLog() {
|
---|
| 235 | Timestamp = source.Timestamp,
|
---|
| 236 | ResourceId = source.ResourceId,
|
---|
| 237 | Message = source.Message
|
---|
| 238 | };
|
---|
| 239 | }
|
---|
| 240 | #endregion
|
---|
[6825] | 241 |
|
---|
| 242 | #region ClientError
|
---|
| 243 | public static DT.ClientError ToDto(DA.ClientError source) {
|
---|
| 244 | return new DT.ClientError() {
|
---|
| 245 | Id = source.Id,
|
---|
| 246 | Timestamp = source.Timestamp,
|
---|
| 247 | Exception = source.Exception,
|
---|
| 248 | UserComment = source.UserComment,
|
---|
| 249 | ConfigDump = source.ConfigDump,
|
---|
| 250 | ClientId = source.ClientId.GetValueOrDefault(),
|
---|
| 251 | UserId = source.UserId.GetValueOrDefault()
|
---|
| 252 | };
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | public static DA.ClientError ToEntity(DT.ClientError source) {
|
---|
| 256 | return new DA.ClientError() {
|
---|
| 257 | Id = source.Id,
|
---|
| 258 | Timestamp = source.Timestamp,
|
---|
| 259 | Exception = source.Exception,
|
---|
| 260 | UserComment = source.UserComment,
|
---|
| 261 | ConfigDump = source.ConfigDump,
|
---|
| 262 | ClientId = source.ClientId,
|
---|
| 263 | UserId = source.UserId
|
---|
| 264 | };
|
---|
| 265 | }
|
---|
| 266 | #endregion
|
---|
| 267 |
|
---|
| 268 | #region UserGroup
|
---|
| 269 | public static DT.UserGroup ToDto(DA.UserGroup source) {
|
---|
| 270 | return new DT.UserGroup() {
|
---|
| 271 | Id = source.Id,
|
---|
| 272 | Name = source.Name
|
---|
| 273 | };
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | public static DA.UserGroup ToEntity(DT.UserGroup source) {
|
---|
| 277 | return new DA.UserGroup() {
|
---|
| 278 | Id = source.Id,
|
---|
| 279 | Name = source.Name
|
---|
| 280 | };
|
---|
| 281 | }
|
---|
| 282 | #endregion
|
---|
| 283 |
|
---|
| 284 | #region User
|
---|
[7367] | 285 |
|
---|
| 286 | public static DT.LightweightUser ToDto(DA.User source, DA.aspnet_User aspUserSource) {
|
---|
| 287 | return new DT.LightweightUser() {
|
---|
| 288 | Id = source.Id,
|
---|
| 289 | FullName = source.FullName,
|
---|
| 290 | UserName = aspUserSource.UserName
|
---|
| 291 | };
|
---|
| 292 | }
|
---|
| 293 |
|
---|
[6825] | 294 | public static DT.User ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource) {
|
---|
| 295 | return new DT.User() {
|
---|
| 296 | Id = source.Id,
|
---|
| 297 | FullName = source.FullName,
|
---|
| 298 | Comment = aspMembershipSource.Comment,
|
---|
| 299 | CreationDate = aspMembershipSource.CreateDate,
|
---|
| 300 | Email = aspMembershipSource.Email,
|
---|
| 301 | IsApproved = aspMembershipSource.IsApproved,
|
---|
| 302 | LastActivityDate = aspUserSource.LastActivityDate,
|
---|
| 303 | LastLoginDate = aspMembershipSource.LastLoginDate,
|
---|
| 304 | LastPasswordChangedDate = aspMembershipSource.LastPasswordChangedDate,
|
---|
| 305 | UserName = aspUserSource.UserName
|
---|
| 306 | };
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[6852] | 309 | public static DA.User ToEntity(DT.User source) {
|
---|
| 310 | return new DA.User() { Id = source.Id, FullName = source.FullName };
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[6825] | 313 | public static void ToEntity(DT.User source, out DA.User accessUser, out DA.aspnet_User aspUser, out DA.aspnet_Membership aspMembership, out bool userExistsInASP) {
|
---|
| 314 | userExistsInASP = false;
|
---|
| 315 | accessUser = new DA.User();
|
---|
| 316 | aspUser = new DA.aspnet_User();
|
---|
| 317 | aspMembership = new DA.aspnet_Membership();
|
---|
| 318 |
|
---|
| 319 | if (source.Id != Guid.Empty) {
|
---|
| 320 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
| 321 | var userCol = context.aspnet_Users.Where(s => s.UserId == source.Id);
|
---|
| 322 | var membershipCol = context.aspnet_Memberships.Where(s => s.UserId == source.Id);
|
---|
| 323 | if (userCol.Count() > 0 && membershipCol.Count() > 0) {
|
---|
| 324 | aspUser = userCol.First();
|
---|
| 325 | aspMembership = membershipCol.First();
|
---|
| 326 | userExistsInASP = true;
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | accessUser.Id = source.Id;
|
---|
| 332 | accessUser.FullName = source.FullName;
|
---|
| 333 |
|
---|
| 334 | aspUser.UserId = source.Id;
|
---|
| 335 | aspUser.LastActivityDate = source.LastActivityDate;
|
---|
| 336 | aspUser.UserName = source.UserName;
|
---|
| 337 |
|
---|
| 338 | aspMembership.UserId = source.Id;
|
---|
| 339 | aspMembership.Comment = source.Comment;
|
---|
| 340 | aspMembership.CreateDate = source.CreationDate;
|
---|
| 341 | aspMembership.Email = source.Email;
|
---|
| 342 | aspMembership.IsApproved = source.IsApproved;
|
---|
| 343 | aspMembership.LastLoginDate = source.LastLoginDate;
|
---|
| 344 | aspMembership.LastPasswordChangedDate = source.LastPasswordChangedDate;
|
---|
| 345 | }
|
---|
| 346 | #endregion
|
---|
[6840] | 347 |
|
---|
| 348 | #region ClientGroupMapping
|
---|
[6852] | 349 | public static DT.ClientGroupMapping ToDto(DA.ResourceResourceGroup source) {
|
---|
[6840] | 350 | return new DT.ClientGroupMapping() {
|
---|
[6852] | 351 | Child = source.ResourceId, Parent = source.ResourceGroupId
|
---|
[6840] | 352 | };
|
---|
| 353 | }
|
---|
| 354 | #endregion
|
---|
| 355 |
|
---|
[6852] | 356 | #region UserGroupBase
|
---|
| 357 | public static DT.UserGroupBase ToDto(DA.UserGroupBase source) {
|
---|
| 358 | return new DT.UserGroupBase() {
|
---|
| 359 | Id = source.Id
|
---|
| 360 | };
|
---|
| 361 | }
|
---|
| 362 | #endregion
|
---|
[6840] | 363 |
|
---|
[6852] | 364 | #region UserGroupMapping
|
---|
| 365 | public static DT.UserGroupMapping ToDto(DA.UserGroupUserGroup source) {
|
---|
| 366 | return new DT.UserGroupMapping() {
|
---|
| 367 | Child = source.UserGroupId, Parent = source.UserGroupUserGroupId
|
---|
| 368 | };
|
---|
| 369 | }
|
---|
| 370 | #endregion
|
---|
[6858] | 371 |
|
---|
| 372 | #region Role
|
---|
| 373 | public static DT.Role ToDto(DA.aspnet_Role r) {
|
---|
| 374 | return new DT.Role() {
|
---|
| 375 | Name = r.RoleName
|
---|
| 376 | };
|
---|
| 377 | }
|
---|
| 378 | public static DA.aspnet_Role ToEntity(DT.Role r) {
|
---|
| 379 | return new DA.aspnet_Role() {
|
---|
| 380 | RoleName = r.Name
|
---|
| 381 | };
|
---|
| 382 | }
|
---|
| 383 | #endregion
|
---|
[6815] | 384 | }
|
---|
| 385 | }
|
---|