Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs @ 6727

Last change on this file since 6727 was 6456, checked in by ascheibe, 14 years ago

#1233

  • fixed Admin Views plugin dependencies
  • use settings instead of magic numbers and strings
File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.ServiceModel;
23using HeuristicLab.Clients.Hive.SlaveCore.Properties;
24using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
25
26namespace HeuristicLab.Clients.Hive.SlaveCore {
27
28  /// <summary>
29  /// Singleton which encapsulates the SlaveCommunicationService
30  /// </summary>
31  public class SlaveClientCom {
32    private static SlaveClientCom instance;
33    private static DuplexChannelFactory<ISlaveCommunication> pipeFactory;
34    public ISlaveCommunication ClientCom { get; set; }
35
36    /// <summary>
37    /// Getter for the Instance of the SlaveClientCom
38    /// </summary>
39    /// <returns>the Instance of the SlaveClientCom class</returns>
40    public static SlaveClientCom Instance {
41      get {
42        if (instance == null) {
43          instance = new SlaveClientCom();
44        }
45        return instance;
46      }
47    }
48
49    private SlaveClientCom() {
50      SetupClientCom();
51    }
52
53    private void SetupClientCom() {
54      DummyListener dummy = new DummyListener();
55      try {
56        pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, Settings.Default.SlaveCommunicationServiceEndpoint);
57      }
58      catch {
59        pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom"));
60      }
61
62      ISlaveCommunication pipeProxy = pipeFactory.CreateChannel();
63      ClientCom = pipeProxy;
64    }
65
66    public static void Close() {
67      if (pipeFactory.State != CommunicationState.Closed)
68        pipeFactory.Close();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.