1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.PluginInfrastructure;
|
---|
6 | using System.ServiceModel;
|
---|
7 | using HeuristicLab.Services.Hive.Common.ServiceContracts;
|
---|
8 | using System.Windows.Forms;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Services.Hive.Standalone {
|
---|
11 | [Application("Hive Server", "Server application for the distributed hive engine.", false)]
|
---|
12 | public class HeuristicLabServicesHiveApplication : ApplicationBase {
|
---|
13 | private IDictionary<string, ServiceHost> serviceHosts = new Dictionary<string, ServiceHost>();
|
---|
14 | private ILifecycleManager lifecycleManager { get { return ServiceLocator.Instance.LifecycleManager; } }
|
---|
15 |
|
---|
16 | public override void Run() {
|
---|
17 | try {
|
---|
18 | CreateAndOpenServiceHost(typeof(IHiveService), "HiveService");
|
---|
19 | Form mainForm = new MainForm(GetBaseAddresses());
|
---|
20 | Application.Run();
|
---|
21 | }
|
---|
22 | finally {
|
---|
23 | foreach (ServiceHost host in serviceHosts.Values) {
|
---|
24 | if (host.State == CommunicationState.Opened)
|
---|
25 | host.Close();
|
---|
26 | }
|
---|
27 | lifecycleManager.Stop();
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | private ServiceHost CreateAndOpenServiceHost(Type serviceInterfaceType, string serviceName) {
|
---|
32 | ServiceHost host = new ServiceHost(ApplicationManager.Manager.GetTypes(serviceInterfaceType).First());
|
---|
33 | host.Open();
|
---|
34 | serviceHosts.Add(serviceName, host);
|
---|
35 | return host;
|
---|
36 | }
|
---|
37 |
|
---|
38 | private IEnumerable<Uri> GetBaseAddresses() {
|
---|
39 | List<Uri> list = new List<Uri>();
|
---|
40 | foreach (KeyValuePair<string, ServiceHost> host in serviceHosts) {
|
---|
41 | foreach (var addr in host.Value.BaseAddresses) {
|
---|
42 | list.Add(addr);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | return list;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|