Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1121 was 1121, checked in by msteinbi, 15 years ago

Add licencse information where missing, added method description comments (#466)

File size: 5.6 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
[1121]53    /// <summary>
54    /// Returns all clients stored in the database
55    /// </summary>
56    /// <returns></returns>
[902]57    public ResponseList<ClientInfo> GetAllClients() {
[907]58      ResponseList<ClientInfo> response = new ResponseList<ClientInfo>();
[929]59
[995]60      response.List = new List<ClientInfo>(clientAdapter.GetAll());
[929]61      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
[907]62      response.Success = true;
[929]63
[907]64      return response;
[800]65    }
66
[1121]67    /// <summary>
68    /// returns all client groups stored in the database
69    /// </summary>
70    /// <returns></returns>
[902]71    public ResponseList<ClientGroup> GetAllClientGroups() {
[907]72      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
[934]73
[995]74      response.List = new List<ClientGroup>(clientGroupAdapter.GetAll());
[934]75      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
[907]76      response.Success = true;
[934]77
[907]78      return response;
[800]79    }
80
[902]81    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
[907]82      ResponseList<UpTimeStatistics> response = new ResponseList<UpTimeStatistics>();
83      response.Success = true;
84      return response;
[800]85    }
86
[1121]87    /// <summary>
88    /// Add a client group into the database
89    /// </summary>
90    /// <param name="clientGroup"></param>
91    /// <returns></returns>
[934]92    public Response AddClientGroup(ClientGroup clientGroup) {
[937]93      Response response = new Response();
94
[995]95      if (clientGroup.Id != 0) {
[942]96        response.Success = false;
97        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
98        return response;
99      }
[995]100      clientGroupAdapter.Update(clientGroup);
[942]101      response.Success = true;
102      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
[937]103
104      return response;
[934]105    }
106
[1121]107    /// <summary>
108    ///  Add a resource to a group
109    /// </summary>
110    /// <param name="clientGroupId"></param>
111    /// <param name="resource"></param>
112    /// <returns></returns>
[934]113    public Response AddResourceToGroup(long clientGroupId, Resource resource) {
[942]114      Response response = new Response();
115
[995]116      if (resource.Id != 0) {
[942]117        response.Success = false;
118        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
119        return response;
120      }
121
[995]122      ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
[942]123      if (clientGroup == null) {
124        response.Success = false;
125        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
126        return response;
127      }
128      clientGroup.Resources.Add(resource);
129
130      response.Success = true;
131      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
132
133      return response;
[934]134    }
135
[1121]136    /// <summary>
137    /// Remove a resource from a group
138    /// </summary>
139    /// <param name="clientGroupId"></param>
140    /// <param name="resourceId"></param>
141    /// <returns></returns>
[934]142    public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) {
[942]143      Response response = new Response();
144
[995]145      ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
[942]146      if (clientGroup == null) {
147        response.Success = false;
148        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
149        return response;
150      }
151      foreach (Resource resource in clientGroup.Resources) {
[995]152        if (resource.Id == resourceId) {
[942]153          clientGroup.Resources.Remove(resource);
154          response.Success = true;
155          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
156          return response;
157        }
158      }
159      response.Success = false;
160      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
161
162      return response;
[934]163    }
[800]164    #endregion
165  }
166}
Note: See TracBrowser for help on using the repository browser.