source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/ServiceLocator.cs @ 4425

Last change on this file since 4425 was 4425, checked in by cneumuel, 9 years ago
  • removed port setting from HiveServerConsole (port is configured in config file)
  • updated Files.txt
File size: 1.7 KB
Line 
1using System;
2using System.ServiceModel;
3using HeuristicLab.Hive.Contracts;
4using HeuristicLab.Hive.Contracts.Interfaces;
5
6namespace 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}
Note: See TracBrowser for help on using the repository browser.