Esempio n. 1
0
        /// <summary>
        /// Creates the UPnP description document for this root device and all embedded devices.
        /// </summary>
        /// <param name="serverData">Current server data structure.</param>
        /// <param name="config">UPnP endpoint which will be used to create the endpoint specific information. The comment of
        /// <see cref="DeviceTreeURLGenerator"/> describes why URLs must be adapted for each UPnP endpoint.</param>
        /// <param name="culture">The culture to localize strings and URLs of the returned description document.</param>
        /// <returns>UPnP device description document for this root device and all embedded devices.</returns>
        public string BuildRootDeviceDescription(ServerData serverData, EndpointConfiguration config, CultureInfo culture)
        {
            StringBuilder result = new StringBuilder(10000);

            using (StringWriterWithEncoding stringWriter = new StringWriterWithEncoding(result, UPnPConsts.UTF8_NO_BOM))
                using (XmlWriter writer = XmlWriter.Create(stringWriter, UPnPConfiguration.DEFAULT_XML_WRITER_SETTINGS))
                {
                    GenerateDescriptionDlgt dgh = DescriptionGenerateHook;

                    writer.WriteStartDocument();
                    writer.WriteStartElement(string.Empty, "root", UPnPConsts.NS_DEVICE_DESCRIPTION);
                    if (dgh != null)
                    {
                        dgh(writer, this, GenerationPosition.RootDeviceStart, config, culture);
                    }

                    writer.WriteAttributeString("configId", config.ConfigId.ToString());
                    writer.WriteStartElement("specVersion");
                    writer.WriteElementString("major", UPnPConsts.UPNP_VERSION_MAJOR.ToString());
                    writer.WriteElementString("minor", UPnPConsts.UPNP_VERSION_MINOR.ToString());
                    writer.WriteEndElement(); // specVersion

                    AddDeviceDescriptionsRecursive(writer, config, culture);

                    if (dgh != null)
                    {
                        dgh(writer, this, GenerationPosition.RootDeviceEnd, config, culture);
                    }

                    writer.WriteEndElement(); // root
                    writer.Close();
                }
            return(result.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the UPnP device description XML fragment for this device, all embedded devices and all services.
        /// </summary>
        /// <param name="writer">Result XML writer to add the device descriptions fragment to.</param>
        /// <param name="config">UPnP endpoint which will be used to create the endpoint specific information.</param>
        /// <param name="culture">Culture to create the culture specific information.</param>
        internal void AddDeviceDescriptionsRecursive(XmlWriter writer, EndpointConfiguration config, CultureInfo culture)
        {
            GenerateDescriptionDlgt     dgh = DescriptionGenerateHook;
            ILocalizedDeviceInformation deviceInformation = _deviceInformation;

            writer.WriteStartElement("device");
            if (dgh != null)
            {
                dgh(writer, this, GenerationPosition.DeviceStart, config, culture);
            }
            writer.WriteElementString("deviceType", DeviceTypeVersion_URN);
            writer.WriteElementString("friendlyName", deviceInformation.GetFriendlyName(culture));
            writer.WriteElementString("manufacturer", deviceInformation.GetManufacturer(culture));
            string manufacturerURL = deviceInformation.GetManufacturerURL(culture);

            if (!string.IsNullOrEmpty(manufacturerURL))
            {
                writer.WriteElementString("manufacturerURL", manufacturerURL);
            }
            string modelDescription = deviceInformation.GetModelDescription(culture);

            if (!string.IsNullOrEmpty(modelDescription))
            {
                writer.WriteElementString("modelDescription", modelDescription);
            }
            writer.WriteElementString("modelName", deviceInformation.GetModelName(culture));
            string modelNumber = deviceInformation.GetModelNumber(culture);

            if (!string.IsNullOrEmpty(modelNumber))
            {
                writer.WriteElementString("modelNumber", modelNumber);
            }
            string modelURL = deviceInformation.GetModelURL(culture);

            if (!string.IsNullOrEmpty(modelURL))
            {
                writer.WriteElementString("modelURL", modelURL);
            }
            string serialNumber = deviceInformation.GetSerialNumber(culture);

            if (!string.IsNullOrEmpty(serialNumber))
            {
                writer.WriteElementString("serialNumber", serialNumber);
            }
            writer.WriteElementString("UDN", UDN);
            string upc = deviceInformation.GetUPC();

            if (!string.IsNullOrEmpty(upc))
            {
                writer.WriteElementString("UPC", upc);
            }
            ICollection <IconDescriptor> icons = deviceInformation.GetIcons(culture);

            if (icons != null && icons.Count > 0)
            {
                writer.WriteStartElement("iconList");
                foreach (IconDescriptor icon in icons)
                {
                    writer.WriteStartElement("icon");
                    writer.WriteElementString("mimetype", icon.MimeType);
                    writer.WriteElementString("width", icon.Width.ToString());
                    writer.WriteElementString("height", icon.Height.ToString());
                    writer.WriteElementString("depth", icon.ColorDepth.ToString());
                    writer.WriteElementString("url", icon.GetIconURLDelegate(config.EndPointIPAddress, culture));
                    writer.WriteEndElement(); // icon
                }
                writer.WriteEndElement();     // iconList
            }
            ICollection <DvService> services = _services;

            if (services.Count > 0)
            {
                writer.WriteStartElement("serviceList");
                foreach (DvService service in services)
                {
                    service.AddDeviceDescriptionForService(writer, config);
                }
                writer.WriteEndElement(); // serviceList
            }
            ICollection <DvDevice> embeddedDevices = _embeddedDevices;

            if (embeddedDevices.Count > 0)
            {
                writer.WriteStartElement("deviceList");
                foreach (DvDevice embeddedDevice in embeddedDevices)
                {
                    embeddedDevice.AddDeviceDescriptionsRecursive(writer, config, culture);
                }
                writer.WriteEndElement(); // deviceList
            }
            if (dgh != null)
            {
                dgh(writer, this, GenerationPosition.AfterDeviceList, config, culture);
            }
            GetURLForEndpointDlgt presentationURLGetter = GetPresentationURLDelegate;
            string presentationURL = null;

            if (presentationURLGetter != null)
            {
                presentationURL = presentationURLGetter(config.EndPointIPAddress, culture);
            }
            if (!string.IsNullOrEmpty(presentationURL))
            {
                writer.WriteElementString("presentationURL", presentationURL);
            }
            if (dgh != null)
            {
                dgh(writer, this, GenerationPosition.DeviceEnd, config, culture);
            }
            writer.WriteEndElement(); // device
        }