1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 18:02:44 +01:00

Resharper code cleanup

This commit is contained in:
Keivan 2010-09-27 22:58:49 -07:00
parent c7286863b0
commit d00744aafa
11 changed files with 46 additions and 130 deletions

View File

@ -11,7 +11,6 @@ namespace NzbDrone.Core
{
public static class Main
{
public static void BindKernel(IKernel kernel)
{
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));

View File

@ -11,7 +11,6 @@ public class ConfigProvider : IConfigProvider
private readonly ILog _logger;
private readonly IRepository _sonicRepo;
public ConfigProvider(ILog logger, IRepository dataRepository)
{
_logger = logger;
@ -19,7 +18,6 @@ public ConfigProvider(ILog logger, IRepository dataRepository)
_sonicRepo = dataRepository;
}
private string GetValue(string key)
{
return GetValue(key, String.Empty, false);
@ -27,39 +25,23 @@ private string GetValue(string key)
public String SeriesRoot
{
get
{
return GetValue(SERIES_ROOTS);
}
get { return GetValue(SERIES_ROOTS); }
set
{
SetValue(SERIES_ROOTS, value);
set { SetValue(SERIES_ROOTS, value); }
}
}
public string GetValue(string key, object defaultValue, bool makePermanent)
{
string value;
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);
if (makePermanent)
{
SetValue(key, defaultValue.ToString());
}
if (makePermanent) SetValue(key, defaultValue.ToString());
value = defaultValue.ToString();
return value;
}
@ -72,10 +54,7 @@ public void SetValue(string key, string value)
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
{
dbValue.Value = value;

View File

@ -6,9 +6,7 @@ namespace NzbDrone.Core.Providers
{
public class EpisodeProvider
{
private static 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+)
@ -23,24 +21,13 @@ public class EpisodeProvider
| (?<episodeName>.*)
)", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace);
public static Episode Parse(string 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)
@ -59,10 +46,8 @@ private static int ParseInt(string s)
private static DateTime ParseAirDate(string s)
{
DateTime d;
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d))
return d;
if (DateTime.TryParse(ReplaceSeparatorChars(s).Replace(' ', '-'), out d)) return d;
return DateTime.MinValue;
}
}
}

View File

@ -1,9 +1,8 @@
using System;
using System.Net;
using System.Net;
namespace NzbDrone.Core.Providers
{
class HttpProvider : IHttpProvider
internal class HttpProvider : IHttpProvider
{
public string DownloadString(string request)
{

View File

@ -1,6 +1,4 @@
using NzbDrone.Core.Repository;
namespace NzbDrone.Core.Providers
namespace NzbDrone.Core.Providers
{
public interface IDownloadProvider
{

View File

@ -1,9 +1,8 @@
using System;
using System.Linq;
using System.Web;
using log4net;
using System.Xml.Linq;
using NzbDrone.Core.Repository;
using log4net;
namespace NzbDrone.Core.Providers
{
@ -38,8 +37,7 @@ public bool AddByUrl(string url, string title)
string response = _http.DownloadString(request).Replace("\n", String.Empty);
_logger.DebugFormat("Queue Repsonse: [{0}]", response);
if (response == "ok")
return true;
if (response == "ok") return true;
return false;
}
@ -53,14 +51,14 @@ public bool IsInQueue(string title)
XDocument xDoc = XDocument.Parse(response);
//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)))
if ((from s in xDoc.Descendants("slot") where s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase) select s).Count() != 0)
if ((from s in xDoc.Descendants("slot")
where s.Element("filename").Value.Equals(title, StringComparison.InvariantCultureIgnoreCase)
select s).Count() != 0)
{
_logger.DebugFormat("Episode in queue - '{0}'", title);
@ -79,9 +77,7 @@ private string GetSabRequest(string action)
string password = _config.GetValue("Password", String.Empty, false);
string apiKey = _config.GetValue("ApiKey", String.Empty, false);
return string.Format(
@"http://{0}/sabnzbd/api?$Action&apikey={1}&ma_username={2}&ma_password={3}",
sabnzbdInfo, apiKey, username, password).Replace("$Action", action);
return string.Format(@"http://{0}/sabnzbd/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey, username, password).Replace("$Action", action);
}
}
}

View File

@ -36,11 +36,8 @@ public Series GetSeries(int tvdbId)
return _sonioRepo.Single<Series>(s => s.TvdbId == tvdbId.ToString());
}
public void SyncSeriesWithDisk()
{
foreach (string seriesFolder in _diskProvider.GetDirectories(_config.SeriesRoot))
{
var cleanPath = DiskProvider.CleanPath(new DirectoryInfo(seriesFolder).FullName);
@ -50,7 +47,6 @@ public void SyncSeriesWithDisk()
AddShow(cleanPath);
}
}
}
#endregion
@ -58,10 +54,7 @@ public void SyncSeriesWithDisk()
private void AddShow(string path)
{
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)

View File

@ -8,6 +8,7 @@ public class Episode
{
[SubSonicPrimaryKey]
public string EpisodeId { get; set; }
public string SeriesId { get; set; }
public string Title { get; set; }
public string Title2 { get; set; }

View File

@ -30,6 +30,5 @@ public enum Quality
/// HD File (Blu-ray Source)
/// </summary>
Bluray = 5
}
}

View File

@ -6,54 +6,21 @@ namespace NzbDrone.Core.Repository
public class Series
{
[SubSonicPrimaryKey]
public string TvdbId
{
get;
set;
}
public string TvdbId { get; set; }
public string SeriesName
{
get;
set;
}
public string SeriesName { get; set; }
public string Status
{
get;
set;
}
public string Status { get; set; }
[SubSonicLongString]
public string Overview
{
get;
set;
}
public string Overview { get; set; }
public DayOfWeek? AirsDayOfWeek
{
get;
set;
}
public DayOfWeek? AirsDayOfWeek { get; set; }
public String AirTimes
{
get;
set;
}
public String AirTimes { get; set; }
public string Language
{
get;
set;
}
public string Path
{
get;
set;
}
public string Language { get; set; }
public string Path { get; set; }
}
}