Fixed: Don't report log exceptions when connection to XBMC fails

This commit is contained in:
Mark McDowall 2014-11-20 17:15:00 -08:00
parent 2dbf9f5baf
commit 6ffeba37cb
1 changed files with 38 additions and 16 deletions

View File

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Tv;
@ -9,10 +12,12 @@ namespace NzbDrone.Core.Notifications.Xbmc
public class Xbmc : NotificationBase<XbmcSettings>
{
private readonly IXbmcService _xbmcService;
private readonly Logger _logger;
public Xbmc(IXbmcService xbmcService)
public Xbmc(IXbmcService xbmcService, Logger logger)
{
_xbmcService = xbmcService;
_logger = logger;
}
public override string Link
@ -24,21 +29,14 @@ namespace NzbDrone.Core.Notifications.Xbmc
{
const string header = "Sonarr [TV] - Grabbed";
if (Settings.Notify)
{
_xbmcService.Notify(Settings, header, message);
}
Notify(Settings, header, message);
}
public override void OnDownload(DownloadMessage message)
{
const string header = "Sonarr [TV] - Downloaded";
if (Settings.Notify)
{
_xbmcService.Notify(Settings, header, message.Message);
}
Notify(Settings, header, message.Message);
UpdateAndClean(message.Series, message.OldFiles.Any());
}
@ -56,7 +54,25 @@ namespace NzbDrone.Core.Notifications.Xbmc
return new ValidationResult(failures);
}
private void Notify(XbmcSettings settings, string header, string message)
{
try
{
if (Settings.Notify)
{
_xbmcService.Notify(Settings, header, message);
}
}
catch (SocketException ex)
{
var logMessage = String.Format("Unable to connect to XBMC Host: {0}:{1}", Settings.Host, Settings.Port);
_logger.DebugException(logMessage, ex);
}
}
private void UpdateAndClean(Series series, bool clean = true)
{
try
{
if (Settings.UpdateLibrary)
{
@ -68,5 +84,11 @@ namespace NzbDrone.Core.Notifications.Xbmc
_xbmcService.Clean(Settings);
}
}
catch (SocketException ex)
{
var logMessage = String.Format("Unable to connect to XBMC Host: {0}:{1}", Settings.Host, Settings.Port);
_logger.DebugException(logMessage, ex);
}
}
}
}