Fixed some resharper line breaks

This commit is contained in:
Keivan 2010-09-27 23:09:24 -07:00
parent d00744aafa
commit de212f8b98
6 changed files with 44 additions and 29 deletions

View File

@ -36,10 +36,12 @@ namespace NzbDrone.Core.Providers
var dbValue = _sonicRepo.Single<Config>(key); var dbValue = _sonicRepo.Single<Config>(key);
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value)) return dbValue.Value; if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
return dbValue.Value;
_logger.WarnFormat("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue); _logger.WarnFormat("Unable to find config key '{0}' defaultValue:'{1}'", key, defaultValue);
if (makePermanent) SetValue(key, defaultValue.ToString()); if (makePermanent)
SetValue(key, defaultValue.ToString());
value = defaultValue.ToString(); value = defaultValue.ToString();
return value; return value;
@ -47,14 +49,22 @@ namespace NzbDrone.Core.Providers
public void SetValue(string key, string value) public void SetValue(string key, string value)
{ {
if (String.IsNullOrEmpty(key)) throw new ArgumentOutOfRangeException("key"); if (String.IsNullOrEmpty(key))
if (value == null) throw new ArgumentNullException("key"); throw new ArgumentOutOfRangeException("key");
if (value == null)
throw new ArgumentNullException("key");
_logger.DebugFormat("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value); _logger.DebugFormat("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
var dbValue = _sonicRepo.Single<Config>(key); var dbValue = _sonicRepo.Single<Config>(key);
if (dbValue == null) _sonicRepo.Add(new Config {Key = key, Value = value}); if (dbValue == null)
{
_sonicRepo.Add(new Config {
Key = key,
Value = value
});
}
else else
{ {
dbValue.Value = value; dbValue.Value = value;

View File

@ -26,7 +26,8 @@ namespace NzbDrone.Core.Providers
public static string CleanPath(string path) public static string CleanPath(string path)
{ {
if (string.IsNullOrEmpty(path)) throw new ArgumentException("Path can not be null or empty"); if (string.IsNullOrEmpty(path))
throw new ArgumentException("Path can not be null or empty");
return path.ToLower().Trim('/', '\\', ' '); return path.ToLower().Trim('/', '\\', ' ');
} }
} }

View File

@ -1,4 +1,3 @@
using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
@ -6,7 +5,7 @@ namespace NzbDrone.Core.Providers
{ {
public class EpisodeProvider public class EpisodeProvider
{ {
private static readonly Regex _parseRegex = new Regex(@"(?<showName>.*) private static readonly Regex ParseRegex = new Regex(@"(?<showName>.*)
(?: (?:
s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+) s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)-?e(?<episodeNumber2>\d+)
| s(?<seasonNumber>\d+)e(?<episodeNumber>\d+) | s(?<seasonNumber>\d+)e(?<episodeNumber>\d+)
@ -23,16 +22,26 @@ namespace NzbDrone.Core.Providers
public static Episode Parse(string title) public static Episode Parse(string title)
{ {
Match match = _parseRegex.Match(title); Match match = ParseRegex.Match(title);
if (!match.Success) return null; if (!match.Success)
return null;
return new Episode {Season = ParseInt(match.Groups["seasonNumber"].Value), EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value), EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value), Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value), Release = ReplaceSeparatorChars(match.Groups["release"].Value), Proper = title.Contains("PROPER")}; return new Episode {
Season = ParseInt(match.Groups["seasonNumber"].Value),
EpisodeNumber = ParseInt(match.Groups["episodeNumber"].Value),
EpisodeNumber2 = ParseInt(match.Groups["episodeNumber2"].Value),
Title = ReplaceSeparatorChars(match.Groups["episodeName"].Value),
Release = ReplaceSeparatorChars(match.Groups["release"].Value),
Proper = title.Contains("PROPER")
};
} }
private static string ReplaceSeparatorChars(string s) private static string ReplaceSeparatorChars(string s)
{ {
if (s == null) return string.Empty; if (s == null)
return string.Empty;
return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim(); return s.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Trim();
} }
@ -42,12 +51,5 @@ namespace NzbDrone.Core.Providers
int.TryParse(s, out i); int.TryParse(s, out i);
return i; return i;
} }
private static DateTime ParseAirDate(string s)
{
DateTime d;
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d)) return d;
return DateTime.MinValue;
}
} }
} }

View File

@ -37,28 +37,29 @@ namespace NzbDrone.Core.Providers
string response = _http.DownloadString(request).Replace("\n", String.Empty); string response = _http.DownloadString(request).Replace("\n", String.Empty);
_logger.DebugFormat("Queue Repsonse: [{0}]", response); _logger.DebugFormat("Queue Repsonse: [{0}]", response);
if (response == "ok") return true; if (response == "ok")
return true;
return false; return false;
} }
public bool IsInQueue(string title) public bool IsInQueue(string title)
{ {
string action = "mode=queue&output=xml"; const string action = "mode=queue&output=xml";
string request = GetSabRequest(action); string request = GetSabRequest(action);
string response = _http.DownloadString(request); string response = _http.DownloadString(request);
XDocument xDoc = XDocument.Parse(response); XDocument xDoc = XDocument.Parse(response);
//If an Error Occurred, retuyrn) //If an Error Occurred, retuyrn)
if (xDoc.Descendants("error").Count() != 0) return false; if (xDoc.Descendants("error").Count() != 0)
return false;
if (xDoc.Descendants("queue").Count() == 0) return false; if (xDoc.Descendants("queue").Count() == 0)
return false;
//Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue))) //Get the Count of Items in Queue where 'filename' is Equal to goodName, if not zero, return true (isInQueue)))
if ((from s in xDoc.Descendants("slot") if ((xDoc.Descendants("slot").Where(s => s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase))).Count() != 0)
where s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase)
select s).Count() != 0)
{ {
_logger.DebugFormat("Episode in queue - '{0}'", title); _logger.DebugFormat("Episode in queue - '{0}'", title);

View File

@ -54,7 +54,8 @@ namespace NzbDrone.Core.Providers
private void AddShow(string path) private void AddShow(string path)
{ {
var searchResults = _tvDb.SearchSeries(new DirectoryInfo(path).Name); var searchResults = _tvDb.SearchSeries(new DirectoryInfo(path).Name);
if (searchResults.Count != 0 && !_sonioRepo.Exists<Series>(s => s.TvdbId == searchResults[0].Id.ToString())) AddShow(path, _tvDb.GetSeries(searchResults[0].Id, searchResults[0].Language)); if (searchResults.Count != 0 && !_sonioRepo.Exists<Series>(s => s.TvdbId == searchResults[0].Id.ToString()))
AddShow(path, _tvDb.GetSeries(searchResults[0].Id, searchResults[0].Language));
} }
private void AddShow(string path, TvdbSeries series) private void AddShow(string path, TvdbSeries series)

View File

@ -8,12 +8,12 @@ namespace NzbDrone.Core.Providers
{ {
public class TvDbProvider : ITvDbProvider public class TvDbProvider : ITvDbProvider
{ {
private const string TvDbApiKey = "5D2D188E86E07F4F"; private const string TVDB_APIKEY = "5D2D188E86E07F4F";
private readonly TvdbHandler _handler; private readonly TvdbHandler _handler;
public TvDbProvider() public TvDbProvider()
{ {
_handler = new TvdbHandler(new XmlCacheProvider(Path.Combine(Main.AppPath, @"cache\tvdbcache.xml")), TvDbApiKey); _handler = new TvdbHandler(new XmlCacheProvider(Path.Combine(Main.AppPath, @"cache\tvdbcache.xml")), TVDB_APIKEY);
} }
#region ITvDbProvider Members #region ITvDbProvider Members