2013-03-25 09:13:53 +03:00
|
|
|
using System;
|
2013-04-01 02:40:19 +03:00
|
|
|
using System.Collections.Generic;
|
2013-03-25 09:13:53 +03:00
|
|
|
using Marr.Data;
|
|
|
|
using Marr.Data.Mapping;
|
2013-09-21 09:39:26 +03:00
|
|
|
using NzbDrone.Common.Reflection;
|
2013-10-23 09:36:31 +03:00
|
|
|
using NzbDrone.Core.Blacklisting;
|
2013-03-25 09:13:53 +03:00
|
|
|
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;
|
2014-04-11 01:19:40 +03:00
|
|
|
using NzbDrone.Core.Datastore.Extensions;
|
2014-02-14 08:31:49 +03:00
|
|
|
using NzbDrone.Core.Download;
|
2014-06-08 11:22:55 +03:00
|
|
|
using NzbDrone.Core.Download.Pending;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
using NzbDrone.Core.Jobs;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2014-01-22 08:22:09 +03:00
|
|
|
using NzbDrone.Core.Metadata;
|
2014-01-24 19:17:56 +03:00
|
|
|
using NzbDrone.Core.Metadata.Files;
|
2014-11-24 02:07:46 +02:00
|
|
|
using NzbDrone.Core.Profiles.Delay;
|
2014-09-11 23:24:00 +03:00
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2013-05-20 02:17:32 +03:00
|
|
|
using NzbDrone.Core.Notifications;
|
2013-04-25 07:27:49 +03:00
|
|
|
using NzbDrone.Core.Organizer;
|
2014-06-08 11:22:55 +03:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.Profiles;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.Qualities;
|
2014-10-28 06:37:35 +02:00
|
|
|
using NzbDrone.Core.Restrictions;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.RootFolders;
|
2013-04-21 02:36:23 +03:00
|
|
|
using NzbDrone.Core.SeriesStats;
|
2014-09-10 03:02:55 +03:00
|
|
|
using NzbDrone.Core.Tags;
|
2013-09-21 09:39:26 +03:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2013-03-25 09:13:53 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
2014-10-13 01:00:03 +03:00
|
|
|
using NzbDrone.Common.Disk;
|
2015-01-26 04:03:21 +02:00
|
|
|
using NzbDrone.Core.Authentication;
|
2013-03-25 09:13:53 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-04-19 18:09:22 +03:00
|
|
|
Mapper.Entity<IndexerDefinition>().RegisterModel("Indexers")
|
2014-08-18 05:25:00 +03:00
|
|
|
.Ignore(i => i.Enable)
|
|
|
|
.Ignore(i => i.Protocol)
|
|
|
|
.Ignore(i => i.SupportsRss)
|
|
|
|
.Ignore(i => i.SupportsSearch);
|
|
|
|
|
2013-05-09 09:38:20 +03:00
|
|
|
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks");
|
2014-01-22 08:22:09 +03:00
|
|
|
Mapper.Entity<NotificationDefinition>().RegisterModel("Notifications");
|
2014-01-24 19:17:56 +03:00
|
|
|
Mapper.Entity<MetadataDefinition>().RegisterModel("Metadata");
|
2014-08-18 05:25:00 +03:00
|
|
|
|
|
|
|
Mapper.Entity<DownloadClientDefinition>().RegisterModel("DownloadClients")
|
|
|
|
.Ignore(d => d.Protocol);
|
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-10-12 21:44:40 +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()
|
2014-06-08 11:22:55 +03:00
|
|
|
.HasOne(s => s.Profile, s => s.ProfileId);
|
2013-03-26 08:51:56 +03:00
|
|
|
|
2014-07-24 02:43:54 +03:00
|
|
|
Mapper.Entity<EpisodeFile>().RegisterModel("EpisodeFiles")
|
|
|
|
.Ignore(f => f.Path)
|
2014-08-21 09:29:34 +03:00
|
|
|
.Relationships.AutoMapICollectionOrComplexProperties()
|
|
|
|
.For("Episodes")
|
|
|
|
.LazyLoad(condition: parent => parent.Id > 0,
|
|
|
|
query: (db, parent) => db.Query<Episode>().Where(c => c.EpisodeFileId == parent.Id).ToList())
|
|
|
|
.HasOne(file => file.Series, file => file.SeriesId);
|
2014-07-24 02:43:54 +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);
|
2014-12-09 05:27:33 +02:00
|
|
|
|
|
|
|
Mapper.Entity<QualityDefinition>().RegisterModel("QualityDefinitions")
|
|
|
|
.Ignore(d => d.Weight);
|
|
|
|
|
|
|
|
|
2014-06-08 11:22:55 +03:00
|
|
|
Mapper.Entity<Profile>().RegisterModel("Profiles");
|
2013-03-25 09:13:53 +03:00
|
|
|
Mapper.Entity<Log>().RegisterModel("Logs");
|
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-10-23 09:36:31 +03:00
|
|
|
Mapper.Entity<Blacklist>().RegisterModel("Blacklist");
|
2014-01-24 19:17:56 +03:00
|
|
|
Mapper.Entity<MetadataFile>().RegisterModel("MetadataFiles");
|
2014-06-08 11:22:55 +03:00
|
|
|
|
|
|
|
Mapper.Entity<PendingRelease>().RegisterModel("PendingReleases")
|
|
|
|
.Ignore(e => e.RemoteEpisode);
|
2014-09-11 23:24:00 +03:00
|
|
|
|
|
|
|
Mapper.Entity<RemotePathMapping>().RegisterModel("RemotePathMappings");
|
2014-09-10 03:02:55 +03:00
|
|
|
Mapper.Entity<Tag>().RegisterModel("Tags");
|
2014-10-28 06:37:35 +02:00
|
|
|
Mapper.Entity<Restriction>().RegisterModel("Restrictions");
|
2014-11-24 02:07:46 +02:00
|
|
|
|
|
|
|
Mapper.Entity<DelayProfile>().RegisterModel("DelayProfiles");
|
2015-01-26 04:03:21 +02:00
|
|
|
Mapper.Entity<User>().RegisterModel("Users");
|
2013-03-25 09:13:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void RegisterMappers()
|
|
|
|
{
|
2013-04-01 03:20:01 +03:00
|
|
|
RegisterEmbeddedConverter();
|
2013-09-21 09:39:26 +03:00
|
|
|
RegisterProviderSettingConverter();
|
2013-04-01 03:20:01 +03:00
|
|
|
|
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());
|
2014-06-08 11:22:55 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileQualityItem>), new EmbeddedDocumentConverter(new QualityIntConverter()));
|
2014-01-29 03:53:59 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(QualityModel), new EmbeddedDocumentConverter(new QualityIntConverter()));
|
2014-09-10 03:02:55 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Dictionary<String, String>), new EmbeddedDocumentConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<Int32>), new EmbeddedDocumentConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<String>), new EmbeddedDocumentConverter());
|
2014-06-08 11:22:55 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedEpisodeInfo), new EmbeddedDocumentConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(ReleaseInfo), new EmbeddedDocumentConverter());
|
2014-09-10 03:02:55 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(HashSet<Int32>), new EmbeddedDocumentConverter());
|
2014-10-13 01:00:03 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(OsPath), new OsPathConverter());
|
2015-01-26 04:03:21 +02:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Guid), new GuidConverter());
|
2013-03-25 09:13:53 +03:00
|
|
|
}
|
2013-04-01 03:20:01 +03:00
|
|
|
|
2013-09-21 09:39:26 +03:00
|
|
|
private static void RegisterProviderSettingConverter()
|
|
|
|
{
|
|
|
|
var settingTypes = typeof(IProviderConfig).Assembly.ImplementationsOf<IProviderConfig>();
|
|
|
|
|
|
|
|
var providerSettingConverter = new ProviderSettingConverter();
|
|
|
|
foreach (var embeddedType in settingTypes)
|
|
|
|
{
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedType, providerSettingConverter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-01 03:20:01 +03:00
|
|
|
private static void RegisterEmbeddedConverter()
|
|
|
|
{
|
2013-09-21 09:39:26 +03:00
|
|
|
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.ImplementationsOf<IEmbeddedDocument>();
|
2013-04-01 03:20:01 +03:00
|
|
|
|
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();
|
2014-09-10 03:02:55 +03:00
|
|
|
|
2013-04-01 03:20:01 +03:00
|
|
|
foreach (var embeddedType in embeddedTypes)
|
|
|
|
{
|
|
|
|
var embeddedListType = genericListDefinition.MakeGenericType(embeddedType);
|
2014-09-10 03:02:55 +03:00
|
|
|
|
2013-04-01 03:20:01 +03:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedType, embeddedConvertor);
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedListType, embeddedConvertor);
|
|
|
|
}
|
|
|
|
}
|
2013-03-25 09:13:53 +03:00
|
|
|
}
|
|
|
|
}
|