update xml parsing

This commit is contained in:
Luke Pulverenti 2016-11-02 13:29:06 -04:00
parent 7cf0f79f85
commit 8f64a5555b
5 changed files with 121 additions and 81 deletions

View File

@ -1329,11 +1329,13 @@ namespace MediaBrowser.LocalMetadata.Parsers
protected Share GetShare(XmlReader reader)
{
reader.MoveToContent();
var item = new Share();
while (reader.Read())
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
@ -1350,12 +1352,17 @@ namespace MediaBrowser.LocalMetadata.Parsers
item.CanEdit = string.Equals(reader.ReadElementContentAsString(), "true", StringComparison.OrdinalIgnoreCase);
break;
}
default:
reader.Skip();
break;
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
// This is valid

View File

@ -31,11 +31,13 @@ namespace MediaBrowser.LocalMetadata.Parsers
private void FetchFromCollectionItemsNode(XmlReader reader, MetadataResult<BoxSet> item)
{
reader.MoveToContent();
var list = new List<LinkedChild>();
while (reader.Read())
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
@ -55,12 +57,17 @@ namespace MediaBrowser.LocalMetadata.Parsers
break;
}
default:
reader.Skip();
break;
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
item.Item.LinkedChildren = list;

View File

@ -65,11 +65,13 @@ namespace MediaBrowser.LocalMetadata.Parsers
private void FetchFromCollectionItemsNode(XmlReader reader, Playlist item)
{
reader.MoveToContent();
var list = new List<LinkedChild>();
while (reader.Read())
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
@ -89,12 +91,17 @@ namespace MediaBrowser.LocalMetadata.Parsers
break;
}
default:
reader.Skip();
break;
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
item.LinkedChildren = list;
@ -102,11 +109,13 @@ namespace MediaBrowser.LocalMetadata.Parsers
private void FetchFromSharesNode(XmlReader reader, Playlist item)
{
reader.MoveToContent();
var list = new List<Share>();
while (reader.Read())
reader.MoveToContent();
reader.Read();
// Loop through each element
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
@ -126,12 +135,17 @@ namespace MediaBrowser.LocalMetadata.Parsers
break;
}
default:
reader.Skip();
break;
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
item.Shares = list;

View File

@ -513,9 +513,10 @@ namespace MediaBrowser.Providers.TV
using (var reader = XmlReader.Create(streamReader, settings))
{
reader.MoveToContent();
reader.Read();
// Loop through each element
while (reader.Read())
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
@ -546,12 +547,17 @@ namespace MediaBrowser.Providers.TV
break;
}
default:
reader.Skip();
break;
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
}
}

View File

@ -82,67 +82,73 @@ namespace MediaBrowser.Providers.TV
// Use XmlReader for best performance
using (reader)
{
reader.MoveToContent();
reader.MoveToContent();
reader.Read();
// Loop through each element
while (reader.Read())
{
cancellationToken.ThrowIfCancellationRequested();
// Loop through each element
while (!reader.EOF)
{
if (reader.NodeType == XmlNodeType.Element)
{
cancellationToken.ThrowIfCancellationRequested();
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.Name)
{
case "thumb_width":
{
var val = reader.ReadElementContentAsString();
switch (reader.Name)
{
case "thumb_width":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
int rval;
if (!string.IsNullOrWhiteSpace(val))
{
int rval;
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
{
width = rval;
}
}
break;
}
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
{
width = rval;
}
}
break;
}
case "thumb_height":
{
var val = reader.ReadElementContentAsString();
case "thumb_height":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
int rval;
if (!string.IsNullOrWhiteSpace(val))
{
int rval;
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
{
height = rval;
}
}
break;
}
// int.TryParse is local aware, so it can be probamatic, force us culture
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out rval))
{
height = rval;
}
}
break;
}
case "filename":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
url = TVUtils.BannerUrl + val;
}
break;
}
default:
reader.Skip();
break;
}
}
}
case "filename":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
url = TVUtils.BannerUrl + val;
}
break;
}
default:
{
reader.Skip();
break;
}
}
}
else
{
reader.Read();
}
}
}
if (string.IsNullOrEmpty(url))