Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Convert.cs @ 4905

Last change on this file since 4905 was 4905, checked in by cneumuel, 13 years ago

#1233

  • added plugin management features
  • took over client-GUI from old branch
  • merged with bugfixes from old branch
  • added hive-web (for IIS)
File size: 8.6 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        ProjectId = source.ProjectId,
45        SlaveId = source.SlaveId,
46        JobState = source.JobState,
47        UserId = source.UserId,
48        PluginsNeededIds = source.RequiredPlugins.Select(x => x.PluginId).ToList()
49      };
50    }
51    public static Job ToEntity(DT.Job source) {
52      if (source == null) return null;
53      var entity = new Job(); ToEntity(source, entity);
54      return entity;
55    }
56    public static void ToEntity(DT.Job source, Job target) {
57      if ((source != null) && (target != null)) {
58        target.JobId = source.Id;
59        target.CoresNeeded = source.CoresNeeded;
60        target.DateCalculated = source.DateCalculated;
61        target.DateCreated = source.DateCreated;
62        target.DateFinished = source.DateFinished;
63        target.Exception = source.Exception;
64        target.ExecutionTime = source.ExecutionTime;
65        target.MemoryNeeded = source.MemoryNeeded;
66        target.ParentJobId = source.ParentJobId;
67        target.Priority = source.Priority;
68        target.ProjectId = source.ProjectId;
69        target.SlaveId = source.SlaveId;
70        target.JobState = source.JobState;
71        target.UserId = source.UserId;
72//        target.RequiredPlugins = db.Plugins.Select(x => source.PluginsNeededIds.Contains(x.PluginId)); - this is difficult
73      }
74    }
75    #endregion
76
77    #region JobData
78    public static DT.JobData ToDto(JobData source) {
79      if (source == null) return null;
80      return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray() };
81    }
82    public static JobData ToEntity(DT.JobData source) {
83      if (source == null) return null;
84      var entity = new JobData(); ToEntity(source, entity);
85      return entity;
86    }
87    public static void ToEntity(DT.JobData source, JobData target) {
88      if ((source != null) && (target != null)) {
89        target.JobId = source.JobId; target.Data = new Binary(source.Data);
90      }
91    }
92    #endregion
93
94    #region HiveExperiment
95    public static DT.HiveExperiment ToDto(HiveExperiment source) {
96      if (source == null) return null;
97      return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, RootJobId = source.RootJobId, UserId = source.UserId };
98    }
99    public static HiveExperiment ToEntity(DT.HiveExperiment source) {
100      if (source == null) return null;
101      var entity = new HiveExperiment(); ToEntity(source, entity);
102      return entity;
103    }
104    public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {
105      if ((source != null) && (target != null)) {
106        target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.RootJobId = source.RootJobId; target.UserId = source.UserId;
107      }
108    }
109    #endregion
110
111    #region Plugin
112    public static DT.Plugin ToDto(Plugin source) {
113      if (source == null) return null;
114      return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version) };
115    }
116    public static Plugin ToEntity(DT.Plugin source) {
117      if (source == null) return null;
118      var entity = new Plugin(); ToEntity(source, entity);
119      return entity;
120    }
121    public static void ToEntity(DT.Plugin source, Plugin target) {
122      if ((source != null) && (target != null)) {
123        target.PluginId = source.Id; target.Name = source.Name; target.Version = source.Version.ToString();
124      }
125    }
126    #endregion
127
128    #region PluginData
129    public static DT.PluginData ToDto(PluginData source) {
130      if (source == null) return null;
131      return new DT.PluginData { PluginId = source.PluginId, Data = source.Data.ToArray() };
132    }
133    public static PluginData ToEntity(DT.PluginData source) {
134      if (source == null) return null;
135      var entity = new PluginData(); ToEntity(source, entity);
136      return entity;
137    }
138    public static void ToEntity(DT.PluginData source, PluginData target) {
139      if ((source != null) && (target != null)) {
140        target.PluginId = source.PluginId; target.Data = new Binary(source.Data);
141      }
142    }
143    #endregion
144
145    #region Slave
146    public static DT.Slave ToDto(Slave source) {
147      if (source == null) return null;
148      return new DT.Slave { Id = source.ResourceId, CalendarSyncState = source.CalendarSyncState, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveConfigId = source.SlaveConfigId, SlaveState = source.SlaveState };
149    }
150    public static Slave ToEntity(DT.Slave source) {
151      if (source == null) return null;
152      var entity = new Slave(); ToEntity(source, entity);
153      return entity;
154    }
155    public static void ToEntity(DT.Slave source, Slave target) {
156      if ((source != null) && (target != null)) {
157        target.ResourceId = source.Id; target.CalendarSyncState = source.CalendarSyncState; 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.SlaveConfigId = source.SlaveConfigId; target.SlaveState = source.SlaveState;
158      }
159    }
160    #endregion
161
162    #region SlaveGroup
163    public static DT.SlaveGroup ToDto(SlaveGroup source) {
164      if (source == null) return null;
165      return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ChildResourcesIds = source.SlaveGroup_Resources_Children.Select(x => x.ResourceId).ToList(), ParentResourcesIds = source.SlaveGroup_Resources_Parents.Select(x => x.ResourceId).ToList() };
166    }
167    public static SlaveGroup ToEntity(DT.SlaveGroup source) {
168      if (source == null) return null;
169      var entity = new SlaveGroup(); ToEntity(source, entity);
170      return entity;
171    }
172    public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {
173      if ((source != null) && (target != null)) {
174        target.ResourceId = source.Id;
175        target.Name = source.Name;
176        //target.SlaveGroup_Resources_Children = // TODO: see how working with groups will work, then decide how to handle enumerations in here
177        //target.SlaveGroup_Resources_Parents =
178      }
179    }
180    #endregion
181
182    #region Resource
183    public static DT.Resource ToDto(Resource source) {
184      if (source == null) return null;
185      return new DT.Resource { Id = source.ResourceId, Name = source.Name };
186    }
187    public static Resource ToEntity(DT.Resource source) {
188      if (source == null) return null;
189      var entity = new Resource(); ToEntity(source, entity);
190      return entity;
191    }
192    public static void ToEntity(DT.Resource source, Resource target) {
193      if ((source != null) && (target != null)) {
194        target.ResourceId = source.Id; target.Name = source.Name;
195      }
196    }
197    #endregion
198  }
199}
Note: See TracBrowser for help on using the repository browser.