Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Services.OKB/3.3/Hoster.cs @ 4306

Last change on this file since 4306 was 4298, checked in by swagner, 14 years ago

Worked on OKB user authentication (#1167)

File size: 3.7 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.Reflection;
24using System.ServiceModel;
25using System.ServiceModel.Description;
26using System.Text;
27using log4net;
28
29namespace HeuristicLab.Services.OKB {
30
31  /// <summary>
32  /// Simple main class for self hosting the OKB service with all necessary
33  /// services for full operation.
34  /// </summary>
35  public class Hoster {
36
37    // you might have to run
38    // netsh http add urlacl url=http://+:8000/OKB/ user=DOMAIN\username
39    // as administrator
40    /// <summary>
41    /// Main method to start the services.
42    /// </summary>
43    /// <param name="args">The args.</param>
44    public static void Main(string[] args) {
45      InitializeLogging();
46      StartService(typeof(QueryService));
47      StartService(typeof(RunnerService));
48      StartService(typeof(AdminService));
49      StartService(typeof(TableService));
50      StartService(typeof(DataService));
51      AppDomain.CurrentDomain.UnhandledException += UnhandledException;
52      Console.ReadLine();
53    }
54
55    static ILog logger = log4net.LogManager.GetLogger("HeuristicLab.Services.OKB.Hoster");
56
57    static void UnhandledException(object sender, UnhandledExceptionEventArgs e) {
58      logger.Warn("unhandled exception, e");
59    }
60
61    private static void InitializeLogging() {
62      log4net.Config.BasicConfigurator.Configure();
63    }
64
65    private static void StartService(Type type) {
66      ServiceHost host = new ServiceHost(type);
67      try {
68        host.Open();
69        PrintConfig(host);
70      }
71      catch (AddressAccessDeniedException x) {
72        Console.WriteLine(
73          "Could not process listerner request. Try running the following as Administrator:\n\n" +
74          "netsh http add urlacl url=http://+port/OKB/ user=DOMAIN\\username\n\n" +
75          x.ToString());
76      }
77      catch (Exception x) {
78        Console.WriteLine("Aborting host of type {0} due to {1}",
79          host.GetType(),
80          x.ToString());
81        host.Abort();
82      }
83    }
84
85    static void PrintConfig(ServiceHost host) {
86      Console.WriteLine("{0}", host.Description.ServiceType.Name);
87      Console.WriteLine("\n  endpoints:");
88      foreach (ServiceEndpoint se in host.Description.Endpoints) {
89        Console.WriteLine("    {0}", se.Address);
90      }
91      Console.WriteLine("\n  methods:");
92      foreach (MethodInfo mi in host.Description.ServiceType.GetMethods(
93          BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)) {
94        StringBuilder sb = new StringBuilder();
95        foreach (ParameterInfo pi in mi.GetParameters()) {
96          sb.Append(pi.ParameterType.Name).Append(' ').Append(pi.Name).Append(", ");
97        }
98        if (sb.Length > 2)
99          sb.Remove(sb.Length - 2, 2);
100        Console.WriteLine("    {0}({1}) : {2}", mi.Name, sb, mi.ReturnType.Name);
101      }
102      Console.WriteLine();
103    }
104
105  }
106}
Note: See TracBrowser for help on using the repository browser.