diff options
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
8 files changed, 145 insertions, 73 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index b6e7bb5e9e..ad9b3960fd 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -6,8 +6,7 @@ using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Implementations; -using MediaBrowser.Common.Implementations.ScheduledTasks; +using Emby.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.Net; using MediaBrowser.Common.Progress; using MediaBrowser.Controller; @@ -38,12 +37,6 @@ using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Subtitles; using MediaBrowser.Controller.Sync; using MediaBrowser.Controller.TV; -using MediaBrowser.Dlna; -using MediaBrowser.Dlna.ConnectionManager; -using MediaBrowser.Dlna.ContentDirectory; -using MediaBrowser.Dlna.Main; -using MediaBrowser.Dlna.MediaReceiverRegistrar; -using MediaBrowser.Dlna.Ssdp; using MediaBrowser.LocalMetadata.Savers; using MediaBrowser.MediaEncoding.BdInfo; using MediaBrowser.MediaEncoding.Encoder; @@ -96,19 +89,27 @@ using System.Net.Sockets; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Emby.Common.Implementations; +using Emby.Common.Implementations.Networking; +using Emby.Common.Implementations.Updates; using Emby.Photos; using MediaBrowser.Model.IO; using MediaBrowser.Api.Playback; -using MediaBrowser.Common.Implementations.Networking; -using MediaBrowser.Common.Implementations.Serialization; -using MediaBrowser.Common.Implementations.Updates; -using MediaBrowser.Common.IO; +using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.Security; +using MediaBrowser.Common.Updates; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; -using MediaBrowser.Controller.Extensions; using MediaBrowser.Controller.IO; +using Emby.Dlna; +using Emby.Dlna.ConnectionManager; +using Emby.Dlna.ContentDirectory; +using Emby.Dlna.Main; +using Emby.Dlna.MediaReceiverRegistrar; +using Emby.Dlna.Ssdp; using MediaBrowser.Model.Activity; +using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Globalization; using MediaBrowser.Model.Net; using MediaBrowser.Model.News; @@ -116,18 +117,24 @@ using MediaBrowser.Model.Reflection; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Services; using MediaBrowser.Model.Social; +using MediaBrowser.Model.TextEncoding; using MediaBrowser.Model.Xml; using MediaBrowser.Server.Implementations.Archiving; using MediaBrowser.Server.Implementations.Reflection; +using MediaBrowser.Server.Implementations.Serialization; +using MediaBrowser.Server.Implementations.TextEncoding; +using MediaBrowser.Server.Implementations.Updates; using MediaBrowser.Server.Implementations.Xml; using OpenSubtitlesHandler; +using ServiceStack; +using StringExtensions = MediaBrowser.Controller.Extensions.StringExtensions; namespace MediaBrowser.Server.Startup.Common { /// <summary> /// Class CompositionRoot /// </summary> - public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost + public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost, IDependencyContainer { /// <summary> /// Gets the server configuration manager. @@ -224,6 +231,17 @@ namespace MediaBrowser.Server.Startup.Common private IPlaylistManager PlaylistManager { get; set; } /// <summary> + /// Gets or sets the installation manager. + /// </summary> + /// <value>The installation manager.</value> + protected IInstallationManager InstallationManager { get; private set; } + /// <summary> + /// Gets the security manager. + /// </summary> + /// <value>The security manager.</value> + protected ISecurityManager SecurityManager { get; private set; } + + /// <summary> /// Gets or sets the zip client. /// </summary> /// <value>The zip client.</value> @@ -397,9 +415,24 @@ namespace MediaBrowser.Server.Startup.Common return new MemoryStreamProvider(); } + protected override ISystemEvents CreateSystemEvents() + { + return new SystemEvents(LogManager.GetLogger("SystemEvents")); + } + protected override IJsonSerializer CreateJsonSerializer() { - var result = base.CreateJsonSerializer(); + try + { + // https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.IntegrationTests/Web.config#L4 + Licensing.RegisterLicense("1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0="); + } + catch + { + // Failing under mono + } + + var result = new JsonSerializer(FileSystemManager, LogManager.GetLogger("JsonSerializer")); ServiceStack.Text.JsConfig<Movie>.ExcludePropertyNames = new[] { "ShortOverview" }; ServiceStack.Text.JsConfig<Movie>.ExcludePropertyNames = new[] { "Taglines" }; @@ -618,7 +651,6 @@ namespace MediaBrowser.Server.Startup.Common { var migrations = new List<IVersionMigration> { - new MovieDbEpisodeProviderMigration(ServerConfigurationManager), new DbMigration(ServerConfigurationManager, TaskManager) }; @@ -642,6 +674,12 @@ namespace MediaBrowser.Server.Startup.Common { await base.RegisterResources(progress).ConfigureAwait(false); + SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager); + RegisterSingleInstance(SecurityManager); + + InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager); + RegisterSingleInstance(InstallationManager); + ZipClient = new ZipClient(FileSystemManager); RegisterSingleInstance(ZipClient); @@ -656,7 +694,10 @@ namespace MediaBrowser.Server.Startup.Common StringExtensions.LocalizationManager = LocalizationManager; RegisterSingleInstance(LocalizationManager); - RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer()); + IEncoding textEncoding = new TextEncoding(); + RegisterSingleInstance(textEncoding); + Utilities.EncodingHelper = textEncoding; + RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer(FileSystemManager, textEncoding)); RegisterSingleInstance<IXmlReaderSettingsFactory>(new XmlReaderSettingsFactory()); RegisterSingleInstance<IAssemblyInfo>(new AssemblyInfo()); @@ -1010,6 +1051,8 @@ namespace MediaBrowser.Server.Startup.Common ConfigurationManager.SaveConfiguration(); } + RegisterModules(); + base.FindParts(); HttpServer.Init(GetExports<IService>(false)); @@ -1686,5 +1729,40 @@ namespace MediaBrowser.Server.Startup.Common { NativeApp.EnableLoopback(appName); } + + private void RegisterModules() + { + var moduleTypes = GetExportTypes<IDependencyModule>(); + + foreach (var type in moduleTypes) + { + try + { + var instance = Activator.CreateInstance(type) as IDependencyModule; + if (instance != null) + instance.BindDependencies(this); + } + catch (Exception ex) + { + Logger.ErrorException("Error setting up dependency bindings for " + type.Name, ex); + } + } + } + + void IDependencyContainer.RegisterSingleInstance<T>(T obj, bool manageLifetime) + { + RegisterSingleInstance(obj, manageLifetime); + } + + void IDependencyContainer.RegisterSingleInstance<T>(Func<T> func) + { + RegisterSingleInstance(func); + } + + void IDependencyContainer.Register(Type typeInterface, Type typeImplementation) + { + Container.Register(typeInterface, typeImplementation); + } + } } diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 042366e887..4c627ceffa 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -32,6 +32,12 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="Emby.Common.Implementations"> + <HintPath>..\ThirdParty\emby\Emby.Common.Implementations.dll</HintPath> + </Reference> + <Reference Include="Emby.Dlna"> + <HintPath>..\ThirdParty\emby\Emby.Dlna.dll</HintPath> + </Reference> <Reference Include="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath> @@ -40,6 +46,9 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Patterns.Logging.1.0.0.2\lib\portable-net45+sl4+wp71+win8+wpa81\Patterns.Logging.dll</HintPath> </Reference> + <Reference Include="RSSDP"> + <HintPath>..\ThirdParty\emby\RSSDP.dll</HintPath> + </Reference> <Reference Include="ServiceStack.Interfaces, Version=4.0.0.0, Culture=neutral, PublicKeyToken=e06fbc6124f57c43, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\ThirdParty\ServiceStack\ServiceStack.Interfaces.dll</HintPath> @@ -48,6 +57,10 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\ThirdParty\ServiceStack.Text\ServiceStack.Text.dll</HintPath> </Reference> + <Reference Include="SimpleInjector, Version=3.2.4.0, Culture=neutral, PublicKeyToken=984cb50dea722e99, processorArchitecture=MSIL"> + <HintPath>..\packages\SimpleInjector.3.2.4\lib\net45\SimpleInjector.dll</HintPath> + <Private>True</Private> + </Reference> <Reference Include="System" /> <Reference Include="System.Configuration" /> <Reference Include="System.Core" /> @@ -73,11 +86,11 @@ <Compile Include="MbLinkShortcutHandler.cs" /> <Compile Include="Migrations\IVersionMigration.cs" /> <Compile Include="Migrations\DbMigration.cs" /> - <Compile Include="Migrations\MovieDbEpisodeProviderMigration.cs" /> <Compile Include="Migrations\UpdateLevelMigration.cs" /> <Compile Include="NativeEnvironment.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="StartupOptions.cs" /> + <Compile Include="SystemEvents.cs" /> <Compile Include="UnhandledExceptionWriter.cs" /> </ItemGroup> <ItemGroup> @@ -93,10 +106,6 @@ <Project>{4fd51ac5-2c16-4308-a993-c3a84f3b4582}</Project> <Name>MediaBrowser.Api</Name> </ProjectReference> - <ProjectReference Include="..\MediaBrowser.Common.Implementations\MediaBrowser.Common.Implementations.csproj"> - <Project>{c4d2573a-3fd3-441f-81af-174ac4cd4e1d}</Project> - <Name>MediaBrowser.Common.Implementations</Name> - </ProjectReference> <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj"> <Project>{9142eefa-7570-41e1-bfcc-468bb571af2f}</Project> <Name>MediaBrowser.Common</Name> @@ -105,10 +114,6 @@ <Project>{17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2}</Project> <Name>MediaBrowser.Controller</Name> </ProjectReference> - <ProjectReference Include="..\MediaBrowser.Dlna\MediaBrowser.Dlna.csproj"> - <Project>{734098eb-6dc1-4dd0-a1ca-3140dcd2737c}</Project> - <Name>MediaBrowser.Dlna</Name> - </ProjectReference> <ProjectReference Include="..\MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj"> <Project>{7ef9f3e0-697d-42f3-a08f-19deb5f84392}</Project> <Name>MediaBrowser.LocalMetadata</Name> diff --git a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs index 5705b3a59a..4a1b4000e1 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Tasks; using MediaBrowser.Server.Implementations.Persistence; diff --git a/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs deleted file mode 100644 index cd2122e57b..0000000000 --- a/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs +++ /dev/null @@ -1,44 +0,0 @@ -using MediaBrowser.Controller.Configuration; -using System.Linq; -using System.Threading.Tasks; - -namespace MediaBrowser.Server.Startup.Common.Migrations -{ - class MovieDbEpisodeProviderMigration : IVersionMigration - { - private readonly IServerConfigurationManager _config; - private const string _providerName = "TheMovieDb"; - - public MovieDbEpisodeProviderMigration(IServerConfigurationManager config) - { - _config = config; - } - - public async Task Run() - { - var migrationKey = this.GetType().FullName; - var migrationKeyList = _config.Configuration.Migrations.ToList(); - - if (!migrationKeyList.Contains(migrationKey)) - { - foreach (var metaDataOption in _config.Configuration.MetadataOptions) - { - if (metaDataOption.ItemType == "Episode") - { - var disabledFetchers = metaDataOption.DisabledMetadataFetchers.ToList(); - if (!disabledFetchers.Contains(_providerName)) - { - disabledFetchers.Add(_providerName); - metaDataOption.DisabledMetadataFetchers = disabledFetchers.ToArray(); - } - } - } - - migrationKeyList.Add(migrationKey); - _config.Configuration.Migrations = migrationKeyList.ToArray(); - _config.SaveConfiguration(); - } - - } - } -} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs index 8483ca904c..b0214041b1 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.Implementations.Updates; +using Emby.Common.Implementations.Updates; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; diff --git a/MediaBrowser.Server.Startup.Common/SystemEvents.cs b/MediaBrowser.Server.Startup.Common/SystemEvents.cs new file mode 100644 index 0000000000..088d04a249 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/SystemEvents.cs @@ -0,0 +1,34 @@ +using System; +using MediaBrowser.Common.Events; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.System; + +namespace MediaBrowser.Server.Startup.Common +{ + public class SystemEvents : ISystemEvents + { + public event EventHandler Resume; + public event EventHandler Suspend; + + private readonly ILogger _logger; + + public SystemEvents(ILogger logger) + { + _logger = logger; + Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; + } + + private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e) + { + switch (e.Mode) + { + case Microsoft.Win32.PowerModes.Resume: + EventHelper.FireEventIfNotNull(Resume, this, EventArgs.Empty, _logger); + break; + case Microsoft.Win32.PowerModes.Suspend: + EventHelper.FireEventIfNotNull(Suspend, this, EventArgs.Empty, _logger); + break; + } + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs index 804533b9d1..696c3892e1 100644 --- a/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs +++ b/MediaBrowser.Server.Startup.Common/UnhandledExceptionWriter.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Configuration; -using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Model.Logging; using System; using System.IO; diff --git a/MediaBrowser.Server.Startup.Common/packages.config b/MediaBrowser.Server.Startup.Common/packages.config index a3235d0ca2..49eee1536b 100644 --- a/MediaBrowser.Server.Startup.Common/packages.config +++ b/MediaBrowser.Server.Startup.Common/packages.config @@ -2,4 +2,5 @@ <packages> <package id="Mono.Posix" version="4.0.0.0" targetFramework="net45" /> <package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" /> + <package id="SimpleInjector" version="3.2.4" targetFramework="net46" /> </packages>
\ No newline at end of file |
