[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;
|
---|
[826] | 34 |
|
---|
| 35 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
[1468] | 36 | class ClientAdapterWrapper :
|
---|
| 37 | DataAdapterWrapperBase<
|
---|
| 38 | dsHiveServerTableAdapters.ClientTableAdapter,
|
---|
| 39 | ClientInfo,
|
---|
| 40 | dsHiveServer.ClientRow> {
|
---|
| 41 | public override void UpdateRow(dsHiveServer.ClientRow row) {
|
---|
| 42 | TransactionalAdapter.Update(row);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public override dsHiveServer.ClientRow
|
---|
| 46 | InsertNewRow(ClientInfo client) {
|
---|
| 47 | dsHiveServer.ClientDataTable data =
|
---|
| 48 | new dsHiveServer.ClientDataTable();
|
---|
| 49 |
|
---|
| 50 | dsHiveServer.ClientRow row = data.NewClientRow();
|
---|
| 51 | row.ResourceId = client.Id;
|
---|
| 52 | data.AddClientRow(row);
|
---|
| 53 |
|
---|
| 54 | return row;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public override IEnumerable<dsHiveServer.ClientRow>
|
---|
| 58 | FindById(Guid id) {
|
---|
| 59 | return TransactionalAdapter.GetDataById(id);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public override IEnumerable<dsHiveServer.ClientRow>
|
---|
| 63 | FindAll() {
|
---|
| 64 | return TransactionalAdapter.GetData();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | protected override void SetConnection(DbConnection connection) {
|
---|
| 68 | adapter.Connection = connection as SqlConnection;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected override void SetTransaction(DbTransaction transaction) {
|
---|
| 72 | adapter.Transaction = transaction as SqlTransaction;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[995] | 76 | class ClientAdapter:
|
---|
[1468] | 77 | DataAdapterBase<
|
---|
[995] | 78 | dsHiveServerTableAdapters.ClientTableAdapter,
|
---|
| 79 | ClientInfo,
|
---|
[1468] | 80 | dsHiveServer.ClientRow>,
|
---|
[995] | 81 | IClientAdapter {
|
---|
| 82 | #region Fields
|
---|
[948] | 83 | private IResourceAdapter resAdapter = null;
|
---|
[925] | 84 |
|
---|
[948] | 85 | private IResourceAdapter ResAdapter {
|
---|
| 86 | get {
|
---|
| 87 | if (resAdapter == null)
|
---|
[1468] | 88 | resAdapter =
|
---|
| 89 | this.Session.GetDataAdapter<Resource, IResourceAdapter>();
|
---|
[948] | 90 |
|
---|
| 91 | return resAdapter;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[965] | 95 | private IClientGroupAdapter clientGroupAdapter = null;
|
---|
| 96 |
|
---|
| 97 | private IClientGroupAdapter ClientGroupAdapter {
|
---|
| 98 | get {
|
---|
| 99 | if (clientGroupAdapter == null) {
|
---|
[1468] | 100 | clientGroupAdapter =
|
---|
| 101 | this.Session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
[965] | 102 | }
|
---|
| 103 |
|
---|
| 104 | return clientGroupAdapter;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[971] | 108 | private IJobAdapter jobAdapter = null;
|
---|
| 109 |
|
---|
| 110 | private IJobAdapter JobAdapter {
|
---|
| 111 | get {
|
---|
| 112 | if (jobAdapter == null) {
|
---|
[1468] | 113 | this.Session.GetDataAdapter<Job, IJobAdapter>();
|
---|
[971] | 114 | }
|
---|
| 115 |
|
---|
| 116 | return jobAdapter;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[995] | 119 | #endregion
|
---|
[971] | 120 |
|
---|
[1468] | 121 | public ClientAdapter():
|
---|
| 122 | base(new ClientAdapterWrapper()) {
|
---|
[925] | 123 | }
|
---|
| 124 |
|
---|
[995] | 125 | #region Overrides
|
---|
[1131] | 126 | protected override ClientInfo ConvertRow(dsHiveServer.ClientRow row,
|
---|
[899] | 127 | ClientInfo client) {
|
---|
| 128 | if(row != null && client != null) {
|
---|
[845] | 129 | /*Parent - resource*/
|
---|
[995] | 130 | client.Id = row.ResourceId;
|
---|
| 131 | ResAdapter.GetById(client);
|
---|
[826] | 132 |
|
---|
[1449] | 133 | /*ClientInfo*/
|
---|
[899] | 134 | if (!row.IsCPUSpeedNull())
|
---|
| 135 | client.CpuSpeedPerCore = row.CPUSpeed;
|
---|
| 136 | else
|
---|
| 137 | client.CpuSpeedPerCore = 0;
|
---|
| 138 |
|
---|
| 139 | if (!row.IsMemoryNull())
|
---|
| 140 | client.Memory = row.Memory;
|
---|
| 141 | else
|
---|
| 142 | client.Memory = 0;
|
---|
| 143 |
|
---|
| 144 | if (!row.IsLoginNull())
|
---|
| 145 | client.Login = row.Login;
|
---|
| 146 | else
|
---|
| 147 | client.Login = DateTime.MinValue;
|
---|
| 148 |
|
---|
| 149 | if (!row.IsStatusNull())
|
---|
[845] | 150 | client.State = (State)Enum.Parse(typeof(State), row.Status, true);
|
---|
[899] | 151 | else
|
---|
[995] | 152 | client.State = State.nullState;
|
---|
[845] | 153 |
|
---|
[899] | 154 | if (!row.IsNumberOfCoresNull())
|
---|
| 155 | client.NrOfCores = row.NumberOfCores;
|
---|
| 156 | else
|
---|
| 157 | client.NrOfCores = 0;
|
---|
| 158 |
|
---|
[1505] | 159 | if (!row.IsNumberOfFreeCoresNull())
|
---|
| 160 | client.NrOfFreeCores = row.NumberOfFreeCores;
|
---|
| 161 | else
|
---|
| 162 | client.NrOfFreeCores = 0;
|
---|
| 163 |
|
---|
| 164 | if (!row.IsFreeMemoryNull())
|
---|
| 165 | client.FreeMemory = row.FreeMemory;
|
---|
| 166 | else
|
---|
| 167 | client.FreeMemory = 0;
|
---|
| 168 |
|
---|
[845] | 169 | //todo: config adapter (client.config)
|
---|
| 170 |
|
---|
| 171 | return client;
|
---|
| 172 | }
|
---|
| 173 | else
|
---|
| 174 | return null;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[1131] | 177 | protected override dsHiveServer.ClientRow ConvertObj(ClientInfo client,
|
---|
[845] | 178 | dsHiveServer.ClientRow row) {
|
---|
[1449] | 179 | if (client != null && row != null) {
|
---|
| 180 | row.ResourceId = client.Id;
|
---|
[845] | 181 | row.CPUSpeed = client.CpuSpeedPerCore;
|
---|
| 182 | row.Memory = client.Memory;
|
---|
| 183 | row.Login = client.Login;
|
---|
[995] | 184 | if (client.State != State.nullState)
|
---|
| 185 | row.Status = client.State.ToString();
|
---|
| 186 | else
|
---|
| 187 | row.SetStatusNull();
|
---|
[845] | 188 | row.NumberOfCores = client.NrOfCores;
|
---|
[1505] | 189 | row.NumberOfFreeCores = client.NrOfFreeCores;
|
---|
| 190 | row.FreeMemory = client.FreeMemory;
|
---|
[845] | 191 |
|
---|
| 192 | //todo: config adapter
|
---|
| 193 | /*if (client.Config != null)
|
---|
| 194 | row.ClientConfigId = client.Config.ClientConfigId;
|
---|
| 195 | else
|
---|
| 196 | row.ClientConfigId = null;*/
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | return row;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[995] | 202 | #endregion
|
---|
[965] | 203 |
|
---|
[995] | 204 | #region IClientAdapter Members
|
---|
[1468] | 205 | protected override void doUpdate(ClientInfo client) {
|
---|
[995] | 206 | if (client != null) {
|
---|
| 207 | ResAdapter.Update(client);
|
---|
[971] | 208 |
|
---|
[1468] | 209 | base.doUpdate(client);
|
---|
[971] | 210 | }
|
---|
[995] | 211 | }
|
---|
[971] | 212 |
|
---|
[995] | 213 | public ClientInfo GetByName(string name) {
|
---|
| 214 | ClientInfo client = new ClientInfo();
|
---|
| 215 | Resource res =
|
---|
| 216 | ResAdapter.GetByName(name);
|
---|
[826] | 217 |
|
---|
[995] | 218 | return GetById(res.Id);
|
---|
[826] | 219 | }
|
---|
| 220 |
|
---|
[1468] | 221 | protected override bool doDelete(ClientInfo client) {
|
---|
[1175] | 222 | bool success = false;
|
---|
| 223 |
|
---|
[925] | 224 | if (client != null) {
|
---|
[995] | 225 | dsHiveServer.ClientRow row =
|
---|
| 226 | GetRowById(client.Id);
|
---|
[925] | 227 |
|
---|
| 228 | if (row != null) {
|
---|
[1468] | 229 | success = base.doDelete(client) &&
|
---|
[995] | 230 | ResAdapter.Delete(client);
|
---|
[925] | 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[1175] | 234 | return success;
|
---|
[826] | 235 | }
|
---|
| 236 |
|
---|
| 237 | #endregion
|
---|
| 238 | }
|
---|
| 239 | }
|
---|