[826] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
[1377] | 26 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[826] | 27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[925] | 28 | using System.Linq.Expressions;
|
---|
[1377] | 29 | using HeuristicLab.DataAccess.Interfaces;
|
---|
| 30 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
[1468] | 31 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
| 32 | using System.Data.Common;
|
---|
| 33 | using System.Data.SqlClient;
|
---|
[1580] | 34 | using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
|
---|
[826] | 35 |
|
---|
| 36 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[995] | 37 | class ClientAdapter:
|
---|
[1468] | 38 | DataAdapterBase<
|
---|
[995] | 39 | dsHiveServerTableAdapters.ClientTableAdapter,
|
---|
[3011] | 40 | ClientDto,
|
---|
[1468] | 41 | dsHiveServer.ClientRow>,
|
---|
[995] | 42 | IClientAdapter {
|
---|
| 43 | #region Fields
|
---|
[948] | 44 | private IResourceAdapter resAdapter = null;
|
---|
[925] | 45 |
|
---|
[948] | 46 | private IResourceAdapter ResAdapter {
|
---|
| 47 | get {
|
---|
| 48 | if (resAdapter == null)
|
---|
[1468] | 49 | resAdapter =
|
---|
[3011] | 50 | this.Session.GetDataAdapter<ResourceDto, IResourceAdapter>();
|
---|
[948] | 51 |
|
---|
| 52 | return resAdapter;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[965] | 56 | private IClientGroupAdapter clientGroupAdapter = null;
|
---|
| 57 |
|
---|
| 58 | private IClientGroupAdapter ClientGroupAdapter {
|
---|
| 59 | get {
|
---|
| 60 | if (clientGroupAdapter == null) {
|
---|
[1468] | 61 | clientGroupAdapter =
|
---|
[3011] | 62 | this.Session.GetDataAdapter<ClientGroupDto, IClientGroupAdapter>();
|
---|
[965] | 63 | }
|
---|
| 64 |
|
---|
| 65 | return clientGroupAdapter;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[971] | 69 | private IJobAdapter jobAdapter = null;
|
---|
| 70 |
|
---|
| 71 | private IJobAdapter JobAdapter {
|
---|
| 72 | get {
|
---|
| 73 | if (jobAdapter == null) {
|
---|
[3011] | 74 | this.Session.GetDataAdapter<JobDto, IJobAdapter>();
|
---|
[971] | 75 | }
|
---|
| 76 |
|
---|
| 77 | return jobAdapter;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[1999] | 80 |
|
---|
| 81 | private IClientConfigAdapter clientConfigAdapter = null;
|
---|
| 82 |
|
---|
| 83 | private IClientConfigAdapter ClientConfigAdapter {
|
---|
| 84 | get {
|
---|
| 85 | if (clientConfigAdapter == null) {
|
---|
| 86 | clientConfigAdapter =
|
---|
[3011] | 87 | this.Session.GetDataAdapter<ClientConfigDto, IClientConfigAdapter>();
|
---|
[1999] | 88 | }
|
---|
| 89 |
|
---|
| 90 | return clientConfigAdapter;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
[995] | 93 | #endregion
|
---|
[971] | 94 |
|
---|
[1468] | 95 | public ClientAdapter():
|
---|
| 96 | base(new ClientAdapterWrapper()) {
|
---|
[925] | 97 | }
|
---|
| 98 |
|
---|
[995] | 99 | #region Overrides
|
---|
[3011] | 100 | protected override ClientDto ConvertRow(dsHiveServer.ClientRow row,
|
---|
| 101 | ClientDto client) {
|
---|
[899] | 102 | if(row != null && client != null) {
|
---|
[845] | 103 | /*Parent - resource*/
|
---|
[995] | 104 | client.Id = row.ResourceId;
|
---|
| 105 | ResAdapter.GetById(client);
|
---|
[826] | 106 |
|
---|
[1449] | 107 | /*ClientInfo*/
|
---|
[899] | 108 | if (!row.IsCPUSpeedNull())
|
---|
| 109 | client.CpuSpeedPerCore = row.CPUSpeed;
|
---|
| 110 | else
|
---|
| 111 | client.CpuSpeedPerCore = 0;
|
---|
| 112 |
|
---|
| 113 | if (!row.IsMemoryNull())
|
---|
| 114 | client.Memory = row.Memory;
|
---|
| 115 | else
|
---|
| 116 | client.Memory = 0;
|
---|
| 117 |
|
---|
| 118 | if (!row.IsLoginNull())
|
---|
| 119 | client.Login = row.Login;
|
---|
| 120 | else
|
---|
| 121 | client.Login = DateTime.MinValue;
|
---|
| 122 |
|
---|
| 123 | if (!row.IsStatusNull())
|
---|
[845] | 124 | client.State = (State)Enum.Parse(typeof(State), row.Status, true);
|
---|
[899] | 125 | else
|
---|
[995] | 126 | client.State = State.nullState;
|
---|
[845] | 127 |
|
---|
[899] | 128 | if (!row.IsNumberOfCoresNull())
|
---|
| 129 | client.NrOfCores = row.NumberOfCores;
|
---|
| 130 | else
|
---|
| 131 | client.NrOfCores = 0;
|
---|
| 132 |
|
---|
[1505] | 133 | if (!row.IsNumberOfFreeCoresNull())
|
---|
| 134 | client.NrOfFreeCores = row.NumberOfFreeCores;
|
---|
| 135 | else
|
---|
| 136 | client.NrOfFreeCores = 0;
|
---|
| 137 |
|
---|
| 138 | if (!row.IsFreeMemoryNull())
|
---|
| 139 | client.FreeMemory = row.FreeMemory;
|
---|
| 140 | else
|
---|
| 141 | client.FreeMemory = 0;
|
---|
| 142 |
|
---|
[1999] | 143 | if (!row.IsClientConfigIdNull())
|
---|
| 144 | client.Config = ClientConfigAdapter.GetById(row.ClientConfigId);
|
---|
| 145 | else
|
---|
| 146 | client.Config = null;
|
---|
[845] | 147 |
|
---|
| 148 | return client;
|
---|
| 149 | }
|
---|
| 150 | else
|
---|
| 151 | return null;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[3011] | 154 | protected override dsHiveServer.ClientRow ConvertObj(ClientDto client,
|
---|
[845] | 155 | dsHiveServer.ClientRow row) {
|
---|
[1449] | 156 | if (client != null && row != null) {
|
---|
| 157 | row.ResourceId = client.Id;
|
---|
[845] | 158 | row.CPUSpeed = client.CpuSpeedPerCore;
|
---|
| 159 | row.Memory = client.Memory;
|
---|
| 160 | row.Login = client.Login;
|
---|
[995] | 161 | if (client.State != State.nullState)
|
---|
| 162 | row.Status = client.State.ToString();
|
---|
| 163 | else
|
---|
| 164 | row.SetStatusNull();
|
---|
[845] | 165 | row.NumberOfCores = client.NrOfCores;
|
---|
[1505] | 166 | row.NumberOfFreeCores = client.NrOfFreeCores;
|
---|
| 167 | row.FreeMemory = client.FreeMemory;
|
---|
[845] | 168 |
|
---|
[1999] | 169 | if (client.Config != null)
|
---|
| 170 | row.ClientConfigId = client.Config.Id;
|
---|
| 171 | else
|
---|
| 172 | row.SetClientConfigIdNull();
|
---|
[845] | 173 | }
|
---|
| 174 |
|
---|
| 175 | return row;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[995] | 178 | #endregion
|
---|
[965] | 179 |
|
---|
[995] | 180 | #region IClientAdapter Members
|
---|
[3011] | 181 | protected override void doUpdate(ClientDto client) {
|
---|
[995] | 182 | if (client != null) {
|
---|
| 183 | ResAdapter.Update(client);
|
---|
[1999] | 184 | ClientConfigAdapter.Update(client.Config);
|
---|
[971] | 185 |
|
---|
[1468] | 186 | base.doUpdate(client);
|
---|
[971] | 187 | }
|
---|
[995] | 188 | }
|
---|
[971] | 189 |
|
---|
[3011] | 190 | public ClientDto GetByName(string name) {
|
---|
| 191 | return (ClientDto)
|
---|
[2082] | 192 | base.doInTransaction(
|
---|
| 193 | delegate() {
|
---|
[3011] | 194 | ClientDto client = new ClientDto();
|
---|
| 195 | ResourceDto res =
|
---|
[2082] | 196 | ResAdapter.GetByName(name);
|
---|
[826] | 197 |
|
---|
[2082] | 198 | return GetById(res.Id);
|
---|
| 199 | });
|
---|
[826] | 200 | }
|
---|
| 201 |
|
---|
[3011] | 202 | protected override bool doDelete(ClientDto client) {
|
---|
[2082] | 203 | return (bool)base.doInTransaction(
|
---|
| 204 | delegate() {
|
---|
| 205 | bool success = false;
|
---|
[925] | 206 |
|
---|
[2082] | 207 | if (client != null) {
|
---|
| 208 | dsHiveServer.ClientRow row =
|
---|
| 209 | GetRowById(client.Id);
|
---|
[925] | 210 |
|
---|
[2082] | 211 | if (row != null) {
|
---|
| 212 | success = base.doDelete(client) &&
|
---|
| 213 | ResAdapter.Delete(client);
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | return success;
|
---|
| 218 | });
|
---|
[826] | 219 | }
|
---|
| 220 |
|
---|
[3011] | 221 | public ICollection<ClientDto> GetGrouplessClients() {
|
---|
[1634] | 222 | return
|
---|
| 223 | base.FindMultiple(
|
---|
| 224 | delegate() {
|
---|
| 225 | return Adapter.GetDataByGroupless();
|
---|
| 226 | });
|
---|
[1632] | 227 | }
|
---|
| 228 |
|
---|
[826] | 229 | #endregion
|
---|
| 230 | }
|
---|
| 231 | }
|
---|