1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Hive.Slave.Communication.SlaveService;
|
---|
6 | using HeuristicLab.Hive.Contracts;
|
---|
7 | using System.ServiceModel;
|
---|
8 | using HeuristicLab.Hive.Slave.Communication.Properties;
|
---|
9 | using HeuristicLab.Tracing;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Hive.Slave.Communication {
|
---|
12 | internal static class ServiceLocator {
|
---|
13 | /// <summary>
|
---|
14 | /// Cache of SlaveFacadeClients, to check if all get disposed
|
---|
15 | /// </summary>
|
---|
16 | private static List<ISlaveFacade> clientCache = new List<ISlaveFacade>();
|
---|
17 |
|
---|
18 | internal static ISlaveFacade CreateSlaveFacade(string hostAddress) {
|
---|
19 | SlaveFacadeClient client = new SlaveFacadeClient("SlaveHttpEndpoint");
|
---|
20 | WcfSettings.SetEndpointAddress(client.Endpoint, hostAddress);
|
---|
21 | SetCredentials(client);
|
---|
22 | client.Open();
|
---|
23 | clientCache.Add(client);
|
---|
24 | Logger.Debug("Created SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
|
---|
25 | return client;
|
---|
26 | }
|
---|
27 |
|
---|
28 | internal static ISlaveFacade CreateStreamedSlaveFacade(string hostAddress) {
|
---|
29 | SlaveFacadeClient client = new SlaveFacadeClient("SlaveTcpStreamedEndpoint");
|
---|
30 | WcfSettings.SetEndpointAddress(client.Endpoint, hostAddress);
|
---|
31 | SetCredentials(client);
|
---|
32 | client.Open();
|
---|
33 | clientCache.Add(client);
|
---|
34 | Logger.Debug("Created SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
|
---|
35 | return client;
|
---|
36 | }
|
---|
37 |
|
---|
38 | private static void SetCredentials(SlaveFacadeClient client) {
|
---|
39 | client.ClientCredentials.UserName.UserName = Settings.Default.HiveUsername;
|
---|
40 | client.ClientCredentials.UserName.Password = Settings.Default.HivePassword;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static void DisposeSlaveClient(ISlaveFacade slaveFacade) {
|
---|
44 | WcfSettings.DisposeWcfClient((ICommunicationObject)slaveFacade);
|
---|
45 | clientCache.Remove(slaveFacade);
|
---|
46 | Logger.Debug("Disposing SlaveFacadeClients. Currently existing SlaveFacadeClients: " + clientCache.Count);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|