示例#1
0
        void cdsDiscovery_DescriptionObtained(object sender, DeviceDescriptionEventArgs e)
        {
            try
            {
                var device = UpnpDescriptionParser.ParseDescription(XDocument.Parse(e.Description), e.Location);
                device.LocalAddress = e.LocalAddress;

                UpdateDeviceNameDictionary(device.UDN, device.FriendlyName, device.ModelName);

                lock (cdsDevices)
                {
                    if (cdsDevices.ContainsKey(device.UDN))
                    {
                        return;
                    }

                    if (device.Services.Any(service => service.Key == URN.ContentDirectory))
                    {
                        DebugUtil.Log("CDS found. Notify discovered.");
                        cdsDevices.Add(device.UDN, device);
                        OnDiscovered(device);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugUtil.Log("failed to parse upnp device description.");
                DebugUtil.Log(() => ex.StackTrace);
            }
        }
        private void DeviceRetrieved(object Sender, DeviceDescriptionEventArgs e)
        {
            try
            {
                if (!(e.DeviceDescriptionDocument is null))
                {
                    UPnPService Service = e.DeviceDescriptionDocument.GetService("urn:schemas-upnp-org:service:WANIPConnection:1");
                    if (Service is null)
                    {
                        Service = e.DeviceDescriptionDocument.GetService("urn:schemas-upnp-org:service:WANIPConnection:2");
                        if (Service is null)
                        {
                            return;
                        }
                    }

                    Service.StartGetService(this.ServiceRetrieved, e.State);
                }
            }
            catch (Exception ex)
            {
                this.exception = ex;
                this.State     = PeerToPeerNetworkState.Error;
            }
        }