2013-03-25 09:13:53 +03:00
|
|
|
using System;
|
2013-04-01 02:40:19 +03:00
|
|
|
using System.Collections.Generic;
|
2013-04-01 03:20:01 +03:00
|
|
|
using System.Linq;
|
2013-03-25 09:13:53 +03:00
|
|
|
using Marr.Data;
|
|
|
|
using Marr.Data.Mapping;
|
|
|
|
using NzbDrone.Core.Configuration;
|
2013-04-01 05:43:58 +03:00
|
|
|
using NzbDrone.Core.DataAugmentation.Scene;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.Datastore.Converters;
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
using NzbDrone.Core.Jobs;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2013-05-20 02:17:32 +03:00
|
|
|
using NzbDrone.Core.Notifications;
|
2013-04-25 07:27:49 +03:00
|
|
|
using NzbDrone.Core.Organizer;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.Qualities;
|
|
|
|
using NzbDrone.Core.RootFolders;
|
2013-04-21 02:36:23 +03:00
|
|
|
using NzbDrone.Core.SeriesStats;
|
2013-03-25 09:13:53 +03:00
|
|
|
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 03:48:07 +03:00
|
|
|
Mapper.Entity<RootFolder>().RegisterModel("RootFolders").Ignore(r => r.FreeSpace);
|
2013-03-25 09:13:53 +03:00
|
|
|
|
2013-05-23 06:58:39 +03:00
|
|
|
Mapper.Entity<IndexerDefinition>().RegisterModel("Indexers");
|
2013-05-09 09:38:20 +03:00
|
|
|
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks");
|
2013-05-23 06:58:39 +03:00
|
|
|
Mapper.Entity<NotificationDefinition>().RegisterModel("Notifications");
|
2013-03-25 09:13:53 +03:00
|
|
|
|
|
|
|
Mapper.Entity<SceneMapping>().RegisterModel("SceneMappings");
|
|
|
|
|
2013-05-03 10:28:02 +03:00
|
|
|
Mapper.Entity<History.History>().RegisterModel("History")
|
2013-06-09 23:50:57 +03:00
|
|
|
.AutoMapChildModels();
|
2013-03-26 08:51:56 +03:00
|
|
|
|
2013-04-11 07:30:51 +03:00
|
|
|
Mapper.Entity<Series>().RegisterModel("Series")
|
2013-05-24 07:10:56 +03:00
|
|
|
.Ignore(s => s.RootFolderPath)
|
2013-04-29 04:47:06 +03:00
|
|
|
.Relationship()
|
|
|
|
.HasOne(s => s.QualityProfile, s => s.QualityProfileId);
|
2013-03-26 08:51:56 +03:00
|
|
|
|
2013-05-03 03:25:51 +03:00
|
|
|
Mapper.Entity<Episode>().RegisterModel("Episodes")
|
2013-05-10 18:19:29 +03:00
|
|
|
.Ignore(e => e.SeriesTitle)
|
2013-07-16 00:53:35 +03:00
|
|
|
.Ignore(e => e.Series)
|
2013-07-08 09:39:19 +03:00
|
|
|
.Ignore(e => e.HasFile)
|
2013-05-13 03:36:23 +03:00
|
|
|
.Relationship()
|
|
|
|
.HasOne(episode => episode.EpisodeFile, episode => episode.EpisodeFileId);
|
2013-05-03 03:25:51 +03:00
|
|
|
|
2013-05-13 03:36:23 +03:00
|
|
|
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles")
|
|
|
|
.Relationships.AutoMapICollectionOrComplexProperties();
|
2013-04-06 04:03:14 +03:00
|
|
|
|
2013-04-29 04:47:06 +03:00
|
|
|
Mapper.Entity<QualityProfile>().RegisterModel("QualityProfiles");
|
2013-04-06 04:03:14 +03:00
|
|
|
|
2013-03-25 09:13:53 +03:00
|
|
|
Mapper.Entity<QualitySize>().RegisterModel("QualitySizes");
|
|
|
|
|
|
|
|
Mapper.Entity<Log>().RegisterModel("Logs");
|
2013-04-20 23:09:12 +03:00
|
|
|
|
2013-04-25 07:27:49 +03:00
|
|
|
Mapper.Entity<NamingConfig>().RegisterModel("NamingConfig");
|
|
|
|
|
2013-04-21 00:23:17 +03:00
|
|
|
Mapper.Entity<SeriesStatistics>().MapResultSet();
|
2013-03-25 09:13:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void RegisterMappers()
|
|
|
|
{
|
2013-04-01 03:20:01 +03:00
|
|
|
RegisterEmbeddedConverter();
|
|
|
|
|
2013-03-25 09:13:53 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Int32), new Int32Converter());
|
2013-06-09 23:50:57 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(DateTime), new UtcConverter());
|
2013-03-25 09:13:53 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Boolean), new BooleanIntConverter());
|
2013-03-26 08:51:56 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Enum), new EnumIntConverter());
|
2013-03-26 11:02:31 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Quality), new QualityIntConverter());
|
2013-06-09 09:20:38 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Dictionary<string, string>), new EmbeddedDocumentConverter());
|
2013-03-25 09:13:53 +03:00
|
|
|
}
|
2013-04-01 03:20:01 +03:00
|
|
|
|
|
|
|
private static void RegisterEmbeddedConverter()
|
|
|
|
{
|
|
|
|
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.GetTypes()
|
|
|
|
.Where(c => c.GetInterfaces().Any(i => i == typeof(IEmbeddedDocument)));
|
|
|
|
|
|
|
|
|
2013-05-13 05:52:55 +03:00
|
|
|
var embeddedConvertor = new EmbeddedDocumentConverter();
|
2013-04-01 03:20:01 +03:00
|
|
|
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 09:13:53 +03:00
|
|
|
}
|
|
|
|
}
|