sonarr-repo-only/NzbDrone.Core/Datastore/TableMapping.cs

99 lines
3.9 KiB
C#
Raw Normal View History

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