Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server/3.3/HeuristicLabHiveServerApplication.cs @ 4333

Last change on this file since 4333 was 4333, checked in by cneumuel, 14 years ago

added authorizationManager which checks for permission to specific jobs (#1168)

File size: 3.2 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Net;
26using System.ServiceModel;
27using System.ServiceModel.Description;
28using System.Windows.Forms;
29using HeuristicLab.Hive.Contracts;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Hive.Server.Core;
33
34namespace HeuristicLab.Hive.Server {
35  [Application("Hive Server", "Server application for the distributed hive engine.", false)]
36  public class HeuristicLabHiveServerApplication : ApplicationBase {
37    private IDictionary<string, ServiceHost> serviceHosts = new Dictionary<string, ServiceHost>();
38    ILifecycleManager lifecycleManager = null;
39
40    public override void Run() {
41      try {
42        CreateAndOpenServiceHost(typeof(ISlaveFacade), WcfSettings.SlaveServiceName);
43        CreateAndOpenServiceHost(typeof(IServerConsoleFacade), WcfSettings.ServerConsoleServiceName);
44        CreateAndOpenServiceHost(typeof(IClientFacade), WcfSettings.ClientServiceName);
45
46        lifecycleManager = ServiceLocator.GetLifecycleManager();
47        lifecycleManager.Init();
48
49        Form mainForm = new MainForm(GetBaseAddresses());
50        Application.Run();
51      } finally {
52        foreach (ServiceHost host in serviceHosts.Values) {
53          if (host.State == CommunicationState.Opened)
54            host.Close();
55        }
56        if (lifecycleManager != null)
57          lifecycleManager.Shutdown();
58      }
59    }
60
61    private ServiceHost CreateAndOpenServiceHost(Type serviceInterfaceType, string serviceName) {
62      try {
63        ServiceHost host = new ServiceHost(ApplicationManager.Manager.GetTypes(serviceInterfaceType).First());
64        host.Open();
65        serviceHosts.Add(serviceName, host);
66        return host;
67      }
68      catch (AddressAccessDeniedException ex) {
69        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);
70      }
71    }
72
73    private IEnumerable<Uri> GetBaseAddresses() {
74      List<Uri> list = new List<Uri>();
75      foreach (KeyValuePair<string, ServiceHost> host in serviceHosts) {
76        foreach (var addr in host.Value.BaseAddresses) {
77          list.Add(addr);
78        }
79      }
80      return list;
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.