Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
0
        } // Invoke()

        #endregion // PUBLIC METHODS

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

        #region PRIVATE METHODS
        /// <summary>
        /// Evaluates the result.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="action">The action.</param>
        /// <returns>An array of objects.</returns>
        /// <exception cref="XmlException">No valid SOAP envelop!</exception>
        private static object[] EvaluateResult(string text, UpnpServiceAction action)
        {
            var output = new List <object>();

            var document = XDocument.Parse(text);
            var xroot    = XmlSupport.GetFirstSubNode(document, "Envelope", false);

            if (xroot == null)
            {
                throw new XmlException("No valid SOAP envelop!");
            } // if

            var xbody = XmlSupport.GetFirstSubNode(xroot, "Body");

            var xfault = XmlSupport.GetFirstSubNode(xbody, "Fault", false);

            if (xfault != null)
            {
                return(EvaluateFaultResult(xfault));
            } // if

            var xaction    = XmlSupport.GetFirstSubNode(xbody, $"{action.Name}Response");
            var resultList =
                from xresult in xaction.Elements()
                select xresult;

            foreach (var xresult in resultList)
            {
                output.Add(xresult.Value);
            } // foreach

            return(output.ToArray());
        } // EvaluateResult()
Beispiel #4
0
        } // ParseDeviceSchema()

        /// <summary>
        /// Parses the service schema.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>A <see cref="UpnpService"/> object.</returns>
        public static UpnpService ParseServiceSchema(string text)
        {
            var service = new UpnpService();

            if (string.IsNullOrEmpty(text))
            {
                return(service);
            } // if

            var document = XDocument.Parse(text);
            var nodes    = document.Elements().Where(e => e.Name.LocalName == "scpd");
            var xroot    = nodes.FirstOrDefault();

            if (xroot == null)
            {
                throw new XmlException("No node 'scpd' found!");
            } // if

            CheckSupportedSpecVersion(xroot, 1, 0);
            var xactionList = XmlSupport.GetFirstSubNode(xroot, "actionList", false);

            if (xactionList != null)
            {
                var actionList =
                    from xaction in xactionList.Elements()
                    where (xaction.Name.LocalName == "action")
                    select xaction;
                foreach (var xaction in actionList)
                {
                    var action = ParseAction(xaction);
                    action.Service = service;
                    service.AddAction(action);
                } // foreach
            }     // if

            var xserviceStateTable = XmlSupport.GetFirstSubNode(xroot, "serviceStateTable");

            if (xserviceStateTable != null)
            {
                var serviceStateTable =
                    from xvariable in xserviceStateTable.Elements()
                    where (xvariable.Name.LocalName == "stateVariable")
                    select xvariable;
                foreach (var xvariable in serviceStateTable)
                {
                    var variable = ParseStateVariable(xvariable);
                    service.AddStateVariable(variable);
                } // foreach
            }     // if

            return(service);
        } // ParseServiceSchema()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
0
        } // DisplayStatusText()

        /// <summary>
        /// Parses a feature list.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>A  list of <see cref="Feature"/> objects.</returns>
        private static List <Feature> ParseFeatureList(string text)
        {
            var result = new List <Feature>();

            var document    = XDocument.Parse(text);
            var featureRoot = XmlSupport.GetFirstSubNode(document, "Features");
            var itemlist    = featureRoot.Elements().Where(e => e.Name.LocalName == "Feature");

            foreach (var item in itemlist)
            {
                var feature = ParseFeature(item);
                result.Add(feature);
            } // foreach

            return(result);
        } // ParseFeatureList()
Beispiel #8
0
        //// ---------------------------------------------------------------------

        #region PUBLIC METHODS
        /// <summary>
        /// Parses the device schema.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>A <see cref="DeviceSchema"/> object.</returns>
        public static DeviceSchema ParseDeviceSchema(string text)
        {
            var document = XDocument.Parse(text);
            var nodes    = document.Elements().Where(e => e.Name.LocalName == "root");
            var xroot    = nodes.FirstOrDefault();

            if (xroot == null)
            {
                throw new XmlException("No node 'root' found!");
            } // if

            CheckSupportedSpecVersion(xroot, 1, 0);
            var xdevice = XmlSupport.GetFirstSubNode(xroot, "device");
            var schema  = ParseDeviceSchema(xdevice);

            return(schema);
        } // ParseDeviceSchema()
Beispiel #9
0
        } // ParseChildData()

        /// <summary>
        /// Parses the DIDL meta data.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>A <see cref="BrowseMetaDataResult"/> object.</returns>
        private BrowseMetaDataResult ParseDidlMetaData(string text)
        {
            var result = new BrowseMetaDataResult();

            var document  = XDocument.Parse(text);
            var didl      = XmlSupport.GetFirstSubNode(document, "DIDL-Lite");
            var container = XmlSupport.GetFirstSubNode(didl, "container", false);

            if (container != null)
            {
                return(ParseDidlContainerMetaData(container));
            } // if

            var item = XmlSupport.GetFirstSubNode(didl, "item");

            if (item != null)
            {
                return(ParseDidlItemMetaData(item));
            } // if

            return(result);
        } // ParseDidlMetaData()
Beispiel #10
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()
Beispiel #11
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()
Beispiel #12
0
        } // ParseFeature()

        /// <summary>
        /// Parses the <c>DIDL</c> child data.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns>A <see cref="BrowseChildDataResult"/> object.</returns>
        private static BrowseChildDataResult ParseDidlChildData(string text)
        {
            var result = new BrowseChildDataResult();

            var document = XDocument.Parse(text);
            var didl     = XmlSupport.GetFirstSubNode(document, "DIDL-Lite");

            // first lokk for containers
            var itemlist = didl.Elements().Where(e => e.Name.LocalName == "container");

            foreach (var item in itemlist)
            {
                result.AddChildItem(ParseChildData(item));
            } // foreach

            itemlist = didl.Elements().Where(e => e.Name.LocalName == "item");
            foreach (var item in itemlist)
            {
                result.AddChildItem(ParseChildData(item));
            } // foreach

            return(result);
        } // ParseDidlChildData()
Beispiel #13
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()