mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-05 07:18:47 +01:00
Update to 3.5.2 and .net core 2.1
This commit is contained in:
@@ -31,25 +31,6 @@ namespace Rssdp
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialisation constructor.
|
||||
/// </summary>
|
||||
/// <param name="location">The url from which the device description document was retrieved.</param>
|
||||
/// <param name="cacheLifetime">A <see cref="System.TimeSpan"/> representing the time maximum period of time the device description can be cached for.</param>
|
||||
/// <param name="deviceDescriptionXml">The device description XML as a string.</param>
|
||||
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="deviceDescriptionXml"/> or <paramref name="location"/> arguments are null.</exception>
|
||||
/// <exception cref="System.ArgumentException">Thrown if the <paramref name="deviceDescriptionXml"/> argument is empty.</exception>
|
||||
public SsdpRootDevice(Uri location, TimeSpan cacheLifetime, string deviceDescriptionXml)
|
||||
: base(deviceDescriptionXml)
|
||||
{
|
||||
if (location == null) throw new ArgumentNullException("location");
|
||||
|
||||
this.CacheLifetime = cacheLifetime;
|
||||
this.Location = location;
|
||||
|
||||
LoadFromDescriptionDocument(deviceDescriptionXml);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
@@ -94,82 +75,5 @@ namespace Rssdp
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Saves the property values of this device object to an a string in the full UPnP device description XML format, including child devices and outer root node and XML document declaration.
|
||||
/// </summary>
|
||||
/// <returns>A string containing XML in the UPnP device description format</returns>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Dispsoing memory stream twice is 'safe' and easier to read than correct code for ensuring it is only closed once.")]
|
||||
public virtual string ToDescriptionDocument()
|
||||
{
|
||||
if (String.IsNullOrEmpty(this.Uuid)) throw new InvalidOperationException("Must provide a UUID value.");
|
||||
|
||||
//This would have been so much nicer with Xml.Linq, but that's
|
||||
//not available until .NET 4.03 at the earliest, and I want to
|
||||
//target 4.0 :(
|
||||
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
||||
{
|
||||
System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(ms, new XmlWriterSettings() { Encoding = System.Text.UTF8Encoding.UTF8, Indent = true, NamespaceHandling = NamespaceHandling.OmitDuplicates });
|
||||
writer.WriteStartDocument();
|
||||
writer.WriteStartElement("root", SsdpConstants.SsdpDeviceDescriptionXmlNamespace);
|
||||
|
||||
writer.WriteStartElement("specVersion");
|
||||
writer.WriteElementString("major", "1");
|
||||
writer.WriteElementString("minor", "0");
|
||||
writer.WriteEndElement();
|
||||
|
||||
if (this.UrlBase != null && this.UrlBase != this.Location)
|
||||
writer.WriteElementString("URLBase", this.UrlBase.ToString());
|
||||
|
||||
WriteDeviceDescriptionXml(writer, this);
|
||||
|
||||
writer.WriteEndElement();
|
||||
writer.Flush();
|
||||
|
||||
ms.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
using (var reader = new System.IO.StreamReader(ms))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#region Deserialisation Methods
|
||||
|
||||
private void LoadFromDescriptionDocument(string deviceDescriptionXml)
|
||||
{
|
||||
using (var ms = new System.IO.MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(deviceDescriptionXml)))
|
||||
{
|
||||
var reader = XmlReader.Create(ms);
|
||||
while (!reader.EOF)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "root") continue;
|
||||
|
||||
while (!reader.EOF)
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
if (reader.NodeType != XmlNodeType.Element) continue;
|
||||
|
||||
if (reader.LocalName == "URLBase")
|
||||
{
|
||||
this.UrlBase = StringToUri(reader.ReadElementContentAsString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user