[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,
|
---|
[7534] | 202 | PerformanceValue = source.PerformanceValue.GetValueOrDefault(),
|
---|
[6825] | 203 | ClientType = ToDto(source.ClientType)
|
---|
[6815] | 204 | };
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | public static DA.Client ToEntity(DT.Client source) {
|
---|
| 208 | return new DA.Client() {
|
---|
| 209 | Id = source.Id,
|
---|
| 210 | Description = source.Description,
|
---|
| 211 | Name = source.Name,
|
---|
[6825] | 212 | ClientConfiguration = ToEntity(source.ClientConfiguration),
|
---|
[6815] | 213 | HeuristicLabVersion = source.HeuristicLabVersion,
|
---|
[6825] | 214 | Country = ToEntity(source.Country),
|
---|
| 215 | OperatingSystem = ToEntity(source.OperatingSystem),
|
---|
[6815] | 216 | MemorySize = source.MemorySize,
|
---|
[6825] | 217 | Timestamp = source.Timestamp,
|
---|
[6815] | 218 | NumberOfCores = source.NumberOfCores,
|
---|
[6820] | 219 | ProcessorType = source.ProcessorType,
|
---|
[7534] | 220 | PerformanceValue = source.PerformanceValue,
|
---|
[6825] | 221 | ClientType = ToEntity(source.ClientType)
|
---|
[6815] | 222 | };
|
---|
| 223 | }
|
---|
| 224 | #endregion
|
---|
| 225 |
|
---|
| 226 | #region ClientLog
|
---|
| 227 | public static DT.ClientLog ToDto(DA.ClientLog source) {
|
---|
| 228 | return new DT.ClientLog() {
|
---|
| 229 | Timestamp = source.Timestamp,
|
---|
| 230 | ResourceId = source.ResourceId,
|
---|
| 231 | Message = source.Message
|
---|
| 232 | };
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | public static DA.ClientLog ToEntity(DT.ClientLog source) {
|
---|
| 236 | return new DA.ClientLog() {
|
---|
| 237 | Timestamp = source.Timestamp,
|
---|
| 238 | ResourceId = source.ResourceId,
|
---|
| 239 | Message = source.Message
|
---|
| 240 | };
|
---|
| 241 | }
|
---|
| 242 | #endregion
|
---|
[6825] | 243 |
|
---|
| 244 | #region ClientError
|
---|
| 245 | public static DT.ClientError ToDto(DA.ClientError source) {
|
---|
| 246 | return new DT.ClientError() {
|
---|
| 247 | Id = source.Id,
|
---|
| 248 | Timestamp = source.Timestamp,
|
---|
| 249 | Exception = source.Exception,
|
---|
| 250 | UserComment = source.UserComment,
|
---|
| 251 | ConfigDump = source.ConfigDump,
|
---|
| 252 | ClientId = source.ClientId.GetValueOrDefault(),
|
---|
| 253 | UserId = source.UserId.GetValueOrDefault()
|
---|
| 254 | };
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | public static DA.ClientError ToEntity(DT.ClientError source) {
|
---|
| 258 | return new DA.ClientError() {
|
---|
| 259 | Id = source.Id,
|
---|
| 260 | Timestamp = source.Timestamp,
|
---|
| 261 | Exception = source.Exception,
|
---|
| 262 | UserComment = source.UserComment,
|
---|
| 263 | ConfigDump = source.ConfigDump,
|
---|
| 264 | ClientId = source.ClientId,
|
---|
| 265 | UserId = source.UserId
|
---|
| 266 | };
|
---|
| 267 | }
|
---|
| 268 | #endregion
|
---|
| 269 |
|
---|
| 270 | #region UserGroup
|
---|
| 271 | public static DT.UserGroup ToDto(DA.UserGroup source) {
|
---|
| 272 | return new DT.UserGroup() {
|
---|
| 273 | Id = source.Id,
|
---|
| 274 | Name = source.Name
|
---|
| 275 | };
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | public static DA.UserGroup ToEntity(DT.UserGroup source) {
|
---|
| 279 | return new DA.UserGroup() {
|
---|
| 280 | Id = source.Id,
|
---|
| 281 | Name = source.Name
|
---|
| 282 | };
|
---|
| 283 | }
|
---|
| 284 | #endregion
|
---|
| 285 |
|
---|
| 286 | #region User
|
---|
[7367] | 287 |
|
---|
| 288 | public static DT.LightweightUser ToDto(DA.User source, DA.aspnet_User aspUserSource) {
|
---|
| 289 | return new DT.LightweightUser() {
|
---|
| 290 | Id = source.Id,
|
---|
| 291 | FullName = source.FullName,
|
---|
| 292 | UserName = aspUserSource.UserName
|
---|
| 293 | };
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[6825] | 296 | public static DT.User ToDto(DA.User source, DA.aspnet_User aspUserSource, DA.aspnet_Membership aspMembershipSource) {
|
---|
| 297 | return new DT.User() {
|
---|
| 298 | Id = source.Id,
|
---|
| 299 | FullName = source.FullName,
|
---|
| 300 | Comment = aspMembershipSource.Comment,
|
---|
| 301 | CreationDate = aspMembershipSource.CreateDate,
|
---|
| 302 | Email = aspMembershipSource.Email,
|
---|
| 303 | IsApproved = aspMembershipSource.IsApproved,
|
---|
| 304 | LastActivityDate = aspUserSource.LastActivityDate,
|
---|
| 305 | LastLoginDate = aspMembershipSource.LastLoginDate,
|
---|
| 306 | LastPasswordChangedDate = aspMembershipSource.LastPasswordChangedDate,
|
---|
| 307 | UserName = aspUserSource.UserName
|
---|
| 308 | };
|
---|
| 309 | }
|
---|
| 310 |
|
---|
[6852] | 311 | public static DA.User ToEntity(DT.User source) {
|
---|
| 312 | return new DA.User() { Id = source.Id, FullName = source.FullName };
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[6825] | 315 | public static void ToEntity(DT.User source, out DA.User accessUser, out DA.aspnet_User aspUser, out DA.aspnet_Membership aspMembership, out bool userExistsInASP) {
|
---|
| 316 | userExistsInASP = false;
|
---|
| 317 | accessUser = new DA.User();
|
---|
| 318 | aspUser = new DA.aspnet_User();
|
---|
| 319 | aspMembership = new DA.aspnet_Membership();
|
---|
| 320 |
|
---|
| 321 | if (source.Id != Guid.Empty) {
|
---|
| 322 | using (DA.ASPNETAuthenticationDataContext context = new DA.ASPNETAuthenticationDataContext()) {
|
---|
| 323 | var userCol = context.aspnet_Users.Where(s => s.UserId == source.Id);
|
---|
| 324 | var membershipCol = context.aspnet_Memberships.Where(s => s.UserId == source.Id);
|
---|
| 325 | if (userCol.Count() > 0 && membershipCol.Count() > 0) {
|
---|
| 326 | aspUser = userCol.First();
|
---|
| 327 | aspMembership = membershipCol.First();
|
---|
| 328 | userExistsInASP = true;
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | accessUser.Id = source.Id;
|
---|
| 334 | accessUser.FullName = source.FullName;
|
---|
| 335 |
|
---|
| 336 | aspUser.UserId = source.Id;
|
---|
| 337 | aspUser.LastActivityDate = source.LastActivityDate;
|
---|
| 338 | aspUser.UserName = source.UserName;
|
---|
| 339 |
|
---|
| 340 | aspMembership.UserId = source.Id;
|
---|
| 341 | aspMembership.Comment = source.Comment;
|
---|
| 342 | aspMembership.CreateDate = source.CreationDate;
|
---|
| 343 | aspMembership.Email = source.Email;
|
---|
| 344 | aspMembership.IsApproved = source.IsApproved;
|
---|
| 345 | aspMembership.LastLoginDate = source.LastLoginDate;
|
---|
| 346 | aspMembership.LastPasswordChangedDate = source.LastPasswordChangedDate;
|
---|
| 347 | }
|
---|
| 348 | #endregion
|
---|
[6840] | 349 |
|
---|
| 350 | #region ClientGroupMapping
|
---|
[6852] | 351 | public static DT.ClientGroupMapping ToDto(DA.ResourceResourceGroup source) {
|
---|
[6840] | 352 | return new DT.ClientGroupMapping() {
|
---|
[6852] | 353 | Child = source.ResourceId, Parent = source.ResourceGroupId
|
---|
[6840] | 354 | };
|
---|
| 355 | }
|
---|
| 356 | #endregion
|
---|
| 357 |
|
---|
[6852] | 358 | #region UserGroupBase
|
---|
| 359 | public static DT.UserGroupBase ToDto(DA.UserGroupBase source) {
|
---|
| 360 | return new DT.UserGroupBase() {
|
---|
| 361 | Id = source.Id
|
---|
| 362 | };
|
---|
| 363 | }
|
---|
| 364 | #endregion
|
---|
[6840] | 365 |
|
---|
[6852] | 366 | #region UserGroupMapping
|
---|
| 367 | public static DT.UserGroupMapping ToDto(DA.UserGroupUserGroup source) {
|
---|
| 368 | return new DT.UserGroupMapping() {
|
---|
| 369 | Child = source.UserGroupId, Parent = source.UserGroupUserGroupId
|
---|
| 370 | };
|
---|
| 371 | }
|
---|
| 372 | #endregion
|
---|
[6858] | 373 |
|
---|
| 374 | #region Role
|
---|
| 375 | public static DT.Role ToDto(DA.aspnet_Role r) {
|
---|
| 376 | return new DT.Role() {
|
---|
| 377 | Name = r.RoleName
|
---|
| 378 | };
|
---|
| 379 | }
|
---|
| 380 | public static DA.aspnet_Role ToEntity(DT.Role r) {
|
---|
| 381 | return new DA.aspnet_Role() {
|
---|
| 382 | RoleName = r.Name
|
---|
| 383 | };
|
---|
| 384 | }
|
---|
| 385 | #endregion
|
---|
[6815] | 386 | }
|
---|
| 387 | }
|
---|