From bdab0a1588fa4347d168c69f803a13cf607b4166 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 19 Nov 2016 11:51:49 -0500 Subject: move TypeMapper to portable project --- .../Reflection/AssemblyInfo.cs | 5 ++ Emby.Common.Implementations/project.json | 2 + Emby.Server.Core/ApplicationHost.cs | 2 +- Emby.Server.Core/Data/SqliteItemRepository.cs | 7 ++- Emby.Server.Core/Data/TypeMapper.cs | 47 ------------------- Emby.Server.Implementations/Data/TypeMapper.cs | 54 ++++++++++++++++++++++ .../Emby.Server.Implementations.csproj | 1 + MediaBrowser.Model/Reflection/IAssemblyInfo.cs | 3 ++ 8 files changed, 71 insertions(+), 50 deletions(-) delete mode 100644 Emby.Server.Core/Data/TypeMapper.cs create mode 100644 Emby.Server.Implementations/Data/TypeMapper.cs diff --git a/Emby.Common.Implementations/Reflection/AssemblyInfo.cs b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs index bd2cb7cf0b..7a92f02d6b 100644 --- a/Emby.Common.Implementations/Reflection/AssemblyInfo.cs +++ b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs @@ -22,5 +22,10 @@ namespace Emby.Common.Implementations.Reflection #endif return type.GetTypeInfo().Assembly.GetManifestResourceNames(); } + + public Assembly[] GetCurrentAssemblies() + { + return AppDomain.CurrentDomain.GetAssemblies(); + } } } diff --git a/Emby.Common.Implementations/project.json b/Emby.Common.Implementations/project.json index b0a35bdf38..409687ea16 100644 --- a/Emby.Common.Implementations/project.json +++ b/Emby.Common.Implementations/project.json @@ -14,6 +14,7 @@ "System.Net.Http": "4.0.0.0", "System.Net.Primitives": "4.0.0.0", "System.Net.Http.WebRequest": "4.0.0.0", + "System.Reflection": "4.0.0.0", "System.Runtime": "4.0.0.0", "System.Runtime.Extensions": "4.0.0.0", "System.Text.Encoding": "4.0.0.0", @@ -57,6 +58,7 @@ "ServiceStack.Text.Core": "1.0.27", "NLog": "4.4.0-betaV15", "sharpcompress": "0.14.0", + "System.AppDomain": "2.0.11", "MediaBrowser.Model": { "target": "project" }, diff --git a/Emby.Server.Core/ApplicationHost.cs b/Emby.Server.Core/ApplicationHost.cs index 00b9b99e62..6b3ca940b6 100644 --- a/Emby.Server.Core/ApplicationHost.cs +++ b/Emby.Server.Core/ApplicationHost.cs @@ -550,7 +550,7 @@ namespace Emby.Server.Core DisplayPreferencesRepository = displayPreferencesRepo; RegisterSingleInstance(DisplayPreferencesRepository); - var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory); + var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, GetDbConnector(), MemoryStreamFactory, assemblyInfo); ItemRepository = itemRepo; RegisterSingleInstance(ItemRepository); diff --git a/Emby.Server.Core/Data/SqliteItemRepository.cs b/Emby.Server.Core/Data/SqliteItemRepository.cs index 2f08081f64..5b8f180881 100644 --- a/Emby.Server.Core/Data/SqliteItemRepository.cs +++ b/Emby.Server.Core/Data/SqliteItemRepository.cs @@ -28,6 +28,8 @@ using MediaBrowser.Model.Querying; using MediaBrowser.Model.Serialization; using MediaBrowser.Server.Implementations.Devices; using MediaBrowser.Server.Implementations.Playlists; +using Emby.Server.Implementations.Data; +using MediaBrowser.Model.Reflection; namespace Emby.Server.Core.Data { @@ -38,7 +40,7 @@ namespace Emby.Server.Core.Data { private IDbConnection _connection; - private readonly TypeMapper _typeMapper = new TypeMapper(); + private readonly TypeMapper _typeMapper; /// /// Gets the name of the repository @@ -95,7 +97,7 @@ namespace Emby.Server.Core.Data /// /// Initializes a new instance of the class. /// - public SqliteItemRepository(IServerConfigurationManager config, IJsonSerializer jsonSerializer, ILogManager logManager, IDbConnector connector, IMemoryStreamFactory memoryStreamProvider) + public SqliteItemRepository(IServerConfigurationManager config, IJsonSerializer jsonSerializer, ILogManager logManager, IDbConnector connector, IMemoryStreamFactory memoryStreamProvider, IAssemblyInfo assemblyInfo) : base(logManager, connector) { if (config == null) @@ -110,6 +112,7 @@ namespace Emby.Server.Core.Data _config = config; _jsonSerializer = jsonSerializer; _memoryStreamProvider = memoryStreamProvider; + _typeMapper = new TypeMapper(assemblyInfo); _criticReviewsPath = Path.Combine(_config.ApplicationPaths.DataPath, "critic-reviews"); DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db"); diff --git a/Emby.Server.Core/Data/TypeMapper.cs b/Emby.Server.Core/Data/TypeMapper.cs deleted file mode 100644 index f8eb5dd2d8..0000000000 --- a/Emby.Server.Core/Data/TypeMapper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Linq; - -namespace Emby.Server.Core.Data -{ - /// - /// Class TypeMapper - /// - public class TypeMapper - { - /// - /// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types - /// - private readonly ConcurrentDictionary _typeMap = new ConcurrentDictionary(); - - /// - /// Gets the type. - /// - /// Name of the type. - /// Type. - /// - public Type GetType(string typeName) - { - if (string.IsNullOrEmpty(typeName)) - { - throw new ArgumentNullException(); - } - - return _typeMap.GetOrAdd(typeName, LookupType); - } - - /// - /// Lookups the type. - /// - /// Name of the type. - /// Type. - private Type LookupType(string typeName) - { - return AppDomain - .CurrentDomain - .GetAssemblies() - .Select(a => a.GetType(typeName, false)) - .FirstOrDefault(t => t != null); - } - } -} diff --git a/Emby.Server.Implementations/Data/TypeMapper.cs b/Emby.Server.Implementations/Data/TypeMapper.cs new file mode 100644 index 0000000000..f4b37749e7 --- /dev/null +++ b/Emby.Server.Implementations/Data/TypeMapper.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Concurrent; +using MediaBrowser.Model.Reflection; +using System.Linq; + +namespace Emby.Server.Implementations.Data +{ + /// + /// Class TypeMapper + /// + public class TypeMapper + { + private readonly IAssemblyInfo _assemblyInfo; + + /// + /// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types + /// + private readonly ConcurrentDictionary _typeMap = new ConcurrentDictionary(); + + public TypeMapper(IAssemblyInfo assemblyInfo) + { + _assemblyInfo = assemblyInfo; + } + + /// + /// Gets the type. + /// + /// Name of the type. + /// Type. + /// + public Type GetType(string typeName) + { + if (string.IsNullOrEmpty(typeName)) + { + throw new ArgumentNullException("typeName"); + } + + return _typeMap.GetOrAdd(typeName, LookupType); + } + + /// + /// Lookups the type. + /// + /// Name of the type. + /// Type. + private Type LookupType(string typeName) + { + return _assemblyInfo + .GetCurrentAssemblies() + .Select(a => a.GetType(typeName)) + .FirstOrDefault(t => t != null); + } + } +} diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 48b5987328..daf221af04 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -54,6 +54,7 @@ + diff --git a/MediaBrowser.Model/Reflection/IAssemblyInfo.cs b/MediaBrowser.Model/Reflection/IAssemblyInfo.cs index 634fadc1b4..e8e9c414cf 100644 --- a/MediaBrowser.Model/Reflection/IAssemblyInfo.cs +++ b/MediaBrowser.Model/Reflection/IAssemblyInfo.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Reflection; namespace MediaBrowser.Model.Reflection { @@ -7,5 +8,7 @@ namespace MediaBrowser.Model.Reflection { Stream GetManifestResourceStream(Type type, string resource); string[] GetManifestResourceNames(Type type); + + Assembly[] GetCurrentAssemblies(); } } -- cgit v1.2.3