1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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.Collections.Generic;
|
---|
24 | using System.Data.Linq;
|
---|
25 | using System.Linq;
|
---|
26 | using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Services.Hive.DataAccess {
|
---|
29 | public static class Convert {
|
---|
30 | #region Job
|
---|
31 | public static DT.Job ToDto(Job source) {
|
---|
32 | if (source == null) return null;
|
---|
33 | return new DT.Job {
|
---|
34 | Id = source.JobId,
|
---|
35 | CoresNeeded = source.CoresNeeded,
|
---|
36 | ExecutionTime = TimeSpan.FromMilliseconds(source.ExecutionTimeMs),
|
---|
37 | MemoryNeeded = source.MemoryNeeded,
|
---|
38 | ParentJobId = source.ParentJobId,
|
---|
39 | Priority = source.Priority,
|
---|
40 | PluginsNeededIds = (source.RequiredPlugins == null ? new List<Guid>() : source.RequiredPlugins.Select(x => x.PluginId).ToList()),
|
---|
41 | LastHeartbeat = source.LastHeartbeat,
|
---|
42 | State = source.State,
|
---|
43 | StateLog = (source.StateLogs == null ? new List<DT.StateLog>() : source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList()),
|
---|
44 | IsParentJob = source.IsParentJob,
|
---|
45 | FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished,
|
---|
46 | Command = source.Command,
|
---|
47 | LastJobDataUpdate = (source.JobData == null ? DateTime.MinValue : source.JobData.LastUpdate),
|
---|
48 | HiveExperimentId = source.HiveExperimentId,
|
---|
49 | IsPrivileged = source.IsPrivileged
|
---|
50 | };
|
---|
51 | }
|
---|
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) {
|
---|
58 | if ((source != null) && (target != null)) {
|
---|
59 | target.JobId = source.Id;
|
---|
60 | target.CoresNeeded = source.CoresNeeded;
|
---|
61 | target.ExecutionTimeMs = source.ExecutionTime.TotalMilliseconds;
|
---|
62 | target.MemoryNeeded = source.MemoryNeeded;
|
---|
63 | target.ParentJobId = source.ParentJobId;
|
---|
64 | target.Priority = source.Priority;
|
---|
65 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
66 | target.State = source.State;
|
---|
67 | if (target.StateLogs == null) target.StateLogs = new EntitySet<StateLog>();
|
---|
68 | foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) {
|
---|
69 | target.StateLogs.Add(Convert.ToEntity(sl));
|
---|
70 | }
|
---|
71 | target.IsParentJob = source.IsParentJob;
|
---|
72 | target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
|
---|
73 | target.Command = source.Command;
|
---|
74 | // RequiredPlugins are added by Dao
|
---|
75 | target.HiveExperimentId = source.HiveExperimentId;
|
---|
76 | target.IsPrivileged = source.IsPrivileged;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | #region JobData
|
---|
82 | public static DT.JobData ToDto(JobData source) {
|
---|
83 | if (source == null) return null;
|
---|
84 | return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate };
|
---|
85 | }
|
---|
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) {
|
---|
92 | if ((source != null) && (target != null)) {
|
---|
93 | target.JobId = source.JobId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | #endregion
|
---|
97 |
|
---|
98 | #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;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | #endregion
|
---|
114 |
|
---|
115 | #region Downtimes
|
---|
116 | public static DT.Downtime ToDto(Downtime source) {
|
---|
117 | if (source == null) return null;
|
---|
118 | 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 | }
|
---|
120 | public static Downtime ToEntity(DT.Downtime source) {
|
---|
121 | if (source == null) return null;
|
---|
122 | var entity = new Downtime(); ToEntity(source, entity);
|
---|
123 | return entity;
|
---|
124 | }
|
---|
125 | public static void ToEntity(DT.Downtime source, Downtime target) {
|
---|
126 | if ((source != null) && (target != null)) {
|
---|
127 | 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;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | #endregion
|
---|
131 |
|
---|
132 | #region HiveExperiment
|
---|
133 | public static DT.HiveExperiment ToDto(HiveExperiment source) {
|
---|
134 | if (source == null) return null;
|
---|
135 | 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 | }
|
---|
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) {
|
---|
143 | if ((source != null) && (target != null)) {
|
---|
144 | 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;
|
---|
145 | }
|
---|
146 | }
|
---|
147 | #endregion
|
---|
148 |
|
---|
149 | #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;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | #endregion
|
---|
165 |
|
---|
166 | #region Plugin
|
---|
167 | public static DT.Plugin ToDto(Plugin source) {
|
---|
168 | if (source == null) return null;
|
---|
169 | 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 | }
|
---|
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) {
|
---|
177 | if ((source != null) && (target != null)) {
|
---|
178 | 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;
|
---|
179 | }
|
---|
180 | }
|
---|
181 | #endregion
|
---|
182 |
|
---|
183 | #region PluginData
|
---|
184 | public static DT.PluginData ToDto(PluginData source) {
|
---|
185 | if (source == null) return null;
|
---|
186 | return new DT.PluginData { Id = source.PluginDataId, PluginId = source.PluginId, Data = source.Data.ToArray(), FileName = source.FileName };
|
---|
187 | }
|
---|
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) {
|
---|
194 | if ((source != null) && (target != null)) {
|
---|
195 | target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = new Binary(source.Data); target.FileName = source.FileName;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | #endregion
|
---|
199 |
|
---|
200 | #region Slave
|
---|
201 | public static DT.Slave ToDto(Slave source) {
|
---|
202 | if (source == null) return null;
|
---|
203 | return new DT.Slave {
|
---|
204 | Id = source.ResourceId,
|
---|
205 | ParentResourceId = source.ParentResourceId,
|
---|
206 | Cores = source.Cores,
|
---|
207 | CpuSpeed = source.CpuSpeed,
|
---|
208 | FreeCores = source.FreeCores,
|
---|
209 | FreeMemory = source.FreeMemory,
|
---|
210 | IsAllowedToCalculate = source.IsAllowedToCalculate,
|
---|
211 | Memory = source.Memory,
|
---|
212 | Name = source.Name,
|
---|
213 | SlaveState = source.SlaveState,
|
---|
214 | CpuArchitecture = source.CpuArchitecture,
|
---|
215 | OperatingSystem = source.OperatingSystem,
|
---|
216 | LastHeartbeat = source.LastHeartbeat,
|
---|
217 | CpuUtilization = source.CpuUtilization
|
---|
218 | };
|
---|
219 | }
|
---|
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) {
|
---|
226 | if ((source != null) && (target != null)) {
|
---|
227 | target.ResourceId = source.Id;
|
---|
228 | target.ParentResourceId = source.ParentResourceId;
|
---|
229 | target.Cores = source.Cores;
|
---|
230 | target.CpuSpeed = source.CpuSpeed;
|
---|
231 | target.FreeCores = source.FreeCores;
|
---|
232 | target.FreeMemory = source.FreeMemory;
|
---|
233 | target.IsAllowedToCalculate = source.IsAllowedToCalculate;
|
---|
234 | target.Memory = source.Memory;
|
---|
235 | target.Name = source.Name;
|
---|
236 | target.SlaveState = source.SlaveState;
|
---|
237 | target.CpuArchitecture = source.CpuArchitecture;
|
---|
238 | target.OperatingSystem = source.OperatingSystem;
|
---|
239 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
240 | target.CpuUtilization = source.CpuUtilization;
|
---|
241 | }
|
---|
242 | }
|
---|
243 | #endregion
|
---|
244 |
|
---|
245 | #region SlaveGroup
|
---|
246 | public static DT.SlaveGroup ToDto(SlaveGroup source) {
|
---|
247 | if (source == null) return null;
|
---|
248 | return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
|
---|
249 | }
|
---|
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) {
|
---|
256 | if ((source != null) && (target != null)) {
|
---|
257 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
|
---|
258 | }
|
---|
259 | }
|
---|
260 | #endregion
|
---|
261 |
|
---|
262 | #region Resource
|
---|
263 | public static DT.Resource ToDto(Resource source) {
|
---|
264 | if (source == null) return null;
|
---|
265 | return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
|
---|
266 | }
|
---|
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) {
|
---|
273 | if ((source != null) && (target != null)) {
|
---|
274 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
|
---|
275 | }
|
---|
276 | }
|
---|
277 | #endregion
|
---|
278 |
|
---|
279 | #region Statistics
|
---|
280 | public static DT.Statistics ToDto(Statistics source) {
|
---|
281 | if (source == null) return null;
|
---|
282 | return new DT.Statistics {
|
---|
283 | Id = source.StatisticsId,
|
---|
284 | TimeStamp = source.Timestamp,
|
---|
285 | SlaveStatistics = source.SlaveStatistics.Select(x => Convert.ToDto(x)).ToArray(),
|
---|
286 | UserStatistics = source.UserStatistics.Select(x => Convert.ToDto(x)).ToArray()
|
---|
287 | };
|
---|
288 | }
|
---|
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) {
|
---|
295 | if ((source != null) && (target != null)) {
|
---|
296 | target.StatisticsId = source.Id;
|
---|
297 | target.Timestamp = source.TimeStamp;
|
---|
298 |
|
---|
299 | }
|
---|
300 | }
|
---|
301 | #endregion
|
---|
302 |
|
---|
303 | #region SlaveStatistics
|
---|
304 | public static DT.SlaveStatistics ToDto(SlaveStatistics source) {
|
---|
305 | if (source == null) return null;
|
---|
306 | return new DT.SlaveStatistics {
|
---|
307 | Id = source.StatisticsId,
|
---|
308 | SlaveId = source.SlaveId,
|
---|
309 | Cores = source.Cores,
|
---|
310 | CpuUtilization = source.CpuUtilization,
|
---|
311 | FreeCores = source.FreeCores,
|
---|
312 | FreeMemory = source.FreeMemory,
|
---|
313 | Memory = source.Memory
|
---|
314 | };
|
---|
315 | }
|
---|
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) {
|
---|
322 | if ((source != null) && (target != null)) {
|
---|
323 | target.StatisticsId = source.Id;
|
---|
324 | target.SlaveId = source.SlaveId;
|
---|
325 | target.Cores = source.Cores;
|
---|
326 | target.CpuUtilization = source.CpuUtilization;
|
---|
327 | target.FreeCores = source.FreeCores;
|
---|
328 | target.FreeMemory = source.FreeMemory;
|
---|
329 | target.Memory = source.Memory;
|
---|
330 | }
|
---|
331 | }
|
---|
332 | #endregion
|
---|
333 |
|
---|
334 | #region UserStatistics
|
---|
335 | public static DT.UserStatistics ToDto(UserStatistics source) {
|
---|
336 | if (source == null) return null;
|
---|
337 | return new DT.UserStatistics {
|
---|
338 | Id = source.StatisticsId,
|
---|
339 | UserId = source.UserId,
|
---|
340 | UsedCores = source.UsedCores,
|
---|
341 | ExecutionTime = TimeSpan.FromMilliseconds(source.ExecutionTimeMs),
|
---|
342 | ExecutionTimeFinishedJobs = TimeSpan.FromMilliseconds(source.ExecutionTimeMsFinishedJobs),
|
---|
343 | StartToEndTime = TimeSpan.FromMilliseconds(source.StartToEndTimeMs)
|
---|
344 | };
|
---|
345 | }
|
---|
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) {
|
---|
352 | if ((source != null) && (target != null)) {
|
---|
353 | target.StatisticsId = source.Id;
|
---|
354 | target.UserId = source.UserId;
|
---|
355 | target.UsedCores = source.UsedCores;
|
---|
356 | target.ExecutionTimeMs = source.ExecutionTime.TotalMilliseconds;
|
---|
357 | target.ExecutionTimeMsFinishedJobs = source.ExecutionTimeFinishedJobs.TotalMilliseconds;
|
---|
358 | target.StartToEndTimeMs = source.StartToEndTime.TotalMilliseconds;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | #endregion
|
---|
362 | }
|
---|
363 | }
|
---|