2014-06-29 20:04:50 -07:00
|
|
|
|
using System.Globalization;
|
2013-10-28 07:56:57 -07:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml;
|
2014-06-29 20:04:50 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-10-28 07:56:57 -07:00
|
|
|
|
|
2014-06-29 20:04:50 -07:00
|
|
|
|
namespace MediaBrowser.LocalMetadata.Parsers
|
2013-10-28 07:56:57 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class EpisodeXmlParser
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class GameXmlParser : BaseItemXmlParser<Game>
|
|
|
|
|
{
|
|
|
|
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
|
|
|
|
2016-08-26 21:33:18 -07:00
|
|
|
|
public GameXmlParser(ILogger logger, IProviderManager providerManager)
|
|
|
|
|
: base(logger, providerManager)
|
2013-10-28 07:56:57 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 10:44:13 -07:00
|
|
|
|
private readonly Task _cachedTask = Task.FromResult(true);
|
2015-06-28 18:10:45 -07:00
|
|
|
|
public Task FetchAsync(MetadataResult<Game> item, string metadataFile, CancellationToken cancellationToken)
|
2013-10-28 07:56:57 -07:00
|
|
|
|
{
|
|
|
|
|
Fetch(item, metadataFile, cancellationToken);
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2014-02-03 10:44:13 -07:00
|
|
|
|
return _cachedTask;
|
2013-10-28 07:56:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fetches the data from XML node.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">The reader.</param>
|
2015-06-28 18:10:45 -07:00
|
|
|
|
/// <param name="result">The result.</param>
|
|
|
|
|
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Game> result)
|
2013-10-28 07:56:57 -07:00
|
|
|
|
{
|
2015-06-28 18:10:45 -07:00
|
|
|
|
var item = result.Item;
|
|
|
|
|
|
2013-10-28 07:56:57 -07:00
|
|
|
|
switch (reader.Name)
|
|
|
|
|
{
|
|
|
|
|
case "GameSystem":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.GameSystem = val;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "GamesDbId":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Gamesdb, val);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Players":
|
|
|
|
|
{
|
|
|
|
|
var val = reader.ReadElementContentAsString();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(val))
|
|
|
|
|
{
|
|
|
|
|
int num;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(val, NumberStyles.Integer, _usCulture, out num))
|
|
|
|
|
{
|
|
|
|
|
item.PlayersSupported = num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2015-06-28 18:10:45 -07:00
|
|
|
|
base.FetchDataFromXmlNode(reader, result);
|
2013-10-28 07:56:57 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|