Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3043 was 3022, checked in by kgrading, 15 years ago

added the calendar in the dal and the server console. Works on every Resource (Group / Client) (#908)

File size: 8.2 KB
RevLine 
[3011]1#region License Information
[3022]2
[907]3/* HeuristicLab
4 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
[3022]21
[907]22#endregion
23
24using System;
[800]25using System.Collections.Generic;
26using System.Linq;
27using System.Text;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Contracts.BusinessObjects;
[902]30using HeuristicLab.Hive.Contracts;
[1377]31using HeuristicLab.Hive.Server.DataAccess;
[1468]32using HeuristicLab.DataAccess.Interfaces;
[2904]33using HeuristicLab.Hive.Server.LINQDataAccess;
[3011]34using ClientGroup=HeuristicLab.Hive.Contracts.BusinessObjects.ClientGroupDto;
[800]35
36namespace HeuristicLab.Hive.Server.Core {
[3022]37  internal class ClientManager : IClientManager {
38    private List<ClientGroup> clientGroups;
[820]39
40    public ClientManager() {
41      clientGroups = new List<ClientGroup>();
42    }
43
[800]44    #region IClientManager Members
45
[1121]46    /// <summary>
47    /// Returns all clients stored in the database
48    /// </summary>
49    /// <returns></returns>
[3011]50    public ResponseList<ClientDto> GetAllClients() {
[3022]51      ResponseList<ClientDto> response = new ResponseList<ClientDto>();
[929]52
[3022]53      response.List = new List<ClientDto>(DaoLocator.ClientDao.FindAll());
54      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
55      response.Success = true;
[929]56
[3022]57      return response;
[800]58    }
59
[1121]60    /// <summary>
61    /// returns all client groups stored in the database
62    /// </summary>
63    /// <returns></returns>
[902]64    public ResponseList<ClientGroup> GetAllClientGroups() {
[3022]65      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
[934]66
[3022]67      List<ClientGroup> allClientGroups =
68        new List<ClientGroup>(DaoLocator.ClientGroupDao.FindAllWithSubGroupsAndClients());
69      ClientGroup emptyClientGroup = new ClientGroup();
70      IEnumerable<ClientDto> groupLessClients = DaoLocator.ClientDao.FindAllClientsWithoutGroup();
71      if (groupLessClients != null) {
72        foreach (ClientDto currClient in groupLessClients) {
73          emptyClientGroup.Resources.Add(currClient);
[1633]74        }
[3022]75      }
76      emptyClientGroup.Id = Guid.Empty;
77      allClientGroups.Add(emptyClientGroup);
[1633]78
[3022]79      response.List = allClientGroups;
80      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
81      response.Success = true;
[1468]82
[3022]83      return response;
[800]84    }
85
[3011]86    public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
87      ResponseList<UpTimeStatisticsDto> response = new ResponseList<UpTimeStatisticsDto>();
[907]88      response.Success = true;
89      return response;
[800]90    }
91
[1121]92    /// <summary>
93    /// Add a client group into the database
94    /// </summary>
95    /// <param name="clientGroup"></param>
96    /// <returns></returns>
[1825]97    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
[3022]98      ResponseObject<ClientGroup> response = new ResponseObject<ClientGroup>();
[937]99
[3022]100      if (clientGroup.Id != Guid.Empty) {
101        response.Success = false;
102        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
103      }
104      else {
105        clientGroup = DaoLocator.ClientGroupDao.Insert(clientGroup);
106        //clientGroupAdapter.Update(clientGroup);
107        response.Obj = clientGroup;
108        response.Success = true;
109        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
110      }
[1468]111
[3022]112      return response;
[934]113    }
114
[1121]115    /// <summary>
116    ///  Add a resource to a group
117    /// </summary>
118    /// <param name="clientGroupId"></param>
119    /// <param name="resource"></param>
120    /// <returns></returns>
[3011]121    public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
[3022]122      Response response = new Response();
[942]123
[3022]124      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
125      if (clientGroup == null) {
126        response.Success = false;
127        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
128        return response;
129      }
130      clientGroup.Resources.Add(resource);
131      DaoLocator.ClientGroupDao.AddRessourceToClientGroup(resource.Id, clientGroup.Id);
132      //clientGroupAdapter.Update(clientGroup);
[942]133
[3022]134      response.Success = true;
135      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
[1468]136
[3022]137      return response;
138    }
[1468]139
[1121]140    /// <summary>
141    /// Remove a resource from a group
142    /// </summary>
143    /// <param name="clientGroupId"></param>
144    /// <param name="resourceId"></param>
145    /// <returns></returns>
[1449]146    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
[3022]147      Response response = new Response();
[942]148
[3022]149      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
150      if (clientGroup == null) {
[942]151        response.Success = false;
[3022]152        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
[942]153        return response;
154      }
[3022]155      foreach (ResourceDto resource in clientGroup.Resources) {
156        if (resource.Id == resourceId) {
157          clientGroup.Resources.Remove(resource);
158          DaoLocator.ClientGroupDao.RemoveRessourceFromClientGroup(resource.Id, clientGroup.Id);
159          //clientGroupAdapter.Update(clientGroup);
160          response.Success = true;
161          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
162          return response;
163        }
[942]164      }
[3022]165      response.Success = false;
166      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
[1757]167
[3022]168      return response;
169    }
170
[1757]171    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
[3022]172      ResponseObject<List<ClientGroup>> response = new ResponseObject<List<ClientGroup>>();
[1757]173
[3022]174      ClientDto client = DaoLocator.ClientDao.FindById(resourceId);
175      if (client != null) {
176        List<ClientGroup> groupsOfClient = new List<ClientGroup>(DaoLocator.ClientGroupDao.MemberOf(client));
177        response.Obj = groupsOfClient;
178        response.Success = true;
179        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_GROUPS_OF_CLIENT;
180      }
181      else {
182        response.Obj = new List<ClientGroup>();
183        response.Success = false;
184        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
185      }
[1757]186
[3022]187      return response;
188    }
[1757]189
[3022]190    public Response DeleteClientGroup(Guid clientGroupId) {
191      Response response = new Response();
[1757]192
[3022]193      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
194      if (clientGroup == null) {
195        response.Success = false;
196        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
[1757]197        return response;
198      }
199
[3022]200      DaoLocator.ClientGroupDao.Delete(clientGroup);
[1824]201
[3022]202      response.Success = true;
203      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DELETED;
204      return response;
205    }
[1824]206
[3022]207    public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
208      ResponseList<AppointmentDto> response = new ResponseList<AppointmentDto>();
209      response.List = new List<AppointmentDto>(DaoLocator.UptimeCalendarDao.GetUptimeCalendarForResource(guid));
210      response.Success = true;
211      return response;
212    }
[1824]213
[3022]214    public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments) {
215      DaoLocator.UptimeCalendarDao.SetUptimeCalendarForResource(guid, appointments);
216      return new Response {Success = true};
217    }
[800]218    #endregion
219  }
[3022]220}
Note: See TracBrowser for help on using the repository browser.