Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3494 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
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      }
[3203]130
[3022]131      clientGroup.Resources.Add(resource);
132      DaoLocator.ClientGroupDao.AddRessourceToClientGroup(resource.Id, clientGroup.Id);
[942]133
[3203]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
[3022]141      response.Success = true;
142      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
[1468]143
[3022]144      return response;
145    }
[1468]146
[1121]147    /// <summary>
148    /// Remove a resource from a group
149    /// </summary>
150    /// <param name="clientGroupId"></param>
151    /// <param name="resourceId"></param>
152    /// <returns></returns>
[1449]153    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
[3022]154      Response response = new Response();
[942]155
[3022]156      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
157      if (clientGroup == null) {
[942]158        response.Success = false;
[3022]159        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
[942]160        return response;
161      }
[3203]162     
163      DaoLocator.ClientGroupDao.RemoveRessourceFromClientGroup(resourceId, clientGroup.Id);
164     
165      response.Success = true;
166      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
167      return response;               
[3022]168    }
169
[1757]170    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
[3022]171      ResponseObject<List<ClientGroup>> response = new ResponseObject<List<ClientGroup>>();
[1757]172
[3022]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      }
[1757]185
[3022]186      return response;
187    }
[1757]188
[3022]189    public Response DeleteClientGroup(Guid clientGroupId) {
190      Response response = new Response();
[1757]191
[3022]192      ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
193      if (clientGroup == null) {
194        response.Success = false;
195        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
[1757]196        return response;
197      }
198
[3022]199      DaoLocator.ClientGroupDao.Delete(clientGroup);
[1824]200
[3022]201      response.Success = true;
202      response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DELETED;
203      return response;
204    }
[1824]205
[3022]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    }
[1824]212
[3203]213    public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
[3022]214      DaoLocator.UptimeCalendarDao.SetUptimeCalendarForResource(guid, appointments);
[3203]215      DaoLocator.UptimeCalendarDao.NotifyClientsOfNewCalendar(guid, isForced);
[3022]216      return new Response {Success = true};
217    }
[800]218    #endregion
219  }
[3022]220}
Note: See TracBrowser for help on using the repository browser.