#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.ServiceModel;
using HeuristicLab.Clients.Hive.SlaveCore.Properties;
using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
namespace HeuristicLab.Clients.Hive.SlaveCore {
public class PipeCom : IClientCom {
private static DuplexChannelFactory pipeFactory;
private ISlaveCommunication clientCom;
public PipeCom() {
SetupClientCom();
}
public ISlaveCommunication GetSlaveCom() {
return clientCom;
}
private void SetupClientCom() {
DummyListener dummy = new DummyListener();
try {
pipeFactory = new DuplexChannelFactory(dummy, Settings.Default.SlaveCommunicationServiceEndpoint);
}
catch {
EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with config!");
try {
pipeFactory = new DuplexChannelFactory(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom"));
}
catch {
EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with fixed addresse!");
return;
}
}
pipeFactory.Faulted += new System.EventHandler(pipeFactory_Faulted);
ISlaveCommunication pipeProxy = pipeFactory.CreateChannel();
clientCom = pipeProxy;
}
void pipeFactory_Faulted(object sender, System.EventArgs e) {
EventLogManager.LogMessage("SlaveClientCom just faulted. Trying to repair it...");
try {
pipeFactory.Faulted -= new System.EventHandler(pipeFactory_Faulted);
SetupClientCom();
}
catch { }
}
public void Close() {
if (pipeFactory.State != CommunicationState.Closed && pipeFactory.State != CommunicationState.Faulted)
pipeFactory.Close();
}
}
}