Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/Server.cs @ 1322

Last change on this file since 1322 was 1287, checked in by gkronber, 16 years ago

Merged change sets from CEDMA branch to trunk:

File size: 3.1 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      IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
54      // windows XP returns the external ip on index 0 while windows vista returns the external ip as one of the last entries
55      // also if IPv6 protocol is installed we want to find an entry that is IPv4
56      int index = 0;
57      if (System.Environment.OSVersion.Version.Major >= 6) {
58        for (index = addresses.Length - 1; index >= 0; index--)
59          if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
60            break;
61      }
62      cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA";
63      this.store = store;
64    }
65
66    public void Start() {
67      host = new ServiceHost(store, new Uri(cedmaServiceUrl));
68      ServiceThrottlingBehavior throttlingBehavior = new ServiceThrottlingBehavior();
69      throttlingBehavior.MaxConcurrentSessions = 20;
70      host.Description.Behaviors.Add(throttlingBehavior);
71      try {
72        NetTcpBinding binding = new NetTcpBinding();
73        binding.SendTimeout = new TimeSpan(1, 0, 0);
74        binding.MaxReceivedMessageSize = 1000000000; // 100Mbytes
75        binding.ReaderQuotas.MaxStringContentLength = 1000000000; // also 100M chars
76        binding.ReaderQuotas.MaxArrayLength = 1000000000; // also 100M elements;
77        host.AddServiceEndpoint(typeof(IStore), binding, cedmaServiceUrl);
78        host.Open();
79      }
80      catch (CommunicationException ex) {
81        MessageBox.Show("An exception occurred: " + ex.Message);
82        host.Abort();
83      }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.