Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientFacade.cs @ 3031

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