Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3491 was 3203, checked in by kgrading, 15 years ago

implemented the server on the client, using push & force push, added refresh buttons, added auto calender methods that traverse the tree... (#908)

File size: 8.1 KB
Line 
1#region License Information
2
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 */
21
22#endregion
23
24using System;
25using System.Collections.Generic;
26using System.Linq;
27using System.Text;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Contracts.BusinessObjects;
30using HeuristicLab.Hive.Contracts;
31using HeuristicLab.Hive.Server.DataAccess;
32using HeuristicLab.DataAccess.Interfaces;
33using HeuristicLab.Hive.Server.LINQDataAccess;
34using ClientGroup=HeuristicLab.Hive.Contracts.BusinessObjects.ClientGroupDto;
35
36namespace HeuristicLab.Hive.Server.Core {
37  internal class ClientManager : IClientManager {
38    private List<ClientGroup> clientGroups;
39
40    public ClientManager() {
41      clientGroups = new List<ClientGroup>();
42    }
43
44    #region IClientManager Members
45
46    /// <summary>
47    /// Returns all clients stored in the database
48    /// </summary>
49    /// <returns></returns>
50    public ResponseList<ClientDto> GetAllClients() {
51      ResponseList<ClientDto> response = new ResponseList<ClientDto>();
52
53      response.List = new List<ClientDto>(DaoLocator.ClientDao.FindAll());
54      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
55      response.Success = true;
56
57      return response;
58    }
59
60    /// <summary>
61    /// returns all client groups stored in the database
62    /// </summary>
63    /// <returns></returns>
64    public ResponseList<ClientGroup> GetAllClientGroups() {
65      ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
66
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);
74        }
75      }
76      emptyClientGroup.Id = Guid.Empty;
77      allClientGroups.Add(emptyClientGroup);
78
79      response.List = allClientGroups;
80      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
81      response.Success = true;
82
83      return response;
84    }
85
86    public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
87      ResponseList<UpTimeStatisticsDto> response = new ResponseList<UpTimeStatisticsDto>();
88      response.Success = true;
89      return response;
90    }
91
92    /// <summary>
93    /// Add a client group into the database
94    /// </summary>
95    /// <param name="clientGroup"></param>
96    /// <returns></returns>
97    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
98      ResponseObject<ClientGroup> response = new ResponseObject<ClientGroup>();
99
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      }
111
112      return response;
113    }
114
115    /// <summary>
116    ///  Add a resource to a group
117    /// </summary>
118    /// <param name="clientGroupId"></param>
119    /// <param name="resource"></param>
120    /// <returns></returns>
121    public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
122      Response response = new Response();
123
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
131      clientGroup.Resources.Add(resource);
132      DaoLocator.ClientGroupDao.AddRessourceToClientGroup(resource.Id, clientGroup.Id);
133
134      //If our resource is in fact a client => set the callendar from the resource as current one.
135     
136      ClientDto dbr = DaoLocator.ClientDao.FindById(resource.Id);
137      if(dbr != null) {
138        DaoLocator.ClientDao.SetServerSideCalendar(dbr, clientGroup.Id); 
139      }
140
141      response.Success = true;
142      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
143
144      return response;
145    }
146
147    /// <summary>
148    /// Remove a resource from a group
149    /// </summary>
150    /// <param name="clientGroupId"></param>
151    /// <param name="resourceId"></param>
152    /// <returns></returns>
153    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
154      Response response = new Response();
155
156      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
157      if (clientGroup == null) {
158        response.Success = false;
159        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
160        return response;
161      }
162     
163      DaoLocator.ClientGroupDao.RemoveRessourceFromClientGroup(resourceId, clientGroup.Id);
164     
165      response.Success = true;
166      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
167      return response;               
168    }
169
170    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
171      ResponseObject<List<ClientGroup>> response = new ResponseObject<List<ClientGroup>>();
172
173      ClientDto client = DaoLocator.ClientDao.FindById(resourceId);
174      if (client != null) {
175        List<ClientGroup> groupsOfClient = new List<ClientGroup>(DaoLocator.ClientGroupDao.MemberOf(client));
176        response.Obj = groupsOfClient;
177        response.Success = true;
178        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_GROUPS_OF_CLIENT;
179      }
180      else {
181        response.Obj = new List<ClientGroup>();
182        response.Success = false;
183        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
184      }
185
186      return response;
187    }
188
189    public Response DeleteClientGroup(Guid clientGroupId) {
190      Response response = new Response();
191
192      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
193      if (clientGroup == null) {
194        response.Success = false;
195        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
196        return response;
197      }
198
199      DaoLocator.ClientGroupDao.Delete(clientGroup);
200
201      response.Success = true;
202      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DELETED;
203      return response;
204    }
205
206    public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
207      ResponseList<AppointmentDto> response = new ResponseList<AppointmentDto>();
208      response.List = new List<AppointmentDto>(DaoLocator.UptimeCalendarDao.GetUptimeCalendarForResource(guid));
209      response.Success = true;
210      return response;
211    }
212
213    public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
214      DaoLocator.UptimeCalendarDao.SetUptimeCalendarForResource(guid, appointments);
215      DaoLocator.UptimeCalendarDao.NotifyClientsOfNewCalendar(guid, isForced);
216      return new Response {Success = true};
217    }
218    #endregion
219  }
220}
Note: See TracBrowser for help on using the repository browser.