Skip to content

Commit

Permalink
ServiceBrowser: bugfix, some code was only executed when event handle…
Browse files Browse the repository at this point in the history
…r was present
  • Loading branch information
tmds committed Nov 25, 2013
1 parent 011af0a commit 0a6210e
Showing 1 changed file with 50 additions and 49 deletions.
99 changes: 50 additions & 49 deletions Tmds/MDns/ServiceBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,73 +64,74 @@ public void StartBrowse(string serviceType)

internal void OnServiceAdded(ServiceInfo service)
{
if (ServiceAdded != null)
var announcement = new ServiceAnnouncement
{
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 =>
{
if (ServiceAdded != null)
{
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 => ServiceAdded(this, new ServiceAnnouncementEventArgs(announcement)));
}
ServiceAdded(this, new ServiceAnnouncementEventArgs(announcement));
}
});
}

internal void OnServiceRemoved(ServiceInfo service)
{
if (ServiceRemoved != null)
var key = Tuple.Create(service.NetworkInterface.Id, service.Name);
ServiceAnnouncement announcement = _serviceAnnouncements[key];
_serviceAnnouncements.Remove(key);
SynchronizationContextPost(o =>
{
var key = Tuple.Create(service.NetworkInterface.Id, service.Name);
ServiceAnnouncement announcement = _serviceAnnouncements[key];
_serviceAnnouncements.Remove(key);
SynchronizationContextPost(o =>
announcement.IsRemoved = true;
if (ServiceRemoved != null)
{
announcement.IsRemoved = true;
ServiceRemoved(this, new ServiceAnnouncementEventArgs(announcement));
});
}
}
});
}

internal void OnServiceChanged(ServiceInfo service)
{
if (ServiceChanged != null)
ServiceAnnouncement announcement = _serviceAnnouncements[Tuple.Create(service.NetworkInterface.Id, service.Name)];
var tmpAnnouncement = new ServiceAnnouncement()
{
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 =>
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)
{
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;
ServiceChanged(this, new ServiceAnnouncementEventArgs(announcement));
});
}
}
});
}

private void OnInterfaceDetect(InterfaceDetectedEventArgs e
)
private void OnInterfaceDetect(InterfaceDetectedEventArgs e)
{
if (InterfaceDetected != null)
{
Expand Down

0 comments on commit 0a6210e

Please sign in to comment.