From 07791d46a571d3d6eed23e98ec0fe1c46ea0d37f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 23 Oct 2016 15:14:57 -0400 Subject: rework scheduled tasks in preparation of common project going portable --- .../BaseApplicationHost.cs | 39 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Common.Implementations/BaseApplicationHost.cs') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index e68fee829..b1e6a0453 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -26,11 +26,16 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Implementations.Cryptography; using MediaBrowser.Common.IO; +using MediaBrowser.Model.Cryptography; +using MediaBrowser.Model.Tasks; namespace MediaBrowser.Common.Implementations { @@ -67,7 +72,7 @@ namespace MediaBrowser.Common.Implementations /// Gets or sets the plugins. /// /// The plugins. - public IEnumerable Plugins { get; protected set; } + public IPlugin[] Plugins { get; protected set; } /// /// Gets or sets the log manager. @@ -174,6 +179,8 @@ namespace MediaBrowser.Common.Implementations /// true if this instance is running as service; otherwise, false. public abstract bool IsRunningAsService { get; } + protected ICryptographyProvider CryptographyProvider = new CryptographyProvider(); + private DeviceId _deviceId; public string SystemId { @@ -202,7 +209,10 @@ namespace MediaBrowser.Common.Implementations ILogManager logManager, IFileSystem fileSystem) { - XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer")); + // hack alert, until common can target .net core + BaseExtensions.CryptographyProvider = CryptographyProvider; + + XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer")); FailedAssemblies = new List(); ApplicationPaths = applicationPaths; @@ -430,7 +440,28 @@ namespace MediaBrowser.Common.Implementations RegisterModules(); ConfigurationManager.AddParts(GetExports()); - Plugins = GetExports(); + Plugins = GetExports().Select(LoadPlugin).Where(i => i != null).ToArray(); + } + + private IPlugin LoadPlugin(IPlugin plugin) + { + var assemblyPlugin = plugin as IPluginAssembly; + + if (assemblyPlugin != null) + { + var assembly = plugin.GetType().Assembly; + var assemblyName = assembly.GetName(); + + var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0]; + var assemblyId = new Guid(attribute.Value); + + var assemblyFileName = assemblyName.Name + ".dll"; + var assemblyFilePath = Path.Combine(ApplicationPaths.PluginsPath, assemblyFileName); + + assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId); + } + + return plugin; } /// @@ -747,7 +778,7 @@ namespace MediaBrowser.Common.Implementations { var list = Plugins.ToList(); list.Remove(plugin); - Plugins = list; + Plugins = list.ToArray(); } /// -- cgit v1.2.3