コード例 #1
0
        public static RetrievedContents Parse(XDocument xml, string action)
        {
            var body     = GetBodyOrThrowError(xml);
            var response = body.Element(NS_U + action + "Response");
            var result   = response.Element("Result");
            var root     = result.Element(NS_DIDL + "DIDL-Lite");

            var numReturned = int.Parse(response.Element("NumberReturned").Value);
            var total       = int.Parse(response.Element("TotalMatches").Value);
            var updateId    = response.Element("UpdateID").Value;

            var containers = root.Elements(NS_DIDL + "container")
                             .Select(element => new Container
            {
                Id          = element.Attribute("id").Value,
                ParentId    = element.Attribute("parentID").Value,
                Title       = element.Element(NS_DC + "title").Value,
                Class       = element.Element(NS_UPNP + "class").Value,
                Restricted  = BoolConversionHelper.Parse(element.Attribute("restricted")),
                ChildCount  = (int?)element.Attribute("childCount"),
                WriteStatus = (string)element.Element(NS_DIDL + "writeStatus"),
            }).ToList();

            var items = root.Elements(NS_DIDL + "item")
                        .Select(element => new Item
            {
                Id          = element.Attribute("id").Value,
                ParentId    = element.Attribute("parentID").Value,
                Title       = element.Element(NS_DC + "title").Value,
                Class       = element.Element(NS_UPNP + "class").Value,
                Restricted  = BoolConversionHelper.Parse(element.Attribute("restricted")),
                WriteStatus = (string)element.Element(NS_DIDL + "writeStatus"),
                Resources   = element.Elements(NS_DIDL + "res").Select(res => new Resource
                {
                    ProtocolInfo = ProtocolInfo.Parse(res.Attribute("protocolInfo")),
                    Resolution   = (string)res.Attribute("resolution"),
                    SizeInByte   = (long?)res.Attribute("size"),
                    ResourceUrl  = (string)res.Value,
                }).ToList(),
                Date  = (string)element.Element(NS_DC + "date"),
                Genre = (string)element.Element(NS_UPNP + "upnp"),
            }).ToList();

            return(new RetrievedContents
            {
                Result = new Result
                {
                    Containers = containers,
                    Items = items,
                },
                NumberReturned = numReturned,
                TotalMatches = total,
                UpdateID = updateId,
            });
        }
コード例 #2
0
        public static ProtocolInfo Parse(XAttribute protocolInfo)
        {
            var protocol = new ProtocolInfo();

            if (protocolInfo == null)
            {
                return(protocol);
            }

            var commSepa = protocolInfo.Value.Split(':');

            if (commSepa.Length < 3)
            {
                return(protocol);
            }

            protocol.MimeType = commSepa[2];

            for (int i = 3; i < commSepa.Length; i++)
            {
                if (commSepa[i].Contains("DLNA.ORG"))
                {
                    var dlnaSepa = commSepa[3].Split(';');
                    foreach (var dlna in dlnaSepa)
                    {
                        if (dlna.StartsWith("DLNA.ORG_PN="))
                        {
                            protocol.DlnaProfileName = dlna.Substring(12);
                        }
                        else if (dlna.StartsWith("DLNA.ORG_CI="))
                        {
                            var ci = 1;
                            if (int.TryParse(dlna.Substring(12), out ci))
                            {
                                protocol.IsOriginalContent = ci == 0;
                            }
                        }
                    }
                    break;
                }
            }

            return(protocol);
        }