1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.PluginInfrastructure;
|
---|
27 | using System.ServiceModel;
|
---|
28 | using System.ServiceModel.Description;
|
---|
29 | using System.Net;
|
---|
30 | using HeuristicLab.Hive.Contracts;
|
---|
31 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Hive.Server {
|
---|
34 | [ClassInfo(Name = "Hive Server",
|
---|
35 | Description = "Server application for the distributed hive engine.",
|
---|
36 | AutoRestart = true)]
|
---|
37 | class HiveServerApplication : ApplicationBase {
|
---|
38 | const int port = 9000;
|
---|
39 |
|
---|
40 | public override void Run() {
|
---|
41 | IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());
|
---|
42 | string externalIP = IPHost.AddressList[0].ToString();
|
---|
43 |
|
---|
44 | DiscoveryService discService =
|
---|
45 | new DiscoveryService();
|
---|
46 | IClientCommunicator[] instances =
|
---|
47 | discService.GetInstances<IClientCommunicator>();
|
---|
48 |
|
---|
49 | if (instances.Length > 0) {
|
---|
50 | Uri uriTcp =
|
---|
51 | new Uri("net.tcp://" + externalIP + ":" + port +"/HiveServer/");
|
---|
52 |
|
---|
53 | ServiceHost serviceHost =
|
---|
54 | new ServiceHost(instances[0].GetType(),
|
---|
55 | uriTcp);
|
---|
56 |
|
---|
57 | System.ServiceModel.Channels.Binding binding =
|
---|
58 | new NetTcpBinding();
|
---|
59 |
|
---|
60 | serviceHost.AddServiceEndpoint(
|
---|
61 | typeof(IClientCommunicator),
|
---|
62 | binding,
|
---|
63 | "ClientCommunicator");
|
---|
64 |
|
---|
65 | ServiceMetadataBehavior behavior =
|
---|
66 | new ServiceMetadataBehavior();
|
---|
67 | serviceHost.Description.Behaviors.Add(behavior);
|
---|
68 |
|
---|
69 | serviceHost.AddServiceEndpoint(
|
---|
70 | typeof(IMetadataExchange),
|
---|
71 | MetadataExchangeBindings.CreateMexTcpBinding(),
|
---|
72 | "mex");
|
---|
73 |
|
---|
74 | serviceHost.Open();
|
---|
75 |
|
---|
76 | Form mainForm = new MainForm(serviceHost.BaseAddresses[0]);
|
---|
77 | Application.Run(mainForm);
|
---|
78 |
|
---|
79 | serviceHost.Close();
|
---|
80 | } else {
|
---|
81 | MessageBox.Show("Error - no ClientCommunicator instance");
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|