diff --git a/NzbDrone.Core/Providers/HttpProvider.cs b/NzbDrone.Core/Providers/HttpProvider.cs index b4c153012..ec6352c2f 100644 --- a/NzbDrone.Core/Providers/HttpProvider.cs +++ b/NzbDrone.Core/Providers/HttpProvider.cs @@ -1,12 +1,43 @@ -using System.Net; +using System; +using System.Net; +using NLog; namespace NzbDrone.Core.Providers { internal class HttpProvider : IHttpProvider { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + public string DownloadString(string request) { - return new WebClient().DownloadString(request); + try + { + return new WebClient().DownloadString(request); + } + catch (Exception ex) + { + Logger.Warn("Failed to get response from: {0}", request); + Logger.TraceException(ex.Message, ex); + } + + return String.Empty; + } + + public string DownloadString(string request, string username, string password) + { + try + { + var webClient = new WebClient(); + webClient.Credentials = new NetworkCredential(username, password); + return webClient.DownloadString(request); + } + catch (Exception ex) + { + Logger.Warn("Failed to get response from: {0}", request); + Logger.TraceException(ex.Message, ex); + } + + return String.Empty; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/IHttpProvider.cs b/NzbDrone.Core/Providers/IHttpProvider.cs index ae4e54ca4..485f8a312 100644 --- a/NzbDrone.Core/Providers/IHttpProvider.cs +++ b/NzbDrone.Core/Providers/IHttpProvider.cs @@ -3,5 +3,6 @@ public interface IHttpProvider { string DownloadString(string request); + string DownloadString(string request, string username, string password); } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/PostProcessingProvider.cs b/NzbDrone.Core/Providers/PostProcessingProvider.cs index 4345528a5..15f8c46a2 100644 --- a/NzbDrone.Core/Providers/PostProcessingProvider.cs +++ b/NzbDrone.Core/Providers/PostProcessingProvider.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Core.Providers foreach (var file in fileList) { - //Todo: Where should we handle XBMC notifying/library updating etc? RenameProvider seems like a likely place, since we want to update XBMC after renaming (might as well) + //Notifications will be sent from the Renamer, depending on the bool NewDownload (which will be set to true from here), a normal rename will be treated as such. _renameProvider.RenameEpisodeFile(file.EpisodeFileId, true); } } diff --git a/NzbDrone.Core/Providers/XbmcProvider.cs b/NzbDrone.Core/Providers/XbmcProvider.cs index 458418d83..afc13f155 100644 --- a/NzbDrone.Core/Providers/XbmcProvider.cs +++ b/NzbDrone.Core/Providers/XbmcProvider.cs @@ -13,14 +13,16 @@ namespace NzbDrone.Core.Providers public class XbmcProvider : IXbmcProvider { private readonly IConfigProvider _configProvider; + private readonly IHttpProvider _httpProvider; private WebClient _webClient; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public XbmcProvider(IConfigProvider configProvider) + public XbmcProvider(IConfigProvider configProvider, IHttpProvider httpProvider) { _webClient = new WebClient(); _configProvider = configProvider; + _httpProvider = httpProvider; } #region IXbmcProvider Members @@ -84,25 +86,14 @@ namespace NzbDrone.Core.Providers { var username = _configProvider.GetValue("XbmcUsername", String.Empty, true); var password = _configProvider.GetValue("XbmcPassword", String.Empty, true); - - if (!String.IsNullOrEmpty(username)) - { - _webClient.Credentials = new NetworkCredential(username, password); - } - var url = String.Format("http://{0}/xbmcCmds/xbmcHttp?command={1}", host, command); - try - { - return _webClient.DownloadString(url); - } - catch (Exception ex) + if (!String.IsNullOrEmpty(username)) { - Logger.Warn("Unable to Connect to XBMC Host: {0}", host); - Logger.DebugException(ex.Message, ex); + return _httpProvider.DownloadString(url, username, password); } - - return string.Empty; + + return _httpProvider.DownloadString(url); } private string GetXbmcSeriesPath(string host, int seriesId)