Free cookie consent management tool by TermsFeed Policy Generator

source: branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfPeerListManager.cs @ 13524

Last change on this file since 13524 was 13524, checked in by thasling, 8 years ago

Upload des Projekts letztendlich, trotz buggendes Clients...

File size: 2.2 KB
Line 
1using DistributedGA.Core.Domain;
2using DistributedGA.Core.Interface;
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using System.ServiceModel;
7using System.Text;
8using System.Threading.Tasks;
9
10namespace DistributedGA.Core.Implementation
11{
12    public class WcfPeerListManager : IPeerListManager
13    {
14        //private const string SERVER_STRING = "http://localhost:9002/DistributedGA.ContactServer/ContactService";
15        private const string SERVER_STRING = "http://localhost:9090/DistributedGA.ContactServer/ContactService";
16
17        private IContactService client = null;
18
19        private PeerInfo myself = null;
20
21        List<PeerInfo> allPeers = null;
22        List<PeerInfo> peersForMessaging = null;
23
24        public void Init(PeerInfo source)
25        {
26            client = CreateClient();
27            myself = source;
28            client.RegisterPeer(source);
29        }
30
31        public List<PeerInfo> GetPeerList()
32        {
33            if(allPeers == null)
34            {
35                allPeers =  client.GetPeerList(myself);
36                peersForMessaging = ChoosePeersForMessaging(allPeers);
37            }
38            //TODO: maybe always request a new list from the contact server so that he can refresh the heartbeat...
39            return peersForMessaging;
40        }
41
42        public void SendLogToServer(string msg)
43        {
44            client.MakeLog(myself, msg);
45        }
46
47        private IContactService CreateClient()
48        {
49            var binding = new BasicHttpBinding();
50            var endpoint = new EndpointAddress(SERVER_STRING);
51            var myChannelFactory = new ChannelFactory<IContactService>(binding, endpoint);
52
53            IContactService client = null;
54            client = myChannelFactory.CreateChannel();
55            return client;
56        }
57
58        private List<PeerInfo> ChoosePeersForMessaging(List<PeerInfo> allPeers)
59        {
60            //TODO: strategy: 10% of list random choosen
61            int noOfPeers = allPeers.Count / 10; //communicate with 10% of the network
62            List<PeerInfo> res = new List<PeerInfo>();
63
64            return allPeers;
65        }
66
67    }
68}
Note: See TracBrowser for help on using the repository browser.