1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 |
|
---|
6 | using System.ServiceModel;
|
---|
7 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
8 | using HeuristicLab.Hive.Contracts;
|
---|
9 | using System.ServiceModel.Description;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
12 |
|
---|
13 | internal class ServiceLocator {
|
---|
14 | private static IServerConsoleFacade serverConsoleFacade = null;
|
---|
15 |
|
---|
16 | internal static string Address { get; set; }
|
---|
17 | internal static string Port { get; set; }
|
---|
18 | internal static string Username { get; set; }
|
---|
19 | internal static string Password { get; set; } // [chn] TODO: Don't store plaintext password in memory!
|
---|
20 |
|
---|
21 | internal static ISlaveManager GetSlaveManager() {
|
---|
22 | return GetServerConsoleFacade() as ISlaveManager;
|
---|
23 | }
|
---|
24 |
|
---|
25 | internal static IJobManager GetJobManager() {
|
---|
26 | return GetServerConsoleFacade() as IJobManager;
|
---|
27 | }
|
---|
28 |
|
---|
29 | internal static IServerConsoleFacade GetServerConsoleFacade() {
|
---|
30 | if (serverConsoleFacade == null && Address != String.Empty && Port != String.Empty) {
|
---|
31 | ChannelFactory<IServerConsoleFacade> factory = new ChannelFactory<IServerConsoleFacade>("ServerConsoleHttpEndpoint");
|
---|
32 | WcfSettings.SetEndpointAddress(factory.Endpoint, Address);
|
---|
33 |
|
---|
34 | factory.Credentials.UserName.UserName = Username;
|
---|
35 | factory.Credentials.UserName.Password = Password;
|
---|
36 |
|
---|
37 | IServerConsoleFacade client = factory.CreateChannel();
|
---|
38 |
|
---|
39 | ((ICommunicationObject)client).Faulted += ServiceLocator_Faulted;
|
---|
40 | serverConsoleFacade = client;
|
---|
41 | }
|
---|
42 | return serverConsoleFacade;
|
---|
43 | }
|
---|
44 |
|
---|
45 | static void ServiceLocator_Faulted(object sender, EventArgs e) {
|
---|
46 | ((ICommunicationObject)serverConsoleFacade).Abort();
|
---|
47 | ((ICommunicationObject)serverConsoleFacade).Faulted -= ServiceLocator_Faulted;
|
---|
48 | serverConsoleFacade = null;
|
---|
49 | }
|
---|
50 |
|
---|
51 | internal static void ShutDownFacade() {
|
---|
52 | serverConsoleFacade = null;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|