Store QualityPofile properly

pull/23/head
Mark McDowall 12 years ago
parent e9b9e63f7a
commit b6ac7638a1

@ -58,7 +58,6 @@ namespace NzbDrone.Core.Datastore
return _dataMapper.Query<TModel>().Single(c => c.Id == id);
}
public TModel SingleOrDefault()
{
return All().Single();

@ -0,0 +1,43 @@
using System;
using Marr.Data.Converters;
using Marr.Data.Mapping;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Datastore.Converters
{
public class QualityIntConverter : IConverter
{
public object FromDB(ColumnMap map, object dbValue)
{
if (dbValue == DBNull.Value)
{
return Quality.Unknown;
}
var val = Convert.ToInt32(dbValue);
return (Quality)val;
}
public object ToDB(object clrValue)
{
if(clrValue == null) return 0;
if(clrValue as Quality == null)
{
throw new InvalidOperationException("Attempted to save a quality that isn't really a quality");
}
var quality = clrValue as Quality;
return (int)quality;
}
public Type DbType
{
get
{
return typeof(int);
}
}
}
}

@ -105,7 +105,7 @@ namespace NzbDrone.Core.Datastore.Migration
.WithColumn("Id").AsInt32().PrimaryKey().Identity()
.WithColumn("CleanTitle").AsString().NotNullable()
.WithColumn("SceneName").AsString().NotNullable()
.WithColumn("SeriesId").AsInt32().NotNullable()
.WithColumn("TvdbId").AsInt32().NotNullable()
.WithColumn("SeasonNumber").AsInt32().NotNullable();
Create.Table("Seasons")

@ -40,23 +40,21 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<History.History>().RegisterModel("History")
.HasOne<History.History, Episode>(h => h.Episode, h => h.EpisodeId);
.LazyLoad((db, history) => db.Query<Episode>().Where(ep => ep.Id == history.EpisodeId).ToList());
Mapper.Entity<Series>().RegisterModel("Series")
.Relationships.AutoMapComplexTypeProperties<ILazyLoaded>()
.For(c => c.Covers)
.LazyLoad((db, series) => db.Query<MediaCover.MediaCover>().Where(cover => cover.SeriesId == series.Id).ToList());
Mapper.Entity<Season>().RegisterModel("Seasons");
Mapper.Entity<Episode>().RegisterModel("Episodes");
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles");
Mapper.Entity<MediaCover.MediaCover>().RegisterModel("MediaCovers");
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles");
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles").For(q => q.DbAllowed).SetColumnName("Allowed").Ignore(q => q.Allowed);
Mapper.Entity<QualitySize>().RegisterModel("QualitySizes");
Mapper.Entity<Log>().RegisterModel("Logs");
}
@ -66,6 +64,7 @@ namespace NzbDrone.Core.Datastore
MapRepository.Instance.RegisterTypeConverter(typeof(Boolean), new BooleanIntConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(Enum), new EnumIntConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(QualityModel), new EmbeddedDocumentConverter());
MapRepository.Instance.RegisterTypeConverter(typeof(Quality), new QualityIntConverter());
}
}
}

@ -196,6 +196,7 @@
<Compile Include="Constants.cs" />
<Compile Include="ContainerExtensions.cs" />
<Compile Include="Datastore\Converters\BooleanIntConverter.cs" />
<Compile Include="Datastore\Converters\QualityIntConverter.cs" />
<Compile Include="Datastore\Converters\Int32Converter.cs" />
<Compile Include="Datastore\Converters\EmbeddedDocumentConverter.cs" />
<Compile Include="Datastore\Database.cs" />

@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Qualities
{
public class Quality : IComparable<Quality>
public class Quality : IComparable<Quality>, IEmbeddedDocument
{
public int Id { get; set; }
public string Name { get; set; }

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using NzbDrone.Core.Datastore;
@ -8,6 +10,32 @@ namespace NzbDrone.Core.Qualities
{
public string Name { get; set; }
public List<Quality> Allowed { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public string DbAllowed
{
get
{
string result = String.Empty;
if (Allowed == null) return result;
foreach (var q in Allowed)
{
result += q.Id + "|";
}
return result.Trim('|');
}
private set
{
var qualities = value.Split('|');
Allowed = new List<Quality>(qualities.Length);
foreach (var quality in qualities.Where(q => !String.IsNullOrWhiteSpace(q)))
{
Allowed.Add(Quality.FindById(Convert.ToInt32(quality)));
}
}
}
public Quality Cutoff { get; set; }
}
}

@ -6,8 +6,8 @@ namespace NzbDrone.Core.ReferenceData
public class SceneMapping : ModelBase
{
public string CleanTitle { get; set; }
public int TvdbId { get; set; }
public string SceneName { get; set; }
public int TvdbId { get; set; }
public int SeasonNumber { get; set; }
}
}

@ -2,7 +2,6 @@
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>True</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>

Loading…
Cancel
Save