Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1848 was 1634, checked in by svonolfe, 15 years ago

Updated ClientAdapter (#372)

File size: 5.7 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;
[1377]26using HeuristicLab.Hive.Server.DataAccess;
[826]27using HeuristicLab.Hive.Contracts.BusinessObjects;
[925]28using System.Linq.Expressions;
[1377]29using HeuristicLab.DataAccess.Interfaces;
30using HeuristicLab.DataAccess.ADOHelper;
[1468]31using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
32using System.Data.Common;
33using System.Data.SqlClient;
[1580]34using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
[826]35
36namespace HeuristicLab.Hive.Server.ADODataAccess {
[995]37  class ClientAdapter:
[1468]38    DataAdapterBase<
[995]39      dsHiveServerTableAdapters.ClientTableAdapter,
40      ClientInfo,
[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 =
50            this.Session.GetDataAdapter<Resource, 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 =
62            this.Session.GetDataAdapter<ClientGroup, 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) {
[1468]74          this.Session.GetDataAdapter<Job, IJobAdapter>();
[971]75        }
76
77        return jobAdapter;
78      }
79    }
[995]80    #endregion
[971]81
[1468]82    public ClientAdapter():
83      base(new ClientAdapterWrapper()) {
[925]84    }
85
[995]86    #region Overrides
[1131]87    protected override ClientInfo ConvertRow(dsHiveServer.ClientRow row,
[899]88      ClientInfo client) {
89      if(row != null && client != null) {     
[845]90        /*Parent - resource*/
[995]91        client.Id = row.ResourceId;
92        ResAdapter.GetById(client);
[826]93
[1449]94        /*ClientInfo*/       
[899]95        if (!row.IsCPUSpeedNull())
96          client.CpuSpeedPerCore = row.CPUSpeed;
97        else
98          client.CpuSpeedPerCore = 0;
99
100        if (!row.IsMemoryNull())
101          client.Memory = row.Memory;
102        else
103          client.Memory = 0;
104
105        if (!row.IsLoginNull())
106          client.Login = row.Login;
107        else
108          client.Login = DateTime.MinValue;
109
110        if (!row.IsStatusNull())
[845]111          client.State = (State)Enum.Parse(typeof(State), row.Status, true);
[899]112        else
[995]113          client.State = State.nullState;
[845]114
[899]115        if (!row.IsNumberOfCoresNull())
116          client.NrOfCores = row.NumberOfCores;
117        else
118          client.NrOfCores = 0;
119
[1505]120        if (!row.IsNumberOfFreeCoresNull())
121          client.NrOfFreeCores = row.NumberOfFreeCores;
122        else
123          client.NrOfFreeCores = 0;
124
125        if (!row.IsFreeMemoryNull())
126          client.FreeMemory = row.FreeMemory;
127        else
128          client.FreeMemory = 0;
129
[845]130        //todo: config adapter (client.config)
131
132        return client;
133      }
134      else
135        return null;
136    }
137
[1131]138    protected override dsHiveServer.ClientRow ConvertObj(ClientInfo client,
[845]139      dsHiveServer.ClientRow row) {
[1449]140      if (client != null && row != null) {
141        row.ResourceId = client.Id;
[845]142        row.CPUSpeed = client.CpuSpeedPerCore;
143        row.Memory = client.Memory;
144        row.Login = client.Login;
[995]145        if (client.State != State.nullState)
146          row.Status = client.State.ToString();
147        else
148          row.SetStatusNull();
[845]149        row.NumberOfCores = client.NrOfCores;
[1505]150        row.NumberOfFreeCores = client.NrOfFreeCores;
151        row.FreeMemory = client.FreeMemory;
[845]152
153        //todo: config adapter
154        /*if (client.Config != null)
155          row.ClientConfigId = client.Config.ClientConfigId;
156         else
157          row.ClientConfigId = null;*/
158      }
159
160      return row;
161    }
162
[995]163    #endregion
[965]164
[995]165    #region IClientAdapter Members
[1468]166    protected override void doUpdate(ClientInfo client) {
[995]167      if (client != null) {
168        ResAdapter.Update(client);
[971]169
[1468]170        base.doUpdate(client);
[971]171      }
[995]172    }
[971]173
[995]174    public ClientInfo GetByName(string name) {
175      ClientInfo client = new ClientInfo();
176      Resource res =
177        ResAdapter.GetByName(name);
[826]178
[995]179      return GetById(res.Id);
[826]180    }
181
[1468]182    protected override bool doDelete(ClientInfo client) {
[1175]183      bool success = false;
184     
[925]185      if (client != null) {
[995]186        dsHiveServer.ClientRow row =
187          GetRowById(client.Id);
[925]188
189        if (row != null) {
[1468]190          success = base.doDelete(client) &&
[995]191            ResAdapter.Delete(client);
[925]192        }
193      }
194
[1175]195      return success;
[826]196    }
197
[1632]198    public ICollection<ClientInfo> GetGrouplessClients() {
[1634]199      return
200        base.FindMultiple(
201          delegate() {
202            return Adapter.GetDataByGroupless();
203          });
[1632]204    }
205
[826]206    #endregion
207  }
208}
Note: See TracBrowser for help on using the repository browser.