#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.ServiceModel; using HeuristicLab.Clients.Hive.SlaveCore.Properties; using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts; namespace HeuristicLab.Clients.Hive.SlaveCore { /// /// Singleton which encapsulates the SlaveCommunicationService /// public class SlaveClientCom { private static SlaveClientCom instance; private static DuplexChannelFactory pipeFactory; public ISlaveCommunication ClientCom { get; set; } /// /// Getter for the Instance of the SlaveClientCom /// /// the Instance of the SlaveClientCom class public static SlaveClientCom Instance { get { if (instance == null) { instance = new SlaveClientCom(); } return instance; } } private SlaveClientCom() { SetupClientCom(); } private void SetupClientCom() { DummyListener dummy = new DummyListener(); try { pipeFactory = new DuplexChannelFactory(dummy, Settings.Default.SlaveCommunicationServiceEndpoint); } catch { pipeFactory = new DuplexChannelFactory(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom")); } ISlaveCommunication pipeProxy = pipeFactory.CreateChannel(); ClientCom = pipeProxy; } public static void Close() { if (pipeFactory.State != CommunicationState.Closed) pipeFactory.Close(); } } }