2017-09-04 02:20:56 +00:00
|
|
|
using System;
|
2013-03-31 23:40:19 +00:00
|
|
|
using System.Collections.Generic;
|
2013-03-25 06:13:53 +00:00
|
|
|
using Marr.Data;
|
|
|
|
using Marr.Data.Mapping;
|
2013-09-21 06:39:26 +00:00
|
|
|
using NzbDrone.Common.Reflection;
|
2013-10-23 06:36:31 +00:00
|
|
|
using NzbDrone.Core.Blacklisting;
|
2013-03-25 06:13:53 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
using NzbDrone.Core.Datastore.Converters;
|
2014-04-10 22:19:40 +00:00
|
|
|
using NzbDrone.Core.Datastore.Extensions;
|
2014-02-14 05:31:49 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Download.Pending;
|
2013-03-25 06:13:53 +00:00
|
|
|
using NzbDrone.Core.Indexers;
|
2018-02-06 23:08:36 +00:00
|
|
|
using NzbDrone.Core.ImportLists;
|
2013-03-25 06:13:53 +00:00
|
|
|
using NzbDrone.Core.Instrumentation;
|
|
|
|
using NzbDrone.Core.Jobs;
|
|
|
|
using NzbDrone.Core.MediaFiles;
|
2014-11-24 00:07:46 +00:00
|
|
|
using NzbDrone.Core.Profiles.Delay;
|
2014-09-11 20:24:00 +00:00
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2013-05-19 23:17:32 +00:00
|
|
|
using NzbDrone.Core.Notifications;
|
2013-04-25 04:27:49 +00:00
|
|
|
using NzbDrone.Core.Organizer;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2017-11-26 03:51:37 +00:00
|
|
|
using NzbDrone.Core.Profiles.Languages;
|
|
|
|
using NzbDrone.Core.Profiles.Metadata;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
2013-03-25 06:13:53 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2014-10-28 04:37:35 +00:00
|
|
|
using NzbDrone.Core.Restrictions;
|
2013-03-25 06:13:53 +00:00
|
|
|
using NzbDrone.Core.RootFolders;
|
2017-06-25 13:17:49 +00:00
|
|
|
using NzbDrone.Core.ArtistStats;
|
2014-09-10 00:02:55 +00:00
|
|
|
using NzbDrone.Core.Tags;
|
2013-09-21 06:39:26 +00:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2014-10-12 22:00:03 +00:00
|
|
|
using NzbDrone.Common.Disk;
|
2017-11-26 03:51:37 +00:00
|
|
|
using NzbDrone.Common.Serializer;
|
2015-01-26 02:03:21 +00:00
|
|
|
using NzbDrone.Core.Authentication;
|
2015-12-25 09:22:00 +00:00
|
|
|
using NzbDrone.Core.Extras.Metadata;
|
|
|
|
using NzbDrone.Core.Extras.Metadata.Files;
|
|
|
|
using NzbDrone.Core.Extras.Others;
|
2017-10-25 01:25:29 +00:00
|
|
|
using NzbDrone.Core.Extras.Lyrics;
|
2015-01-16 00:30:09 +00:00
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
2017-04-20 23:19:47 +00:00
|
|
|
using NzbDrone.Core.Music;
|
2017-09-04 02:20:56 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
2013-03-25 06:13:53 +00: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");
|
2018-02-10 04:25:28 +00:00
|
|
|
|
|
|
|
Mapper.Entity<RootFolder>().RegisterModel("RootFolders")
|
|
|
|
.Ignore(r => r.FreeSpace)
|
|
|
|
.Ignore(r => r.TotalSpace);
|
|
|
|
|
2015-04-25 16:02:17 +00:00
|
|
|
Mapper.Entity<ScheduledTask>().RegisterModel("ScheduledTasks");
|
2013-03-25 06:13:53 +00:00
|
|
|
|
2015-04-25 16:02:17 +00:00
|
|
|
Mapper.Entity<IndexerDefinition>().RegisterDefinition("Indexers")
|
2014-08-18 02:25:00 +00:00
|
|
|
.Ignore(i => i.Enable)
|
|
|
|
.Ignore(i => i.Protocol)
|
|
|
|
.Ignore(i => i.SupportsRss)
|
2017-09-04 02:20:56 +00:00
|
|
|
.Ignore(i => i.SupportsSearch)
|
|
|
|
.Ignore(d => d.Tags);
|
2014-08-18 02:25:00 +00:00
|
|
|
|
2018-02-06 23:08:36 +00:00
|
|
|
Mapper.Entity<ImportListDefinition>().RegisterDefinition("ImportLists")
|
|
|
|
.Ignore(i => i.Enable)
|
|
|
|
.Ignore(d => d.Tags);
|
|
|
|
|
2015-05-20 23:22:10 +00:00
|
|
|
Mapper.Entity<NotificationDefinition>().RegisterDefinition("Notifications")
|
|
|
|
.Ignore(i => i.SupportsOnGrab)
|
|
|
|
.Ignore(i => i.SupportsOnDownload)
|
2018-04-04 03:45:59 +00:00
|
|
|
.Ignore(i => i.SupportsOnAlbumDownload)
|
2015-05-20 23:22:10 +00:00
|
|
|
.Ignore(i => i.SupportsOnUpgrade)
|
|
|
|
.Ignore(i => i.SupportsOnRename);
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
Mapper.Entity<MetadataDefinition>().RegisterDefinition("Metadata")
|
|
|
|
.Ignore(d => d.Tags);
|
2014-08-18 02:25:00 +00:00
|
|
|
|
2015-04-25 16:02:17 +00:00
|
|
|
Mapper.Entity<DownloadClientDefinition>().RegisterDefinition("DownloadClients")
|
2017-09-04 02:20:56 +00:00
|
|
|
.Ignore(d => d.Protocol)
|
|
|
|
.Ignore(d => d.Tags);
|
2013-03-25 06:13:53 +00:00
|
|
|
|
2013-05-03 07:28:02 +00:00
|
|
|
Mapper.Entity<History.History>().RegisterModel("History")
|
2017-11-26 03:51:37 +00:00
|
|
|
.AutoMapChildModels();
|
2013-03-26 05:51:56 +00:00
|
|
|
|
2017-06-13 02:02:17 +00:00
|
|
|
Mapper.Entity<Artist>().RegisterModel("Artists")
|
2017-11-26 03:51:37 +00:00
|
|
|
.Ignore(s => s.RootFolderPath)
|
|
|
|
.Relationship()
|
|
|
|
.HasOne(a => a.Profile, a => a.ProfileId)
|
|
|
|
.HasOne(s => s.LanguageProfile, s => s.LanguageProfileId)
|
|
|
|
.HasOne(s => s.MetadataProfile, s => s.MetadataProfileId);
|
2017-04-20 23:19:47 +00:00
|
|
|
|
2017-06-18 02:27:01 +00:00
|
|
|
Mapper.Entity<Album>().RegisterModel("Albums");
|
2017-06-13 02:02:17 +00:00
|
|
|
|
2017-04-20 23:19:47 +00:00
|
|
|
Mapper.Entity<TrackFile>().RegisterModel("TrackFiles")
|
|
|
|
.Ignore(f => f.Path)
|
|
|
|
.Relationships.AutoMapICollectionOrComplexProperties()
|
|
|
|
.For("Tracks")
|
|
|
|
.LazyLoad(condition: parent => parent.Id > 0,
|
2017-09-26 03:44:53 +00:00
|
|
|
query: (db, parent) => db.Query<Track>().Where(c => c.TrackFileId == parent.Id).ToList()) // TODO: Figure what the hell to do here
|
2017-08-14 02:58:42 +00:00
|
|
|
.HasOne(file => file.Artist, file => file.ArtistId);
|
2017-04-20 23:19:47 +00:00
|
|
|
|
|
|
|
Mapper.Entity<Track>().RegisterModel("Tracks")
|
|
|
|
//.Ignore(e => e.SeriesTitle)
|
|
|
|
.Ignore(e => e.Album)
|
|
|
|
.Ignore(e => e.HasFile)
|
|
|
|
.Relationship()
|
2017-05-07 22:50:07 +00:00
|
|
|
// TODO: Need to implement ArtistId to Artist.Id here
|
2017-04-27 23:28:36 +00:00
|
|
|
.HasOne(track => track.TrackFile, track => track.TrackFileId); // TODO: Check lazy load for artists
|
2017-04-20 23:19:47 +00:00
|
|
|
|
2014-12-09 03:27:33 +00:00
|
|
|
Mapper.Entity<QualityDefinition>().RegisterModel("QualityDefinitions")
|
2017-11-16 02:24:33 +00:00
|
|
|
.Ignore(d => d.GroupName)
|
2017-11-21 00:20:21 +00:00
|
|
|
.Ignore(d => d.GroupWeight)
|
2014-12-09 03:27:33 +00:00
|
|
|
.Ignore(d => d.Weight);
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
Mapper.Entity<Profile>().RegisterModel("Profiles");
|
2017-09-04 02:20:56 +00:00
|
|
|
Mapper.Entity<LanguageProfile>().RegisterModel("LanguageProfiles");
|
2017-11-26 03:51:37 +00:00
|
|
|
Mapper.Entity<MetadataProfile>().RegisterModel("MetadataProfiles");
|
2013-03-25 06:13:53 +00:00
|
|
|
Mapper.Entity<Log>().RegisterModel("Logs");
|
2013-04-25 04:27:49 +00:00
|
|
|
Mapper.Entity<NamingConfig>().RegisterModel("NamingConfig");
|
2017-06-25 13:17:49 +00:00
|
|
|
Mapper.Entity<AlbumStatistics>().MapResultSet();
|
2013-10-23 06:36:31 +00:00
|
|
|
Mapper.Entity<Blacklist>().RegisterModel("Blacklist");
|
2014-01-24 16:17:56 +00:00
|
|
|
Mapper.Entity<MetadataFile>().RegisterModel("MetadataFiles");
|
2017-10-25 01:25:29 +00:00
|
|
|
Mapper.Entity<LyricFile>().RegisterModel("LyricFiles");
|
2015-12-25 09:22:00 +00:00
|
|
|
Mapper.Entity<OtherExtraFile>().RegisterModel("ExtraFiles");
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
Mapper.Entity<PendingRelease>().RegisterModel("PendingReleases")
|
2017-10-19 01:42:57 +00:00
|
|
|
.Ignore(e => e.RemoteAlbum);
|
2014-09-11 20:24:00 +00:00
|
|
|
|
|
|
|
Mapper.Entity<RemotePathMapping>().RegisterModel("RemotePathMappings");
|
2014-09-10 00:02:55 +00:00
|
|
|
Mapper.Entity<Tag>().RegisterModel("Tags");
|
2014-10-28 04:37:35 +00:00
|
|
|
Mapper.Entity<Restriction>().RegisterModel("Restrictions");
|
2014-11-24 00:07:46 +00:00
|
|
|
|
|
|
|
Mapper.Entity<DelayProfile>().RegisterModel("DelayProfiles");
|
2015-01-26 02:03:21 +00:00
|
|
|
Mapper.Entity<User>().RegisterModel("Users");
|
2015-01-16 00:30:09 +00:00
|
|
|
Mapper.Entity<CommandModel>().RegisterModel("Commands")
|
|
|
|
.Ignore(c => c.Message);
|
2015-06-27 09:43:17 +00:00
|
|
|
|
|
|
|
Mapper.Entity<IndexerStatus>().RegisterModel("IndexerStatus");
|
2017-10-27 03:21:06 +00:00
|
|
|
Mapper.Entity<DownloadClientStatus>().RegisterModel("DownloadClientStatus");
|
2018-02-06 23:08:36 +00:00
|
|
|
Mapper.Entity<ImportListStatus>().RegisterModel("ImportListStatus");
|
2013-03-25 06:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void RegisterMappers()
|
|
|
|
{
|
2013-04-01 00:20:01 +00:00
|
|
|
RegisterEmbeddedConverter();
|
2013-09-21 06:39:26 +00:00
|
|
|
RegisterProviderSettingConverter();
|
2013-04-01 00:20:01 +00:00
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(int), new Int32Converter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(double), new DoubleConverter());
|
2013-06-09 20:50:57 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(DateTime), new UtcConverter());
|
2015-10-03 17:45:26 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(bool), 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());
|
2014-06-08 08:22:55 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileQualityItem>), new EmbeddedDocumentConverter(new QualityIntConverter()));
|
2014-01-29 00:53:59 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(QualityModel), new EmbeddedDocumentConverter(new QualityIntConverter()));
|
2015-10-03 17:45:26 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Dictionary<string, string>), new EmbeddedDocumentConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<int>), new EmbeddedDocumentConverter());
|
2017-09-04 02:20:56 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Language), new LanguageIntConverter());
|
2015-10-03 17:45:26 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<string>), new EmbeddedDocumentConverter());
|
2017-09-04 02:20:56 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileLanguageItem>), new EmbeddedDocumentConverter(new LanguageIntConverter()));
|
2017-11-26 03:51:37 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfilePrimaryAlbumTypeItem>), new EmbeddedDocumentConverter(new PrimaryAlbumTypeIntConverter()));
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileSecondaryAlbumTypeItem>), new EmbeddedDocumentConverter(new SecondaryAlbumTypeIntConverter()));
|
2018-03-22 00:43:10 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(List<ProfileReleaseStatusItem>), new EmbeddedDocumentConverter(new ReleaseStatusIntConverter()));
|
2017-10-19 01:42:57 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedAlbumInfo), new EmbeddedDocumentConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedTrackInfo), new EmbeddedDocumentConverter());
|
2014-06-08 08:22:55 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(ReleaseInfo), new EmbeddedDocumentConverter());
|
2015-10-03 17:45:26 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(HashSet<int>), new EmbeddedDocumentConverter());
|
2014-10-12 22:00:03 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(OsPath), new OsPathConverter());
|
2015-01-26 02:03:21 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Guid), new GuidConverter());
|
2015-01-16 00:30:09 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(Command), new CommandConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(TimeSpan), new TimeSpanConverter());
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(typeof(TimeSpan?), new TimeSpanConverter());
|
2013-03-25 06:13:53 +00:00
|
|
|
}
|
2013-04-01 00:20:01 +00:00
|
|
|
|
2013-09-21 06:39:26 +00: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 00:20:01 +00:00
|
|
|
private static void RegisterEmbeddedConverter()
|
|
|
|
{
|
2013-09-21 06:39:26 +00:00
|
|
|
var embeddedTypes = typeof(IEmbeddedDocument).Assembly.ImplementationsOf<IEmbeddedDocument>();
|
2013-04-01 00:20:01 +00:00
|
|
|
|
2013-05-13 02:52:55 +00:00
|
|
|
var embeddedConvertor = new EmbeddedDocumentConverter();
|
2013-04-01 00:20:01 +00:00
|
|
|
var genericListDefinition = typeof(List<>).GetGenericTypeDefinition();
|
2014-09-10 00:02:55 +00:00
|
|
|
|
2013-04-01 00:20:01 +00:00
|
|
|
foreach (var embeddedType in embeddedTypes)
|
|
|
|
{
|
|
|
|
var embeddedListType = genericListDefinition.MakeGenericType(embeddedType);
|
2014-09-10 00:02:55 +00:00
|
|
|
|
2013-04-01 00:20:01 +00:00
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedType, embeddedConvertor);
|
|
|
|
MapRepository.Instance.RegisterTypeConverter(embeddedListType, embeddedConvertor);
|
|
|
|
}
|
|
|
|
}
|
2013-03-25 06:13:53 +00:00
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|