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.PluginInfrastructure;
|
---|
30 | using System.IO;
|
---|
31 | using System.Runtime.Serialization.Formatters.Binary;
|
---|
32 | using System.ServiceModel;
|
---|
33 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
34 | using System.Transactions;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Hive.Server.Core {
|
---|
37 | [ServiceBehavior(InstanceContextMode =
|
---|
38 | InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
|
---|
39 | public class ClientFacade: IClientFacade {
|
---|
40 |
|
---|
41 | public ClientFacade() {
|
---|
42 | }
|
---|
43 |
|
---|
44 | private IClientCommunicator clientCommunicator =
|
---|
45 | ServiceLocator.GetClientCommunicator();
|
---|
46 |
|
---|
47 | #region IClientCommunicator Members
|
---|
48 |
|
---|
49 | public Response Login(ClientDto clientInfo) {
|
---|
50 | return clientCommunicator.Login(clientInfo);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ResponseHB ProcessHeartBeat(HeartBeatData hbData) {
|
---|
54 | return clientCommunicator.ProcessHeartBeat(hbData);
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | public ResponseJob SendJob(Guid clientId) {
|
---|
59 | return clientCommunicator.SendJob(clientId);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /*public ResponseSerializedJob SendSerializedJob(Guid clientId) {
|
---|
63 | return clientCommunicator.SendSerializedJob(clientId);
|
---|
64 | } */
|
---|
65 |
|
---|
66 | public ResponseResultReceived StoreFinishedJobResult(Guid clientId,
|
---|
67 | Guid jobId,
|
---|
68 | byte[] result,
|
---|
69 | double percentage,
|
---|
70 | Exception exception) {
|
---|
71 | return clientCommunicator.StoreFinishedJobResult(clientId, jobId, result, percentage, exception);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public Response Logout(Guid clientId) {
|
---|
75 | return clientCommunicator.Logout(clientId);
|
---|
76 | }
|
---|
77 |
|
---|
78 | public Response IsJobStillNeeded(Guid jobId) {
|
---|
79 | return clientCommunicator.IsJobStillNeeded(jobId);
|
---|
80 | }
|
---|
81 |
|
---|
82 | public ResponsePlugin SendPlugins(List<HivePluginInfoDto> pluginList) {
|
---|
83 | return clientCommunicator.SendPlugins(pluginList);
|
---|
84 | }
|
---|
85 |
|
---|
86 | public ResponseResultReceived ProcessSnapshot(Guid clientId, Guid jobId, byte[] result, double percentage, Exception exception) {
|
---|
87 | return clientCommunicator.ProcessSnapshot(clientId, jobId, result, percentage, exception);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | public ResponseCalendar GetCalendar(Guid clientId) {
|
---|
92 | return clientCommunicator.GetCalendar(clientId);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public Response SetCalendarStatus(Guid clientId, CalendarState state) {
|
---|
96 | return clientCommunicator.SetCalendarStatus(clientId, state);
|
---|
97 | }
|
---|
98 | #endregion
|
---|
99 |
|
---|
100 | #region IClientFacade Members
|
---|
101 |
|
---|
102 | [SpringTransaction(UserTransaction = true)]
|
---|
103 | public Stream SendStreamedJob(Guid clientId) {
|
---|
104 | MultiStream stream =
|
---|
105 | new MultiStream();
|
---|
106 |
|
---|
107 | ResponseJob job = null;
|
---|
108 |
|
---|
109 | job = this.SendJob(clientId);
|
---|
110 |
|
---|
111 | //first send response
|
---|
112 | stream.AddStream(
|
---|
113 | new StreamedObject<ResponseJob>(job));
|
---|
114 |
|
---|
115 | IJobManager jobManager =
|
---|
116 | ServiceLocator.GetJobManager();
|
---|
117 | IInternalJobManager internalJobManager = (IInternalJobManager) jobManager;
|
---|
118 |
|
---|
119 | //second stream the job binary data
|
---|
120 | MemoryStream memoryStream = new MemoryStream();
|
---|
121 | if(job.Job != null)
|
---|
122 | stream.AddStream(new MemoryStream(internalJobManager.GetSerializedJobDataById(job.Job.Id)));
|
---|
123 |
|
---|
124 | OperationContext clientContext = OperationContext.Current;
|
---|
125 | clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) {
|
---|
126 | if (stream != null) {
|
---|
127 | stream.Dispose();
|
---|
128 | }
|
---|
129 | });
|
---|
130 |
|
---|
131 | return stream;
|
---|
132 | }
|
---|
133 |
|
---|
134 | public Stream SendStreamedPlugins(List<HivePluginInfoDto> pluginList) {
|
---|
135 | return
|
---|
136 | new StreamedObject<ResponsePlugin>(
|
---|
137 | this.SendPlugins(pluginList));
|
---|
138 | }
|
---|
139 |
|
---|
140 | public ResponseResultReceived StoreFinishedJobResultStreamed(Stream stream) {
|
---|
141 | return ((IInternalClientCommunicator)
|
---|
142 | clientCommunicator).ProcessJobResult(stream, true);
|
---|
143 | }
|
---|
144 |
|
---|
145 | public ResponseResultReceived ProcessSnapshotStreamed(Stream stream) {
|
---|
146 | return ((IInternalClientCommunicator)
|
---|
147 | clientCommunicator).ProcessJobResult(stream, false);
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 | #endregion
|
---|
153 | }
|
---|
154 | }
|
---|