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