XBMC version is cached by host & port

Cache is cleared on test
Version is cached for 12 hours
pull/4/head
Mark McDowall 10 years ago
parent fc46018c9a
commit ff99c383da

@ -4,6 +4,7 @@ using System.Linq;
using FluentValidation.Results;
using Newtonsoft.Json.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Notifications.Xbmc.Model;
using NzbDrone.Core.Tv;
@ -25,11 +26,18 @@ namespace NzbDrone.Core.Notifications.Xbmc
private readonly IEnumerable<IApiProvider> _apiProviders;
private readonly Logger _logger;
public XbmcService(IXbmcJsonApiProxy proxy, IEnumerable<IApiProvider> apiProviders, Logger logger)
private readonly ICached<XbmcVersion> _xbmcVersionCache;
public XbmcService(IXbmcJsonApiProxy proxy,
IEnumerable<IApiProvider> apiProviders,
ICacheManager cacheManager,
Logger logger)
{
_proxy = proxy;
_apiProviders = apiProviders;
_logger = logger;
_xbmcVersionCache = cacheManager.GetCache<XbmcVersion>(GetType());
}
public void Notify(XbmcSettings settings, string title, string message)
@ -54,6 +62,9 @@ namespace NzbDrone.Core.Notifications.Xbmc
{
try
{
return _xbmcVersionCache.Get(settings.Address, () =>
{
var response = _proxy.GetJsonVersion(settings);
_logger.Debug("Getting version from response: " + response);
@ -61,13 +72,12 @@ namespace NzbDrone.Core.Notifications.Xbmc
var versionObject = result.Result.Property("version");
if (versionObject.Value.Type == JTokenType.Integer)
return new XbmcVersion((int)versionObject.Value);
if (versionObject.Value.Type == JTokenType.Integer) return new XbmcVersion((int) versionObject.Value);
if (versionObject.Value.Type == JTokenType.Object)
return Json.Deserialize<XbmcVersion>(versionObject.Value.ToString());
if (versionObject.Value.Type == JTokenType.Object) return Json.Deserialize<XbmcVersion>(versionObject.Value.ToString());
throw new InvalidCastException("Unknown Version structure!: " + versionObject);
}, TimeSpan.FromHours(12));
}
catch (Exception ex)
@ -94,6 +104,8 @@ namespace NzbDrone.Core.Notifications.Xbmc
public ValidationFailure Test(XbmcSettings settings)
{
_xbmcVersionCache.Clear();
try
{
_logger.Debug("Determining version of XBMC Host: {0}", settings.Address);

@ -70,5 +70,10 @@ namespace NzbDrone.Core.Notifications.Xbmc
{
return Validator.Validate(this);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

Loading…
Cancel
Save