internal void OnServiceAdded(ServiceInfo service) { var announcement = new ServiceAnnouncement { Hostname = service.HostName.Labels[0], Domain = service.HostName.SubName(1).ToString(), Addresses = service.Addresses, Instance = service.Name.Labels[0], NetworkInterface = service.NetworkInterface, Port = (ushort)service.Port, Txt = service.Txt, Type = service.Name.SubName(1, 2).ToString() }; _serviceAnnouncements.Add(Tuple.Create(service.NetworkInterface.Id, service.Name), announcement); SynchronizationContextPost(o => { lock (_services) { _services.Add(announcement); } if (ServiceAdded != null) { ServiceAdded(this, new ServiceAnnouncementEventArgs(announcement)); } }); }
internal void OnServiceRemoved(ServiceInfo service) { var key = Tuple.Create(service.NetworkInterface.Id, service.Name); ServiceAnnouncement announcement = _serviceAnnouncements[key]; _serviceAnnouncements.Remove(key); SynchronizationContextPost(o => { announcement.IsRemoved = true; lock (_services) { _services.Remove(announcement); } if (ServiceRemoved != null) { ServiceRemoved(this, new ServiceAnnouncementEventArgs(announcement)); } }); }
internal void OnServiceChanged(ServiceInfo service) { ServiceAnnouncement announcement = _serviceAnnouncements[Tuple.Create(service.NetworkInterface.Id, service.Name)]; var tmpAnnouncement = new ServiceAnnouncement() { Hostname = service.HostName.Labels[0], Domain = service.HostName.SubName(1).ToString(), Addresses = service.Addresses, Instance = service.Name.Labels[0], NetworkInterface = service.NetworkInterface, Port = (ushort)service.Port, Txt = service.Txt, Type = service.Name.SubName(1, 2).ToString() }; SynchronizationContextPost(o => { announcement.Hostname = tmpAnnouncement.Hostname; announcement.Domain = tmpAnnouncement.Domain; announcement.Addresses = tmpAnnouncement.Addresses; announcement.Instance = tmpAnnouncement.Instance; announcement.NetworkInterface = tmpAnnouncement.NetworkInterface; announcement.Port = tmpAnnouncement.Port; announcement.Txt = tmpAnnouncement.Txt; announcement.Type = tmpAnnouncement.Type; if (ServiceChanged != null) { ServiceChanged(this, new ServiceAnnouncementEventArgs(announcement)); } }); }
private void AddServiceHostInfo(ServiceInfo service) { Name hostname = service.HostName; HostInfo hostInfo; _hostInfos.TryGetValue(hostname, out hostInfo); if (hostInfo == null) { hostInfo = new HostInfo(); HostAddresses hostAddresses; if (_packetHostAddresses.TryGetValue(hostname, out hostAddresses)) { hostInfo.Addresses = hostAddresses.IPv4Addresses; if (hostInfo.Addresses == null) { hostInfo.Addresses = hostAddresses.IPv6Addresses; } else if (hostAddresses.IPv6Addresses != null) { hostInfo.Addresses.AddRange(hostAddresses.IPv6Addresses); } } _hostInfos.Add(hostname, hostInfo); } Debug.Assert(!hostInfo.ServiceInfos.Contains(service)); hostInfo.ServiceInfos.Add(service); service.Addresses = hostInfo.Addresses; }
private void ClearServiceHostInfo(ServiceInfo service) { Name hostname = service.HostName; HostInfo hostInfo; _hostInfos.TryGetValue(hostname, out hostInfo); if (hostInfo != null) { hostInfo.ServiceInfos.Remove(service); if (hostInfo.ServiceInfos.Count == 0) { _hostInfos.Remove(hostname); } service.HostName = null; service.Addresses = null; } }
private ServiceInfo FindOrCreatePacketService(Name name) { ServiceInfo service; bool found = _packetServiceInfos.TryGetValue(name, out service); if (service == null) { if (found) { _packetServiceInfos.Remove(name); } service = new ServiceInfo(NetworkInterface, name); _packetServiceInfos.Add(name, service); } return service; }