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