Exemple #1
0
        private UPnPServiceException ParseActionError(string action, Stream response, Exception actualException)
        {
            UPnPServiceException exception = null;

            try
            {
                var reader = XmlReader.Create(response, xmlReaderSettings);

                if (reader.ReadToDescendant("UPnPError", Namespaces.Control.NamespaceName))
                {
                    // Moving to a first parameter
                    reader.Read();

                    int?   errorCode        = null;
                    string errorDescription = null;

                    while (!reader.EOF)
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (StringComparer.OrdinalIgnoreCase.Compare(reader.LocalName, "errorCode") == 0)
                            {
                                errorCode = reader.ReadElementContentAsInt();
                            }
                            else if (StringComparer.OrdinalIgnoreCase.Compare(reader.LocalName, "errorDescription") == 0)
                            {
                                errorDescription = reader.ReadElementContentAsString();
                            }
                            else
                            {
                                reader.Skip();
                            }
                        }
                        else
                        {
                            reader.Read();
                        }
                    }

                    if (errorCode.HasValue)
                    {
                        exception = new UPnPServiceException(errorCode.Value, errorDescription, actualException);
                    }
                    else
                    {
                        this.logger.Instance().Warning("Can't parse '{0}' response with error. The 'errorCode' element is missing".F(action));
                    }
                }
                else
                {
                    this.logger.Instance().Warning("Can't parse '{0}' response with error. The 'UPnPError' element is missing".F(action));
                }
            }
            catch (XmlException ex)
            {
                this.logger.Instance().Warning(ex, "An error occurred when parsing '{0}' response with error".F(action));
            }

            return(exception);
        }
Exemple #2
0
		private UPnPServiceException ParseActionError(string action, Stream response, Exception actualException)
		{
			UPnPServiceException exception = null;

			try
			{
				var reader = XmlReader.Create(response, xmlReaderSettings);

				if (reader.ReadToDescendant("UPnPError", Namespaces.Control.NamespaceName))
				{
					// Moving to a first parameter
					reader.Read();

					int? errorCode = null;
					string errorDescription = null;

					while (!reader.EOF)
					{
						if (reader.NodeType == XmlNodeType.Element)
						{
							if (StringComparer.OrdinalIgnoreCase.Compare(reader.LocalName, "errorCode") == 0)
							{
								errorCode = reader.ReadElementContentAsInt();
							}
							else if (StringComparer.OrdinalIgnoreCase.Compare(reader.LocalName, "errorDescription") == 0)
							{
								errorDescription = reader.ReadElementContentAsString();
							}
							else
							{
								reader.Skip();
							}
						}
						else
						{
							reader.Read();
						}
					}

					if (errorCode.HasValue)
					{
						exception = new UPnPServiceException(errorCode.Value, errorDescription, actualException);
					}
					else
					{
						this.logger.Instance().Warning("Can't parse '{0}' response with error. The 'errorCode' element is missing".F(action));
					}
				}
				else
				{
					this.logger.Instance().Warning("Can't parse '{0}' response with error. The 'UPnPError' element is missing".F(action));
				}
			}
			catch (XmlException ex)
			{
				this.logger.Instance().Warning(ex, "An error occurred when parsing '{0}' response with error".F(action));
			}

			return exception;
		}