#region License Information /* HeuristicLab * Copyright (C) 2002-2010 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 System.ServiceModel; using System.Threading; using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts; namespace HeuristicLab.Clients.Hive.SlaveCore.Tests { /// /// mock a client, simply print out messages /// [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)] public class SlaveCommListener : ISlaveCommunicationCallbacks, IDisposable { ISlaveCommunication pipeProxy; DuplexChannelFactory pipeFactory; public void Open() { pipeFactory = new DuplexChannelFactory(this, "SlaveCommunicationServiceEndpoint"); while (!ReconnectToSlaveCore()) { Thread.Sleep(500); } } public bool ReconnectToSlaveCore() { try { pipeProxy = pipeFactory.CreateChannel(); pipeProxy.Subscribe(); return true; } catch (Exception e) { OnMessageLogged("Couldn't connect to Slave core. Is it possible that the Slave Core isn't running?" + Environment.NewLine + "Exception is: " + e.ToString()); return false; } } public void Close() { if (pipeFactory.State != CommunicationState.Closed) { pipeProxy.Unsubscribe(); pipeFactory.Close(); } } public void OnStatusChanged(SlaveCore.StatusCommons status) { System.Console.WriteLine("SlaveCommListener: " + status); } public void OnMessageLogged(string message) { System.Console.WriteLine("SlaveCommListener: " + message); } public void OnShutdown() { System.Console.WriteLine("SlaveCommListner: Slave quit"); } public void Dispose() { Close(); } } }