Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Core/3.3/Facades/ClientFacade.cs @ 4107

Last change on this file since 4107 was 4107, checked in by cneumuel, 14 years ago

migration from 3.2 to 3.3 completed. Hive Server and Client are now executable and as functional as they were in 3.2. (#1096)

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