#region License Information /* HeuristicLab * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Hive.Contracts.Interfaces; using HeuristicLab.Hive.Contracts.BusinessObjects; using HeuristicLab.Hive.Contracts; using HeuristicLab.Hive.Server.Core.InternalInterfaces.DataAccess; namespace HeuristicLab.Hive.Server.Core { class ClientManager: IClientManager { IClientAdapter clientAdapter; IClientGroupAdapter clientGroupAdapter; List clientGroups; public ClientManager() { clientAdapter = ServiceLocator.GetClientAdapter(); clientGroupAdapter = ServiceLocator.GetClientGroupAdapter(); clientGroups = new List(); ClientGroup cg = new ClientGroup { Id = 4, Name = "SuperGroup" }; cg.Resources = new List(); clientGroups.Add(cg); } #region IClientManager Members /// /// Returns all clients stored in the database /// /// public ResponseList GetAllClients() { ResponseList response = new ResponseList(); response.List = new List(clientAdapter.GetAll()); response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS; response.Success = true; return response; } /// /// returns all client groups stored in the database /// /// public ResponseList GetAllClientGroups() { ResponseList response = new ResponseList(); response.List = new List(clientGroupAdapter.GetAll()); response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS; response.Success = true; return response; } public ResponseList GetAllUpTimeStatistics() { ResponseList response = new ResponseList(); response.Success = true; return response; } /// /// Add a client group into the database /// /// /// public Response AddClientGroup(ClientGroup clientGroup) { Response response = new Response(); if (clientGroup.Id != 0) { response.Success = false; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; return response; } clientGroupAdapter.Update(clientGroup); response.Success = true; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED; return response; } /// /// Add a resource to a group /// /// /// /// public Response AddResourceToGroup(long clientGroupId, Resource resource) { Response response = new Response(); if (resource.Id != 0) { response.Success = false; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET; return response; } ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); if (clientGroup == null) { response.Success = false; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; return response; } clientGroup.Resources.Add(resource); response.Success = true; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP; return response; } /// /// Remove a resource from a group /// /// /// /// public Response DeleteResourceFromGroup(long clientGroupId, long resourceId) { Response response = new Response(); ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId); if (clientGroup == null) { response.Success = false; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST; return response; } foreach (Resource resource in clientGroup.Resources) { if (resource.Id == resourceId) { clientGroup.Resources.Remove(resource); response.Success = true; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED; return response; } } response.Success = false; response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND; return response; } #endregion } }