1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.ServiceModel.Description;
|
---|
6 | using System.ServiceModel;
|
---|
7 | using HeuristicLab.PluginInfrastructure;
|
---|
8 | using HeuristicLab.Hive.Client.Core.ClientConsoleService.Interfaces;
|
---|
9 | using HeuristicLab.Hive.Contracts;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Hive.Client.Core.ClientConsoleService {
|
---|
12 | public class ClientConsoleServer {
|
---|
13 |
|
---|
14 | private bool AddMexEndpoint(ServiceHost serviceHost) {
|
---|
15 | if (serviceHost != null) {
|
---|
16 | ServiceMetadataBehavior behavior =
|
---|
17 | new ServiceMetadataBehavior();
|
---|
18 | serviceHost.Description.Behaviors.Add(behavior);
|
---|
19 |
|
---|
20 | return serviceHost.AddServiceEndpoint(
|
---|
21 | typeof(IMetadataExchange),
|
---|
22 | MetadataExchangeBindings.CreateMexTcpBinding(),
|
---|
23 | "mex") != null;
|
---|
24 | } else
|
---|
25 | return false;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public ServiceHost StartClientConsoleServer(Uri uriTcp) {
|
---|
29 | IEnumerable<IClientConsoleCommunicator> clientConsoleServerInstances =
|
---|
30 | ApplicationManager.Manager.GetInstances<IClientConsoleCommunicator>();
|
---|
31 |
|
---|
32 | if (clientConsoleServerInstances.Count() > 0) {
|
---|
33 | ServiceHost serviceHost =
|
---|
34 | new ServiceHost(clientConsoleServerInstances.First().GetType(),
|
---|
35 | uriTcp);
|
---|
36 |
|
---|
37 | serviceHost.AddServiceEndpoint(
|
---|
38 | typeof(IClientConsoleCommunicator),
|
---|
39 | WcfSettings.GetBinding(),
|
---|
40 | "ClientConsoleCommunicator");
|
---|
41 |
|
---|
42 | AddMexEndpoint(serviceHost);
|
---|
43 |
|
---|
44 | serviceHost.Open();
|
---|
45 | return serviceHost;
|
---|
46 | } else {
|
---|
47 | return null;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|