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

Last change on this file since 4424 was 4424, checked in by cneumuel, 9 years ago
  • Added and updated License Information in every file
  • Sort and remove usings in every file
  • Deleted obsolete DataAccess.ADOHelper
  • Deleted some obsolete files
File size: 1.8 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 Port { get; set; }
13    internal static string Username { get; set; }
14    internal static string Password { get; set; } // [chn] TODO: Don't store plaintext password in memory!
15
16    internal static ISlaveManager GetSlaveManager() {
17      return GetServerConsoleFacade() as ISlaveManager;
18    }
19
20    internal static IJobManager GetJobManager() {
21      return GetServerConsoleFacade() as IJobManager;
22    }
23
24    internal static IServerConsoleFacade GetServerConsoleFacade() {
25      if (serverConsoleFacade == null && Address != String.Empty && Port != String.Empty) {
26        ChannelFactory<IServerConsoleFacade> factory = new ChannelFactory<IServerConsoleFacade>("ServerConsoleHttpEndpoint");
27        WcfSettings.SetEndpointAddress(factory.Endpoint, Address);
28
29        factory.Credentials.UserName.UserName = Username;
30        factory.Credentials.UserName.Password = Password;
31
32        IServerConsoleFacade client = factory.CreateChannel();
33
34        ((ICommunicationObject)client).Faulted += ServiceLocator_Faulted;
35        serverConsoleFacade = client;
36      }
37      return serverConsoleFacade;
38    }
39
40    static void ServiceLocator_Faulted(object sender, EventArgs e) {
41      ((ICommunicationObject)serverConsoleFacade).Abort();
42      ((ICommunicationObject)serverConsoleFacade).Faulted -= ServiceLocator_Faulted;
43      serverConsoleFacade = null;
44    }
45
46    internal static void ShutDownFacade() {
47      serverConsoleFacade = null;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.