Async'd xml parsing - more to come on that
This commit is contained in:
parent
76f4b2adc9
commit
3dc824e1a4
|
@ -17,37 +17,33 @@ namespace MediaBrowser.Controller.Xml
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches metadata for an item from one xml file
|
/// Fetches metadata for an item from one xml file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Task Fetch(T item, string metadataFile)
|
public async Task Fetch(T item, string metadataFile)
|
||||||
{
|
{
|
||||||
// Wrapping this for now until I have a chance to async the whole process
|
// Use XmlReader for best performance
|
||||||
return Task.Run(() =>
|
using (XmlReader reader = XmlReader.Create(metadataFile, new XmlReaderSettings() { Async = true }))
|
||||||
{
|
{
|
||||||
// Use XmlReader for best performance
|
await reader.MoveToContentAsync();
|
||||||
using (XmlReader reader = XmlReader.Create(metadataFile))
|
|
||||||
{
|
|
||||||
reader.MoveToContent();
|
|
||||||
|
|
||||||
// Loop through each element
|
// Loop through each element
|
||||||
while (reader.Read())
|
while (await reader.ReadAsync())
|
||||||
|
{
|
||||||
|
if (reader.NodeType == XmlNodeType.Element)
|
||||||
{
|
{
|
||||||
if (reader.NodeType == XmlNodeType.Element)
|
FetchDataFromXmlNode(reader, item);
|
||||||
{
|
|
||||||
FetchDataFromXmlNode(reader, item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If dates weren't supplied in metadata, use values from the xml file
|
// If dates weren't supplied in metadata, use values from the xml file
|
||||||
if (item.DateCreated == DateTime.MinValue)
|
if (item.DateCreated == DateTime.MinValue)
|
||||||
{
|
{
|
||||||
item.DateCreated = File.GetCreationTime(metadataFile);
|
item.DateCreated = File.GetCreationTime(metadataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.DateModified == DateTime.MinValue)
|
if (item.DateModified == DateTime.MinValue)
|
||||||
{
|
{
|
||||||
item.DateModified = File.GetLastWriteTime(metadataFile);
|
item.DateModified = File.GetLastWriteTime(metadataFile);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user