Пример #1
0
        } // ParseDidlContainerMetaData

        /// <summary>
        /// Parses DIDL item meta data.
        /// </summary>
        /// <param name="xitem">The parent.</param>
        /// <returns>A <see cref="BrowseMetaDataResult"/> object.</returns>
        private static BrowseMetaDataResult ParseDidlItemMetaData(XElement xitem)
        {
            var result = new BrowseMetaDataResult();

            result.Id       = XmlSupport.GetAttributeValue(xitem, "id");
            result.ParentId = XmlSupport.GetAttributeValue(xitem, "parentID");
            var help = XmlSupport.GetAttributeValue(xitem, "restricted");

            if (!string.IsNullOrEmpty(help))
            {
                result.Restricted = UPNP.ParseUpnpBoolean(help);
            } // if

            result.Title = XmlSupport.GetFirstSubNodeValue(xitem, "title");
            result.Class = XmlSupport.GetFirstSubNodeValue(xitem, "class");
            result.Date  = XmlSupport.GetFirstSubNodeValue(xitem, "date", false);

#if false
            result.Title = XmlSupport.XmlSupport.GetFirstSubNodeValue(xitem, "channelName", false);
            result.Title = XmlSupport.XmlSupport.GetFirstSubNodeValue(xitem, "date", false); // iso8601
            result.Title = XmlSupport.XmlSupport.GetFirstSubNodeValue(xitem, "objectType", false);
            result.Title = XmlSupport.XmlSupport.GetFirstSubNodeValue(xitem, "groupID", false);
            result.Title = XmlSupport.XmlSupport.GetFirstSubNodeValue(xitem, "storageMedium", false);
#endif

            var res = XmlSupport.GetFirstSubNode(xitem, "res", false);
            if (res != null)
            {
                result.ProtocolInfo = XmlSupport.GetAttributeValue(res, "protocolInfo", false);
                result.Resolution   = XmlSupport.GetAttributeValue(res, "resolution", false);
                help = XmlSupport.GetAttributeValue(res, "size", false);
                if (!string.IsNullOrEmpty(help))
                {
                    result.Size = long.Parse(help);
                } // if

                help = XmlSupport.GetAttributeValue(res, "bitrate", false);
                if (!string.IsNullOrEmpty(help))
                {
                    result.Bitrate = int.Parse(help);
                } // if

                result.Duration = XmlSupport.GetAttributeValue(xitem, "duration", false);
                help            = XmlSupport.GetAttributeValue(res, "nrAudioChannels", false);
                if (!string.IsNullOrEmpty(help))
                {
                    result.NumAudioChannels = int.Parse(help);
                } // if

                help = XmlSupport.GetAttributeValue(res, "sampleFrequency", false);
                if (!string.IsNullOrEmpty(help))
                {
                    result.SampleFrequency = int.Parse(help);
                } // if

                result.Resource = res.Value;
            } // if

            return(result);
        } // ParseDidlItemMetaData()
Пример #2
0
        } // ParseDidlMetaData()

        /// <summary>
        /// Parses DIDL container meta data.
        /// </summary>
        /// <param name="xcontainer">The parent.</param>
        /// <returns>A <see cref="BrowseMetaDataResult"/> object.</returns>
        private static BrowseMetaDataResult ParseDidlContainerMetaData(XElement xcontainer)
        {
            /*
             * <DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
             *   xmlns:dc="http://purl.org/dc/elements/1.1/"
             *   xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
             *   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             *   xsi:schemaLocation="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite-v2-20060531.xsd urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp-v2-20060531.xsd">
             *   <container id="AV_ALL" parentID="AV" restricted="0">
             *     <dc:title>Alle</dc:title>
             *     <upnp:writeStatus>NOT_WRITABLE</upnp:writeStatus>
             *     <upnp:recordable>0</upnp:recordable>
             *     <upnp:class name="container">object.container</upnp:class>
             *   </container>
             * </DIDL-Lite>
             */

            var result = new BrowseMetaDataResult();

            result.Id       = XmlSupport.GetAttributeValue(xcontainer, "id");
            result.ParentId = XmlSupport.GetAttributeValue(xcontainer, "parentID");

            result.Title       = XmlSupport.GetFirstSubNodeValue(xcontainer, "title");
            result.WriteStatus = XmlSupport.GetFirstSubNodeValue(xcontainer, "writeStatus", false);
            ////result.IsRecordable = XmlSupport.XmlSupport.ParseUpnpBoolean(XmlSupport.XmlSupport.GetFirstSubNodeValue(xcontainer, "recordable"));
            result.Class = XmlSupport.GetFirstSubNodeValue(xcontainer, "class");

            return(result);
        } // ParseDidlContainerMetaData
Пример #3
0
        } // EvaluateResult()

        /// <summary>
        /// Evaluates a fault result.
        /// </summary>
        /// <param name="xfault">The parent element.</param>
        /// <returns>An array of objects.</returns>
        private static object[] EvaluateFaultResult(XContainer xfault)
        {
            Log.Error("Fault answer for SOAP call:");
            var faultcode   = XmlSupport.GetFirstSubNodeValue(xfault, "faultcode");
            var faultstring = XmlSupport.GetFirstSubNodeValue(xfault, "faultstring");
            var faultdetail = XmlSupport.GetFirstSubNode(xfault, "detail");

#if ENHANCED_ERROR_OUTPUT
            Log.Error($"Code = {faultcode}");
            Log.Error($"Text = {faultstring}");
            Log.Error($"Details = {faultdetail}");
#endif // ENHANCED_ERROR_OUTPUT

            var upnperror = ParseUpnpError(faultdetail);

#if ENHANCED_ERROR_OUTPUT
            Log.Error($"UPnP error: {upnperror}");
#endif // ENHANCED_ERROR_OUTPUT

            var result = new object[3];
            result[0] = faultcode;
            result[1] = faultstring;
            result[2] = upnperror;

            return(result);
        } // EvaluateFaultResult()
Пример #4
0
        } // ParseAction()

        /// <summary>
        /// Parses the argument.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>A <see cref="UpnpArgument"/> object.</returns>
        private static UpnpArgument ParseArgument(XContainer element)
        {
            var argument = new UpnpArgument();

            argument.Name                 = XmlSupport.GetFirstSubNodeValue(element, "name");
            argument.Direction            = XmlSupport.GetFirstSubNodeValue(element, "direction");
            argument.RelatedStateVariable =
                XmlSupport.GetFirstSubNodeValue(element, "relatedStateVariable");
            argument.ReturnValue =
                XmlSupport.GetFirstSubNodeValue(element, "retVal", false);
            return(argument);
        } // ParseArgument()
Пример #5
0
        } // ParseDidlChildData()

        /// <summary>
        /// Parses <c>UPnP</c> child data.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <returns>A <see cref="UpnpChildData"/> object.</returns>
        private static UpnpChildData ParseChildData(XElement parent)
        {
            var result = new UpnpChildData();

            result.Id       = XmlSupport.GetAttributeValue(parent, "id");
            result.ParentId = XmlSupport.GetAttributeValue(parent, "parentID");

            result.Title = XmlSupport.GetFirstSubNodeValue(parent, "title");
            ////result.WriteStatus = XmlSupport.XmlSupport.GetFirstSubNodeValue(xcontainer, "writeStatus", false);
            ////result.IsRecordable = XmlSupport.XmlSupport.ParseUpnpBoolean(XmlSupport.XmlSupport.GetFirstSubNodeValue(xcontainer, "recordable"));
            result.Class = XmlSupport.GetFirstSubNodeValue(parent, "class");

            return(result);
        } // ParseChildData()
Пример #6
0
        } // EvaluateFaultResult()

        /// <summary>
        /// Parses a <c>UPnP</c> error.
        /// </summary>
        /// <param name="faultdetail">The fault detail.</param>
        /// <returns>
        /// A <see cref="UpnpError" /> object.
        /// </returns>
        private static UpnpError ParseUpnpError(XContainer faultdetail)
        {
            var error = new UpnpError();

            var xupnperror = XmlSupport.GetFirstSubNode(faultdetail, "UPnPError", false);

            if (xupnperror != null)
            {
                error.ErrorCode        = int.Parse(XmlSupport.GetFirstSubNodeValue(xupnperror, "errorCode"));
                error.ErrorDescription = XmlSupport.GetFirstSubNodeValue(xupnperror, "errorDescription");
            } // if

            return(error);
        } // ParseUpnpError()
Пример #7
0
        } // ParseDeviceSchema()

        /// <summary>
        /// Checks the supported spec version.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="majorSupported">The supported major version.</param>
        /// <param name="minorSupported">The supported minor version.</param>
        private static void CheckSupportedSpecVersion(XContainer parent, int majorSupported, int minorSupported)
        {
            var xversion = XmlSupport.GetFirstSubNode(parent, "specVersion");
            var major    = int.Parse(XmlSupport.GetFirstSubNodeValue(xversion, "major"));
            var minor    = int.Parse(XmlSupport.GetFirstSubNodeValue(xversion, "minor"));

            if (major > majorSupported)
            {
                throw new XmlException("Specversion not supported!");
            } // if

            if (minor > minorSupported)
            {
                throw new XmlException("Specversion not supported!");
            } // if
        }     // CheckSupportedSpecVersion()
Пример #8
0
        } // ParseStateVariable()

        /// <summary>
        /// Parses the action.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>A <see cref="UpnpServiceAction"/> object.</returns>
        private static UpnpServiceAction ParseAction(XContainer element)
        {
            var action = new UpnpServiceAction();

            action.Name = XmlSupport.GetFirstSubNodeValue(element, "name");

            var xargumentList = XmlSupport.GetFirstSubNode(element, "argumentList", false);

            if (xargumentList != null)
            {
                var argumentList =
                    from xargument in xargumentList.Elements()
                    where (xargument.Name.LocalName == "argument")
                    select xargument;
                foreach (var xargument in argumentList)
                {
                    var argument = ParseArgument(xargument);
                    action.AddArgument(argument);
                } // foreach
            }     // if

            return(action);
        } // ParseAction()
Пример #9
0
        } // ParseUpnpBoolean

        #endregion // PUBLIC METHODS

        //// ---------------------------------------------------------------------

        #region PRIVATE METHODS
        /// <summary>
        /// Parses the state variable.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>A <see cref="UpnpStateVariable"/> object.</returns>
        private static UpnpStateVariable ParseStateVariable(XContainer element)
        {
            var variable = new UpnpStateVariable();

            variable.Name         = XmlSupport.GetFirstSubNodeValue(element, "name");
            variable.Type         = XmlSupport.GetFirstSubNodeValue(element, "dataType");
            variable.DefaultValue = XmlSupport.GetFirstSubNodeValue(element, "defaultValue", false);
            var xallowedValueList = XmlSupport.GetFirstSubNode(element, "allowedValueList", false);

            if (xallowedValueList != null)
            {
                var allowedValueList =
                    from xallowedValue in xallowedValueList.Elements()
                    where (xallowedValue.Name.LocalName == "allowedValue")
                    select xallowedValue;
                foreach (var xargument in allowedValueList)
                {
                    variable.AddAllowedValue(xargument.Value);
                } // foreach
            }     // if

            return(variable);
        } // ParseStateVariable()
Пример #10
0
        } // ParseArgument()

        /// <summary>
        /// Parses the device schema.
        /// </summary>
        /// <param name="xdevice">The parent element.</param>
        /// <returns>A <see cref="DeviceSchema"/> object.</returns>
        private static DeviceSchema ParseDeviceSchema(XContainer xdevice)
        {
            var schema = new DeviceSchema();

            schema.DeviceType       = XmlSupport.GetFirstSubNodeValue(xdevice, "deviceType");
            schema.FriendlyName     = XmlSupport.GetFirstSubNodeValue(xdevice, "friendlyName");
            schema.Manufacturer     = XmlSupport.GetFirstSubNodeValue(xdevice, "manufacturer");
            schema.ManufacturerUrl  = XmlSupport.GetFirstSubNodeValue(xdevice, "manufacturerURL", false);
            schema.ModelDescription = XmlSupport.GetFirstSubNodeValue(xdevice, "modelDescription", false);
            schema.ModelName        = XmlSupport.GetFirstSubNodeValue(xdevice, "modelName");
            schema.ModelNumber      = XmlSupport.GetFirstSubNodeValue(xdevice, "modelNumber", false);
            schema.ModelUrl         = XmlSupport.GetFirstSubNodeValue(xdevice, "modelURL", false);
            schema.SerialNumber     = XmlSupport.GetFirstSubNodeValue(xdevice, "serialNumber", false);
            schema.UDN = XmlSupport.GetFirstSubNodeValue(xdevice, "UDN");

            var xiconList = XmlSupport.GetFirstSubNode(xdevice, "iconList", false);

            if (xiconList != null)
            {
                var iconList =
                    from xicon in xiconList.Elements()
                    where (xicon.Name.LocalName == "icon")
                    select xicon;
                foreach (var xicon in iconList)
                {
                    var icon = new DeviceIcon();
                    icon.MimeType = XmlSupport.GetFirstSubNodeValue(xicon, "mimetype");
                    icon.Width    = int.Parse(XmlSupport.GetFirstSubNodeValue(xicon, "width"));
                    icon.Height   = int.Parse(XmlSupport.GetFirstSubNodeValue(xicon, "height"));
                    icon.Depth    = int.Parse(XmlSupport.GetFirstSubNodeValue(xicon, "depth"));
                    icon.URL      = XmlSupport.GetFirstSubNodeValue(xicon, "url");
                    schema.AddIcon(icon);
                } // foreach
            }     // if

            var xserviceList = XmlSupport.GetFirstSubNode(xdevice, "serviceList");
            var serviceList  =
                from xservice in xserviceList.Elements()
                where (xservice.Name.LocalName == "service")
                select xservice;

            foreach (var xservice in serviceList)
            {
                var service = new UpnpService();
                service.Type        = XmlSupport.GetFirstSubNodeValue(xservice, "serviceType");
                service.Id          = XmlSupport.GetFirstSubNodeValue(xservice, "serviceId");
                service.ControlUrl  = XmlSupport.GetFirstSubNodeValue(xservice, "controlURL");
                service.EventSubURL = XmlSupport.GetFirstSubNodeValue(xservice, "eventSubURL");
                service.ScpdUrl     = XmlSupport.GetFirstSubNodeValue(xservice, "SCPDURL");
                schema.AddService(service);
            } // foreach

            var xdeviceList = XmlSupport.GetFirstSubNode(xdevice, "deviceList", false);

            if (xdeviceList != null)
            {
                var deviceList =
                    from xsubDevice in xdeviceList.Elements()
                    where (xsubDevice.Name.LocalName == "device")
                    select xsubDevice;
                foreach (var xsubDevice in deviceList)
                {
                    var device = ParseDeviceSchema(xsubDevice);
                    schema.AddSubDevice(device);
                } // foreach
            }     // if

            schema.PresentationUrl = XmlSupport.GetFirstSubNodeValue(xdevice, "presentationURL", false);

            return(schema);
        } // ParseDeviceSchema()