[799] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 |
|
---|
| 6 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
| 7 | using System.ServiceModel;
|
---|
[1579] | 8 | using HeuristicLab.Hive.Contracts;
|
---|
[799] | 9 |
|
---|
[1089] | 10 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
[799] | 11 | internal class ServiceLocator {
|
---|
[1084] | 12 | private static IServerConsoleFacade serverConsoleFacade = null;
|
---|
[799] | 13 |
|
---|
| 14 | internal static string Address { get; set; }
|
---|
| 15 | internal static string Port { get; set; }
|
---|
| 16 |
|
---|
[4267] | 17 | internal static ISlaveManager GetSlaveManager() {
|
---|
[4253] | 18 | return GetServerConsoleFacade() as ISlaveManager;
|
---|
[799] | 19 | }
|
---|
| 20 |
|
---|
| 21 | internal static IJobManager GetJobManager() {
|
---|
[1084] | 22 | return GetServerConsoleFacade() as IJobManager;
|
---|
| 23 | }
|
---|
[799] | 24 |
|
---|
[1084] | 25 | internal static IServerConsoleFacade GetServerConsoleFacade() {
|
---|
| 26 | if (serverConsoleFacade == null &&
|
---|
[799] | 27 | Address != String.Empty &&
|
---|
| 28 | Port != String.Empty) {
|
---|
[1136] | 29 |
|
---|
[1084] | 30 | ChannelFactory<IServerConsoleFacade> factory =
|
---|
| 31 | new ChannelFactory<IServerConsoleFacade>(
|
---|
[1579] | 32 | WcfSettings.GetBinding(),
|
---|
[1084] | 33 | new EndpointAddress("net.tcp://" + Address + ":" + Port + "/HiveServerConsole/ServerConsoleFacade"));
|
---|
[2103] | 34 |
|
---|
[1084] | 35 | serverConsoleFacade = factory.CreateChannel();
|
---|
[4042] | 36 | ((ICommunicationObject)serverConsoleFacade).Faulted += ServiceLocator_Faulted;
|
---|
[799] | 37 | }
|
---|
[2103] | 38 |
|
---|
[1084] | 39 | return serverConsoleFacade;
|
---|
[799] | 40 | }
|
---|
[1723] | 41 |
|
---|
[4042] | 42 | static void ServiceLocator_Faulted(object sender, EventArgs e) {
|
---|
| 43 | ((ICommunicationObject)serverConsoleFacade).Abort();
|
---|
| 44 | ((ICommunicationObject)serverConsoleFacade).Faulted -= ServiceLocator_Faulted;
|
---|
| 45 | serverConsoleFacade = null;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[1723] | 48 | internal static void ShutDownFacade() {
|
---|
| 49 | serverConsoleFacade = null;
|
---|
| 50 | }
|
---|
[799] | 51 | }
|
---|
| 52 | }
|
---|