2020-01-22 20:00:07 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2016-11-04 08:31:05 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
2016-10-29 22:22:20 +00:00
|
|
|
using System.Xml;
|
2016-11-04 08:31:05 +00:00
|
|
|
using Emby.Dlna.Didl;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2016-10-29 22:34:54 +00:00
|
|
|
namespace Emby.Dlna.Service
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2020-01-21 16:59:41 +00:00
|
|
|
public static class ControlErrorHandler
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2020-08-20 15:59:27 +00:00
|
|
|
private const string NsSoapEnv = "http://schemas.xmlsoap.org/soap/envelope/";
|
2019-01-07 23:27:46 +00:00
|
|
|
|
2020-01-21 16:59:41 +00:00
|
|
|
public static ControlResponse GetResponse(Exception ex)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
2016-11-04 08:31:05 +00:00
|
|
|
var settings = new XmlWriterSettings
|
|
|
|
{
|
|
|
|
Encoding = Encoding.UTF8,
|
|
|
|
CloseOutput = false
|
|
|
|
};
|
|
|
|
|
|
|
|
StringWriter builder = new StringWriterWithEncoding(Encoding.UTF8);
|
|
|
|
|
2019-01-13 20:37:13 +00:00
|
|
|
using (var writer = XmlWriter.Create(builder, settings))
|
2016-11-04 08:31:05 +00:00
|
|
|
{
|
|
|
|
writer.WriteStartDocument(true);
|
|
|
|
|
2020-08-20 15:59:27 +00:00
|
|
|
writer.WriteStartElement("SOAP-ENV", "Envelope", NsSoapEnv);
|
|
|
|
writer.WriteAttributeString(string.Empty, "encodingStyle", NsSoapEnv, "http://schemas.xmlsoap.org/soap/encoding/");
|
2016-11-04 08:31:05 +00:00
|
|
|
|
2020-08-20 15:59:27 +00:00
|
|
|
writer.WriteStartElement("SOAP-ENV", "Body", NsSoapEnv);
|
|
|
|
writer.WriteStartElement("SOAP-ENV", "Fault", NsSoapEnv);
|
2016-11-04 08:31:05 +00:00
|
|
|
|
|
|
|
writer.WriteElementString("faultcode", "500");
|
|
|
|
writer.WriteElementString("faultstring", ex.Message);
|
|
|
|
|
|
|
|
writer.WriteStartElement("detail");
|
|
|
|
writer.WriteRaw("<UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\"><errorCode>401</errorCode><errorDescription>Invalid Action</errorDescription></UPnPError>");
|
2016-11-06 17:30:44 +00:00
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 08:31:05 +00:00
|
|
|
|
2016-11-06 17:30:44 +00:00
|
|
|
writer.WriteFullEndElement();
|
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 08:31:05 +00:00
|
|
|
|
2016-11-06 17:30:44 +00:00
|
|
|
writer.WriteFullEndElement();
|
2016-11-04 08:31:05 +00:00
|
|
|
writer.WriteEndDocument();
|
|
|
|
}
|
2016-10-29 22:22:20 +00:00
|
|
|
|
|
|
|
return new ControlResponse
|
|
|
|
{
|
2016-11-04 08:31:05 +00:00
|
|
|
Xml = builder.ToString(),
|
2016-10-29 22:22:20 +00:00
|
|
|
IsSuccessful = false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|