Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Convert.cs @ 5106

Last change on this file since 5106 was 5106, checked in by cneumuel, 14 years ago

#1233

  • made MockJob to execute asynchronously with the option to spinWait
  • added methods to IHiveService
  • implemented methods for Slave handling in HiveService
  • added more tests for server
  • changed db-schema of slaves and slavegroups
File size: 8.3 KB
Line 
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
22using System.Collections.Generic;
23using System.Data.Linq;
24using System.Linq;
25using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
26using System;
27
28namespace 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        DateCalculated = source.DateCalculated,
37        DateCreated = source.DateCreated,
38        DateFinished = source.DateFinished,
39        Exception = source.Exception,
40        ExecutionTime = source.ExecutionTime,
41        MemoryNeeded = source.MemoryNeeded,
42        ParentJobId = source.ParentJobId,
43        Priority = source.Priority,
44        SlaveId = source.SlaveId,
45        JobState = source.JobState,
46        UserId = source.UserId,
47        PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList()
48      };
49    }
50    public static Job ToEntity(DT.Job source) {
51      if (source == null) return null;
52      var entity = new Job(); ToEntity(source, entity);
53      return entity;
54    }
55    public static void ToEntity(DT.Job source, Job target) {
56      if ((source != null) && (target != null)) {
57        target.JobId = source.Id;
58        target.CoresNeeded = source.CoresNeeded;
59        target.DateCalculated = source.DateCalculated;
60        target.DateCreated = source.DateCreated;
61        target.DateFinished = source.DateFinished;
62        target.Exception = source.Exception;
63        target.ExecutionTime = source.ExecutionTime;
64        target.MemoryNeeded = source.MemoryNeeded;
65        target.ParentJobId = source.ParentJobId;
66        target.Priority = source.Priority;
67        target.SlaveId = source.SlaveId;
68        target.JobState = source.JobState;
69        target.UserId = source.UserId;
70        //        target.RequiredPlugins = db.Plugins.Select(x => source.PluginsNeededIds.Contains(x.PluginId)); - this is difficult
71      }
72    }
73    #endregion
74
75    #region JobData
76    public static DT.JobData ToDto(JobData source) {
77      if (source == null) return null;
78      return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate };
79    }
80    public static JobData ToEntity(DT.JobData source) {
81      if (source == null) return null;
82      var entity = new JobData(); ToEntity(source, entity);
83      return entity;
84    }
85    public static void ToEntity(DT.JobData source, JobData target) {
86      if ((source != null) && (target != null)) {
87        target.JobId = source.JobId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate;
88      }
89    }
90    #endregion
91
92    #region HiveExperiment
93    public static DT.HiveExperiment ToDto(HiveExperiment source) {
94      if (source == null) return null;
95      return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, RootJobId = source.RootJobId, UserId = source.UserId, DateCreated = source.DateCreated };
96    }
97    public static HiveExperiment ToEntity(DT.HiveExperiment source) {
98      if (source == null) return null;
99      var entity = new HiveExperiment(); ToEntity(source, entity);
100      return entity;
101    }
102    public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {
103      if ((source != null) && (target != null)) {
104        target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.RootJobId = source.RootJobId; target.UserId = source.UserId; target.DateCreated = source.DateCreated;
105      }
106    }
107    #endregion
108
109    #region Plugin
110    public static DT.Plugin ToDto(Plugin source) {
111      if (source == null) return null;
112      return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version) };
113    }
114    public static Plugin ToEntity(DT.Plugin source) {
115      if (source == null) return null;
116      var entity = new Plugin(); ToEntity(source, entity);
117      return entity;
118    }
119    public static void ToEntity(DT.Plugin source, Plugin target) {
120      if ((source != null) && (target != null)) {
121        target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString();
122      }
123    }
124    #endregion
125
126    #region PluginData
127    public static DT.PluginData ToDto(PluginData source) {
128      if (source == null) return null;
129      return new DT.PluginData { PluginId = source.PluginId, Data = source.Data.ToArray() };
130    }
131    public static PluginData ToEntity(DT.PluginData source) {
132      if (source == null) return null;
133      var entity = new PluginData(); ToEntity(source, entity);
134      return entity;
135    }
136    public static void ToEntity(DT.PluginData source, PluginData target) {
137      if ((source != null) && (target != null)) {
138        target.PluginId = source.PluginId; target.Data = new Binary(source.Data);
139      }
140    }
141    #endregion
142
143    #region Slave
144    public static DT.Slave ToDto(Slave source) {
145      if (source == null) return null;
146      return new DT.Slave { Id = source.ResourceId, ParentResourceId = source.ParentResourceId, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveState = source.SlaveState };
147    }
148    public static Slave ToEntity(DT.Slave source) {
149      if (source == null) return null;
150      var entity = new Slave(); ToEntity(source, entity);
151      return entity;
152    }
153    public static void ToEntity(DT.Slave source, Slave target) {
154      if ((source != null) && (target != null)) {
155        target.ResourceId = source.Id; target.ParentResourceId = source.ParentResourceId; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveState = source.SlaveState;
156      }
157    }
158    #endregion
159
160    #region SlaveGroup
161    public static DT.SlaveGroup ToDto(SlaveGroup source) {
162      if (source == null) return null;
163      return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
164    }
165    public static SlaveGroup ToEntity(DT.SlaveGroup source) {
166      if (source == null) return null;
167      var entity = new SlaveGroup(); ToEntity(source, entity);
168      return entity;
169    }
170    public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {
171      if ((source != null) && (target != null)) {
172        target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
173      }
174    }
175    #endregion
176
177    #region Resource
178    public static DT.Resource ToDto(Resource source) {
179      if (source == null) return null;
180      return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId };
181    }
182    public static Resource ToEntity(DT.Resource source) {
183      if (source == null) return null;
184      var entity = new Resource(); ToEntity(source, entity);
185      return entity;
186    }
187    public static void ToEntity(DT.Resource source, Resource target) {
188      if ((source != null) && (target != null)) {
189        target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId;
190      }
191    }
192    #endregion
193  }
194}
Note: See TracBrowser for help on using the repository browser.