using System; using System.Configuration; using System.Threading; using DistributedGA.Core.Domain; using DistributedGA.Core.Implementation; using DistributedGA.Core.Interface; namespace DistributedGA.Core.Host { class Program { static void Main(string[] args) { try { Console.WriteLine("Starting peer..."); string ipPrefix = ConfigurationManager.AppSettings["LanIpPrefix"]; string serverUrl = ConfigurationManager.AppSettings["ContactServerURL"]; IMessageHandler h = new PeerNetworkMessageHandler(); h.Init(ipPrefix, serverUrl); PeerInfo pi = h.GetPeerInfo(); Console.WriteLine(string.Format("Peer is hostet at IP: {0} and port: {1}", pi.IpAddress, pi.Port)); Thread.Sleep(1000 * 20); Console.WriteLine("Current peers within network:"); foreach (var item in h.GetCurrentNetwork()) { Console.WriteLine(string.Format("Peer at {0}:{1}", item.IpAddress, item.Port)); } int i = 1; while (i < 10) { i++; Thread.Sleep(1000 * 10); var pop1 = CreatePopulation(); Console.WriteLine("Publish population into network..."); h.PublishDataToNetwork(pop1); Console.WriteLine("Population published."); Console.WriteLine("Recieved populations:"); foreach (var item in h.GetDataFromNetwork()) { Console.WriteLine(string.Format("Population with Quality: {0:2} in Iteration {1}", item.Quality, item.IterationNumber)); } } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("press any key to continue..."); Console.ReadLine(); } } private static SolutionInfo[] CreatePopulation() { SolutionInfo si1 = new SolutionInfo() { IterationNumber = 1, Quality = 3.5f, Solution = new Solution() { } }; SolutionInfo si2 = new SolutionInfo() { IterationNumber = 2, Quality = 3.5f, Solution = new Solution() { } }; SolutionInfo si3 = new SolutionInfo() { IterationNumber = 3, Quality = 3.5f, Solution = new Solution() { } }; return new SolutionInfo[] { si1, si2, si3 }; } } }