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