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;
|
---|
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;
|
---|
28 | using HeuristicLab.Hive.Contracts;
|
---|
29 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
30 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
31 | using System.ServiceModel;
|
---|
32 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
33 |
|
---|
34 |
|
---|
35 | namespace HeuristicLab.Hive.Server.Core {
|
---|
36 | public class ServerConsoleFacade : IServerConsoleFacade {
|
---|
37 | private IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
38 |
|
---|
39 | private IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
40 |
|
---|
41 | private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
|
---|
42 |
|
---|
43 | private IContextFactory contextFactory = ServiceLocator.GetContextFactory();
|
---|
44 |
|
---|
45 | public Guid sessionID = Guid.Empty;
|
---|
46 |
|
---|
47 | public ServerConsoleFacade() {
|
---|
48 | }
|
---|
49 |
|
---|
50 | public Response Login(string username, string password) {
|
---|
51 | Response resp = new Response();
|
---|
52 |
|
---|
53 | sessionID = secMan.Login(username, password);
|
---|
54 | if (sessionID == Guid.Empty) {
|
---|
55 | resp.Success = false;
|
---|
56 | resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_FAILED;
|
---|
57 | } else {
|
---|
58 | resp.Success = true;
|
---|
59 | resp.StatusMessage =
|
---|
60 | ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
|
---|
61 | }
|
---|
62 | return resp;
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | public ResponseList<ClientDto> GetAllClients() {
|
---|
67 | using (contextFactory.GetContext(false)) {
|
---|
68 | secMan.Authorize("AccessClients", sessionID, Guid.Empty);
|
---|
69 | return clientManager.GetAllClients();
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public ResponseList<ClientGroupDto> GetAllClientGroups() {
|
---|
74 | using (contextFactory.GetContext(false)) {
|
---|
75 | //secMan.Authorize("AccessClientGroup", sessionID, Guid.Empty);
|
---|
76 | return clientManager.GetAllClientGroups();
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public ResponseList<UpTimeStatisticsDto> GetAllUpTimeStatistics() {
|
---|
81 | using (contextFactory.GetContext(false)) {
|
---|
82 | secMan.Authorize("AccessStatistics", sessionID, Guid.Empty);
|
---|
83 | return clientManager.GetAllUpTimeStatistics();
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | public ResponseObject<ClientGroupDto> AddClientGroup(ClientGroupDto clientGroup) {
|
---|
88 | using (contextFactory.GetContext()) {
|
---|
89 | secMan.Authorize("AddClientGroup", sessionID, Guid.Empty);
|
---|
90 | return clientManager.AddClientGroup(clientGroup);
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | public Response AddResourceToGroup(Guid clientGroupId, ResourceDto resource) {
|
---|
95 | using (contextFactory.GetContext()) {
|
---|
96 | secMan.Authorize("AddResource", sessionID, Guid.Empty);
|
---|
97 | return clientManager.AddResourceToGroup(clientGroupId, resource);
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
102 | using (contextFactory.GetContext()) {
|
---|
103 | return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | public ResponseList<JobDto> GetAllJobs() {
|
---|
108 | using (contextFactory.GetContext(false)) {
|
---|
109 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
110 | return jobManager.GetAllJobs();
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | public ResponseList<JobDto> GetAllJobsWithFilter(State jobState, int offset, int count) {
|
---|
115 | using (contextFactory.GetContext(false)) {
|
---|
116 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
117 | return jobManager.GetAllJobsWithFilter(jobState, offset, count);
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | public ResponseObject<JobDto> GetJobById(Guid jobId) {
|
---|
122 | using (contextFactory.GetContext(false)) {
|
---|
123 | secMan.Authorize("AccessJobs", sessionID, jobId);
|
---|
124 | return jobManager.GetJobById(jobId);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | public ResponseObject<JobDto> GetJobByIdWithDetails(Guid jobId) {
|
---|
129 | using (contextFactory.GetContext(false)) {
|
---|
130 | secMan.Authorize("AccessJobs", sessionID, jobId);
|
---|
131 | return jobManager.GetJobByIdWithDetails(jobId);
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | public ResponseObject<JobDto> AddNewJob(SerializedJob job) {
|
---|
136 | using (contextFactory.GetContext()) {
|
---|
137 | secMan.Authorize("AddJob", sessionID, job.JobInfo.Id);
|
---|
138 | return jobManager.AddNewJob(job);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | public ResponseObject<JobDto> GetLastJobResultOf(Guid jobId) {
|
---|
143 | using (contextFactory.GetContext(false)) {
|
---|
144 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
145 | return jobManager.GetLastJobResultOf(jobId);
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | public ResponseObject<SerializedJob> GetLastSerializedJobResultOf(Guid jobId, bool requested, bool snapshot) {
|
---|
150 | using (contextFactory.GetContext(false)) {
|
---|
151 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
152 | return jobManager.GetLastSerializedJobResultOf(jobId, requested, snapshot);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
|
---|
157 | using (contextFactory.GetContext(false)) {
|
---|
158 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
159 | return jobManager.GetAllJobResults(jobId);
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | public Response RemoveJob(Guid jobId) {
|
---|
164 | using (contextFactory.GetContext()) {
|
---|
165 | secMan.Authorize("RemoveJob", sessionID, jobId);
|
---|
166 | return jobManager.RemoveJob(jobId);
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | public Response RequestSnapshot(Guid jobId) {
|
---|
171 | using (contextFactory.GetContext()) {
|
---|
172 | secMan.Authorize("AccessJobResults", sessionID, jobId);
|
---|
173 | return jobManager.RequestSnapshot(jobId);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | public Response AbortJob(Guid jobId) {
|
---|
178 | using (contextFactory.GetContext()) {
|
---|
179 | secMan.Authorize("AbortJob", sessionID, Guid.Empty);
|
---|
180 | return jobManager.AbortJob(jobId);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | public ResponseObject<ClientGroupDtoList> GetAllGroupsOfResource(Guid resourceId) {
|
---|
185 | using (contextFactory.GetContext(false)) {
|
---|
186 | secMan.Authorize("AccessUserGroup", sessionID, Guid.Empty);
|
---|
187 | return clientManager.GetAllGroupsOfResource(resourceId);
|
---|
188 | }
|
---|
189 | }
|
---|
190 |
|
---|
191 | public Response DeleteClientGroup(Guid clientGroupId) {
|
---|
192 | using (contextFactory.GetContext()) {
|
---|
193 | secMan.Authorize("DeleteClientGroup", sessionID, Guid.Empty);
|
---|
194 | return clientManager.DeleteClientGroup(clientGroupId);
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | public ResponseList<ProjectDto> GetAllProjects() {
|
---|
199 | using (contextFactory.GetContext(false)) {
|
---|
200 | secMan.Authorize("AccessProjects", sessionID, Guid.Empty);
|
---|
201 | return jobManager.GetAllProjects();
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | public Response CreateProject(ProjectDto project) {
|
---|
206 | using (contextFactory.GetContext()) {
|
---|
207 | secMan.Authorize("CreateProjects", sessionID, Guid.Empty);
|
---|
208 | return jobManager.CreateProject(project);
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | public Response ChangeProject(ProjectDto project) {
|
---|
213 | using (contextFactory.GetContext()) {
|
---|
214 | secMan.Authorize("ChangeProjects", sessionID, Guid.Empty);
|
---|
215 | return jobManager.ChangeProject(project);
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | public Response DeleteProject(Guid projectId) {
|
---|
220 | using (contextFactory.GetContext()) {
|
---|
221 | secMan.Authorize("DeleteProjects", sessionID, projectId);
|
---|
222 | return jobManager.DeleteProject(projectId);
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | public ResponseList<JobDto> GetJobsByProject(Guid projectId) {
|
---|
227 | using (contextFactory.GetContext(false)) {
|
---|
228 | secMan.Authorize("AccessJobs", sessionID, Guid.Empty);
|
---|
229 | return jobManager.GetJobsByProject(projectId);
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | public ResponseList<AppointmentDto> GetUptimeCalendarForResource(Guid guid) {
|
---|
234 | using (contextFactory.GetContext(false)) {
|
---|
235 | return clientManager.GetUptimeCalendarForResource(guid);
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | public Response SetUptimeCalendarForResource(Guid guid, IEnumerable<AppointmentDto> appointments, bool isForced) {
|
---|
240 | using (contextFactory.GetContext()) {
|
---|
241 | return clientManager.SetUptimeCalendarForResource(guid, appointments, isForced);
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | public ResponseObject<JobDto> AddJobWithGroupStrings(SerializedJob job, IEnumerable<string> resources) {
|
---|
246 | using (contextFactory.GetContext()) {
|
---|
247 | return jobManager.AddJobWithGroupStrings(job, resources);
|
---|
248 | }
|
---|
249 | }
|
---|
250 | }
|
---|
251 | }
|
---|