Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3362 was 3220, checked in by kgrading, 15 years ago

improved the DAL further, changed minor details for the presentation (#830)

File size: 4.8 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;
34using System.Transactions;
35
36namespace 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    public Stream SendStreamedJob(Guid clientId) {
103      MultiStream stream =
104        new MultiStream();
105
106      ResponseJob job = null;
107
108      job = this.SendJob(clientId);     
109
110      //first send response
111      stream.AddStream(
112        new StreamedObject<ResponseJob>(job));
113
114      IJobManager jobManager =
115        ServiceLocator.GetJobManager();
116
117      //second stream the job binary data
118     
119      if(job.Job != null)
120        stream.AddStream(
121          ((IInternalJobManager) (jobManager)).
122            GetJobStreamById(
123            job.Job.Id));
124     
125      OperationContext clientContext = OperationContext.Current;
126        clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) {
127          if (stream != null) {
128            stream.Dispose();
129          }
130        });
131
132      return stream;
133    }
134
135    public Stream SendStreamedPlugins(List<HivePluginInfoDto> pluginList) {
136      return
137        new StreamedObject<ResponsePlugin>(
138          this.SendPlugins(pluginList));
139    }
140
141    public ResponseResultReceived StoreFinishedJobResultStreamed(Stream stream) {
142      return ((IInternalClientCommunicator)
143        clientCommunicator).ProcessJobResult(stream, true);
144    }
145
146    public ResponseResultReceived ProcessSnapshotStreamed(Stream stream) {
147      return ((IInternalClientCommunicator)
148        clientCommunicator).ProcessJobResult(stream, false);
149    }
150
151
152
153    #endregion
154  }
155}
Note: See TracBrowser for help on using the repository browser.