Exemple #1
0
 void Service_Resolved(object o, ServiceResolvedEventArgs args)
 {
     var service = args.Service;
     foreach (IPAddress addr in service.HostEntry.AddressList)
     {
         var host = new HostModel() { Address = addr.ToString(), Port = (ushort)service.Port, Name = service.FullName, Id = new Guid(service.TxtRecord["NODEID"].ValueRaw) };
         Console.WriteLine("Address {0}:{1} resolved for {2} - {3} - ({4})", addr, (ushort)(service.Port), service.HostTarget, service.FullName, host.Id);
         lock (knownHosts)
         {
             if (!knownHosts.Any(i => i.Address == addr.ToString()) && !IPAddress.IsLoopback(addr))
             {
                 knownHosts.Add(host);
             }
             else
             {
                 for (int x = 0; x < knownHosts.Count; x++)
                 {
                     if (knownHosts[x].Address == addr.ToString())
                     {
                         host.Probed = knownHosts[x].Id == host.Id && knownHosts[x].Probed;
                         knownHosts[x] = host;
                         break;
                     }
                 }
             }
         }
     }
 }
 public async Task<bool> Post(HostModel host)
 {
     if (host == null) return false;
     return await host.Probe();
 }