/// <summary> /// Initializes a new instance of the Service class. /// </summary> /// <param name="uri">Must specify device base uri, Because the description file does not contain uri.</param> /// <param name="root">Root device.</param> /// <param name="parent">Parent device.</param> /// <param name="serviceNode">Service XmlNode.</param> /// <param name="nm">XmlNamespaceManager.</param> /// <exception cref="Exception"/> public UPnPService(Uri uri, UPnPRootDevice root, UPnPDevice parent, XmlNode serviceNode, XmlNamespaceManager nm) { if (uri is null) { throw new ArgumentNullException(nameof(uri)); } if (serviceNode is null) { throw new ArgumentNullException(nameof(serviceNode)); } this.Root = root; this.Parent = parent; this.ServiceType = serviceNode.SelectSingleNode("ns:serviceType", nm).InnerText.Trim(); this.ServiceID = serviceNode.SelectSingleNode("ns:serviceId", nm).InnerText.Trim(); this.ScpdUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}", uri.AbsoluteUri, serviceNode.SelectSingleNode("ns:SCPDURL", nm).InnerText.Trim().Trim('/')); this.ControlUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}", uri.AbsoluteUri, serviceNode.SelectSingleNode("ns:controlURL", nm).InnerText.Trim().Trim('/')); this.EventSubUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}", uri.AbsoluteUri, serviceNode.SelectSingleNode("ns:eventSubURL", nm).InnerText.Trim().Trim('/')); }
/// <summary> /// Initializes a new instance of the Device class. /// </summary> /// <param name="uri">Must specify device base uri, Because the description file does not contain uri.</param> /// <param name="root">Root device info.</param> /// <param name="parent">Parent device.</param> /// <param name="deviceNode">Device XmlNode.</param> /// <param name="nm">XmlNamespaceManager.</param> /// <exception cref="Exception"/> public UPnPDevice(Uri uri, UPnPRootDevice root, UPnPDevice parent, XmlNode deviceNode, XmlNamespaceManager nm) { if (deviceNode is null) { throw new ArgumentNullException(nameof(deviceNode)); } List <UPnPDevice> childDevices = new List <UPnPDevice>(); List <UPnPService> services = new List <UPnPService>(); // this.Root = root; this.Parent = parent; this.DeviceType = deviceNode.SelectSingleNode("ns:deviceType", nm).InnerText.Trim(); this.FriendlyName = deviceNode.SelectSingleNode("ns:friendlyName", nm).InnerText.Trim(); this.Manufacturer = deviceNode.SelectSingleNode("ns:manufacturer", nm).InnerText.Trim(); this.ManufacturerUrl = deviceNode.SelectSingleNode("ns:manufacturerURL", nm).InnerText.Trim(); this.ModelDescription = deviceNode.SelectSingleNode("ns:modelDescription", nm).InnerText.Trim(); this.ModelName = deviceNode.SelectSingleNode("ns:modelName", nm).InnerText.Trim(); this.ModelNumber = deviceNode.SelectSingleNode("ns:modelNumber", nm).InnerText.Trim(); this.ModelUrl = deviceNode.SelectSingleNode("ns:modelURL", nm).InnerText.Trim(); this.SerialNumber = deviceNode.SelectSingleNode("ns:serialNumber", nm).InnerText.Trim(); this.Udn = deviceNode.SelectSingleNode("ns:UDN", nm).InnerText.Replace("uuid:", string.Empty).Trim(); XmlNodeList childDeviceNodes = deviceNode.SelectNodes("ns:deviceList/ns:device", nm); // foreach (XmlNode childDeviceNode in childDeviceNodes) { childDevices.Add(new UPnPDevice(uri, root, this, childDeviceNode, nm)); } // XmlNodeList serviceNodes = deviceNode.SelectNodes("ns:serviceList/ns:service", nm); foreach (XmlNode serviceNode in serviceNodes) { services.Add(new UPnPService(uri, root, this, serviceNode, nm)); } // this.Devices = childDevices.ToArray(); this.Services = services.ToArray(); }