source: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Server.cs @ 1044

Last change on this file since 1044 was 1044, checked in by gkronber, 13 years ago

worked on dispatcher for CEDMA agents. #419 (Refactor CEDMA plugins)

File size: 2.9 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.Text;
25using System.Windows.Forms;
26using HeuristicLab.PluginInfrastructure;
27using System.Net;
28using System.ServiceModel;
29using HeuristicLab.CEDMA.DB.Interfaces;
30using HeuristicLab.CEDMA.DB;
31using System.ServiceModel.Description;
32
33namespace HeuristicLab.CEDMA.Server {
34  public class Server {
35    private ServiceHost host;
36    private IStore store;
37
38    private string gridServiceUrl;
39
40    public string GridServiceUrl {
41      get { return gridServiceUrl; }
42      set { gridServiceUrl = value; }
43    }
44
45    private string cedmaServiceUrl;
46
47    public string CedmaServiceUrl {
48      get { return cedmaServiceUrl; }
49      set { cedmaServiceUrl = value; }
50    }
51
52    public Server(IStore store) {
53      // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2
54      if (System.Environment.OSVersion.Version.Major >= 6) {
55        cedmaServiceUrl = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8002/CEDMA/World";
56      } else {
57        cedmaServiceUrl = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
58      }
59      this.store = store;
60    }
61
62    public void Start() {
63      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
64      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
65      throttlingBehavior.MaxConcurrentSessions = 20;
66      host.Description.Behaviors.Add(throttlingBehavior);
67      try {
68        NetTcpBinding binding = new NetTcpBinding();
69        binding.MaxReceivedMessageSize = 100000000; // 100Mbytes
70        binding.ReaderQuotas.MaxStringContentLength = 100000000; // also 100M chars
71        binding.ReaderQuotas.MaxArrayLength = 100000000; // also 100M elements;
72        binding.Security.Mode = SecurityMode.None;
73
74        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
75        host.Open();
76      }
77      catch (CommunicationException ex) {
78        MessageBox.Show("An exception occurred: " + ex.Message);
79        host.Abort();
80      }
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.