Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/16 17:46:40 (8 years ago)
Author:
thasling
Message:

#2615: implemented Dispose()-Method in all classes
also sending a message with the wcf-sender class was rewritten, because of Dispose
added new log entries when server removes peers from its dicionary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageSender.cs

    r13887 r13918  
    44using DistributedGA.Core.Interface;
    55
    6 namespace DistributedGA.Core.Implementation
    7 {
    8     public class WcfMessageSender : IMessageSender
    9     {
    10         private PeerInfo myself;
     6namespace DistributedGA.Core.Implementation {
     7  public class WcfMessageSender : IMessageSender {
     8    private PeerInfo myself;
    119
    12         public void Init(PeerInfo source)
    13         {
    14             myself = source;
     10    public void Init(PeerInfo source) {
     11      myself = source;
     12    }
     13
     14    public void SendData(PeerInfo destination, byte[][] data) {
     15
     16      var serviceUrl = "DistributedGA.svc";
     17      var baseUri = new Uri(string.Concat("net.tcp://", destination.IpAddress, ":", destination.Port, "/DistributedGA"));
     18      var serviceUri = new Uri(baseUri, serviceUrl);
     19
     20      var binding = new NetTcpBinding();
     21      var endpoint = new EndpointAddress(serviceUri);
     22      using (var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint)) {
     23        using (IClientChannel client = (IClientChannel)myChannelFactory.CreateChannel()) {
     24          ((IMessageContract)client).SendData(myself, data); //maybe timout exception...
    1525        }
     26      }
     27    }
    1628
    17         public void SendData(PeerInfo destination, byte[][] data)
    18         {
    19             var client = CreateServerClient(destination.IpAddress, destination.Port);
    20             client.SendData(myself, data); //maybe timout exception...
    21         }
    22 
    23         private IMessageContract CreateServerClient(string ip, int port)
    24         {
    25             var serviceUrl = "DistributedGA.svc";
    26             var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA"));
    27             var serviceUri = new Uri(baseUri, serviceUrl);
    28 
    29             var binding = new NetTcpBinding();
    30             var endpoint = new EndpointAddress(serviceUri);
    31             var myChannelFactory = new ChannelFactory<IMessageContract>(binding, endpoint);
    32 
    33             IMessageContract client = null;
    34             client = myChannelFactory.CreateChannel();
    35             return client;
    36         }
     29    public void Dispose() {
    3730
    3831    }
     32  }
    3933}
Note: See TracChangeset for help on using the changeset viewer.