#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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; using HeuristicLab.Clients.Hive.SlaveCore.Properties; using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts; namespace HeuristicLab.Clients.Hive.SlaveCore { public enum ClientComType { Pipe, Trace }; /// /// Singleton which encapsulates the SlaveCommunicationService /// public class SlaveClientCom { private static SlaveClientCom instance; //private static DuplexChannelFactory pipeFactory; private static IClientCom clientComInstance; 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; } } public static IClientCom ClientComInstance { get { if (clientComInstance != null) { return clientComInstance; } throw new NullReferenceException("No instance of SlaveClientCom"); } } public void LogMessage(string message) { try { ClientCom.LogMessage(message); } catch (Exception ex) { EventLogManager.LogMessage("Exception on LogMessage: " + ex.ToString() + Environment.NewLine + "Orginal message was: " + message); } } public void StatusChanged(StatusCommons status) { try { ClientCom.StatusChanged(status); } catch (Exception ex) { EventLogManager.LogMessage("Exception on StatusChanged: " + ex.ToString()); } } private SlaveClientCom() { ClientComType type = Settings.Default.ClientComType; if (type == ClientComType.Pipe) { clientComInstance = new PipeCom(); } else if (type == ClientComType.Trace) { clientComInstance = new TraceCom(); } else { throw new InvalidStateException("Invalid client communication type"); } ClientCom = clientComInstance.GetSlaveCom(); } public static void Close() { ClientComInstance.Close(); } } }