- Timestamp:
- 07/05/12 17:39:12 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs
r7259 r8242 20 20 #endregion 21 21 22 using System .ServiceModel;22 using System; 23 23 using HeuristicLab.Clients.Hive.SlaveCore.Properties; 24 24 using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts; 25 using System;26 25 27 26 namespace HeuristicLab.Clients.Hive.SlaveCore { 27 28 public enum ClientComType { Pipe, Trace }; 28 29 29 30 /// <summary> … … 32 33 public class SlaveClientCom { 33 34 private static SlaveClientCom instance; 34 private static DuplexChannelFactory<ISlaveCommunication> pipeFactory; 35 //private static DuplexChannelFactory<ISlaveCommunication> pipeFactory; 36 private static IClientCom clientComInstance; 35 37 public ISlaveCommunication ClientCom { get; set; } 36 38 … … 45 47 } 46 48 return instance; 49 } 50 } 51 52 public static IClientCom ClientComInstance { 53 get { 54 if (clientComInstance != null) { 55 return clientComInstance; 56 } 57 throw new NullReferenceException("No instance of SlaveClientCom<T>"); 47 58 } 48 59 } … … 67 78 68 79 private SlaveClientCom() { 69 SetupClientCom(); 70 } 80 ClientComType type = Settings.Default.ClientComType; 81 if (type == ClientComType.Pipe) { 82 clientComInstance = new PipeCom(); 83 } else if (type == ClientComType.Trace) { 84 clientComInstance = new TraceCom(); 85 } else { 86 throw new InvalidStateException("Invalid client communication type"); 87 } 71 88 72 private void SetupClientCom() { 73 DummyListener dummy = new DummyListener(); 74 try { 75 pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, Settings.Default.SlaveCommunicationServiceEndpoint); 76 } 77 catch { 78 EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with config!"); 79 80 try { 81 pipeFactory = new DuplexChannelFactory<ISlaveCommunication>(dummy, new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/HeuristicLabSlaveCom")); 82 } 83 catch { 84 EventLogManager.LogMessage("Couldn't create pipe for SlaveClientCom with fixed addresse!"); 85 return; 86 } 87 } 88 pipeFactory.Faulted += new System.EventHandler(pipeFactory_Faulted); 89 90 ISlaveCommunication pipeProxy = pipeFactory.CreateChannel(); 91 ClientCom = pipeProxy; 92 } 93 94 void pipeFactory_Faulted(object sender, System.EventArgs e) { 95 EventLogManager.LogMessage("SlaveClientCom just faulted. Trying to repair it..."); 96 97 try { 98 pipeFactory.Faulted -= new System.EventHandler(pipeFactory_Faulted); 99 SetupClientCom(); 100 } 101 catch { } 89 ClientCom = clientComInstance.GetSlaveCom(); 102 90 } 103 91 104 92 public static void Close() { 105 if (pipeFactory.State != CommunicationState.Closed && pipeFactory.State != CommunicationState.Faulted) 106 pipeFactory.Close(); 93 ClientComInstance.Close(); 107 94 } 108 95 }
Note: See TracChangeset
for help on using the changeset viewer.