Free cookie consent management tool by TermsFeed Policy Generator

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

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

Implementation of Client Manager (#427)

File size: 4.9 KB
Line 
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.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts;
29using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess;
30
31namespace HeuristicLab.Hive.Server.Core {
32  class ClientManager: IClientManager {
33
34    IClientAdapter clientAdapter;
35    IClientGroupAdapter clientGroupAdapter;
36
37    List<ClientGroup> clientGroups;
38
39    public ClientManager() {
40      clientAdapter = ServiceLocator.GetClientAdapter();
41      clientGroupAdapter = ServiceLocator.GetClientGroupAdapter();
42
43      clientGroups = new List<ClientGroup>();
44
45      ClientGroup cg = new ClientGroup { ResourceId = 4, Name = "SuperGroup" };
46      cg.Resources = new List<Resource>();
47
48      clientGroups.Add(cg);
49    }
50
51    #region IClientManager Members
52
53    public ResponseList<ClientInfo> GetAllClients() {
54      ResponseList<ClientInfo> response = new ResponseList<ClientInfo>();
55
56      response.List = new List<ClientInfo>(clientAdapter.GetAllClients());
57      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
58      response.Success = true;
59
60      return response;
61    }
62
63    public ResponseList<ClientGroup> GetAllClientGroups() {
64      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
65
66      response.List = new List<ClientGroup>(clientGroupAdapter.GetAllClientGroups());
67      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
68      response.Success = true;
69
70      return response;
71    }
72
73    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
74      ResponseList<UpTimeStatistics> response = new ResponseList<UpTimeStatistics>();
75      response.Success = true;
76      return response;
77    }
78
79    public Response AddClientGroup(ClientGroup clientGroup) {
80      Response response = new Response();
81
82      if (clientGroup.ResourceId != 0) {
83        response.Success = false;
84        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
85        return response;
86      }
87      clientGroupAdapter.UpdateClientGroup(clientGroup);
88      response.Success = true;
89      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
90
91      return response;
92    }
93
94    public Response AddResourceToGroup(long clientGroupId, Resource resource) {
95      Response response = new Response();
96
97      if (resource.ResourceId != 0) {
98        response.Success = false;
99        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
100        return response;
101      }
102
103      ClientGroup clientGroup = clientGroupAdapter.GetClientGroupById(clientGroupId);
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;
115    }
116
117    public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) {
118      Response response = new Response();
119
120      ClientGroup clientGroup = clientGroupAdapter.GetClientGroupById(clientGroupId);
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) {
127        if (resource.ResourceId == resourceId) {
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;
138    }
139    #endregion
140  }
141}
Note: See TracBrowser for help on using the repository browser.