Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3020 was 3011, checked in by kgrading, 15 years ago

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

File size: 10.1 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.DataAccess;
30using HeuristicLab.DataAccess.Interfaces;
31using HeuristicLab.Hive.Server.LINQDataAccess;
32using ClientGroup=HeuristicLab.Hive.Contracts.BusinessObjects.ClientGroupDto;
33
34namespace HeuristicLab.Hive.Server.Core {
35  class ClientManager: IClientManager {
36   
37    //ISessionFactory factory;
38    List<ClientGroup> clientGroups;
39
40    public ClientManager() {
41      //factory = ServiceLocator.GetSessionFactory();
42     
43      clientGroups = new List<ClientGroup>();
44    }
45
46    #region IClientManager Members
47
48    /// <summary>
49    /// Returns all clients stored in the database
50    /// </summary>
51    /// <returns></returns>
52    public ResponseList<ClientDto> GetAllClients() {
53      /*ISession session = factory.GetSessionForCurrentThread();
54
55      try {
56       
57        IClientAdapter clientAdapter =
58          session.GetDataAdapter<ClientDto, IClientAdapter>();*/
59
60        ResponseList<ClientDto> response = new ResponseList<ClientDto>();
61
62        response.List = new List<ClientDto>(DaoLocator.ClientDao.FindAll());
63        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
64        response.Success = true;
65
66        return response;
67      /*}
68      finally {
69        if (session != null)
70          session.EndSession();
71      }*/
72    }
73
74    /// <summary>
75    /// returns all client groups stored in the database
76    /// </summary>
77    /// <returns></returns>
78    public ResponseList<ClientGroup> GetAllClientGroups() {
79      /*ISession session = factory.GetSessionForCurrentThread();
80
81      try {
82        IClientGroupAdapter clientGroupAdapter =
83          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
84        IClientAdapter clientAdapter =
85          session.GetDataAdapter<ClientDto, IClientAdapter>();*/
86        ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
87
88        List<ClientGroup> allClientGroups = new List<ClientGroup>(DaoLocator.ClientGroupDao.FindAllWithSubGroupsAndClients());
89        ClientGroup emptyClientGroup = new ClientGroup();
90        IEnumerable<ClientDto> groupLessClients = DaoLocator.ClientDao.FindAllClientsWithoutGroup();
91        if (groupLessClients != null) {
92          foreach (ClientDto currClient in groupLessClients) {
93            emptyClientGroup.Resources.Add(currClient);
94          }
95        }
96        emptyClientGroup.Id = Guid.Empty;
97        allClientGroups.Add(emptyClientGroup);
98
99        response.List = allClientGroups;
100        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
101        response.Success = true;
102
103        return response;
104   /*   }
105      finally {
106        if (session != null)
107          session.EndSession();
108      }*/
109    }
110
111    public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
112      ResponseList<UpTimeStatisticsDto> response = new ResponseList<UpTimeStatisticsDto>();
113      response.Success = true;
114      return response;
115    }
116
117    /// <summary>
118    /// Add a client group into the database
119    /// </summary>
120    /// <param name="clientGroup"></param>
121    /// <returns></returns>
122    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
123      /*ISession session = factory.GetSessionForCurrentThread();
124
125      try {
126        IClientGroupAdapter clientGroupAdapter =
127          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();*/
128
129        ResponseObject<ClientGroup> response = new ResponseObject<ClientGroup>();
130
131        if (clientGroup.Id != Guid.Empty) {
132          response.Success = false;
133          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
134        } else {
135          clientGroup = DaoLocator.ClientGroupDao.Insert(clientGroup);
136          //clientGroupAdapter.Update(clientGroup);
137          response.Obj = clientGroup;
138          response.Success = true;
139          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
140        }
141
142        return response;
143      /*}
144      finally {
145        if (session != null)
146          session.EndSession();
147      } */
148    }
149
150    /// <summary>
151    ///  Add a resource to a group
152    /// </summary>
153    /// <param name="clientGroupId"></param>
154    /// <param name="resource"></param>
155    /// <returns></returns>
156    public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
157      /*ISession session = factory.GetSessionForCurrentThread();
158
159      try {
160        IClientGroupAdapter clientGroupAdapter =
161          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();*/
162
163        Response response = new Response();
164
165        ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
166        if (clientGroup == null) {
167          response.Success = false;
168          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
169          return response;
170        }
171        clientGroup.Resources.Add(resource);
172        DaoLocator.ClientGroupDao.AddRessourceToClientGroup(resource.Id, clientGroup.Id);         
173        //clientGroupAdapter.Update(clientGroup);
174
175        response.Success = true;
176        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
177
178        return response;
179      }
180      /*finally {
181        if (session != null)
182          session.EndSession();
183      }
184    }   */
185
186    /// <summary>
187    /// Remove a resource from a group
188    /// </summary>
189    /// <param name="clientGroupId"></param>
190    /// <param name="resourceId"></param>
191    /// <returns></returns>
192    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
193      /*ISession session = factory.GetSessionForCurrentThread();
194
195      try {
196        IClientGroupAdapter clientGroupAdapter =
197          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();*/
198
199        Response response = new Response();
200
201        ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
202        if (clientGroup == null) {
203          response.Success = false;
204          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
205          return response;
206        }
207        foreach (ResourceDto resource in clientGroup.Resources) {
208          if (resource.Id == resourceId) {
209            clientGroup.Resources.Remove(resource);
210            DaoLocator.ClientGroupDao.RemoveRessourceFromClientGroup(resource.Id, clientGroup.Id);
211            //clientGroupAdapter.Update(clientGroup);
212            response.Success = true;
213            response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
214            return response;
215          }
216        }
217        response.Success = false;
218        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
219
220        return response;
221      }
222      /*finally {
223        if (session != null)
224          session.EndSession();
225      }
226    }   */
227
228    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
229      /*ISession session = factory.GetSessionForCurrentThread();
230
231      try {
232        IClientGroupAdapter clientGroupAdapter =
233          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
234        IClientAdapter clientAdapter =
235          session.GetDataAdapter<ClientDto, IClientAdapter>();*/
236
237        ResponseObject<List<ClientGroup>> response = new ResponseObject<List<ClientGroup>>();
238
239        ClientDto client = DaoLocator.ClientDao.FindById(resourceId);
240        if (client != null) {
241          List<ClientGroup> groupsOfClient = new List<ClientGroup>(DaoLocator.ClientGroupDao.MemberOf(client));
242          response.Obj = groupsOfClient;
243          response.Success = true;
244          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_GROUPS_OF_CLIENT;
245        } else {
246          response.Obj = new List<ClientGroup>();
247          response.Success = false;
248          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
249        }
250
251        return response;
252      }
253      /*finally {
254        if (session != null)
255          session.EndSession();
256      }
257    }   */
258
259    public Response DeleteClientGroup(Guid clientGroupId) {
260      /*ISession session = factory.GetSessionForCurrentThread();
261
262      try {
263        IClientGroupAdapter clientGroupAdapter =
264          session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();*/
265
266        Response response = new Response();
267
268        ClientGroup clientGroup = DaoLocator.ClientGroupDao.FindById(clientGroupId);
269        if (clientGroup == null) {
270          response.Success = false;
271          response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
272          return response;
273        }
274
275        DaoLocator.ClientGroupDao.Delete(clientGroup);
276
277        response.Success = true;
278        response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DELETED;
279        return response;
280
281      }/* finally {
282        if (session != null)
283          session.EndSession();
284      }
285    }    */
286
287    #endregion
288  }
289}
Note: See TracBrowser for help on using the repository browser.