Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs @ 833

Last change on this file since 833 was 826, checked in by svonolfe, 16 years ago

Added initial version of the DAL (#372)

File size: 3.6 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28
29namespace HeuristicLab.Hive.Server.ADODataAccess {
30  class ClientAdapter: IClientAdapter {
31    #region IClientAdapter Members
32    private dsHiveServerTableAdapters.ClientTableAdapter adapter =
33        new dsHiveServerTableAdapters.ClientTableAdapter();
34
35    private ResourceAdapter resAdapter =
36      new ResourceAdapter();
37
38    public void UpdateClient(ClientInfo client) {
39      if (client != null) {
40        resAdapter.UpdateResource(client);
41
42        dsHiveServer.ClientDataTable data =
43          adapter.GetDataById(client.ClientId);
44
45        dsHiveServer.ClientRow row;
46        if (data.Count == 0) {
47          row = data.NewClientRow();
48          row.ResourceId = client.ResourceId;
49          data.AddClientRow(row);
50        } else {
51          row = data[0];
52        }
53
54        row.ResourceId = client.ResourceId;
55        row.GUID = client.ClientId;
56        row.CPUSpeed = client.CpuSpeedPerCore;
57        //row.Memory = client.Memory;
58        /*if(client.Login != null)
59          row.Login = client.Login.ToString();*/
60        row.Status = client.State.ToString();
61       
62        //todo: config adapter
63        /*if (client.Config != null)
64          row.ClientConfigId = client.Config.ClientConfigId;*/
65       
66        row.NumberOfCores = client.NrOfCores;
67
68        adapter.Update(data);
69      }
70    }
71
72    private ClientInfo Convert(dsHiveServer.ClientRow row) {
73      ClientInfo client = new ClientInfo();
74
75      client.ResourceId = row.ResourceId;
76      client.ClientId = row.GUID;
77      client.CpuSpeedPerCore = row.CPUSpeed;
78      //client.Memory = row.Memory;
79      //client.Login = row.Login;
80      //client.State =;
81      //client.Config
82      client.NrOfCores = row.NumberOfCores;
83
84      return client;
85    }
86
87    public ClientInfo GetClientById(Guid clientId) {
88      dsHiveServer.ClientDataTable data =
89          adapter.GetDataById(clientId);
90      if (data.Count == 1) {
91        dsHiveServer.ClientRow row =
92          data[0];
93        return Convert(row);
94      } else {
95        return null;
96      }
97    }
98
99    public ICollection<ClientInfo> GetAllClients() {
100      ICollection<ClientInfo> allClients =
101        new List<ClientInfo>();
102
103      dsHiveServer.ClientDataTable data =
104          adapter.GetData();
105
106      foreach (dsHiveServer.ClientRow row in data) {
107        allClients.Add(Convert(row));
108      }
109
110      return allClients;
111    }
112
113    public bool DeleteClient(ClientInfo client) {
114      //referential integrity will delete the client object
115      return resAdapter.DeleteResource(client);
116    }
117
118    #endregion
119  }
120}
Note: See TracBrowser for help on using the repository browser.