[1044] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.PluginInfrastructure;
|
---|
| 27 | using System.Net;
|
---|
| 28 | using System.ServiceModel;
|
---|
| 29 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
| 30 | using HeuristicLab.CEDMA.DB;
|
---|
| 31 | using System.ServiceModel.Description;
|
---|
| 32 |
|
---|
| 33 | namespace 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) {
|
---|
[1287] | 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;
|
---|
[1044] | 57 | if (System.Environment.OSVersion.Version.Major >= 6) {
|
---|
[1287] | 58 | for (index = addresses.Length - 1; index >= 0; index--)
|
---|
| 59 | if (addresses[index].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
---|
| 60 | break;
|
---|
[1044] | 61 | }
|
---|
[1287] | 62 | cedmaServiceUrl = "net.tcp://" + addresses[index] + ":8002/CEDMA";
|
---|
[1044] | 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();
|
---|
[1417] | 73 | binding.SendTimeout = new TimeSpan(10, 0, 0);
|
---|
| 74 | binding.MaxReceivedMessageSize = int.MaxValue;
|
---|
| 75 | binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
|
---|
| 76 | binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
|
---|
[1044] | 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 | }
|
---|