Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/20/08 17:52:05 (16 years ago)
Author:
msteinbi
Message:

Added additional WCF endpoint for the server management console - fixed #381

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server/HiveServerApplication.cs

    r780 r800  
    3636      AutoRestart = true)]
    3737  class HiveServerApplication : ApplicationBase {
    38     const int port = 9000;
     38    const int port =
     39      9000;
    3940
    40     public override void Run() {
    41       IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());
    42       string externalIP = IPHost.AddressList[0].ToString();
     41    DiscoveryService discService =
     42        new DiscoveryService();
    4343
    44       DiscoveryService discService =
    45         new DiscoveryService();
    46       IClientCommunicator[] instances =
     44    private bool AddMexEndpoint(ServiceHost serviceHost) {
     45      if(serviceHost != null) {
     46        ServiceMetadataBehavior behavior =
     47            new ServiceMetadataBehavior();
     48          serviceHost.Description.Behaviors.Add(behavior);
     49
     50          return serviceHost.AddServiceEndpoint(
     51            typeof(IMetadataExchange),
     52            MetadataExchangeBindings.CreateMexTcpBinding(),
     53            "mex") != null;
     54      } else
     55        return false;
     56    }
     57
     58    private ServiceHost StartClientCommunicator(Uri uriTcp) {
     59      IClientCommunicator[] clientCommunicatorInstances =
    4760        discService.GetInstances<IClientCommunicator>();
    4861
    49       if (instances.Length > 0) {
    50         Uri uriTcp =
    51           new Uri("net.tcp://" + externalIP + ":" + port +"/HiveServer/");
    52 
     62      if (clientCommunicatorInstances.Length > 0) {
    5363        ServiceHost serviceHost =
    54                 new ServiceHost(instances[0].GetType(),
     64                new ServiceHost(clientCommunicatorInstances[0].GetType(),
    5565                  uriTcp);
    5666
    57         System.ServiceModel.Channels.Binding binding = 
     67        System.ServiceModel.Channels.Binding binding =
    5868          new NetTcpBinding();
    5969
     
    6373              "ClientCommunicator");
    6474
    65         ServiceMetadataBehavior behavior =
    66           new ServiceMetadataBehavior();
    67         serviceHost.Description.Behaviors.Add(behavior);
    68 
    69         serviceHost.AddServiceEndpoint(
    70           typeof(IMetadataExchange),
    71           MetadataExchangeBindings.CreateMexTcpBinding(),
    72           "mex");
     75        AddMexEndpoint(serviceHost);
    7376
    7477        serviceHost.Open();
    7578
    76         Form mainForm = new MainForm(serviceHost.BaseAddresses[0]);
    77         Application.Run(mainForm);
     79        return serviceHost;
     80      } else
     81        return null;
     82    }
    7883
    79         serviceHost.Close();
    80       } else {
    81         MessageBox.Show("Error - no ClientCommunicator instance");
    82       }
     84    private ServiceHost StartServerConsoleFacade(Uri uriTcp) {
     85      IServerConsoleFacade[] serverConsoleInstances =
     86        discService.GetInstances<IServerConsoleFacade>();
     87
     88      if (serverConsoleInstances.Length > 0) {
     89        ServiceHost serviceHost =
     90                new ServiceHost(serverConsoleInstances[0].GetType(),
     91                  uriTcp);
     92
     93        System.ServiceModel.Channels.Binding binding =
     94          new NetTcpBinding();
     95
     96        serviceHost.AddServiceEndpoint(
     97          typeof(IClientManager),
     98              binding,
     99              "ClientManager");
     100
     101        serviceHost.AddServiceEndpoint(
     102          typeof(IJobManager),
     103              binding,
     104              "JobManager");
     105
     106        serviceHost.AddServiceEndpoint(
     107          typeof(IUserRoleManager),
     108              binding,
     109              "UserRoleManager");
     110
     111        AddMexEndpoint(serviceHost);
     112
     113        serviceHost.Open();
     114
     115        return serviceHost;
     116      } else
     117        return null;
     118    }
     119
     120    public override void Run() {
     121      string externalIP =
     122        Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
     123
     124      Uri uriTcp =
     125          new Uri("net.tcp://" + externalIP + ":" + port + "/HiveServer/");
     126
     127      ServiceHost clientCommunicator =
     128        StartClientCommunicator(uriTcp);
     129
     130      uriTcp =
     131        new Uri("net.tcp://" + externalIP + ":" + port + "/HiveServerConsole/");
     132
     133      ServiceHost serverConsoleFacade =
     134        StartServerConsoleFacade(uriTcp);
     135
     136      Form mainForm = new MainForm(clientCommunicator.BaseAddresses[0],
     137        serverConsoleFacade.BaseAddresses[0]);
     138
     139      Application.Run(mainForm);
     140
     141      clientCommunicator.Close();
     142      serverConsoleFacade.Close();
    83143    }
    84144  }
Note: See TracChangeset for help on using the changeset viewer.