private void AddRoutesToList(RouteMessage message) { if (this.Routes.Count < (RoutesToHold * 2)) { foreach (var item in message.Routes) { this.Routes.Add(item); } } }
public void CheckRecieve() { while (!CloseClass) { DataMessage dm = null; Message message = null; lock (queue) { if (queue.Count > 0) { message = queue.Dequeue(); } } if(message != null) { if (message is DataMessage) { dm = (DataMessage)message; } switch (dm.Data.Key.ToString()) { case "True": { //Ping ping = new Ping(); //PingReply pr = ping.Send(dm.ReturnIP, 500); lock (Locations) { if (!Locations.Exists(x => x.IP == dm.ReturnIP)) Locations.Add(new Routing(dm.ReturnIP, dm.Port, 0)); } Console.WriteLine("Added Location " + dm.ReturnIP); break; } case "False": { lock (Locations) { Locations.Remove(Locations.Find(x => x.IP == dm.ReturnIP)); } Console.WriteLine("Removed Location " + dm.ReturnIP); break; } default: { RouteMessage returnMessage = new RouteMessage(); returnMessage.ReturnIP = dm.ReturnIP; returnMessage.Port = dm.Port; returnMessage.Routes = GetSomeLocations(); if (returnMessage.Routes.Count() != 0) { new NetworkResponseActor(returnMessage).Start(); } break; } } } } }