1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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.Linq;
|
---|
24 | using DA = HeuristicLab.Services.OKB.DataAccess;
|
---|
25 | using DT = HeuristicLab.Services.OKB.Query.DataTransfer;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Services.OKB.Query {
|
---|
28 | public static class Convert {
|
---|
29 | public static DT.Run ToDto(DA.Run source, bool includeBinaryValues) {
|
---|
30 | if (source == null) return null;
|
---|
31 | var dto = new DT.Run { Id = source.Id, Algorithm = Convert.ToDto(source.Algorithm), Problem = Convert.ToDto(source.Problem), CreatedDate = source.CreatedDate, RandomSeed = source.RandomSeed, ClientId = source.ClientId, UserId = source.UserId };
|
---|
32 | dto.ParameterValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Parameter).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();
|
---|
33 | dto.ResultValues = source.Values.Where(x => x.ValueName.Category == DA.ValueNameCategory.Result).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();
|
---|
34 | return dto;
|
---|
35 | }
|
---|
36 |
|
---|
37 | private static DT.Algorithm ToDto(DA.Algorithm source) {
|
---|
38 | if (source == null) return null;
|
---|
39 | return new DT.Algorithm { Name = source.Name, Description = source.Description, AlgorithmClass = source.AlgorithmClass.Name, Platform = source.Platform.Name, DataType = Convert.ToDto(source.DataType) };
|
---|
40 | }
|
---|
41 |
|
---|
42 | private static DT.Problem ToDto(DA.Problem source) {
|
---|
43 | if (source == null) return null;
|
---|
44 | return new DT.Problem { Name = source.Name, Description = source.Description, ProblemClass = source.ProblemClass.Name, Platform = source.Platform.Name, DataType = Convert.ToDto(source.DataType) };
|
---|
45 | }
|
---|
46 |
|
---|
47 | private static DT.DataType ToDto(DA.DataType source) {
|
---|
48 | if (source == null) return null;
|
---|
49 | return new DT.DataType { Name = source.Name, TypeName = source.TypeName };
|
---|
50 | }
|
---|
51 |
|
---|
52 | private static DT.Value ToDto(DA.Value source, bool includeBinaryValues) {
|
---|
53 | if (source == null) return null;
|
---|
54 | if (source.ValueName.Type == DA.ValueNameType.Bool) {
|
---|
55 | return new DT.BoolValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.BoolValue.GetValueOrDefault() };
|
---|
56 | } else if (source.ValueName.Type == DA.ValueNameType.Int) {
|
---|
57 | return new DT.IntValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.IntValue.GetValueOrDefault() };
|
---|
58 | } else if (source.ValueName.Type == DA.ValueNameType.Long) {
|
---|
59 | return new DT.LongValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.LongValue.GetValueOrDefault() };
|
---|
60 | } else if (source.ValueName.Type == DA.ValueNameType.Float) {
|
---|
61 | return new DT.FloatValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.FloatValue.GetValueOrDefault() };
|
---|
62 | } else if (source.ValueName.Type == DA.ValueNameType.Double) {
|
---|
63 | return new DT.DoubleValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.DoubleValue.GetValueOrDefault() };
|
---|
64 | } else if (source.ValueName.Type == DA.ValueNameType.String) {
|
---|
65 | return new DT.StringValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = source.StringValue };
|
---|
66 | } else if (source.ValueName.Type == DA.ValueNameType.Binary) {
|
---|
67 | return new DT.BinaryValue { Name = source.ValueName.Name, DataType = Convert.ToDto(source.DataType), Value = includeBinaryValues ? source.BinaryData.Data.ToArray() : null };
|
---|
68 | } else {
|
---|
69 | throw new ArgumentException("Unknown value type.", "source");
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|