1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00
Sonarr/NzbDrone.Core/Providers/QualityProvider.cs

94 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using Ninject;
using NLog;
using NzbDrone.Core.Repository.Quality;
2011-06-17 23:31:25 +03:00
using PetaPoco;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class QualityProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2011-06-17 23:31:25 +03:00
private readonly IDatabase _database;
2011-04-08 09:50:30 +03:00
public QualityProvider()
{
}
[Inject]
2011-06-17 23:31:25 +03:00
public QualityProvider(IDatabase database)
{
2011-06-17 23:31:25 +03:00
_database = database;
}
public virtual int Add(QualityProfile profile)
{
2011-06-17 23:31:25 +03:00
return Convert.ToInt32(_database.Insert(profile));
}
public virtual void Update(QualityProfile profile)
{
2011-06-17 23:31:25 +03: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 23:31:25 +03:00
_database.Update(profile);
}
public virtual void Delete(int profileId)
{
2011-06-17 23:31:25 +03:00
_database.Delete<QualityProfile>(profileId);
}
public virtual List<QualityProfile> GetAllProfiles()
{
2011-06-17 23:31:25 +03:00
var profiles = _database.Fetch<QualityProfile>().ToList();
return profiles;
}
public virtual QualityProfile Find(int profileId)
{
2011-06-17 23:31:25 +03:00
return _database.SingleOrDefault<QualityProfile>(profileId);
}
public virtual void SetupDefaultProfiles()
{
Logger.Info("Setting up default quality profiles");
var profiles = GetAllProfiles();
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.HDTV, QualityTypes.WEBDL, QualityTypes.Bluray720p },
Cutoff = QualityTypes.HDTV
};
//Add or Update SD
Logger.Debug(String.Format("Checking for default QualityProfile: {0}", sd.Name));
var sdDb = profiles.Where(p => p.Name == sd.Name).FirstOrDefault();
if (sdDb == null)
{
Logger.Debug(String.Format("Adding new default QualityProfile: {0}", sd.Name));
Add(sd);
}
//Add or Update HD
Logger.Debug(String.Format("Checking for default QualityProfile: {0}", hd.Name));
var hdDb = profiles.Where(p => p.Name == hd.Name).FirstOrDefault();
if (hdDb == null)
{
Logger.Debug(String.Format("Adding new default QualityProfile: {0}", hd.Name));
Add(hd);
}
}
}
2011-04-10 05:44:01 +03:00
}