2013-03-25 06:13:53 +00:00
|
|
|
|
using System;
|
2013-03-31 23:40:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-04-01 00:20:01 +00:00
|
|
|
|
using System.Linq;
|
2013-03-25 06:13:53 +00:00
|
|
|
|
using Marr.Data;
|
|
|
|
|
using Marr.Data.Mapping;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-04-01 02:43:58 +00:00
|
|
|
|
using NzbDrone.Core.DataAugmentation;
|
|
|
|
|
using NzbDrone.Core.DataAugmentation.Scene;
|
2013-03-25 06:13:53 +00:00
|
|
|
|
using NzbDrone.Core.Datastore.Converters;
|
|
|
|
|
using NzbDrone.Core.ExternalNotification;
|
|
|
|
|
using NzbDrone.Core.Indexers;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
using NzbDrone.Core.Indexers.Newznab;
|
2013-03-25 06:13:53 +00:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
|
using NzbDrone.Core.Jobs;
|
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
|
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
|
using NzbDrone.Core.RootFolders;
|
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
|
{
|
|
|
|
|
public static class TableMapping
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private static readonly FluentMappings Mapper = new FluentMappings(true);
|
|
|
|
|
|
|
|
|
|
public static void Map()
|
|
|
|
|
{
|
|
|
|
|
RegisterMappers();
|
|
|
|
|
|
|
|
|
|
Mapper.Entity<Config>().RegisterModel("Config");
|
2013-03-27 00:48:07 +00:00
|
|
|
|
Mapper.Entity<RootFolder>().RegisterModel("RootFolders").Ignore(r => r.FreeSpace);
|
2013-03-25 06:13:53 +00:00
|
|
|
|
|
2013-04-07 07:30:37 +00:00
|
|
|
|
Mapper.Entity<IndexerDefinition>().RegisterModel("IndexerDefinitions");
|
2013-03-25 06:13:53 +00:00
|
|
|
|
Mapper.Entity<NewznabDefinition>().RegisterModel("NewznabDefinitions");
|
|
|
|
|
Mapper.Entity<JobDefinition>().RegisterModel("JobDefinitions");
|
|
|
|
|
Mapper.Entity<ExternalNotificationDefinition>().RegisterModel("ExternalNotificationDefinitions");
|
|
|
|
|
|
|
|
|
|
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");
|
|
|
|
|
|
2013-03-26 05:51:56 +00:00
|
|
|
|
Mapper.Entity<History.History>().RegisterModel("History")
|
2013-04-06 01:03:14 +00:00
|
|
|
|
.HasOne(h => h.Episode, h => h.EpisodeId);
|
2013-03-26 05:51:56 +00:00
|
|
|
|
|
2013-04-11 04:30:51 +00:00
|
|
|
|
Mapper.Entity<Series>().RegisterModel("Series")
|
|
|
|
|
.HasOne(s => s.RootFolder, s => s.RootFolderId);
|
2013-03-26 05:51:56 +00:00
|
|
|
|
|
2013-03-25 06:13:53 +00:00
|
|
|
|
Mapper.Entity<Season>().RegisterModel("Seasons");
|
|
|
|
|
Mapper.Entity<Episode>().RegisterModel("Episodes");
|
|
|
|
|
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles");
|
2013-04-06 01:03:14 +00:00
|
|
|
|
|
|
|
|
|
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles")
|
|
|
|
|
.For(q => q.DbAllowed).SetColumnName("Allowed")
|
|
|
|
|
.Ignore(q => q.Allowed);
|
|
|
|
|
|
2013-03-25 06:13:53 +00:00
|
|
|
|
Mapper.Entity<QualitySize>().RegisterModel("QualitySizes");
|
|
|
|
|
|
|
|
|
|
Mapper.Entity<Log>().RegisterModel("Logs");
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-26 07:50:18 +00:00
|
|
|
|
|
2013-03-25 06:13:53 +00:00
|
|
|
|
private static void RegisterMappers()
|
|
|
|
|
{
|
2013-04-01 00:20:01 +00:00
|
|
|
|
RegisterEmbeddedConverter();
|
|
|
|
|
|
2013-03-25 06:13:53 +00:00
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Int32), new Int32Converter());
|
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Boolean), new BooleanIntConverter());
|
2013-03-26 05:51:56 +00:00
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Enum), new EnumIntConverter());
|
2013-03-26 08:02:31 +00:00
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Quality), new QualityIntConverter());
|
2013-03-25 06:13:53 +00:00
|
|
|
|
}
|
2013-04-01 00:20:01 +00:00
|
|
|
|
|
|
|
|
|
private static void RegisterEmbeddedConverter()
|
|
|
|
|
{
|
|
|
|
|
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.GetTypes()
|
|
|
|
|
.Where(c => c.GetInterfaces().Any(i => i == typeof(IEmbeddedDocument)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var embeddedConvertor = new EmbeddedDocumentConverter();
|
|
|
|
|
var genericListDefinition = typeof(List<>).GetGenericTypeDefinition();
|
|
|
|
|
foreach (var embeddedType in embeddedTypes)
|
|
|
|
|
{
|
|
|
|
|
var embeddedListType = genericListDefinition.MakeGenericType(embeddedType);
|
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedType, embeddedConvertor);
|
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedListType, embeddedConvertor);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-25 06:13:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|