Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication/Convert.cs @ 5335

Last change on this file since 5335 was 5335, checked in by fruehrli, 13 years ago

#1197
modified and new service methods

File size: 4.5 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.Data.Linq;
23using HeuristicLab.Services.Authentication.DataTransfer;
24using DA = HeuristicLab.Services.Authentication.DataAccess;
25using DT = HeuristicLab.Services.Authentication.DataTransfer;
26using System;
27
28namespace HeuristicLab.Services.Authentication {
29  public static class Convert {
30
31    #region Client
32    public static DT.Client ToDto(DA.Client source) {
33      if (source == null) return null;
34      return new DT.Client {
35        Id = source.Id,
36        Name = source.Name,
37        Description = source.Description,
38        ResourceType = (DT.Resource.ResourceTypes) Enum.Parse(typeof(DT.Resource.ResourceTypes), source.ResourceType),
39        ProcessorType = source.ProcessorType,
40        NumberOfProcessors = source.NumberOfProcessors,
41        NumberOfThreads = source.NumberOfThreads,
42        IPAdress = source.IPAdress,
43        MemorySize = source.MemorySize,
44        OperatingSystem = source.OperatingSystem
45      };
46    }
47
48    public static DA.Client ToEntity(DT.Client source) {
49      if (source == null) return null;
50      return new DA.Client {
51        Id = source.Id,
52        Name = source.Name,
53        Description = source.Description,
54        ResourceType = source.ResourceType.ToString(),
55        ProcessorType = source.ProcessorType,
56        NumberOfProcessors = source.NumberOfProcessors,
57        NumberOfThreads = source.NumberOfThreads,
58        IPAdress = source.IPAdress,
59        MemorySize = source.MemorySize,
60        OperatingSystem = source.OperatingSystem
61      };
62    }
63
64    public static DA.Resource ToEntity(DT.Resource source) {
65      if (source == null) return null;
66      if (source is DT.Client) {
67        DT.Client client = (Client)source;
68        return ToEntity(client);
69      }
70      if (source is DT.ResourceGroup) {
71        DT.ResourceGroup resourceGroup = (ResourceGroup)source;
72        return ToEntity(resourceGroup);
73      }
74      return null;
75    }
76
77    public static void ToEntity(DT.Client source, DA.Client target) {
78      if ((source != null) && (target != null)) {
79        target.Id = source.Id;
80        target.Name = source.Name;
81        target.Description = source.Description;
82        target.ResourceType = source.ResourceType.ToString();
83        target.ProcessorType = source.ProcessorType;
84        target.NumberOfProcessors = source.NumberOfProcessors;
85        target.NumberOfThreads = source.NumberOfThreads;
86        target.IPAdress = source.IPAdress;
87        target.MemorySize = source.MemorySize;
88        target.OperatingSystem = source.OperatingSystem;
89      }
90    }
91    #endregion // Client
92
93    #region ResourceGroup
94    public static DT.ResourceGroup ToDto(DA.ResourceGroup source) {
95      if (source == null) return null;
96      return new DT.ResourceGroup {
97        Id = source.Id,
98        Name = source.Name,
99        Description = source.Description,
100        ResourceType = (DT.Resource.ResourceTypes)Enum.Parse(typeof(DT.Resource.ResourceTypes), source.ResourceType)
101      };
102    }
103
104    public static DA.ResourceGroup ToEntity(DT.ResourceGroup source) {
105      if (source == null) return null;
106      return new DA.ResourceGroup {
107        Id = source.Id,
108        Name = source.Name,
109        Description = source.Description,
110        ResourceType = source.ResourceType.ToString()
111      };
112    }
113
114    public static void ToEntity(DT.ResourceGroup source, DA.ResourceGroup target) {
115      if ((source != null) && (target != null)) {
116        target.Id = source.Id;
117        target.Name = source.Name;
118        target.Description = source.Description;
119        target.ResourceType = source.ResourceType.ToString();
120      }
121    }
122    #endregion // ResourceGroup
123  }
124}
Note: See TracBrowser for help on using the repository browser.