- Timestamp:
- 09/08/11 10:38:36 (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.3/Convert.cs
r6703 r6717 24 24 using System.Data.Linq; 25 25 using System.Linq; 26 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; 27 28 namespace HeuristicLab.Services.Hive.DataAccess { 26 using DB = HeuristicLab.Services.Hive.DataAccess; 27 using DT = HeuristicLab.Services.Hive.DataTransfer; 28 29 30 namespace HeuristicLab.Services.Hive.DataTransfer { 29 31 public static class Convert { 30 32 #region Job 31 public static DT.Job ToDto( Job source) {33 public static DT.Job ToDto(DB.Job source) { 32 34 if (source == null) return null; 33 35 return new DT.Job { … … 40 42 PluginsNeededIds = (source.RequiredPlugins == null ? new List<Guid>() : source.RequiredPlugins.Select(x => x.PluginId).ToList()), 41 43 LastHeartbeat = source.LastHeartbeat, 42 State = source.State,44 State = Convert.ToDto(source.State), 43 45 StateLog = (source.StateLogs == null ? new List<DT.StateLog>() : source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList()), 44 46 IsParentJob = source.IsParentJob, 45 47 FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished, 46 Command = source.Command,48 Command = Convert.ToDto(source.Command), 47 49 LastJobDataUpdate = (source.JobData == null ? DateTime.MinValue : source.JobData.LastUpdate), 48 50 HiveExperimentId = source.HiveExperimentId, … … 50 52 }; 51 53 } 52 public static Job ToEntity(DT.Job source) { 53 if (source == null) return null; 54 var entity = new Job(); ToEntity(source, entity); 55 return entity; 56 } 57 public static void ToEntity(DT.Job source, Job target) { 54 55 public static DB.Job ToEntity(DT.Job source) { 56 if (source == null) return null; 57 var entity = new DB.Job(); ToEntity(source, entity); 58 return entity; 59 } 60 public static void ToEntity(DT.Job source, DB.Job target) { 58 61 if ((source != null) && (target != null)) { 59 62 target.JobId = source.Id; … … 64 67 target.Priority = source.Priority; 65 68 target.LastHeartbeat = source.LastHeartbeat; 66 target.State = source.State;67 if (target.StateLogs == null) target.StateLogs = new EntitySet< StateLog>();69 target.State = Convert.ToEntity(source.State); 70 if (target.StateLogs == null) target.StateLogs = new EntitySet<DB.StateLog>(); 68 71 foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) { 69 72 target.StateLogs.Add(Convert.ToEntity(sl)); … … 71 74 target.IsParentJob = source.IsParentJob; 72 75 target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished; 73 target.Command = source.Command;76 target.Command = Convert.ToEntity(source.Command); 74 77 // RequiredPlugins are added by Dao 75 78 target.HiveExperimentId = source.HiveExperimentId; … … 80 83 81 84 #region JobData 82 public static DT.JobData ToDto( JobData source) {85 public static DT.JobData ToDto(DB.JobData source) { 83 86 if (source == null) return null; 84 87 return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate }; 85 88 } 86 public static JobData ToEntity(DT.JobData source) {87 if (source == null) return null; 88 var entity = new JobData(); ToEntity(source, entity);89 return entity; 90 } 91 public static void ToEntity(DT.JobData source, JobData target) {89 public static DB.JobData ToEntity(DT.JobData source) { 90 if (source == null) return null; 91 var entity = new DB.JobData(); ToEntity(source, entity); 92 return entity; 93 } 94 public static void ToEntity(DT.JobData source, DB.JobData target) { 92 95 if ((source != null) && (target != null)) { 93 96 target.JobId = source.JobId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate; … … 97 100 98 101 #region StateLog 99 public static DT.StateLog ToDto( StateLog source) {100 if (source == null) return null; 101 return new DT.StateLog { Id = source.StateLogId, DateTime = source.DateTime, Exception = source.Exception, JobId = source.JobId, SlaveId = source.SlaveId, State = source.State, UserId = source.UserId };102 } 103 public static StateLog ToEntity(DT.StateLog source) {104 if (source == null) return null; 105 var entity = new StateLog(); ToEntity(source, entity);106 return entity; 107 } 108 public static void ToEntity(DT.StateLog source, StateLog target) {109 if ((source != null) && (target != null)) { 110 target.StateLogId = source.Id; target.DateTime = source.DateTime; target.Exception = source.Exception; target.JobId = source.JobId; target.SlaveId = source.SlaveId; target.State = source.State; target.UserId = source.UserId;102 public static DT.StateLog ToDto(DB.StateLog source) { 103 if (source == null) return null; 104 return new DT.StateLog { Id = source.StateLogId, DateTime = source.DateTime, Exception = source.Exception, JobId = source.JobId, SlaveId = source.SlaveId, State = Convert.ToDto(source.State), UserId = source.UserId }; 105 } 106 public static DB.StateLog ToEntity(DT.StateLog source) { 107 if (source == null) return null; 108 var entity = new DB.StateLog(); ToEntity(source, entity); 109 return entity; 110 } 111 public static void ToEntity(DT.StateLog source, DB.StateLog target) { 112 if ((source != null) && (target != null)) { 113 target.StateLogId = source.Id; target.DateTime = source.DateTime; target.Exception = source.Exception; target.JobId = source.JobId; target.SlaveId = source.SlaveId; target.State = Convert.ToEntity(source.State); target.UserId = source.UserId; 111 114 } 112 115 } … … 114 117 115 118 #region Downtimes 116 public static DT.Downtime ToDto(D owntime source) {119 public static DT.Downtime ToDto(DB.Downtime source) { 117 120 if (source == null) return null; 118 121 return new DT.Downtime { Id = source.DowntimeId, AllDayEvent = source.AllDayEvent, EndDate = source.EndDate, Recurring = source.Recurring, RecurringId = source.RecurringId, ResourceId = source.ResourceId, StartDate = source.StartDate }; 119 122 } 120 public static D owntime ToEntity(DT.Downtime source) {121 if (source == null) return null; 122 var entity = new D owntime(); ToEntity(source, entity);123 return entity; 124 } 125 public static void ToEntity(DT.Downtime source, D owntime target) {123 public static DB.Downtime ToEntity(DT.Downtime source) { 124 if (source == null) return null; 125 var entity = new DB.Downtime(); ToEntity(source, entity); 126 return entity; 127 } 128 public static void ToEntity(DT.Downtime source, DB.Downtime target) { 126 129 if ((source != null) && (target != null)) { 127 130 target.DowntimeId = source.Id; target.AllDayEvent = source.AllDayEvent; target.EndDate = source.EndDate; target.Recurring = source.Recurring; target.RecurringId = source.RecurringId; target.ResourceId = source.ResourceId; target.StartDate = source.StartDate; … … 131 134 132 135 #region HiveExperiment 133 public static DT.HiveExperiment ToDto( HiveExperiment source) {136 public static DT.HiveExperiment ToDto(DB.HiveExperiment source) { 134 137 if (source == null) return null; 135 138 return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, OwnerUserId = source.OwnerUserId, DateCreated = source.DateCreated, ResourceNames = source.ResourceIds, LastAccessed = source.LastAccessed }; 136 139 } 137 public static HiveExperiment ToEntity(DT.HiveExperiment source) {138 if (source == null) return null; 139 var entity = new HiveExperiment(); ToEntity(source, entity);140 return entity; 141 } 142 public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {140 public static DB.HiveExperiment ToEntity(DT.HiveExperiment source) { 141 if (source == null) return null; 142 var entity = new DB.HiveExperiment(); ToEntity(source, entity); 143 return entity; 144 } 145 public static void ToEntity(DT.HiveExperiment source, DB.HiveExperiment target) { 143 146 if ((source != null) && (target != null)) { 144 147 target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.OwnerUserId = source.OwnerUserId; target.DateCreated = source.DateCreated; target.ResourceIds = source.ResourceNames; target.LastAccessed = source.LastAccessed; … … 148 151 149 152 #region HiveExperimentPermission 150 public static DT.HiveExperimentPermission ToDto( HiveExperimentPermission source) {151 if (source == null) return null; 152 return new DT.HiveExperimentPermission { HiveExperimentId = source.HiveExperimentId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = source.Permission};153 } 154 public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) {155 if (source == null) return null; 156 var entity = new HiveExperimentPermission(); ToEntity(source, entity);157 return entity; 158 } 159 public static void ToEntity(DT.HiveExperimentPermission source, HiveExperimentPermission target) {160 if ((source != null) && (target != null)) { 161 target.HiveExperimentId = source.HiveExperimentId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = source.Permission;153 public static DT.HiveExperimentPermission ToDto(DB.HiveExperimentPermission source) { 154 if (source == null) return null; 155 return new DT.HiveExperimentPermission { HiveExperimentId = source.HiveExperimentId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = Convert.ToDto(source.Permission) }; 156 } 157 public static DB.HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) { 158 if (source == null) return null; 159 var entity = new DB.HiveExperimentPermission(); ToEntity(source, entity); 160 return entity; 161 } 162 public static void ToEntity(DT.HiveExperimentPermission source, DB.HiveExperimentPermission target) { 163 if ((source != null) && (target != null)) { 164 target.HiveExperimentId = source.HiveExperimentId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = Convert.ToEntity(source.Permission); 162 165 } 163 166 } … … 165 168 166 169 #region Plugin 167 public static DT.Plugin ToDto( Plugin source) {170 public static DT.Plugin ToDto(DB.Plugin source) { 168 171 if (source == null) return null; 169 172 return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version), UserId = source.UserId, DateCreated = source.DateCreated, Hash = source.Hash }; 170 173 } 171 public static Plugin ToEntity(DT.Plugin source) {172 if (source == null) return null; 173 var entity = new Plugin(); ToEntity(source, entity);174 return entity; 175 } 176 public static void ToEntity(DT.Plugin source, Plugin target) {174 public static DB.Plugin ToEntity(DT.Plugin source) { 175 if (source == null) return null; 176 var entity = new DB.Plugin(); ToEntity(source, entity); 177 return entity; 178 } 179 public static void ToEntity(DT.Plugin source, DB.Plugin target) { 177 180 if ((source != null) && (target != null)) { 178 181 target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString(); target.UserId = source.UserId; target.DateCreated = source.DateCreated; target.Hash = source.Hash; … … 182 185 183 186 #region PluginData 184 public static DT.PluginData ToDto( PluginData source) {187 public static DT.PluginData ToDto(DB.PluginData source) { 185 188 if (source == null) return null; 186 189 return new DT.PluginData { Id = source.PluginDataId, PluginId = source.PluginId, Data = source.Data.ToArray(), FileName = source.FileName }; 187 190 } 188 public static PluginData ToEntity(DT.PluginData source) {189 if (source == null) return null; 190 var entity = new PluginData(); ToEntity(source, entity);191 return entity; 192 } 193 public static void ToEntity(DT.PluginData source, PluginData target) {191 public static DB.PluginData ToEntity(DT.PluginData source) { 192 if (source == null) return null; 193 var entity = new DB.PluginData(); ToEntity(source, entity); 194 return entity; 195 } 196 public static void ToEntity(DT.PluginData source, DB.PluginData target) { 194 197 if ((source != null) && (target != null)) { 195 198 target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = new Binary(source.Data); target.FileName = source.FileName; … … 199 202 200 203 #region Slave 201 public static DT.Slave ToDto( Slave source) {204 public static DT.Slave ToDto(DB.Slave source) { 202 205 if (source == null) return null; 203 206 return new DT.Slave { … … 211 214 Memory = source.Memory, 212 215 Name = source.Name, 213 SlaveState = source.SlaveState,214 CpuArchitecture = source.CpuArchitecture,216 SlaveState = Convert.ToDto(source.SlaveState), 217 CpuArchitecture = Convert.ToDto(source.CpuArchitecture), 215 218 OperatingSystem = source.OperatingSystem, 216 219 LastHeartbeat = source.LastHeartbeat, … … 218 221 }; 219 222 } 220 public static Slave ToEntity(DT.Slave source) {221 if (source == null) return null; 222 var entity = new Slave(); ToEntity(source, entity);223 return entity; 224 } 225 public static void ToEntity(DT.Slave source, Slave target) {223 public static DB.Slave ToEntity(DT.Slave source) { 224 if (source == null) return null; 225 var entity = new DB.Slave(); ToEntity(source, entity); 226 return entity; 227 } 228 public static void ToEntity(DT.Slave source, DB.Slave target) { 226 229 if ((source != null) && (target != null)) { 227 230 target.ResourceId = source.Id; … … 234 237 target.Memory = source.Memory; 235 238 target.Name = source.Name; 236 target.SlaveState = source.SlaveState;237 target.CpuArchitecture = source.CpuArchitecture;239 target.SlaveState = Convert.ToEntity(source.SlaveState); 240 target.CpuArchitecture = Convert.ToEntity(source.CpuArchitecture); 238 241 target.OperatingSystem = source.OperatingSystem; 239 242 target.LastHeartbeat = source.LastHeartbeat; … … 244 247 245 248 #region SlaveGroup 246 public static DT.SlaveGroup ToDto( SlaveGroup source) {249 public static DT.SlaveGroup ToDto(DB.SlaveGroup source) { 247 250 if (source == null) return null; 248 251 return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId }; 249 252 } 250 public static SlaveGroup ToEntity(DT.SlaveGroup source) {251 if (source == null) return null; 252 var entity = new SlaveGroup(); ToEntity(source, entity);253 return entity; 254 } 255 public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {253 public static DB.SlaveGroup ToEntity(DT.SlaveGroup source) { 254 if (source == null) return null; 255 var entity = new DB.SlaveGroup(); ToEntity(source, entity); 256 return entity; 257 } 258 public static void ToEntity(DT.SlaveGroup source, DB.SlaveGroup target) { 256 259 if ((source != null) && (target != null)) { 257 260 target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId; … … 261 264 262 265 #region Resource 263 public static DT.Resource ToDto( Resource source) {266 public static DT.Resource ToDto(DB.Resource source) { 264 267 if (source == null) return null; 265 268 return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId }; 266 269 } 267 public static Resource ToEntity(DT.Resource source) {268 if (source == null) return null; 269 var entity = new Resource(); ToEntity(source, entity);270 return entity; 271 } 272 public static void ToEntity(DT.Resource source, Resource target) {270 public static DB.Resource ToEntity(DT.Resource source) { 271 if (source == null) return null; 272 var entity = new DB.Resource(); ToEntity(source, entity); 273 return entity; 274 } 275 public static void ToEntity(DT.Resource source, DB.Resource target) { 273 276 if ((source != null) && (target != null)) { 274 277 target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId; … … 278 281 279 282 #region Statistics 280 public static DT.Statistics ToDto( Statistics source) {283 public static DT.Statistics ToDto(DB.Statistics source) { 281 284 if (source == null) return null; 282 285 return new DT.Statistics { … … 287 290 }; 288 291 } 289 public static Statistics ToEntity(DT.Statistics source) {290 if (source == null) return null; 291 var entity = new Statistics(); ToEntity(source, entity);292 return entity; 293 } 294 public static void ToEntity(DT.Statistics source, Statistics target) {292 public static DB.Statistics ToEntity(DT.Statistics source) { 293 if (source == null) return null; 294 var entity = new DB.Statistics(); ToEntity(source, entity); 295 return entity; 296 } 297 public static void ToEntity(DT.Statistics source, DB.Statistics target) { 295 298 if ((source != null) && (target != null)) { 296 299 target.StatisticsId = source.Id; … … 302 305 303 306 #region SlaveStatistics 304 public static DT.SlaveStatistics ToDto( SlaveStatistics source) {307 public static DT.SlaveStatistics ToDto(DB.SlaveStatistics source) { 305 308 if (source == null) return null; 306 309 return new DT.SlaveStatistics { … … 314 317 }; 315 318 } 316 public static SlaveStatistics ToEntity(DT.SlaveStatistics source) {317 if (source == null) return null; 318 var entity = new SlaveStatistics(); ToEntity(source, entity);319 return entity; 320 } 321 public static void ToEntity(DT.SlaveStatistics source, SlaveStatistics target) {319 public static DB.SlaveStatistics ToEntity(DT.SlaveStatistics source) { 320 if (source == null) return null; 321 var entity = new DB.SlaveStatistics(); ToEntity(source, entity); 322 return entity; 323 } 324 public static void ToEntity(DT.SlaveStatistics source, DB.SlaveStatistics target) { 322 325 if ((source != null) && (target != null)) { 323 326 target.StatisticsId = source.Id; … … 333 336 334 337 #region UserStatistics 335 public static DT.UserStatistics ToDto( UserStatistics source) {338 public static DT.UserStatistics ToDto(DB.UserStatistics source) { 336 339 if (source == null) return null; 337 340 return new DT.UserStatistics { … … 344 347 }; 345 348 } 346 public static UserStatistics ToEntity(DT.UserStatistics source) {347 if (source == null) return null; 348 var entity = new UserStatistics(); ToEntity(source, entity);349 return entity; 350 } 351 public static void ToEntity(DT.UserStatistics source, UserStatistics target) {349 public static DB.UserStatistics ToEntity(DT.UserStatistics source) { 350 if (source == null) return null; 351 var entity = new DB.UserStatistics(); ToEntity(source, entity); 352 return entity; 353 } 354 public static void ToEntity(DT.UserStatistics source, DB.UserStatistics target) { 352 355 if ((source != null) && (target != null)) { 353 356 target.StatisticsId = source.Id; … … 360 363 } 361 364 #endregion 365 366 367 #region JobState 368 public static DT.JobState ToDto(DB.JobState source) { 369 if (source == DB.JobState.Aborted) { 370 return JobState.Aborted; 371 } else if (source == DB.JobState.Calculating) { 372 return JobState.Calculating; 373 } else if (source == DB.JobState.Failed) { 374 return JobState.Failed; 375 } else if (source == DB.JobState.Finished) { 376 return JobState.Finished; 377 } else if (source == DB.JobState.Offline) { 378 return JobState.Offline; 379 } else if (source == DB.JobState.Paused) { 380 return JobState.Paused; 381 } else if (source == DB.JobState.Transferring) { 382 return JobState.Transferring; 383 } else if (source == DB.JobState.Waiting) { 384 return JobState.Waiting; 385 } else 386 return JobState.Failed; 387 } 388 389 public static DB.JobState ToEntity(DT.JobState source) { 390 if (source == DT.JobState.Aborted) { 391 return DB.JobState.Aborted; 392 } else if (source == DT.JobState.Calculating) { 393 return DB.JobState.Calculating; 394 } else if (source == DT.JobState.Failed) { 395 return DB.JobState.Failed; 396 } else if (source == DT.JobState.Finished) { 397 return DB.JobState.Finished; 398 } else if (source == DT.JobState.Offline) { 399 return DB.JobState.Offline; 400 } else if (source == DT.JobState.Paused) { 401 return DB.JobState.Paused; 402 } else if (source == DT.JobState.Transferring) { 403 return DB.JobState.Transferring; 404 } else if (source == DT.JobState.Waiting) { 405 return DB.JobState.Waiting; 406 } else 407 return DB.JobState.Failed; 408 } 409 #endregion 410 411 #region Permission 412 public static DT.Permission ToDto(DB.Permission source) { 413 if (source == DB.Permission.Full) { 414 return Permission.Full; 415 } else if (source == DB.Permission.NotAllowed) { 416 return Permission.NotAllowed; 417 } else if (source == DB.Permission.Read) { 418 return Permission.Read; 419 } else 420 return Permission.NotAllowed; 421 } 422 423 public static DB.Permission ToEntity(DT.Permission source) { 424 if (source == DT.Permission.Full) { 425 return DB.Permission.Full; 426 } else if (source == DT.Permission.NotAllowed) { 427 return DB.Permission.NotAllowed; 428 } else if (source == DT.Permission.Read) { 429 return DB.Permission.Read; 430 } else 431 return DB.Permission.NotAllowed; 432 } 433 #endregion 434 435 436 #region Command 437 public static DT.Command? ToDto(DB.Command? source) { 438 if (source.HasValue) { 439 if (source.Value == DB.Command.Abort) { 440 return Command.Abort; 441 } else if (source.Value == DB.Command.Pause) { 442 return Command.Pause; 443 } else if (source.Value == DB.Command.Stop) { 444 return Command.Stop; 445 } else 446 return Command.Pause; 447 } 448 return null; 449 } 450 451 public static DB.Command? ToEntity(DT.Command? source) { 452 if (source.HasValue) { 453 if (source == DT.Command.Abort) { 454 return DB.Command.Abort; 455 } else if (source == DT.Command.Pause) { 456 return DB.Command.Pause; 457 } else if (source == DT.Command.Stop) { 458 return DB.Command.Stop; 459 } else 460 return DB.Command.Pause; 461 } else 462 return null; 463 } 464 465 #endregion 466 467 #region CpuArchiteture 468 public static DT.CpuArchitecture ToDto(DB.CpuArchitecture source) { 469 if (source == DB.CpuArchitecture.x64) { 470 return CpuArchitecture.x64; 471 } else if (source == DB.CpuArchitecture.x86) { 472 return CpuArchitecture.x86; 473 } else 474 return CpuArchitecture.x86; 475 } 476 477 public static DB.CpuArchitecture ToEntity(DT.CpuArchitecture source) { 478 if (source == DT.CpuArchitecture.x64) { 479 return DB.CpuArchitecture.x64; 480 } else if (source == DT.CpuArchitecture.x86) { 481 return DB.CpuArchitecture.x86; 482 } else 483 return DB.CpuArchitecture.x86; 484 } 485 #endregion 486 487 #region SlaveState 488 public static DT.SlaveState ToDto(DB.SlaveState source) { 489 if (source == DB.SlaveState.Calculating) { 490 return SlaveState.Calculating; 491 } else if (source == DB.SlaveState.Idle) { 492 return SlaveState.Idle; 493 } else if (source == DB.SlaveState.Offline) { 494 return SlaveState.Offline; 495 } else 496 return SlaveState.Offline; 497 } 498 499 public static DB.SlaveState ToEntity(DT.SlaveState source) { 500 if (source == DT.SlaveState.Calculating) { 501 return DB.SlaveState.Calculating; 502 } else if (source == DT.SlaveState.Idle) { 503 return DB.SlaveState.Idle; 504 } else if (source == DT.SlaveState.Offline) { 505 return DB.SlaveState.Offline; 506 } else 507 return DB.SlaveState.Offline; 508 } 509 #endregion 362 510 } 363 511 }
Note: See TracChangeset
for help on using the changeset viewer.