Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/Standalone/HeuristicLabServicesHiveApplication.cs @ 5095

Last change on this file since 5095 was 5095, checked in by cneumuel, 13 years ago

#1233

  • fixed config merge process
  • worked on hive server test setup
File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.PluginInfrastructure;
6using System.ServiceModel;
7using HeuristicLab.Services.Hive.Common.ServiceContracts;
8using System.Windows.Forms;
9
10namespace 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}
Note: See TracBrowser for help on using the repository browser.