protected virtual void OnResponseReceived(ResponseReceivedEventArgs e) { if (ResponseReceived != null) { ResponseReceived(this, e); } }
private void SsdpFinder_ResponseReceived(object sender, ResponseReceivedEventArgs e) { string locationUriString = e.Headers["location"]; if (String.IsNullOrEmpty(locationUriString)) { Debug.WriteLine("No location in headers"); return; } Uri location = new Uri(locationUriString); Debug.WriteLine("Begin track {0}", location); workTracker.BeginTask(); var wc = new WebClient(); wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((o, args) => { if (args.Error == null) { var doc = XElement.Parse(args.Result); if (doc.GetDefaultNamespace() == UpnpDeviceNamespace) { var computer = new Computer(); computer.IPAddress = e.IPAddress; computer.LastSeen = DateTime.Now; computer.Name = (string)doc.Descendants(XName.Get("friendlyName", UpnpDeviceNamespace)).FirstOrDefault(); computer.State = ComputerState.Online; OnComputerDiscovered(new ComputerDiscoveredEventArgs(computer)); } } Debug.WriteLine("End track {0}", location); workTracker.EndTask(); }); wc.DownloadStringAsync(location); }