Added Quality Provider to interface with QualityProfiles.

Changed QualityProfile and AllowedQuality to be meet requirements
This commit is contained in:
markus101 2011-02-02 17:07:36 -08:00
parent 9eaec6a2e9
commit 3b63cfb5d2
5 changed files with 112 additions and 26 deletions

View File

@ -171,9 +171,11 @@
<Compile Include="Providers\IHistoryProvider.cs" /> <Compile Include="Providers\IHistoryProvider.cs" />
<Compile Include="Providers\IIndexerProvider.cs" /> <Compile Include="Providers\IIndexerProvider.cs" />
<Compile Include="Providers\IndexerProvider.cs" /> <Compile Include="Providers\IndexerProvider.cs" />
<Compile Include="Providers\IQualityProvider.cs" />
<Compile Include="Providers\IRssSyncProvider.cs" /> <Compile Include="Providers\IRssSyncProvider.cs" />
<Compile Include="Providers\IRssProvider.cs" /> <Compile Include="Providers\IRssProvider.cs" />
<Compile Include="Providers\ITimerProvider.cs" /> <Compile Include="Providers\ITimerProvider.cs" />
<Compile Include="Providers\QualityProvider.cs" />
<Compile Include="Providers\RssSyncProvider.cs" /> <Compile Include="Providers\RssSyncProvider.cs" />
<Compile Include="Providers\RssProvider.cs" /> <Compile Include="Providers\RssProvider.cs" />
<Compile Include="Providers\TimerProvider.cs" /> <Compile Include="Providers\TimerProvider.cs" />

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Providers
{
public interface IQualityProvider
{
void AddProfile(QualityProfile profile, List<AllowedQuality> allowedQualities);
void UpdateProfile(QualityProfile profile, List<AllowedQuality> allowedQualities);
void RemoveProfile(int profileId);
List<QualityProfile> GetProfiles();
}
}

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Repository.Quality;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class QualityProvider : IQualityProvider
{
private IRepository _sonicRepo;
public QualityProvider(IRepository sonicRepo)
{
_sonicRepo = sonicRepo;
}
#region IQualityProvider Members
public void AddProfile(QualityProfile profile, List<AllowedQuality> allowedQualities)
{
var profileId = _sonicRepo.Add(profile);
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = (int)profileId;
_sonicRepo.Add<AllowedQuality>(allowed);
}
}
public void UpdateProfile(QualityProfile profile, List<AllowedQuality> allowedQualities)
{
if (!_sonicRepo.Exists<QualityProfile>(q => q.ProfileId == profile.ProfileId))
{
//Log Error
throw new NotImplementedException();
}
_sonicRepo.Update<QualityProfile>(profile);
//Check to see if any items in the DB do not exist in this list
//Check to see if any of the allowedQualities already exist, if so update, else add
foreach (var inDb in _sonicRepo.All<AllowedQuality>().Where(q => q.ProfileId == profile.ProfileId))
{
if (!allowedQualities.Exists(l => l.ProfileId == inDb.ProfileId && l.Quality == inDb.Quality))
_sonicRepo.Delete<AllowedQuality>(inDb.Id);
}
foreach (var allowed in allowedQualities)
{
allowed.ProfileId = profile.ProfileId;
if (!_sonicRepo.Exists<AllowedQuality>(q => q.ProfileId == profile.ProfileId && q.Quality == allowed.Quality))
_sonicRepo.Add(allowed);
else
_sonicRepo.Update(allowed);
}
}
public void RemoveProfile(int profileId)
{
_sonicRepo.DeleteMany<AllowedQuality>(q => q.ProfileId == profileId);
_sonicRepo.Delete<QualityProfile>(profileId);
}
public List<QualityProfile> GetProfiles()
{
var profiles = _sonicRepo.All<QualityProfile>().ToList();
foreach (var profile in profiles)
{
profile.AllowedQualities = _sonicRepo.Find<AllowedQuality>(q => q.ProfileId == profile.ProfileId).ToList();
}
return profiles;
}
#endregion
}
}

View File

@ -1,4 +1,6 @@
namespace NzbDrone.Core.Repository.Quality using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository.Quality
{ {
public class AllowedQuality public class AllowedQuality
{ {
@ -7,5 +9,8 @@
public int Order { get; set; } public int Order { get; set; }
public bool MarkComplete { get; set; } public bool MarkComplete { get; set; }
public QualityTypes Quality { get; set; } public QualityTypes Quality { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual QualityProfile QualityProfile { get; private set; }
} }
} }

View File

@ -7,33 +7,15 @@ namespace NzbDrone.Core.Repository.Quality
{ {
public class QualityProfile public class QualityProfile
{ {
public int Id { get; set; } [SubSonicPrimaryKey(true)]
public QualityTypes Cutoff { get; set; } public int ProfileId { get; set; }
public string Name { get; set; }
public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles
[EditorBrowsable(EditorBrowsableState.Never)] [SubSonicToManyRelation]
public string SonicAllowed public virtual List<AllowedQuality> Allowed { get; private set; }
{
get
{
string result = String.Empty;
foreach (var q in Allowed)
{
result += (int)q + "|";
}
return result.Trim('|');
}
private set
{
var qualities = value.Split('|');
Allowed = new List<QualityTypes>(qualities.Length);
foreach (var quality in qualities)
{
Allowed.Add((QualityTypes)Convert.ToInt32(quality));
}
}
}
[SubSonicIgnore] [SubSonicIgnore]
public List<QualityTypes> Allowed { get; set; } public List<AllowedQuality> AllowedQualities { get; set; }
} }
} }