Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs @ 4710

Last change on this file since 4710 was 4424, checked in by cneumuel, 14 years ago
  • Added and updated License Information in every file
  • Sort and remove usings in every file
  • Deleted obsolete DataAccess.ADOHelper
  • Deleted some obsolete files
File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.ServiceModel;
26using System.Windows.Forms;
27using HeuristicLab.Hive.Contracts;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Server.Core;
30using HeuristicLab.PluginInfrastructure;
31
32namespace HeuristicLab.Hive.Server {
33  [Application("Hive Server", "Server application for the distributed hive engine.", false)]
34  public class HeuristicLabHiveServerApplication : ApplicationBase {
35    private IDictionary<string, ServiceHost> serviceHosts = new Dictionary<string, ServiceHost>();
36    ILifecycleManager lifecycleManager = null;
37
38    public override void Run() {
39      try {
40        CreateAndOpenServiceHost(typeof(ISlaveFacade), WcfSettings.SlaveServiceName);
41        CreateAndOpenServiceHost(typeof(IServerConsoleFacade), WcfSettings.ServerConsoleServiceName);
42        CreateAndOpenServiceHost(typeof(IClientFacade), WcfSettings.ClientServiceName);
43
44        lifecycleManager = ServiceLocator.GetLifecycleManager();
45        lifecycleManager.Start();
46
47        Form mainForm = new MainForm(GetBaseAddresses());
48        Application.Run();
49       
50      } finally {
51        foreach (ServiceHost host in serviceHosts.Values) {
52          if (host.State == CommunicationState.Opened)
53            host.Close();
54        }
55        if (lifecycleManager != null)
56          lifecycleManager.Stop();
57      }
58    }
59
60    private ServiceHost CreateAndOpenServiceHost(Type serviceInterfaceType, string serviceName) {
61      try {
62        ServiceHost host = new ServiceHost(ApplicationManager.Manager.GetTypes(serviceInterfaceType).First());
63        host.Open();
64        serviceHosts.Add(serviceName, host);
65        return host;
66      }
67      catch (AddressAccessDeniedException ex) {
68        throw new Exception("Unable to start WCF-Services due to missing rights. Run the following command as administrator: \"netsh http add urlacl url=http://+:" + WcfSettings.DefaultPort + "/ user=MYMACHINE\\UserName\". See inner exception for more details.", ex);
69      }
70    }
71
72    private IEnumerable<Uri> GetBaseAddresses() {
73      List<Uri> list = new List<Uri>();
74      foreach (KeyValuePair<string, ServiceHost> host in serviceHosts) {
75        foreach (var addr in host.Value.BaseAddresses) {
76          list.Add(addr);
77        }
78      }
79      return list;
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.