[5156] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[6371] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5156] | 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.ServiceModel;
|
---|
[6456] | 23 | using HeuristicLab.Clients.Hive.SlaveCore.Properties;
|
---|
[5599] | 24 | using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
|
---|
[5156] | 25 |
|
---|
[5599] | 26 | namespace HeuristicLab.Clients.Hive.SlaveCore {
|
---|
[5156] | 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;
|
---|
[5795] | 34 | public ISlaveCommunication ClientCom { get; set; }
|
---|
| 35 |
|
---|
[5156] | 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() {
|
---|
[5450] | 50 | SetupClientCom();
|
---|
[5156] | 51 | }
|
---|
| 52 |
|
---|
[5450] | 53 | private void SetupClientCom() {
|
---|
[5156] | 54 | DummyListener dummy = new DummyListener();
|
---|
[6371] | 55 | try {
|
---|
[6456] | 56 | pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, Settings.Default.SlaveCommunicationServiceEndpoint);
|
---|
[6371] | 57 | }
|
---|
| 58 | catch {
|
---|
| 59 | pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom"));
|
---|
| 60 | }
|
---|
[5795] | 61 |
|
---|
[5156] | 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 | } |
---|