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 Username { get; set; }
|
---|
12 | internal static string Password { get; set; } // [chn] TODO: Don't store plaintext password in memory!
|
---|
13 |
|
---|
14 | internal static ISlaveManager GetSlaveManager() {
|
---|
15 | return GetServerConsoleFacade() as ISlaveManager;
|
---|
16 | }
|
---|
17 |
|
---|
18 | internal static IJobManager GetJobManager() {
|
---|
19 | return GetServerConsoleFacade() as IJobManager;
|
---|
20 | }
|
---|
21 |
|
---|
22 | internal static IServerConsoleFacade GetServerConsoleFacade() {
|
---|
23 | if (serverConsoleFacade == null) {
|
---|
24 | ChannelFactory<IServerConsoleFacade> factory = new ChannelFactory<IServerConsoleFacade>("ServerConsoleHttpEndpoint");
|
---|
25 | //WcfSettings.SetEndpointAddress(factory.Endpoint, Address);
|
---|
26 |
|
---|
27 | factory.Credentials.UserName.UserName = Username;
|
---|
28 | factory.Credentials.UserName.Password = Password;
|
---|
29 |
|
---|
30 | IServerConsoleFacade client = factory.CreateChannel();
|
---|
31 |
|
---|
32 | ((ICommunicationObject)client).Faulted += ServiceLocator_Faulted;
|
---|
33 | serverConsoleFacade = client;
|
---|
34 | }
|
---|
35 | return serverConsoleFacade;
|
---|
36 | }
|
---|
37 |
|
---|
38 | static void ServiceLocator_Faulted(object sender, EventArgs e) {
|
---|
39 | ((ICommunicationObject)serverConsoleFacade).Abort();
|
---|
40 | ((ICommunicationObject)serverConsoleFacade).Faulted -= ServiceLocator_Faulted;
|
---|
41 | serverConsoleFacade = null;
|
---|
42 | }
|
---|
43 |
|
---|
44 | internal static void ShutDownFacade() {
|
---|
45 | serverConsoleFacade = null;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|