Radarr/NzbDrone.Core/Providers/QualityProvider.cs

78 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Repository.Quality;
2011-06-17 20:31:25 +00:00
using PetaPoco;
namespace NzbDrone.Core.Providers
{
public class QualityProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2011-06-17 20:31:25 +00:00
private readonly IDatabase _database;
2011-04-08 06:50:30 +00:00
public QualityProvider()
{
}
2011-06-17 20:31:25 +00:00
public QualityProvider(IDatabase database)
{
2011-06-17 20:31:25 +00:00
_database = database;
}
public virtual int Add(QualityProfile profile)
{
2011-06-17 20:31:25 +00:00
return Convert.ToInt32(_database.Insert(profile));
}
public virtual void Update(QualityProfile profile)
{
2011-06-17 20:31:25 +00:00
if (!_database.Exists<QualityProfile>("WHERE QualityProfileid = @0", profile.QualityProfileId))
{
Logger.Error("Unable to update non-existing profile");
throw new InvalidOperationException("Unable to update non-existing profile");
}
2011-06-17 20:31:25 +00:00
_database.Update(profile);
}
public virtual void Delete(int profileId)
{
2011-06-17 20:31:25 +00:00
_database.Delete<QualityProfile>(profileId);
}
2011-07-08 05:41:08 +00:00
public virtual List<QualityProfile> All()
{
2011-06-17 20:31:25 +00:00
var profiles = _database.Fetch<QualityProfile>().ToList();
return profiles;
}
public virtual QualityProfile Get(int profileId)
{
return _database.Single<QualityProfile>(profileId);
}
public virtual void SetupDefaultProfiles()
{
2011-07-08 05:41:08 +00:00
if (All().Count != 0)
return;
Logger.Info("Setting up default quality profiles");
var sd = new QualityProfile { Name = "SD", Allowed = new List<QualityTypes> { QualityTypes.SDTV, QualityTypes.DVD }, Cutoff = QualityTypes.SDTV };
var hd = new QualityProfile
{
Name = "HD",
Allowed = new List<QualityTypes> { QualityTypes.HDTV720p, QualityTypes.WEBDL720p, QualityTypes.Bluray720p },
Cutoff = QualityTypes.HDTV720p
};
Add(sd);
Add(hd);
}
}
2011-04-10 02:44:01 +00:00
}