2011-02-02 17:07:36 -08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2011-06-13 18:23:04 -07:00
|
|
|
using Ninject;
|
2011-02-03 18:58:02 -08:00
|
|
|
using NLog;
|
2011-02-02 17:07:36 -08:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2011-06-17 13:31:25 -07:00
|
|
|
using PetaPoco;
|
2011-02-02 17:07:36 -08:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
{
|
2011-04-07 21:03:46 -07:00
|
|
|
public class QualityProvider
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-02-03 18:58:02 -08:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-06-17 13:31:25 -07:00
|
|
|
private readonly IDatabase _database;
|
2011-02-02 17:07:36 -08:00
|
|
|
|
2011-04-07 23:50:30 -07:00
|
|
|
public QualityProvider()
|
|
|
|
{
|
|
|
|
}
|
2011-04-07 21:03:46 -07:00
|
|
|
|
2011-06-13 18:23:04 -07:00
|
|
|
[Inject]
|
2011-06-17 13:31:25 -07:00
|
|
|
public QualityProvider(IDatabase database)
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-06-17 13:31:25 -07:00
|
|
|
_database = database;
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:30:19 -07:00
|
|
|
public virtual int Add(QualityProfile profile)
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-06-17 13:31:25 -07:00
|
|
|
return Convert.ToInt32(_database.Insert(profile));
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
|
|
|
|
2011-04-07 21:03:46 -07:00
|
|
|
public virtual void Update(QualityProfile profile)
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-06-17 13:31:25 -07:00
|
|
|
if (!_database.Exists<QualityProfile>("WHERE QualityProfileid = @0", profile.QualityProfileId))
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-02-03 18:58:02 -08:00
|
|
|
Logger.Error("Unable to update non-existing profile");
|
|
|
|
throw new InvalidOperationException("Unable to update non-existing profile");
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
|
|
|
|
2011-06-17 13:31:25 -07:00
|
|
|
_database.Update(profile);
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
|
|
|
|
2011-04-07 21:03:46 -07:00
|
|
|
public virtual void Delete(int profileId)
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-06-17 13:31:25 -07:00
|
|
|
_database.Delete<QualityProfile>(profileId);
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
|
|
|
|
2011-07-07 22:41:08 -07:00
|
|
|
public virtual List<QualityProfile> All()
|
2011-02-02 17:07:36 -08:00
|
|
|
{
|
2011-06-17 13:31:25 -07:00
|
|
|
var profiles = _database.Fetch<QualityProfile>().ToList();
|
2011-02-02 17:07:36 -08:00
|
|
|
|
|
|
|
return profiles;
|
|
|
|
}
|
|
|
|
|
2011-06-17 21:39:02 -07:00
|
|
|
public virtual QualityProfile Get(int profileId)
|
2011-02-04 22:07:25 -08:00
|
|
|
{
|
2011-06-18 16:03:58 -07:00
|
|
|
return _database.Single<QualityProfile>(profileId);
|
2011-02-04 22:07:25 -08:00
|
|
|
}
|
2011-06-12 20:45:22 -07:00
|
|
|
|
|
|
|
public virtual void SetupDefaultProfiles()
|
|
|
|
{
|
2011-07-07 22:41:08 -07:00
|
|
|
if (All().Count != 0)
|
2011-07-07 20:57:31 -07:00
|
|
|
return;
|
2011-06-12 20:45:22 -07:00
|
|
|
|
2011-07-07 20:57:31 -07:00
|
|
|
Logger.Info("Setting up default quality profiles");
|
2011-06-12 20:45:22 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2011-07-07 20:57:31 -07:00
|
|
|
Add(sd);
|
|
|
|
Add(hd);
|
2011-06-12 20:45:22 -07:00
|
|
|
|
|
|
|
}
|
2011-02-02 17:07:36 -08:00
|
|
|
}
|
2011-04-09 19:44:01 -07:00
|
|
|
}
|