[4598] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
[5266] | 22 | using System;
|
---|
[4598] | 23 | using System.Data.Linq;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Services.Hive.DataAccess {
|
---|
| 28 | public static class Convert {
|
---|
| 29 | #region Job
|
---|
| 30 | public static DT.Job ToDto(Job source) {
|
---|
| 31 | if (source == null) return null;
|
---|
[4649] | 32 | return new DT.Job {
|
---|
| 33 | Id = source.JobId,
|
---|
| 34 | CoresNeeded = source.CoresNeeded,
|
---|
[5511] | 35 | ExecutionTime = string.IsNullOrEmpty(source.ExecutionTime) ? TimeSpan.Zero : TimeSpan.Parse(source.ExecutionTime),
|
---|
[4649] | 36 | MemoryNeeded = source.MemoryNeeded,
|
---|
| 37 | ParentJobId = source.ParentJobId,
|
---|
| 38 | Priority = source.Priority,
|
---|
[5405] | 39 | PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList(),
|
---|
[5511] | 40 | LastHeartbeat = source.LastHeartbeat,
|
---|
| 41 | State = source.State,
|
---|
[5526] | 42 | StateLog = source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(),
|
---|
| 43 | IsParentJob = source.IsParentJob,
|
---|
| 44 | FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished
|
---|
[4649] | 45 | };
|
---|
[4598] | 46 | }
|
---|
| 47 | public static Job ToEntity(DT.Job source) {
|
---|
| 48 | if (source == null) return null;
|
---|
[4649] | 49 | var entity = new Job(); ToEntity(source, entity);
|
---|
| 50 | return entity;
|
---|
[4598] | 51 | }
|
---|
| 52 | public static void ToEntity(DT.Job source, Job target) {
|
---|
| 53 | if ((source != null) && (target != null)) {
|
---|
[4649] | 54 | target.JobId = source.Id;
|
---|
| 55 | target.CoresNeeded = source.CoresNeeded;
|
---|
[5511] | 56 | target.ExecutionTime = source.ExecutionTime.ToString();
|
---|
[4649] | 57 | target.MemoryNeeded = source.MemoryNeeded;
|
---|
| 58 | target.ParentJobId = source.ParentJobId;
|
---|
| 59 | target.Priority = source.Priority;
|
---|
[5405] | 60 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
[5511] | 61 | target.State = source.State;
|
---|
| 62 | if (target.StateLogs == null) target.StateLogs = new EntitySet<StateLog>();
|
---|
[5526] | 63 | foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) {
|
---|
| 64 | target.StateLogs.Add(Convert.ToEntity(sl));
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | //target.StateLogs.AddRange(source.StateLog.Select(x => Convert.ToEntity(x)).OrderBy(x => x.DateTime));
|
---|
| 68 | target.IsParentJob = source.IsParentJob;
|
---|
| 69 | target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
|
---|
[5405] | 70 | // RequiredPlugins are added by Dao
|
---|
[4598] | 71 | }
|
---|
| 72 | }
|
---|
| 73 | #endregion
|
---|
| 74 |
|
---|
| 75 | #region JobData
|
---|
| 76 | public static DT.JobData ToDto(JobData source) {
|
---|
| 77 | if (source == null) return null;
|
---|
[5106] | 78 | return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate };
|
---|
[4598] | 79 | }
|
---|
| 80 | public static JobData ToEntity(DT.JobData source) {
|
---|
| 81 | if (source == null) return null;
|
---|
[4649] | 82 | var entity = new JobData(); ToEntity(source, entity);
|
---|
| 83 | return entity;
|
---|
[4598] | 84 | }
|
---|
| 85 | public static void ToEntity(DT.JobData source, JobData target) {
|
---|
| 86 | if ((source != null) && (target != null)) {
|
---|
[5106] | 87 | target.JobId = source.JobId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate;
|
---|
[4598] | 88 | }
|
---|
| 89 | }
|
---|
| 90 | #endregion
|
---|
[4649] | 91 |
|
---|
[5511] | 92 | #region StateLog
|
---|
| 93 | public static DT.StateLog ToDto(StateLog source) {
|
---|
| 94 | if (source == null) return null;
|
---|
| 95 | 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 };
|
---|
| 96 | }
|
---|
| 97 | public static StateLog ToEntity(DT.StateLog source) {
|
---|
| 98 | if (source == null) return null;
|
---|
| 99 | var entity = new StateLog(); ToEntity(source, entity);
|
---|
| 100 | return entity;
|
---|
| 101 | }
|
---|
| 102 | public static void ToEntity(DT.StateLog source, StateLog target) {
|
---|
| 103 | if ((source != null) && (target != null)) {
|
---|
| 104 | 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;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | #endregion
|
---|
| 108 |
|
---|
[4598] | 109 | #region HiveExperiment
|
---|
| 110 | public static DT.HiveExperiment ToDto(HiveExperiment source) {
|
---|
| 111 | if (source == null) return null;
|
---|
[5511] | 112 | return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, RootJobId = source.RootJobId, OwnerUserId = source.OwnerUserId, DateCreated = source.DateCreated, ResourceNames = source.ResourceIds, LastAccessed = source.LastAccessed };
|
---|
[4598] | 113 | }
|
---|
| 114 | public static HiveExperiment ToEntity(DT.HiveExperiment source) {
|
---|
| 115 | if (source == null) return null;
|
---|
[4649] | 116 | var entity = new HiveExperiment(); ToEntity(source, entity);
|
---|
| 117 | return entity;
|
---|
[4598] | 118 | }
|
---|
| 119 | public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {
|
---|
| 120 | if ((source != null) && (target != null)) {
|
---|
[5511] | 121 | target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.RootJobId = source.RootJobId; target.OwnerUserId = source.OwnerUserId; target.DateCreated = source.DateCreated; target.ResourceIds = source.ResourceNames; target.LastAccessed = source.LastAccessed;
|
---|
[4598] | 122 | }
|
---|
| 123 | }
|
---|
| 124 | #endregion
|
---|
| 125 |
|
---|
[5511] | 126 | #region HiveExperimentPermission
|
---|
| 127 | public static DT.HiveExperimentPermission ToDto(HiveExperimentPermission source) {
|
---|
| 128 | if (source == null) return null;
|
---|
| 129 | return new DT.HiveExperimentPermission { HiveExperimentId = source.HiveExperimentId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = source.Permission };
|
---|
| 130 | }
|
---|
| 131 | public static HiveExperimentPermission ToEntity(DT.HiveExperimentPermission source) {
|
---|
| 132 | if (source == null) return null;
|
---|
| 133 | var entity = new HiveExperimentPermission(); ToEntity(source, entity);
|
---|
| 134 | return entity;
|
---|
| 135 | }
|
---|
| 136 | public static void ToEntity(DT.HiveExperimentPermission source, HiveExperimentPermission target) {
|
---|
| 137 | if ((source != null) && (target != null)) {
|
---|
| 138 | target.HiveExperimentId = source.HiveExperimentId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = source.Permission;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | #endregion
|
---|
| 142 |
|
---|
[4905] | 143 | #region Plugin
|
---|
| 144 | public static DT.Plugin ToDto(Plugin source) {
|
---|
| 145 | if (source == null) return null;
|
---|
[5402] | 146 | return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version), UserId = source.UserId, IsLocal = source.IsLocal, DateCreated = source.DateCreated };
|
---|
[4905] | 147 | }
|
---|
| 148 | public static Plugin ToEntity(DT.Plugin source) {
|
---|
| 149 | if (source == null) return null;
|
---|
| 150 | var entity = new Plugin(); ToEntity(source, entity);
|
---|
| 151 | return entity;
|
---|
| 152 | }
|
---|
| 153 | public static void ToEntity(DT.Plugin source, Plugin target) {
|
---|
| 154 | if ((source != null) && (target != null)) {
|
---|
[5402] | 155 | target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString(); target.UserId = source.UserId; target.IsLocal = source.IsLocal; target.DateCreated = source.DateCreated;
|
---|
[4905] | 156 | }
|
---|
| 157 | }
|
---|
| 158 | #endregion
|
---|
| 159 |
|
---|
| 160 | #region PluginData
|
---|
| 161 | public static DT.PluginData ToDto(PluginData source) {
|
---|
| 162 | if (source == null) return null;
|
---|
[5402] | 163 | return new DT.PluginData { Id = source.PluginDataId, PluginId = source.PluginId, Data = source.Data.ToArray(), FileName = source.FileName };
|
---|
[4905] | 164 | }
|
---|
| 165 | public static PluginData ToEntity(DT.PluginData source) {
|
---|
| 166 | if (source == null) return null;
|
---|
| 167 | var entity = new PluginData(); ToEntity(source, entity);
|
---|
| 168 | return entity;
|
---|
| 169 | }
|
---|
| 170 | public static void ToEntity(DT.PluginData source, PluginData target) {
|
---|
| 171 | if ((source != null) && (target != null)) {
|
---|
[5402] | 172 | target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = new Binary(source.Data); target.FileName = source.FileName;
|
---|
[4905] | 173 | }
|
---|
| 174 | }
|
---|
| 175 | #endregion
|
---|
| 176 |
|
---|
[4598] | 177 | #region Slave
|
---|
| 178 | public static DT.Slave ToDto(Slave source) {
|
---|
| 179 | if (source == null) return null;
|
---|
[5511] | 180 | return new DT.Slave {
|
---|
| 181 | Id = source.ResourceId,
|
---|
| 182 | ParentResourceId = source.ParentResourceId,
|
---|
[5405] | 183 | Cores = source.Cores,
|
---|
[5511] | 184 | CpuSpeed = source.CpuSpeed,
|
---|
| 185 | FreeCores = source.FreeCores,
|
---|
| 186 | FreeMemory = source.FreeMemory,
|
---|
| 187 | IsAllowedToCalculate = source.IsAllowedToCalculate,
|
---|
| 188 | Memory = source.Memory,
|
---|
| 189 | Name = source.Name,
|
---|
| 190 | SlaveState = source.SlaveState,
|
---|
| 191 | CpuArchitecture = source.CpuArchitecture,
|
---|
[5405] | 192 | OperatingSystem = source.OperatingSystem,
|
---|
| 193 | LastHeartbeat = source.LastHeartbeat
|
---|
| 194 | };
|
---|
[4598] | 195 | }
|
---|
| 196 | public static Slave ToEntity(DT.Slave source) {
|
---|
| 197 | if (source == null) return null;
|
---|
[4649] | 198 | var entity = new Slave(); ToEntity(source, entity);
|
---|
| 199 | return entity;
|
---|
[4598] | 200 | }
|
---|
| 201 | public static void ToEntity(DT.Slave source, Slave target) {
|
---|
| 202 | if ((source != null) && (target != null)) {
|
---|
[5405] | 203 | target.ResourceId = source.Id;
|
---|
| 204 | target.ParentResourceId = source.ParentResourceId;
|
---|
[5511] | 205 | target.Cores = source.Cores;
|
---|
[5405] | 206 | target.CpuSpeed = source.CpuSpeed;
|
---|
| 207 | target.FreeCores = source.FreeCores;
|
---|
[5511] | 208 | target.FreeMemory = source.FreeMemory;
|
---|
[5405] | 209 | target.IsAllowedToCalculate = source.IsAllowedToCalculate;
|
---|
| 210 | target.Memory = source.Memory;
|
---|
[5511] | 211 | target.Name = source.Name;
|
---|
| 212 | target.SlaveState = source.SlaveState;
|
---|
| 213 | target.CpuArchitecture = source.CpuArchitecture;
|
---|
[5405] | 214 | target.OperatingSystem = source.OperatingSystem;
|
---|
| 215 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
[4598] | 216 | }
|
---|
| 217 | }
|
---|
| 218 | #endregion
|
---|
| 219 |
|
---|
| 220 | #region SlaveGroup
|
---|
| 221 | public static DT.SlaveGroup ToDto(SlaveGroup source) {
|
---|
| 222 | if (source == null) return null;
|
---|
[5106] | 223 | return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
|
---|
[4598] | 224 | }
|
---|
| 225 | public static SlaveGroup ToEntity(DT.SlaveGroup source) {
|
---|
| 226 | if (source == null) return null;
|
---|
[4649] | 227 | var entity = new SlaveGroup(); ToEntity(source, entity);
|
---|
| 228 | return entity;
|
---|
[4598] | 229 | }
|
---|
| 230 | public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {
|
---|
| 231 | if ((source != null) && (target != null)) {
|
---|
[5106] | 232 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
|
---|
[4598] | 233 | }
|
---|
| 234 | }
|
---|
| 235 | #endregion
|
---|
| 236 |
|
---|
| 237 | #region Resource
|
---|
| 238 | public static DT.Resource ToDto(Resource source) {
|
---|
| 239 | if (source == null) return null;
|
---|
[5106] | 240 | return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
|
---|
[4598] | 241 | }
|
---|
| 242 | public static Resource ToEntity(DT.Resource source) {
|
---|
| 243 | if (source == null) return null;
|
---|
[4649] | 244 | var entity = new Resource(); ToEntity(source, entity);
|
---|
| 245 | return entity;
|
---|
[4598] | 246 | }
|
---|
| 247 | public static void ToEntity(DT.Resource source, Resource target) {
|
---|
| 248 | if ((source != null) && (target != null)) {
|
---|
[5106] | 249 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
|
---|
[4598] | 250 | }
|
---|
| 251 | }
|
---|
| 252 | #endregion
|
---|
| 253 | }
|
---|
| 254 | }
|
---|