[907] | 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 |
|
---|
| 22 | using System;
|
---|
[800] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
| 27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[902] | 28 | using HeuristicLab.Hive.Contracts;
|
---|
[1377] | 29 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[1468] | 30 | using HeuristicLab.DataAccess.Interfaces;
|
---|
[800] | 31 |
|
---|
| 32 | namespace HeuristicLab.Hive.Server.Core {
|
---|
| 33 | class ClientManager: IClientManager {
|
---|
[820] | 34 |
|
---|
[1468] | 35 | ISessionFactory factory;
|
---|
[820] | 36 | List<ClientGroup> clientGroups;
|
---|
| 37 |
|
---|
| 38 | public ClientManager() {
|
---|
[1468] | 39 | factory = ServiceLocator.GetSessionFactory();
|
---|
| 40 |
|
---|
[820] | 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>
|
---|
[902] | 50 | public ResponseList<ClientInfo> GetAllClients() {
|
---|
[1468] | 51 | ISession session = factory.GetSessionForCurrentThread();
|
---|
[929] | 52 |
|
---|
[1468] | 53 | try {
|
---|
| 54 | IClientAdapter clientAdapter =
|
---|
| 55 | session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[929] | 56 |
|
---|
[1468] | 57 | ResponseList<ClientInfo> response = new ResponseList<ClientInfo>();
|
---|
| 58 |
|
---|
| 59 | response.List = new List<ClientInfo>(clientAdapter.GetAll());
|
---|
| 60 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTS;
|
---|
| 61 | response.Success = true;
|
---|
| 62 |
|
---|
| 63 | return response;
|
---|
| 64 | }
|
---|
| 65 | finally {
|
---|
| 66 | if (session != null)
|
---|
| 67 | session.EndSession();
|
---|
| 68 | }
|
---|
[800] | 69 | }
|
---|
| 70 |
|
---|
[1121] | 71 | /// <summary>
|
---|
| 72 | /// returns all client groups stored in the database
|
---|
| 73 | /// </summary>
|
---|
| 74 | /// <returns></returns>
|
---|
[902] | 75 | public ResponseList<ClientGroup> GetAllClientGroups() {
|
---|
[1468] | 76 | ISession session = factory.GetSessionForCurrentThread();
|
---|
[934] | 77 |
|
---|
[1468] | 78 | try {
|
---|
| 79 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 80 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
| 81 | ResponseList<ClientGroup> response = new ResponseList<ClientGroup>();
|
---|
[934] | 82 |
|
---|
[1468] | 83 | response.List = new List<ClientGroup>(clientGroupAdapter.GetAll());
|
---|
| 84 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_GET_ALL_CLIENTGROUPS;
|
---|
| 85 | response.Success = true;
|
---|
| 86 |
|
---|
| 87 | return response;
|
---|
| 88 | }
|
---|
| 89 | finally {
|
---|
| 90 | if (session != null)
|
---|
| 91 | session.EndSession();
|
---|
| 92 | }
|
---|
[800] | 93 | }
|
---|
| 94 |
|
---|
[902] | 95 | public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
|
---|
[907] | 96 | ResponseList<UpTimeStatistics> response = new ResponseList<UpTimeStatistics>();
|
---|
| 97 | response.Success = true;
|
---|
| 98 | return response;
|
---|
[800] | 99 | }
|
---|
| 100 |
|
---|
[1121] | 101 | /// <summary>
|
---|
| 102 | /// Add a client group into the database
|
---|
| 103 | /// </summary>
|
---|
| 104 | /// <param name="clientGroup"></param>
|
---|
| 105 | /// <returns></returns>
|
---|
[934] | 106 | public Response AddClientGroup(ClientGroup clientGroup) {
|
---|
[1468] | 107 | ISession session = factory.GetSessionForCurrentThread();
|
---|
[937] | 108 |
|
---|
[1468] | 109 | try {
|
---|
| 110 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 111 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
| 112 |
|
---|
| 113 | Response response = new Response();
|
---|
| 114 |
|
---|
| 115 | if (clientGroup.Id != Guid.Empty) {
|
---|
| 116 | response.Success = false;
|
---|
| 117 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
|
---|
| 118 | } else {
|
---|
| 119 | clientGroupAdapter.Update(clientGroup);
|
---|
| 120 | response.Success = true;
|
---|
| 121 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_ADDED;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[942] | 124 | return response;
|
---|
| 125 | }
|
---|
[1468] | 126 | finally {
|
---|
| 127 | if (session != null)
|
---|
| 128 | session.EndSession();
|
---|
| 129 | }
|
---|
[934] | 130 | }
|
---|
| 131 |
|
---|
[1121] | 132 | /// <summary>
|
---|
| 133 | /// Add a resource to a group
|
---|
| 134 | /// </summary>
|
---|
| 135 | /// <param name="clientGroupId"></param>
|
---|
| 136 | /// <param name="resource"></param>
|
---|
| 137 | /// <returns></returns>
|
---|
[1449] | 138 | public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
|
---|
[1468] | 139 | ISession session = factory.GetSessionForCurrentThread();
|
---|
[942] | 140 |
|
---|
[1468] | 141 | try {
|
---|
| 142 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 143 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
[942] | 144 |
|
---|
[1468] | 145 | Response response = new Response();
|
---|
| 146 |
|
---|
| 147 | if (resource.Id != Guid.Empty) {
|
---|
| 148 | response.Success = false;
|
---|
| 149 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_ID_MUST_NOT_BE_SET;
|
---|
| 150 | return response;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
|
---|
| 154 | if (clientGroup == null) {
|
---|
| 155 | response.Success = false;
|
---|
| 156 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
|
---|
| 157 | return response;
|
---|
| 158 | }
|
---|
| 159 | clientGroup.Resources.Add(resource);
|
---|
| 160 |
|
---|
| 161 | response.Success = true;
|
---|
| 162 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_ADDED_TO_GROUP;
|
---|
| 163 |
|
---|
[942] | 164 | return response;
|
---|
| 165 | }
|
---|
[1468] | 166 | finally {
|
---|
| 167 | if (session != null)
|
---|
| 168 | session.EndSession();
|
---|
| 169 | }
|
---|
[934] | 170 | }
|
---|
| 171 |
|
---|
[1121] | 172 | /// <summary>
|
---|
| 173 | /// Remove a resource from a group
|
---|
| 174 | /// </summary>
|
---|
| 175 | /// <param name="clientGroupId"></param>
|
---|
| 176 | /// <param name="resourceId"></param>
|
---|
| 177 | /// <returns></returns>
|
---|
[1449] | 178 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
[1468] | 179 | ISession session = factory.GetSessionForCurrentThread();
|
---|
[942] | 180 |
|
---|
[1468] | 181 | try {
|
---|
| 182 | IClientGroupAdapter clientGroupAdapter =
|
---|
| 183 | session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
|
---|
| 184 |
|
---|
| 185 | Response response = new Response();
|
---|
| 186 |
|
---|
| 187 | ClientGroup clientGroup = clientGroupAdapter.GetById(clientGroupId);
|
---|
| 188 | if (clientGroup == null) {
|
---|
| 189 | response.Success = false;
|
---|
| 190 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_CLIENTGROUP_DOESNT_EXIST;
|
---|
| 191 | return response;
|
---|
| 192 | }
|
---|
| 193 | foreach (Resource resource in clientGroup.Resources) {
|
---|
| 194 | if (resource.Id == resourceId) {
|
---|
| 195 | clientGroup.Resources.Remove(resource);
|
---|
| 196 | response.Success = true;
|
---|
| 197 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_REMOVED;
|
---|
| 198 | return response;
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
[942] | 201 | response.Success = false;
|
---|
[1468] | 202 | response.StatusMessage = ApplicationConstants.RESPONSE_CLIENT_RESOURCE_NOT_FOUND;
|
---|
| 203 |
|
---|
[942] | 204 | return response;
|
---|
| 205 | }
|
---|
[1468] | 206 | finally {
|
---|
| 207 | if (session != null)
|
---|
| 208 | session.EndSession();
|
---|
[942] | 209 | }
|
---|
[934] | 210 | }
|
---|
[800] | 211 | #endregion
|
---|
| 212 | }
|
---|
| 213 | }
|
---|