[6983] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7268] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6983] | 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 DB = HeuristicLab.Services.Hive.DataAccess;
|
---|
| 27 | using DT = HeuristicLab.Services.Hive.DataTransfer;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Services.Hive.DataTransfer {
|
---|
| 30 | public static class Convert {
|
---|
| 31 | #region Task
|
---|
| 32 | public static DT.Task ToDto(DB.Task source) {
|
---|
| 33 | if (source == null) return null;
|
---|
| 34 | return new DT.Task {
|
---|
| 35 | Id = source.TaskId,
|
---|
| 36 | CoresNeeded = source.CoresNeeded,
|
---|
| 37 | ExecutionTime = TimeSpan.FromMilliseconds(source.ExecutionTimeMs),
|
---|
| 38 | MemoryNeeded = source.MemoryNeeded,
|
---|
| 39 | ParentTaskId = source.ParentTaskId,
|
---|
| 40 | Priority = source.Priority,
|
---|
| 41 | PluginsNeededIds = (source.RequiredPlugins == null ? new List<Guid>() : source.RequiredPlugins.Select(x => x.PluginId).ToList()),
|
---|
| 42 | LastHeartbeat = source.LastHeartbeat,
|
---|
| 43 | State = Convert.ToDto(source.State),
|
---|
| 44 | StateLog = (source.StateLogs == null ? new List<DT.StateLog>() : source.StateLogs.Select(x => Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList()),
|
---|
| 45 | IsParentTask = source.IsParentTask,
|
---|
| 46 | FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished,
|
---|
| 47 | Command = Convert.ToDto(source.Command),
|
---|
| 48 | LastTaskDataUpdate = (source.JobData == null ? DateTime.MinValue : source.JobData.LastUpdate),
|
---|
| 49 | JobId = source.JobId,
|
---|
| 50 | IsPrivileged = source.IsPrivileged
|
---|
| 51 | };
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | public static DB.Task ToEntity(DT.Task source) {
|
---|
| 55 | if (source == null) return null;
|
---|
| 56 | var entity = new DB.Task(); ToEntity(source, entity);
|
---|
| 57 | return entity;
|
---|
| 58 | }
|
---|
| 59 | public static void ToEntity(DT.Task source, DB.Task target) {
|
---|
| 60 | if ((source != null) && (target != null)) {
|
---|
| 61 | target.TaskId = source.Id;
|
---|
| 62 | target.CoresNeeded = source.CoresNeeded;
|
---|
| 63 | target.ExecutionTimeMs = source.ExecutionTime.TotalMilliseconds;
|
---|
| 64 | target.MemoryNeeded = source.MemoryNeeded;
|
---|
| 65 | target.ParentTaskId = source.ParentTaskId;
|
---|
| 66 | target.Priority = source.Priority;
|
---|
| 67 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
| 68 | target.State = Convert.ToEntity(source.State);
|
---|
| 69 | if (target.StateLogs == null) target.StateLogs = new EntitySet<DB.StateLog>();
|
---|
| 70 | foreach (DT.StateLog sl in source.StateLog.Where(x => x.Id == Guid.Empty)) {
|
---|
| 71 | target.StateLogs.Add(Convert.ToEntity(sl));
|
---|
| 72 | }
|
---|
| 73 | target.IsParentTask = source.IsParentTask;
|
---|
| 74 | target.FinishWhenChildJobsFinished = source.FinishWhenChildJobsFinished;
|
---|
| 75 | target.Command = Convert.ToEntity(source.Command);
|
---|
| 76 | // RequiredPlugins are added by Dao
|
---|
| 77 | target.JobId = source.JobId;
|
---|
| 78 | target.IsPrivileged = source.IsPrivileged;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | #endregion
|
---|
| 82 |
|
---|
| 83 | #region TaskData
|
---|
| 84 | public static DT.TaskData ToDto(DB.TaskData source) {
|
---|
| 85 | if (source == null) return null;
|
---|
| 86 | return new DT.TaskData { TaskId = source.TaskId, Data = source.Data.ToArray(), LastUpdate = source.LastUpdate };
|
---|
| 87 | }
|
---|
| 88 | public static DB.TaskData ToEntity(DT.TaskData source) {
|
---|
| 89 | if (source == null) return null;
|
---|
| 90 | var entity = new DB.TaskData(); ToEntity(source, entity);
|
---|
| 91 | return entity;
|
---|
| 92 | }
|
---|
| 93 | public static void ToEntity(DT.TaskData source, DB.TaskData target) {
|
---|
| 94 | if ((source != null) && (target != null)) {
|
---|
| 95 | target.TaskId = source.TaskId; target.Data = new Binary(source.Data); target.LastUpdate = source.LastUpdate;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | #endregion
|
---|
| 99 |
|
---|
| 100 | #region StateLog
|
---|
| 101 | public static DT.StateLog ToDto(DB.StateLog source) {
|
---|
| 102 | if (source == null) return null;
|
---|
| 103 | return new DT.StateLog { Id = source.StateLogId, DateTime = source.DateTime, Exception = source.Exception, TaskId = source.TaskId, SlaveId = source.SlaveId, State = Convert.ToDto(source.State), UserId = source.UserId };
|
---|
| 104 | }
|
---|
| 105 | public static DB.StateLog ToEntity(DT.StateLog source) {
|
---|
| 106 | if (source == null) return null;
|
---|
| 107 | var entity = new DB.StateLog(); ToEntity(source, entity);
|
---|
| 108 | return entity;
|
---|
| 109 | }
|
---|
| 110 | public static void ToEntity(DT.StateLog source, DB.StateLog target) {
|
---|
| 111 | if ((source != null) && (target != null)) {
|
---|
| 112 | target.StateLogId = source.Id; target.DateTime = source.DateTime; target.Exception = source.Exception; target.TaskId = source.TaskId; target.SlaveId = source.SlaveId; target.State = Convert.ToEntity(source.State); target.UserId = source.UserId;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | #endregion
|
---|
| 116 |
|
---|
| 117 | #region Downtimes
|
---|
| 118 | public static DT.Downtime ToDto(DB.Downtime source) {
|
---|
| 119 | if (source == null) return null;
|
---|
| 120 | 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 };
|
---|
| 121 | }
|
---|
| 122 | public static DB.Downtime ToEntity(DT.Downtime source) {
|
---|
| 123 | if (source == null) return null;
|
---|
| 124 | var entity = new DB.Downtime(); ToEntity(source, entity);
|
---|
| 125 | return entity;
|
---|
| 126 | }
|
---|
| 127 | public static void ToEntity(DT.Downtime source, DB.Downtime target) {
|
---|
| 128 | if ((source != null) && (target != null)) {
|
---|
| 129 | 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;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | #endregion
|
---|
| 133 |
|
---|
| 134 | #region Job
|
---|
| 135 | public static DT.Job ToDto(DB.Job source) {
|
---|
| 136 | if (source == null) return null;
|
---|
| 137 | return new DT.Job { Id = source.JobId, Description = source.Description, Name = source.Name, OwnerUserId = source.OwnerUserId, DateCreated = source.DateCreated, ResourceNames = source.ResourceIds };
|
---|
| 138 | }
|
---|
| 139 | public static DB.Job ToEntity(DT.Job source) {
|
---|
| 140 | if (source == null) return null;
|
---|
| 141 | var entity = new DB.Job(); ToEntity(source, entity);
|
---|
| 142 | return entity;
|
---|
| 143 | }
|
---|
| 144 | public static void ToEntity(DT.Job source, DB.Job target) {
|
---|
| 145 | if ((source != null) && (target != null)) {
|
---|
| 146 | target.JobId = source.Id; target.Description = source.Description; target.Name = source.Name; target.OwnerUserId = source.OwnerUserId; target.DateCreated = source.DateCreated; target.ResourceIds = source.ResourceNames;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | #endregion
|
---|
| 150 |
|
---|
| 151 | #region JobPermission
|
---|
| 152 | public static DT.JobPermission ToDto(DB.JobPermission source) {
|
---|
| 153 | if (source == null) return null;
|
---|
| 154 | return new DT.JobPermission { JobId = source.JobId, GrantedUserId = source.GrantedUserId, GrantedByUserId = source.GrantedByUserId, Permission = Convert.ToDto(source.Permission) };
|
---|
| 155 | }
|
---|
| 156 | public static DB.JobPermission ToEntity(DT.JobPermission source) {
|
---|
| 157 | if (source == null) return null;
|
---|
| 158 | var entity = new DB.JobPermission(); ToEntity(source, entity);
|
---|
| 159 | return entity;
|
---|
| 160 | }
|
---|
| 161 | public static void ToEntity(DT.JobPermission source, DB.JobPermission target) {
|
---|
| 162 | if ((source != null) && (target != null)) {
|
---|
| 163 | target.JobId = source.JobId; target.GrantedUserId = source.GrantedUserId; target.GrantedByUserId = source.GrantedByUserId; target.Permission = Convert.ToEntity(source.Permission);
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | #endregion
|
---|
| 167 |
|
---|
| 168 | #region Plugin
|
---|
| 169 | public static DT.Plugin ToDto(DB.Plugin source) {
|
---|
| 170 | if (source == null) return null;
|
---|
| 171 | return new DT.Plugin { Id = source.PluginId, Name = source.Name, Version = new Version(source.Version), UserId = source.UserId, DateCreated = source.DateCreated, Hash = source.Hash };
|
---|
| 172 | }
|
---|
| 173 | public static DB.Plugin ToEntity(DT.Plugin source) {
|
---|
| 174 | if (source == null) return null;
|
---|
| 175 | var entity = new DB.Plugin(); ToEntity(source, entity);
|
---|
| 176 | return entity;
|
---|
| 177 | }
|
---|
| 178 | public static void ToEntity(DT.Plugin source, DB.Plugin target) {
|
---|
| 179 | if ((source != null) && (target != null)) {
|
---|
| 180 | 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;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | #endregion
|
---|
| 184 |
|
---|
| 185 | #region PluginData
|
---|
| 186 | public static DT.PluginData ToDto(DB.PluginData source) {
|
---|
| 187 | if (source == null) return null;
|
---|
| 188 | return new DT.PluginData { Id = source.PluginDataId, PluginId = source.PluginId, Data = source.Data.ToArray(), FileName = source.FileName };
|
---|
| 189 | }
|
---|
| 190 | public static DB.PluginData ToEntity(DT.PluginData source) {
|
---|
| 191 | if (source == null) return null;
|
---|
| 192 | var entity = new DB.PluginData(); ToEntity(source, entity);
|
---|
| 193 | return entity;
|
---|
| 194 | }
|
---|
| 195 | public static void ToEntity(DT.PluginData source, DB.PluginData target) {
|
---|
| 196 | if ((source != null) && (target != null)) {
|
---|
| 197 | target.PluginDataId = source.Id; target.PluginId = source.PluginId; target.Data = new Binary(source.Data); target.FileName = source.FileName;
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | #endregion
|
---|
| 201 |
|
---|
| 202 | #region Slave
|
---|
| 203 | public static DT.Slave ToDto(DB.Slave source) {
|
---|
| 204 | if (source == null) return null;
|
---|
| 205 | return new DT.Slave {
|
---|
| 206 | Id = source.ResourceId,
|
---|
| 207 | ParentResourceId = source.ParentResourceId,
|
---|
| 208 | Cores = source.Cores,
|
---|
| 209 | CpuSpeed = source.CpuSpeed,
|
---|
| 210 | FreeCores = source.FreeCores,
|
---|
| 211 | FreeMemory = source.FreeMemory,
|
---|
| 212 | IsAllowedToCalculate = source.IsAllowedToCalculate,
|
---|
| 213 | Memory = source.Memory,
|
---|
| 214 | Name = source.Name,
|
---|
| 215 | SlaveState = Convert.ToDto(source.SlaveState),
|
---|
| 216 | CpuArchitecture = Convert.ToDto(source.CpuArchitecture),
|
---|
| 217 | OperatingSystem = source.OperatingSystem,
|
---|
| 218 | LastHeartbeat = source.LastHeartbeat,
|
---|
| 219 | CpuUtilization = source.CpuUtilization,
|
---|
| 220 | HbInterval = source.HbInterval
|
---|
| 221 | };
|
---|
| 222 | }
|
---|
| 223 | public static DB.Slave ToEntity(DT.Slave source) {
|
---|
| 224 | if (source == null) return null;
|
---|
| 225 | var entity = new DB.Slave(); ToEntity(source, entity);
|
---|
| 226 | return entity;
|
---|
| 227 | }
|
---|
| 228 | public static void ToEntity(DT.Slave source, DB.Slave target) {
|
---|
| 229 | if ((source != null) && (target != null)) {
|
---|
| 230 | target.ResourceId = source.Id;
|
---|
| 231 | target.ParentResourceId = source.ParentResourceId;
|
---|
| 232 | target.Cores = source.Cores;
|
---|
| 233 | target.CpuSpeed = source.CpuSpeed;
|
---|
| 234 | target.FreeCores = source.FreeCores;
|
---|
| 235 | target.FreeMemory = source.FreeMemory;
|
---|
| 236 | target.IsAllowedToCalculate = source.IsAllowedToCalculate;
|
---|
| 237 | target.Memory = source.Memory;
|
---|
| 238 | target.Name = source.Name;
|
---|
| 239 | target.SlaveState = Convert.ToEntity(source.SlaveState);
|
---|
| 240 | target.CpuArchitecture = Convert.ToEntity(source.CpuArchitecture);
|
---|
| 241 | target.OperatingSystem = source.OperatingSystem;
|
---|
| 242 | target.LastHeartbeat = source.LastHeartbeat;
|
---|
| 243 | target.CpuUtilization = source.CpuUtilization;
|
---|
| 244 | target.HbInterval = source.HbInterval;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | #endregion
|
---|
| 248 |
|
---|
| 249 | #region SlaveGroup
|
---|
| 250 | public static DT.SlaveGroup ToDto(DB.SlaveGroup source) {
|
---|
| 251 | if (source == null) return null;
|
---|
| 252 | return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId, HbInterval = source.HbInterval };
|
---|
| 253 | }
|
---|
| 254 | public static DB.SlaveGroup ToEntity(DT.SlaveGroup source) {
|
---|
| 255 | if (source == null) return null;
|
---|
| 256 | var entity = new DB.SlaveGroup(); ToEntity(source, entity);
|
---|
| 257 | return entity;
|
---|
| 258 | }
|
---|
| 259 | public static void ToEntity(DT.SlaveGroup source, DB.SlaveGroup target) {
|
---|
| 260 | if ((source != null) && (target != null)) {
|
---|
| 261 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId; target.HbInterval = source.HbInterval;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | #endregion
|
---|
| 265 |
|
---|
| 266 | #region Resource
|
---|
| 267 | public static DT.Resource ToDto(DB.Resource source) {
|
---|
| 268 | if (source == null) return null;
|
---|
| 269 | return new DT.Resource { Id = source.ResourceId, Name = source.Name, ParentResourceId = source.ParentResourceId, HbInterval = source.HbInterval };
|
---|
| 270 | }
|
---|
| 271 | public static DB.Resource ToEntity(DT.Resource source) {
|
---|
| 272 | if (source == null) return null;
|
---|
| 273 | var entity = new DB.Resource(); ToEntity(source, entity);
|
---|
| 274 | return entity;
|
---|
| 275 | }
|
---|
| 276 | public static void ToEntity(DT.Resource source, DB.Resource target) {
|
---|
| 277 | if ((source != null) && (target != null)) {
|
---|
| 278 | target.ResourceId = source.Id; target.Name = source.Name; target.ParentResourceId = source.ParentResourceId; target.HbInterval = source.HbInterval;
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | #endregion
|
---|
| 282 |
|
---|
| 283 | #region Statistics
|
---|
| 284 | public static DT.Statistics ToDto(DB.Statistics source) {
|
---|
| 285 | if (source == null) return null;
|
---|
| 286 | return new DT.Statistics {
|
---|
| 287 | Id = source.StatisticsId,
|
---|
| 288 | TimeStamp = source.Timestamp,
|
---|
| 289 | SlaveStatistics = source.SlaveStatistics.Select(x => Convert.ToDto(x)).ToArray(),
|
---|
| 290 | UserStatistics = source.UserStatistics.Select(x => Convert.ToDto(x)).ToArray()
|
---|
| 291 | };
|
---|
| 292 | }
|
---|
| 293 | public static DB.Statistics ToEntity(DT.Statistics source) {
|
---|
| 294 | if (source == null) return null;
|
---|
| 295 | var entity = new DB.Statistics(); ToEntity(source, entity);
|
---|
| 296 | return entity;
|
---|
| 297 | }
|
---|
| 298 | public static void ToEntity(DT.Statistics source, DB.Statistics target) {
|
---|
| 299 | if ((source != null) && (target != null)) {
|
---|
| 300 | target.StatisticsId = source.Id;
|
---|
| 301 | target.Timestamp = source.TimeStamp;
|
---|
| 302 |
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 | #endregion
|
---|
| 306 |
|
---|
| 307 | #region SlaveStatistics
|
---|
| 308 | public static DT.SlaveStatistics ToDto(DB.SlaveStatistics source) {
|
---|
| 309 | if (source == null) return null;
|
---|
| 310 | return new DT.SlaveStatistics {
|
---|
| 311 | Id = source.StatisticsId,
|
---|
| 312 | SlaveId = source.SlaveId,
|
---|
| 313 | Cores = source.Cores,
|
---|
| 314 | CpuUtilization = source.CpuUtilization,
|
---|
| 315 | FreeCores = source.FreeCores,
|
---|
| 316 | FreeMemory = source.FreeMemory,
|
---|
| 317 | Memory = source.Memory
|
---|
| 318 | };
|
---|
| 319 | }
|
---|
| 320 | public static DB.SlaveStatistics ToEntity(DT.SlaveStatistics source) {
|
---|
| 321 | if (source == null) return null;
|
---|
| 322 | var entity = new DB.SlaveStatistics(); ToEntity(source, entity);
|
---|
| 323 | return entity;
|
---|
| 324 | }
|
---|
| 325 | public static void ToEntity(DT.SlaveStatistics source, DB.SlaveStatistics target) {
|
---|
| 326 | if ((source != null) && (target != null)) {
|
---|
| 327 | target.StatisticsId = source.Id;
|
---|
| 328 | target.SlaveId = source.SlaveId;
|
---|
| 329 | target.Cores = source.Cores;
|
---|
| 330 | target.CpuUtilization = source.CpuUtilization;
|
---|
| 331 | target.FreeCores = source.FreeCores;
|
---|
| 332 | target.FreeMemory = source.FreeMemory;
|
---|
| 333 | target.Memory = source.Memory;
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 | #endregion
|
---|
| 337 |
|
---|
| 338 | #region UserStatistics
|
---|
| 339 | public static DT.UserStatistics ToDto(DB.UserStatistics source) {
|
---|
| 340 | if (source == null) return null;
|
---|
| 341 | return new DT.UserStatistics {
|
---|
| 342 | Id = source.StatisticsId,
|
---|
| 343 | UserId = source.UserId,
|
---|
| 344 | UsedCores = source.UsedCores,
|
---|
| 345 | ExecutionTime = TimeSpan.FromMilliseconds(source.ExecutionTimeMs),
|
---|
| 346 | ExecutionTimeFinishedJobs = TimeSpan.FromMilliseconds(source.ExecutionTimeMsFinishedJobs),
|
---|
| 347 | StartToEndTime = TimeSpan.FromMilliseconds(source.StartToEndTimeMs)
|
---|
| 348 | };
|
---|
| 349 | }
|
---|
| 350 | public static DB.UserStatistics ToEntity(DT.UserStatistics source) {
|
---|
| 351 | if (source == null) return null;
|
---|
| 352 | var entity = new DB.UserStatistics(); ToEntity(source, entity);
|
---|
| 353 | return entity;
|
---|
| 354 | }
|
---|
| 355 | public static void ToEntity(DT.UserStatistics source, DB.UserStatistics target) {
|
---|
| 356 | if ((source != null) && (target != null)) {
|
---|
| 357 | target.StatisticsId = source.Id;
|
---|
| 358 | target.UserId = source.UserId;
|
---|
| 359 | target.UsedCores = source.UsedCores;
|
---|
| 360 | target.ExecutionTimeMs = source.ExecutionTime.TotalMilliseconds;
|
---|
| 361 | target.ExecutionTimeMsFinishedJobs = source.ExecutionTimeFinishedJobs.TotalMilliseconds;
|
---|
| 362 | target.StartToEndTimeMs = source.StartToEndTime.TotalMilliseconds;
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | #endregion
|
---|
| 366 |
|
---|
| 367 | #region TaskData
|
---|
| 368 | public static DT.TaskState ToDto(DB.TaskState source) {
|
---|
| 369 | if (source == DB.TaskState.Aborted) {
|
---|
| 370 | return TaskState.Aborted;
|
---|
| 371 | } else if (source == DB.TaskState.Calculating) {
|
---|
| 372 | return TaskState.Calculating;
|
---|
| 373 | } else if (source == DB.TaskState.Failed) {
|
---|
| 374 | return TaskState.Failed;
|
---|
| 375 | } else if (source == DB.TaskState.Finished) {
|
---|
| 376 | return TaskState.Finished;
|
---|
| 377 | } else if (source == DB.TaskState.Offline) {
|
---|
| 378 | return TaskState.Offline;
|
---|
| 379 | } else if (source == DB.TaskState.Paused) {
|
---|
| 380 | return TaskState.Paused;
|
---|
| 381 | } else if (source == DB.TaskState.Transferring) {
|
---|
| 382 | return TaskState.Transferring;
|
---|
| 383 | } else if (source == DB.TaskState.Waiting) {
|
---|
| 384 | return TaskState.Waiting;
|
---|
| 385 | } else
|
---|
| 386 | return TaskState.Failed;
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | public static DB.TaskState ToEntity(DT.TaskState source) {
|
---|
| 390 | if (source == DT.TaskState.Aborted) {
|
---|
| 391 | return DB.TaskState.Aborted;
|
---|
| 392 | } else if (source == DT.TaskState.Calculating) {
|
---|
| 393 | return DB.TaskState.Calculating;
|
---|
| 394 | } else if (source == DT.TaskState.Failed) {
|
---|
| 395 | return DB.TaskState.Failed;
|
---|
| 396 | } else if (source == DT.TaskState.Finished) {
|
---|
| 397 | return DB.TaskState.Finished;
|
---|
| 398 | } else if (source == DT.TaskState.Offline) {
|
---|
| 399 | return DB.TaskState.Offline;
|
---|
| 400 | } else if (source == DT.TaskState.Paused) {
|
---|
| 401 | return DB.TaskState.Paused;
|
---|
| 402 | } else if (source == DT.TaskState.Transferring) {
|
---|
| 403 | return DB.TaskState.Transferring;
|
---|
| 404 | } else if (source == DT.TaskState.Waiting) {
|
---|
| 405 | return DB.TaskState.Waiting;
|
---|
| 406 | } else
|
---|
| 407 | return DB.TaskState.Failed;
|
---|
| 408 | }
|
---|
| 409 | #endregion
|
---|
| 410 |
|
---|
| 411 | #region Permission
|
---|
| 412 | public static DT.Permission ToDto(DB.Permission source) {
|
---|
| 413 | if (source == DB.Permission.Full) {
|
---|
| 414 | return Permission.Full;
|
---|
| 415 | } else if (source == DB.Permission.NotAllowed) {
|
---|
| 416 | return Permission.NotAllowed;
|
---|
| 417 | } else if (source == DB.Permission.Read) {
|
---|
| 418 | return Permission.Read;
|
---|
| 419 | } else
|
---|
| 420 | return Permission.NotAllowed;
|
---|
| 421 | }
|
---|
| 422 |
|
---|
| 423 | public static DB.Permission ToEntity(DT.Permission source) {
|
---|
| 424 | if (source == DT.Permission.Full) {
|
---|
| 425 | return DB.Permission.Full;
|
---|
| 426 | } else if (source == DT.Permission.NotAllowed) {
|
---|
| 427 | return DB.Permission.NotAllowed;
|
---|
| 428 | } else if (source == DT.Permission.Read) {
|
---|
| 429 | return DB.Permission.Read;
|
---|
| 430 | } else
|
---|
| 431 | return DB.Permission.NotAllowed;
|
---|
| 432 | }
|
---|
| 433 | #endregion
|
---|
| 434 |
|
---|
| 435 | #region Command
|
---|
| 436 | public static DT.Command? ToDto(DB.Command? source) {
|
---|
| 437 | if (source.HasValue) {
|
---|
| 438 | if (source.Value == DB.Command.Abort) {
|
---|
| 439 | return Command.Abort;
|
---|
| 440 | } else if (source.Value == DB.Command.Pause) {
|
---|
| 441 | return Command.Pause;
|
---|
| 442 | } else if (source.Value == DB.Command.Stop) {
|
---|
| 443 | return Command.Stop;
|
---|
| 444 | } else
|
---|
| 445 | return Command.Pause;
|
---|
| 446 | }
|
---|
| 447 | return null;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | public static DB.Command? ToEntity(DT.Command? source) {
|
---|
| 451 | if (source.HasValue) {
|
---|
| 452 | if (source == DT.Command.Abort) {
|
---|
| 453 | return DB.Command.Abort;
|
---|
| 454 | } else if (source == DT.Command.Pause) {
|
---|
| 455 | return DB.Command.Pause;
|
---|
| 456 | } else if (source == DT.Command.Stop) {
|
---|
| 457 | return DB.Command.Stop;
|
---|
| 458 | } else
|
---|
| 459 | return DB.Command.Pause;
|
---|
| 460 | } else
|
---|
| 461 | return null;
|
---|
| 462 | }
|
---|
| 463 | #endregion
|
---|
| 464 |
|
---|
| 465 | #region CpuArchiteture
|
---|
| 466 | public static DT.CpuArchitecture ToDto(DB.CpuArchitecture source) {
|
---|
| 467 | if (source == DB.CpuArchitecture.x64) {
|
---|
| 468 | return CpuArchitecture.x64;
|
---|
| 469 | } else if (source == DB.CpuArchitecture.x86) {
|
---|
| 470 | return CpuArchitecture.x86;
|
---|
| 471 | } else
|
---|
| 472 | return CpuArchitecture.x86;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | public static DB.CpuArchitecture ToEntity(DT.CpuArchitecture source) {
|
---|
| 476 | if (source == DT.CpuArchitecture.x64) {
|
---|
| 477 | return DB.CpuArchitecture.x64;
|
---|
| 478 | } else if (source == DT.CpuArchitecture.x86) {
|
---|
| 479 | return DB.CpuArchitecture.x86;
|
---|
| 480 | } else
|
---|
| 481 | return DB.CpuArchitecture.x86;
|
---|
| 482 | }
|
---|
| 483 | #endregion
|
---|
| 484 |
|
---|
| 485 | #region SlaveState
|
---|
| 486 | public static DT.SlaveState ToDto(DB.SlaveState source) {
|
---|
| 487 | if (source == DB.SlaveState.Calculating) {
|
---|
| 488 | return SlaveState.Calculating;
|
---|
| 489 | } else if (source == DB.SlaveState.Idle) {
|
---|
| 490 | return SlaveState.Idle;
|
---|
| 491 | } else if (source == DB.SlaveState.Offline) {
|
---|
| 492 | return SlaveState.Offline;
|
---|
| 493 | } else
|
---|
| 494 | return SlaveState.Offline;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | public static DB.SlaveState ToEntity(DT.SlaveState source) {
|
---|
| 498 | if (source == DT.SlaveState.Calculating) {
|
---|
| 499 | return DB.SlaveState.Calculating;
|
---|
| 500 | } else if (source == DT.SlaveState.Idle) {
|
---|
| 501 | return DB.SlaveState.Idle;
|
---|
| 502 | } else if (source == DT.SlaveState.Offline) {
|
---|
| 503 | return DB.SlaveState.Offline;
|
---|
| 504 | } else
|
---|
| 505 | return DB.SlaveState.Offline;
|
---|
| 506 | }
|
---|
| 507 | #endregion
|
---|
| 508 | }
|
---|
| 509 | }
|
---|