Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/ClientManager.cs @ 995

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

Refactored DAL, Improved Caching (#372)

File size: 4.8 KB
RevLine 
[907]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;
[800]23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
[902]28using HeuristicLab.Hive.Contracts;
[929]29using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
[800]30
31namespace HeuristicLab.Hive.Server.Core {
32  class ClientManager: IClientManager {
[820]33
[929]34    IClientAdapter clientAdapter;
[934]35    IClientGroupAdapter clientGroupAdapter;
[929]36
[820]37    List<ClientGroup> clientGroups;
38
39    public ClientManager() {
[929]40      clientAdapter = ServiceLocator.GetClientAdapter();
[934]41      clientGroupAdapter = ServiceLocator.GetClientGroupAdapter();
[929]42
[820]43      clientGroups = new List<ClientGroup>();
44
[995]45      ClientGroup cg = new ClientGroup { Id = 4, Name = "SuperGroup" };
[829]46      cg.Resources = new List<Resource>();
[827]47
48      clientGroups.Add(cg);
[820]49    }
50
[800]51    #region IClientManager Members
52
[902]53    public ResponseList<ClientInfo> GetAllClients() {
[907]54      ResponseList<ClientInfo> response = new ResponseList<ClientInfo>();
[929]55
[995]56      response.List = new List<ClientInfo>(clientAdapter.GetAll());
[929]57      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
[907]58      response.Success = true;
[929]59
[907]60      return response;
[800]61    }
62
[902]63    public ResponseList<ClientGroup> GetAllClientGroups() {
[907]64      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
[934]65
[995]66      response.List = new List<ClientGroup>(clientGroupAdapter.GetAll());
[934]67      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
[907]68      response.Success = true;
[934]69
[907]70      return response;
[800]71    }
72
[902]73    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
[907]74      ResponseList<UpTimeStatistics> response = new ResponseList<UpTimeStatistics>();
75      response.Success = true;
76      return response;
[800]77    }
78
[934]79    public Response AddClientGroup(ClientGroup clientGroup) {
[937]80      Response response = new Response();
81
[995]82      if (clientGroup.Id != 0) {
[942]83        response.Success = false;
84        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
85        return response;
86      }
[995]87      clientGroupAdapter.Update(clientGroup);
[942]88      response.Success = true;
89      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
[937]90
91      return response;
[934]92    }
93
94    public Response AddResourceToGroup(long clientGroupId, Resource resource) {
[942]95      Response response = new Response();
96
[995]97      if (resource.Id != 0) {
[942]98        response.Success = false;
99        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
100        return response;
101      }
102
[995]103      ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
[942]104      if (clientGroup == null) {
105        response.Success = false;
106        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
107        return response;
108      }
109      clientGroup.Resources.Add(resource);
110
111      response.Success = true;
112      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
113
114      return response;
[934]115    }
116
117    public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) {
[942]118      Response response = new Response();
119
[995]120      ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
[942]121      if (clientGroup == null) {
122        response.Success = false;
123        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
124        return response;
125      }
126      foreach (Resource resource in clientGroup.Resources) {
[995]127        if (resource.Id == resourceId) {
[942]128          clientGroup.Resources.Remove(resource);
129          response.Success = true;
130          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
131          return response;
132        }
133      }
134      response.Success = false;
135      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
136
137      return response;
[934]138    }
[800]139    #endregion
140  }
141}
Note: See TracBrowser for help on using the repository browser.