From dccba7d1fdff94f14c2a09105b93d6daa602eb4d Mon Sep 17 00:00:00 2001 From: ScottRapsey Date: Mon, 4 Mar 2013 14:29:09 +1100 Subject: [PATCH 1/4] Added useLegacyV2RuntimeActivationPolicy Added useLegacyV2RuntimeActivationPolicy="true" to the Startup section of the config so that we can get .net dependencies to load if/when required. --- MediaBrowser.ServerApplication/App.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config index 13283e4b5b..2d47c4bea2 100644 --- a/MediaBrowser.ServerApplication/App.config +++ b/MediaBrowser.ServerApplication/App.config @@ -15,7 +15,7 @@ - + From 2ca4b7d03adfa3cc7c9c6a597a11762142d5b34b Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 00:43:06 -0500 Subject: [PATCH 2/4] Created IConfigurationManager --- MediaBrowser.Api/Images/ImageService.cs | 2 +- MediaBrowser.Api/Library/LibraryService.cs | 3 +- MediaBrowser.Api/PackageService.cs | 27 +- .../Playback/BaseStreamingService.cs | 42 +- .../Playback/Hls/AudioHlsService.cs | 12 +- .../Playback/Hls/BaseHlsService.cs | 8 +- .../Playback/Hls/VideoHlsService.cs | 12 +- .../Playback/Progressive/AudioService.cs | 11 +- .../BaseProgressiveStreamingService.cs | 11 +- .../Playback/Progressive/VideoService.cs | 13 +- MediaBrowser.Api/Plugin.cs | 8 +- MediaBrowser.Api/PluginService.cs | 29 +- MediaBrowser.Api/SystemService.cs | 30 +- MediaBrowser.Api/UserService.cs | 4 - MediaBrowser.Api/WeatherService.cs | 6 +- .../BaseApplicationHost.cs | 125 ++- .../BaseApplicationPaths.cs | 3 +- .../Configuration/BaseConfigurationManager.cs | 123 +++ .../HttpClientManager/HttpClientManager.cs | 3 +- .../HttpServer/BaseRestService.cs | 11 +- ...MediaBrowser.Common.Implementations.csproj | 5 + .../ScheduledTasks/ScheduledTaskWorker.cs | 3 +- .../ScheduledTasks/TaskManager.cs | 3 +- .../Tasks/DeleteCacheFileTask.cs | 16 +- .../ScheduledTasks/Tasks/DeleteLogFileTask.cs | 20 +- .../ScheduledTasks/Tasks/ReloadLoggerTask.cs | 16 +- .../ScheduledTasks/Tasks/SystemUpdateTask.cs | 25 +- .../Security}/PluginSecurityManager.cs | 7 +- .../ServerManager/ServerManager.cs | 37 +- .../Updates/PackageManager.cs | 64 +- .../Configuration/ConfigurationHelper.cs | 68 ++ .../IApplicationPaths.cs | 2 +- .../Configuration/IConfigurationManager.cs | 36 + .../{Kernel => }/IApplicationHost.cs | 8 +- MediaBrowser.Common/Kernel/BaseKernel.cs | 225 +---- MediaBrowser.Common/Kernel/IKernel.cs | 46 +- MediaBrowser.Common/Kernel/ResourcePool.cs | 79 -- .../MediaBrowser.Common.csproj | 10 +- .../Net/Handlers/BaseHandler.cs | 808 ------------------ .../Net/Handlers/IHttpServerHandler.cs | 32 - .../Net/Handlers/StaticFileHandler.cs | 264 ------ MediaBrowser.Common/Plugins/BasePlugin.cs | 33 +- .../Updates/ApplicationUpdater.cs | 1 + .../Updates/IPackageManager.cs | 36 +- .../IServerConfigurationManager.cs | 23 + .../Drawing/ImageManager.cs | 12 +- MediaBrowser.Controller/Entities/BaseItem.cs | 13 +- MediaBrowser.Controller/Entities/User.cs | 14 +- .../IO/DirectoryWatchers.cs | 20 +- .../IO/FileSystemManager.cs | 10 +- .../IServerApplicationPaths.cs | 3 +- MediaBrowser.Controller/Kernel.cs | 99 +-- MediaBrowser.Controller/Library/DtoBuilder.cs | 34 - .../Library/ItemResolveArgs.cs | 24 +- .../Localization/LocalizedStrings.cs | 25 +- .../Localization/Ratings.cs | 12 +- .../Localization/RatingsDefinition.cs | 19 +- .../MediaBrowser.Controller.csproj | 5 +- .../MediaInfo/FFMpegManager.cs | 18 +- .../Providers/BaseMetadataProvider.cs | 13 +- .../Providers/FanartBaseProvider.cs | 7 +- .../Providers/FolderProviderFromXml.cs | 5 +- .../ImageFromMediaLocationProvider.cs | 5 +- .../Providers/ImagesByNameProvider.cs | 7 +- .../MediaInfo/BaseFFMpegImageProvider.cs | 5 +- .../Providers/MediaInfo/BaseFFMpegProvider.cs | 3 +- .../MediaInfo/BaseFFProbeProvider.cs | 5 +- .../MediaInfo/FFMpegAudioImageProvider.cs | 5 +- .../MediaInfo/FFMpegVideoImageProvider.cs | 9 +- .../MediaInfo/FFProbeAudioInfoProvider.cs | 3 +- .../MediaInfo/FFProbeVideoInfoProvider.cs | 54 +- .../Providers/Movies/FanArtMovieProvider.cs | 64 +- .../Providers/Movies/MovieDbProvider.cs | 114 +-- .../Providers/Movies/MovieProviderFromJson.cs | 5 +- .../Providers/Movies/MovieProviderFromXml.cs | 5 +- .../Movies/PersonProviderFromJson.cs | 5 +- .../Providers/Movies/TmdbPersonProvider.cs | 51 +- .../Providers/Music/LastfmBaseProvider.cs | 54 +- .../Providers/ProviderManager.cs | 39 +- .../Providers/SortNameProvider.cs | 16 +- .../EpisodeImageFromMediaLocationProvider.cs | 5 +- .../Providers/TV/EpisodeProviderFromXml.cs | 5 +- .../Providers/TV/FanArtTVProvider.cs | 28 +- .../Providers/TV/RemoteEpisodeProvider.cs | 33 +- .../Providers/TV/RemoteSeasonProvider.cs | 31 +- .../Providers/TV/RemoteSeriesProvider.cs | 69 +- .../Providers/TV/SeriesProviderFromXml.cs | 5 +- .../Updates/InstallationManager.cs | 7 +- MediaBrowser.Model/DTO/BaseItemDto.cs | 28 - .../ServerConfigurationManager.cs | 55 ++ .../Library/LibraryManager.cs | 27 +- .../Library/Resolvers/Movies/MovieResolver.cs | 10 +- .../Library/UserManager.cs | 17 +- ...MediaBrowser.Server.Implementations.csproj | 1 + .../SQLiteDisplayPreferencesRepository.cs | 3 +- .../Sqlite/SQLiteItemRepository.cs | 1 + .../Sqlite/SQLiteUserDataRepository.cs | 3 +- .../Sqlite/SQLiteUserRepository.cs | 3 +- .../WorldWeatherOnline/WeatherProvider.cs | 1 - MediaBrowser.ServerApplication/App.xaml.cs | 81 +- .../ApplicationHost.cs | 127 +-- .../LibraryExplorer.xaml.cs | 12 +- .../Logging/LogWindow.xaml.cs | 12 +- .../MainWindow.xaml.cs | 52 +- .../StartupWizard.cs | 10 +- .../Api/DashboardService.cs | 12 +- 106 files changed, 1338 insertions(+), 2432 deletions(-) create mode 100644 MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs rename {MediaBrowser.Controller/Plugins => MediaBrowser.Common.Implementations/Security}/PluginSecurityManager.cs (95%) create mode 100644 MediaBrowser.Common/Configuration/ConfigurationHelper.cs rename MediaBrowser.Common/{Kernel => Configuration}/IApplicationPaths.cs (98%) create mode 100644 MediaBrowser.Common/Configuration/IConfigurationManager.cs rename MediaBrowser.Common/{Kernel => }/IApplicationHost.cs (93%) delete mode 100644 MediaBrowser.Common/Kernel/ResourcePool.cs delete mode 100644 MediaBrowser.Common/Net/Handlers/BaseHandler.cs delete mode 100644 MediaBrowser.Common/Net/Handlers/IHttpServerHandler.cs delete mode 100644 MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs create mode 100644 MediaBrowser.Controller/Configuration/IServerConfigurationManager.cs create mode 100644 MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 4f06ae4245..1c0e6c68da 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -268,7 +268,7 @@ namespace MediaBrowser.Api.Images /// private object GetImage(ImageRequest request, BaseItem item) { - var kernel = (Kernel)Kernel; + var kernel = Kernel.Instance; var index = request.Index ?? 0; diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 11d8777111..b49cc568fe 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Implementations.HttpServer; +using MediaBrowser.Common; +using MediaBrowser.Common.Implementations.HttpServer; using MediaBrowser.Common.Kernel; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index a45b11e269..75dffc67b6 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations.HttpServer; using MediaBrowser.Common.Kernel; using MediaBrowser.Controller; @@ -108,13 +109,11 @@ namespace MediaBrowser.Api /// Unsupported PackageType public object Get(GetPackageVersionUpdates request) { - var kernel = (Kernel)Kernel; - var result = new List(); if (request.PackageType == PackageType.UserInstalled || request.PackageType == PackageType.All) { - result.AddRange(kernel.InstallationManager.GetAvailablePluginUpdates(false, CancellationToken.None).Result.ToList()); + result.AddRange(Kernel.Instance.InstallationManager.GetAvailablePluginUpdates(false, CancellationToken.None).Result.ToList()); } else if (request.PackageType == PackageType.System || request.PackageType == PackageType.All) @@ -137,9 +136,7 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetPackage request) { - var kernel = (Kernel)Kernel; - - var packages = kernel.InstallationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: ApplicationHost.ApplicationVersion).Result; + var packages = Kernel.Instance.InstallationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: ApplicationHost.ApplicationVersion).Result; var result = packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); @@ -153,9 +150,7 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetPackages request) { - var kernel = (Kernel)Kernel; - - var packages = kernel.InstallationManager.GetAvailablePackages(CancellationToken.None, request.PackageType, ApplicationHost.ApplicationVersion).Result; + var packages = Kernel.Instance.InstallationManager.GetAvailablePackages(CancellationToken.None, request.PackageType, ApplicationHost.ApplicationVersion).Result; return ToOptimizedResult(packages.ToList()); } @@ -167,18 +162,16 @@ namespace MediaBrowser.Api /// public void Post(InstallPackage request) { - var kernel = (Kernel)Kernel; - var package = string.IsNullOrEmpty(request.Version) ? - kernel.InstallationManager.GetLatestCompatibleVersion(request.Name, request.UpdateClass).Result : - kernel.InstallationManager.GetPackage(request.Name, request.UpdateClass, Version.Parse(request.Version)).Result; + Kernel.Instance.InstallationManager.GetLatestCompatibleVersion(request.Name, request.UpdateClass).Result : + Kernel.Instance.InstallationManager.GetPackage(request.Name, request.UpdateClass, Version.Parse(request.Version)).Result; if (package == null) { throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name)); } - Task.Run(() => kernel.InstallationManager.InstallPackage(package, new Progress { }, CancellationToken.None)); + Task.Run(() => Kernel.Instance.InstallationManager.InstallPackage(package, new Progress { }, CancellationToken.None)); } /// @@ -187,9 +180,7 @@ namespace MediaBrowser.Api /// The request. public void Delete(CancelPackageInstallation request) { - var kernel = (Kernel)Kernel; - - var info = kernel.InstallationManager.CurrentInstallations.FirstOrDefault(i => i.Item1.Id == request.Id); + var info = Kernel.Instance.InstallationManager.CurrentInstallations.FirstOrDefault(i => i.Item1.Id == request.Id); if (info != null) { diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 9808564105..5107d13c21 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -40,15 +40,12 @@ namespace MediaBrowser.Api.Playback /// /// The library manager. protected ILibraryManager LibraryManager { get; set; } - + /// - /// Gets the server kernel. + /// Gets or sets the iso manager. /// - /// The server kernel. - protected Kernel ServerKernel - { - get { return Kernel as Kernel; } - } + /// The iso manager. + protected IIsoManager IsoManager { get; set; } /// /// Initializes a new instance of the class. @@ -56,11 +53,13 @@ namespace MediaBrowser.Api.Playback /// The app paths. /// The user manager. /// The library manager. - protected BaseStreamingService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) + /// The iso manager. + protected BaseStreamingService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) { ApplicationPaths = appPaths; UserManager = userManager; LibraryManager = libraryManager; + IsoManager = isoManager; } /// @@ -307,11 +306,11 @@ namespace MediaBrowser.Api.Playback /// System.String. private string GetExtractedAssPath(Video video, MediaStream subtitleStream) { - var path = ServerKernel.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass"); + var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass"); if (!File.Exists(path)) { - var success = ServerKernel.FFMpegManager.ExtractTextSubtitle(video, subtitleStream.Index, path, CancellationToken.None).Result; + var success = Kernel.Instance.FFMpegManager.ExtractTextSubtitle(video, subtitleStream.Index, path, CancellationToken.None).Result; if (!success) { @@ -330,11 +329,11 @@ namespace MediaBrowser.Api.Playback /// System.String. private string GetConvertedAssPath(Video video, MediaStream subtitleStream) { - var path = ServerKernel.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass"); + var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass"); if (!File.Exists(path)) { - var success = ServerKernel.FFMpegManager.ConvertTextSubtitle(subtitleStream, path, CancellationToken.None).Result; + var success = Kernel.Instance.FFMpegManager.ConvertTextSubtitle(subtitleStream, path, CancellationToken.None).Result; if (!success) { @@ -476,8 +475,8 @@ namespace MediaBrowser.Api.Playback protected string GetInputArgument(BaseItem item, IIsoMount isoMount) { return isoMount == null ? - ServerKernel.FFMpegManager.GetInputArgument(item) : - ServerKernel.FFMpegManager.GetInputArgument(item as Video, isoMount); + Kernel.Instance.FFMpegManager.GetInputArgument(item) : + Kernel.Instance.FFMpegManager.GetInputArgument(item as Video, isoMount); } /// @@ -490,11 +489,10 @@ namespace MediaBrowser.Api.Playback { var video = state.Item as Video; - //if (video != null && video.VideoType == VideoType.Iso && - // video.IsoType.HasValue && Kernel.IsoManager.CanMount(video.Path)) - //{ - // IsoMount = await Kernel.IsoManager.Mount(video.Path, CancellationToken.None).ConfigureAwait(false); - //} + if (video != null && video.VideoType == VideoType.Iso && video.IsoType.HasValue && IsoManager.CanMount(video.Path)) + { + state.IsoMount = await IsoManager.Mount(video.Path, CancellationToken.None).ConfigureAwait(false); + } var process = new Process { @@ -507,8 +505,8 @@ namespace MediaBrowser.Api.Playback RedirectStandardOutput = true, RedirectStandardError = true, - FileName = ServerKernel.FFMpegManager.FFMpegPath, - WorkingDirectory = Path.GetDirectoryName(ServerKernel.FFMpegManager.FFMpegPath), + FileName = Kernel.Instance.FFMpegManager.FFMpegPath, + WorkingDirectory = Path.GetDirectoryName(Kernel.Instance.FFMpegManager.FFMpegPath), Arguments = GetCommandLineArguments(outputPath, state), WindowStyle = ProcessWindowStyle.Hidden, @@ -522,7 +520,7 @@ namespace MediaBrowser.Api.Playback //Logger.Info(process.StartInfo.FileName + " " + process.StartInfo.Arguments); - var logFilePath = Path.Combine(Kernel.ApplicationPaths.LogDirectoryPath, "ffmpeg-" + Guid.NewGuid() + ".txt"); + var logFilePath = Path.Combine(ApplicationPaths.LogDirectoryPath, "ffmpeg-" + Guid.NewGuid() + ".txt"); // FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory. state.LogFileStream = new FileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); diff --git a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs index 0735f3b623..a98f274998 100644 --- a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using System; @@ -10,13 +11,8 @@ namespace MediaBrowser.Api.Playback.Hls /// public class AudioHlsService : BaseHlsService { - /// - /// Initializes a new instance of the class. - /// - /// The app paths. - /// The user manager. - public AudioHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + public AudioHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) + : base(appPaths, userManager, libraryManager, isoManager) { } diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index d616565ca8..f73109dd00 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -17,8 +17,8 @@ namespace MediaBrowser.Api.Playback.Hls /// public const string SegmentFilePrefix = "segment-"; - protected BaseHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + protected BaseHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) + : base(appPaths, userManager, libraryManager, isoManager) { } @@ -174,9 +174,7 @@ namespace MediaBrowser.Api.Playback.Hls segmentOutputPath = Path.Combine(segmentOutputPath, segmentOutputName + "%03d." + GetSegmentFileExtension(state).TrimStart('.')); - var kernel = (Kernel)Kernel; - - var probeSize = kernel.FFMpegManager.GetProbeSizeArgument(state.Item); + var probeSize = Kernel.Instance.FFMpegManager.GetProbeSizeArgument(state.Item); return string.Format("{0} {1} -i {2}{3} -threads 0 {4} {5} {6} -f ssegment -segment_list_flags +live -segment_time 9 -segment_list \"{7}\" \"{8}\"", probeSize, diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 41d818ce77..7fcd4357be 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using System; @@ -6,13 +7,8 @@ namespace MediaBrowser.Api.Playback.Hls { public class VideoHlsService : BaseHlsService { - /// - /// Initializes a new instance of the class. - /// - /// The app paths. - /// The user manager. - public VideoHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + public VideoHlsService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) + : base(appPaths, userManager, libraryManager, isoManager) { } diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs index e81f0ac0df..86d9931524 100644 --- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs +++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using ServiceStack.ServiceHost; using System.Collections.Generic; @@ -24,12 +25,8 @@ namespace MediaBrowser.Api.Playback.Progressive /// public class AudioService : BaseProgressiveStreamingService { - /// - /// Initializes a new instance of the class. - /// - /// The app paths. - public AudioService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + public AudioService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) + : base(appPaths, userManager, libraryManager, isoManager) { } diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index bbfe65504b..eba8decf2f 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Net; +using MediaBrowser.Common.IO; +using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -14,12 +15,8 @@ namespace MediaBrowser.Api.Playback.Progressive /// public abstract class BaseProgressiveStreamingService : BaseStreamingService { - /// - /// Initializes a new instance of the class. - /// - /// The app paths. - protected BaseProgressiveStreamingService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + protected BaseProgressiveStreamingService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) : + base(appPaths, userManager, libraryManager, isoManager) { } diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 6261d32ee7..22f3320caf 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using System; using MediaBrowser.Controller.Library; @@ -30,12 +31,8 @@ namespace MediaBrowser.Api.Playback.Progressive /// public class VideoService : BaseProgressiveStreamingService { - /// - /// Initializes a new instance of the class. - /// - /// The app paths. - public VideoService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager) - : base(appPaths, userManager, libraryManager) + public VideoService(IServerApplicationPaths appPaths, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager) + : base(appPaths, userManager, libraryManager, isoManager) { } @@ -59,7 +56,7 @@ namespace MediaBrowser.Api.Playback.Progressive { var video = (Video)state.Item; - var probeSize = ServerKernel.FFMpegManager.GetProbeSizeArgument(video.VideoType, video.IsoType); + var probeSize = Kernel.Instance.FFMpegManager.GetProbeSizeArgument(video.VideoType, video.IsoType); // Get the output codec name var videoCodec = GetVideoCodec(state.Request); diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index b8c81bbe12..321267b041 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; @@ -13,9 +14,10 @@ namespace MediaBrowser.Api /// /// Initializes a new instance of the class. /// - /// The kernel. + /// The app paths. /// The XML serializer. - public Plugin(IKernel kernel, IXmlSerializer xmlSerializer) : base(kernel, xmlSerializer) + public Plugin(IApplicationPaths appPaths, IXmlSerializer xmlSerializer) + : base(appPaths, xmlSerializer) { Instance = this; } diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs index 7e907c2dd2..932a3e5454 100644 --- a/MediaBrowser.Api/PluginService.cs +++ b/MediaBrowser.Api/PluginService.cs @@ -1,6 +1,7 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations.HttpServer; -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Security; using MediaBrowser.Controller; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Plugins; @@ -129,13 +130,16 @@ namespace MediaBrowser.Api /// private readonly IApplicationHost _appHost; + private readonly ISecurityManager _securityManager; + /// /// Initializes a new instance of the class. /// /// The json serializer. /// The app host. + /// The security manager. /// jsonSerializer - public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost) + public PluginService(IJsonSerializer jsonSerializer, IApplicationHost appHost, ISecurityManager securityManager) : base() { if (jsonSerializer == null) @@ -144,6 +148,7 @@ namespace MediaBrowser.Api } _appHost = appHost; + _securityManager = securityManager; _jsonSerializer = jsonSerializer; } @@ -206,13 +211,11 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetPluginSecurityInfo request) { - var kernel = (Kernel)Kernel; - var result = new PluginSecurityInfo { - IsMBSupporter = kernel.SecurityManager.IsMBSupporter, - SupporterKey = kernel.SecurityManager.SupporterKey, - LegacyKey = kernel.SecurityManager.LegacyKey + IsMBSupporter = _securityManager.IsMBSupporter, + SupporterKey = _securityManager.SupporterKey, + LegacyKey = _securityManager.LegacyKey }; return ToOptimizedResult(result); @@ -224,12 +227,10 @@ namespace MediaBrowser.Api /// The request. public void Post(UpdatePluginSecurityInfo request) { - var kernel = (Kernel)Kernel; - var info = _jsonSerializer.DeserializeFromStream(request.RequestStream); - kernel.SecurityManager.SupporterKey = info.SupporterKey; - kernel.SecurityManager.LegacyKey = info.LegacyKey; + _securityManager.SupporterKey = info.SupporterKey; + _securityManager.LegacyKey = info.LegacyKey; } /// @@ -256,11 +257,9 @@ namespace MediaBrowser.Api /// The request. public void Delete(UninstallPlugin request) { - var kernel = (Kernel)Kernel; - var plugin = _appHost.Plugins.First(p => p.Id == request.Id); - kernel.InstallationManager.UninstallPlugin(plugin); + Kernel.Instance.InstallationManager.UninstallPlugin(plugin); } } } diff --git a/MediaBrowser.Api/SystemService.cs b/MediaBrowser.Api/SystemService.cs index 7edaed1c72..0d5d47e4b7 100644 --- a/MediaBrowser.Api/SystemService.cs +++ b/MediaBrowser.Api/SystemService.cs @@ -1,7 +1,8 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations.HttpServer; -using MediaBrowser.Common.Kernel; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; @@ -72,13 +73,19 @@ namespace MediaBrowser.Api /// private readonly IApplicationHost _appHost; + /// + /// The _configuration manager + /// + private readonly IServerConfigurationManager _configurationManager; + /// /// Initializes a new instance of the class. /// /// The json serializer. /// The app host. + /// The configuration manager. /// jsonSerializer - public SystemService(IJsonSerializer jsonSerializer, IApplicationHost appHost) + public SystemService(IJsonSerializer jsonSerializer, IApplicationHost appHost, IServerConfigurationManager configurationManager) : base() { if (jsonSerializer == null) @@ -91,6 +98,7 @@ namespace MediaBrowser.Api } _appHost = appHost; + _configurationManager = configurationManager; _jsonSerializer = jsonSerializer; } @@ -101,7 +109,7 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetSystemInfo request) { - var result = Kernel.GetSystemInfo(); + var result = Kernel.Instance.GetSystemInfo(); return ToOptimizedResult(result); } @@ -113,13 +121,11 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetConfiguration request) { - var kernel = (Kernel)Kernel; + var dateModified = File.GetLastWriteTimeUtc(_configurationManager.ApplicationPaths.SystemConfigurationFilePath); - var dateModified = File.GetLastWriteTimeUtc(Kernel.ApplicationPaths.SystemConfigurationFilePath); + var cacheKey = (_configurationManager.ApplicationPaths.SystemConfigurationFilePath + dateModified.Ticks).GetMD5(); - var cacheKey = (Kernel.ApplicationPaths.SystemConfigurationFilePath + dateModified.Ticks).GetMD5(); - - return ToOptimizedResultUsingCache(cacheKey, dateModified, null, () => kernel.Configuration); + return ToOptimizedResultUsingCache(cacheKey, dateModified, null, () => _configurationManager.Configuration); } /// @@ -131,7 +137,7 @@ namespace MediaBrowser.Api Task.Run(async () => { await Task.Delay(100); - Kernel.PerformPendingRestart(); + Kernel.Instance.PerformPendingRestart(); }); } @@ -156,9 +162,7 @@ namespace MediaBrowser.Api { var serverConfig = _jsonSerializer.DeserializeFromStream(request.RequestStream); - var kernel = (Kernel)Kernel; - - kernel.UpdateConfiguration(serverConfig); + _configurationManager.ReplaceConfiguration(serverConfig); } } } diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 7302420633..d4442ff448 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -181,8 +181,6 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetUsers request) { - var kernel = (Kernel)Kernel; - var dtoBuilder = new DtoBuilder(Logger); var result = _userManager.Users.OrderBy(u => u.Name).Select(dtoBuilder.GetDtoUser).ToList(); @@ -312,8 +310,6 @@ namespace MediaBrowser.Api /// System.Object. public object Post(CreateUser request) { - var kernel = (Kernel)Kernel; - var dtoUser = _jsonSerializer.DeserializeFromStream(request.RequestStream); var newUser = _userManager.CreateUser(dtoUser.Name).Result; diff --git a/MediaBrowser.Api/WeatherService.cs b/MediaBrowser.Api/WeatherService.cs index 930daa2703..7c85d849d7 100644 --- a/MediaBrowser.Api/WeatherService.cs +++ b/MediaBrowser.Api/WeatherService.cs @@ -32,11 +32,7 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetWeather request) { - var kernel = (Kernel) Kernel; - - var location = string.IsNullOrWhiteSpace(request.Location) ? kernel.Configuration.WeatherLocation : request.Location; - - var result = kernel.WeatherProviders.First().GetWeatherInfoAsync(location, CancellationToken.None).Result; + var result = Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(request.Location, CancellationToken.None).Result; return ToOptimizedResult(result); } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 4e1b4634ec..b25c1808d0 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -1,4 +1,9 @@ -using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Implementations.Logging; +using MediaBrowser.Common.Implementations.NetworkManagement; +using MediaBrowser.Common.Implementations.ScheduledTasks; +using MediaBrowser.Common.Implementations.Security; +using MediaBrowser.Common.Implementations.Serialization; using MediaBrowser.Common.Implementations.Udp; using MediaBrowser.Common.Implementations.Updates; using MediaBrowser.Common.Implementations.WebSocket; @@ -6,9 +11,11 @@ using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Common.Security; using MediaBrowser.Common.Updates; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; +using MediaBrowser.Model.Updates; using SimpleInjector; using System; using System.Collections.Generic; @@ -16,16 +23,18 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Common.Implementations { - public abstract class BaseApplicationHost + public abstract class BaseApplicationHost : IApplicationHost + where TApplicationPathsType : class, IApplicationPaths, new() { /// /// Gets or sets the logger. /// /// The logger. - public ILogger Logger { get; protected set; } + protected ILogger Logger { get; private set; } /// /// Gets or sets the plugins. @@ -43,13 +52,23 @@ namespace MediaBrowser.Common.Implementations /// Gets the application paths. /// /// The application paths. - protected IApplicationPaths ApplicationPaths { get; private set; } + protected TApplicationPathsType ApplicationPaths = new TApplicationPathsType(); /// /// The container /// protected readonly Container Container = new Container(); + /// + /// The json serializer + /// + protected readonly IJsonSerializer JsonSerializer = new JsonSerializer(); + + /// + /// The _XML serializer + /// + protected readonly IXmlSerializer XmlSerializer = new XmlSerializer(); + /// /// Gets assemblies that failed to load /// @@ -109,12 +128,26 @@ namespace MediaBrowser.Common.Implementations } } + /// + /// Gets the kernel. + /// + /// The kernel. + protected IKernel Kernel { get; private set; } + protected ITaskManager TaskManager { get; private set; } + protected ISecurityManager SecurityManager { get; private set; } + + protected IConfigurationManager ConfigurationManager { get; private set; } + /// /// Initializes a new instance of the class. /// protected BaseApplicationHost() { FailedAssemblies = new List(); + + LogManager = new NlogManager(ApplicationPaths.LogDirectoryPath, LogFilePrefixName); + + ConfigurationManager = GetConfigurationManager(); } /// @@ -125,15 +158,25 @@ namespace MediaBrowser.Common.Implementations { return Task.Run(() => { - ApplicationPaths = GetApplicationPaths(); - - LogManager = GetLogManager(); - Logger = LogManager.GetLogger("App"); IsFirstRun = !File.Exists(ApplicationPaths.SystemConfigurationFilePath); DiscoverTypes(); + + LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); + + Logger.Info("Version {0} initializing", ApplicationVersion); + + Kernel = GetKernel(); + + RegisterResources(); + + FindParts(); + + Task.Run(() => ConfigureAutoRunAtStartup()); + + Kernel.Init(); }); } @@ -144,16 +187,13 @@ namespace MediaBrowser.Common.Implementations protected abstract IEnumerable GetComposablePartAssemblies(); /// - /// Gets the log manager. + /// Gets the name of the log file prefix. /// - /// ILogManager. - protected abstract ILogManager GetLogManager(); + /// The name of the log file prefix. + protected abstract string LogFilePrefixName { get; } - /// - /// Gets the application paths. - /// - /// IApplicationPaths. - protected abstract IApplicationPaths GetApplicationPaths(); + protected abstract IKernel GetKernel(); + protected abstract IConfigurationManager GetConfigurationManager(); /// /// Finds the parts. @@ -184,21 +224,44 @@ namespace MediaBrowser.Common.Implementations /// /// Registers resources that classes will depend on /// - protected virtual void RegisterResources(ITaskManager taskManager, INetworkManager networkManager, IServerManager serverManager) + protected virtual void RegisterResources() { + RegisterSingleInstance(ConfigurationManager); + RegisterSingleInstance(this); + + RegisterSingleInstance(ApplicationPaths); + + var networkManager = new NetworkManager(); + + var serverManager = new ServerManager.ServerManager(this, Kernel, networkManager, JsonSerializer, Logger, ConfigurationManager); + + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, Logger, serverManager); + + RegisterSingleInstance(JsonSerializer); + RegisterSingleInstance(XmlSerializer); + RegisterSingleInstance(LogManager); RegisterSingleInstance(Logger); - RegisterSingleInstance(ApplicationPaths); - RegisterSingleInstance(taskManager); + RegisterSingleInstance(Kernel); + + RegisterSingleInstance(TaskManager); RegisterSingleInstance(() => new AlchemyServer(Logger)); RegisterSingleInstance(ProtobufSerializer); RegisterSingleInstance(new UdpServer(Logger), false); - RegisterSingleInstance(new PackageManager()); - RegisterSingleInstance(new HttpClientManager.HttpClientManager(ApplicationPaths, Logger)); - RegisterSingleInstance(networkManager); - RegisterSingleInstance(serverManager); + var httpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, Logger); + + RegisterSingleInstance(httpClient); + + RegisterSingleInstance(networkManager); + RegisterSingleInstance(serverManager); + + SecurityManager = new PluginSecurityManager(Kernel, httpClient, JsonSerializer, ApplicationPaths); + + RegisterSingleInstance(SecurityManager); + + RegisterSingleInstance(new PackageManager(SecurityManager, networkManager, httpClient, ApplicationPaths, JsonSerializer, Logger)); } /// @@ -336,7 +399,7 @@ namespace MediaBrowser.Common.Implementations Logger.Info("Composing instances of " + currentType.Name); - var parts = AllConcreteTypes.Where(currentType.IsAssignableFrom).Select(CreateInstance).Cast().ToArray(); + var parts = AllConcreteTypes.AsParallel().Where(currentType.IsAssignableFrom).Select(CreateInstance).Cast().ToArray(); if (manageLiftime) { @@ -361,10 +424,8 @@ namespace MediaBrowser.Common.Implementations /// /// Configures the auto run at startup. /// - /// if set to true [autorun]. - public void ConfigureAutoRunAtStartup(bool autorun) + private void ConfigureAutoRunAtStartup() { - } /// @@ -409,5 +470,15 @@ namespace MediaBrowser.Common.Implementations } } } + + public abstract void Restart(); + + public abstract bool CanSelfUpdate { get; } + + public abstract Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress); + + public abstract Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress progress); + + public abstract void Shutdown(); } } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index 37bd622004..d169336162 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using System; using System.Configuration; using System.IO; diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs new file mode 100644 index 0000000000..2f50f5f7aa --- /dev/null +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -0,0 +1,123 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Events; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; +using System; +using System.Threading; + +namespace MediaBrowser.Common.Implementations.Configuration +{ + /// + /// Class BaseConfigurationManager + /// + public abstract class BaseConfigurationManager : IConfigurationManager + { + /// + /// Gets the type of the configuration. + /// + /// The type of the configuration. + protected abstract Type ConfigurationType { get; } + + /// + /// Occurs when [configuration updated]. + /// + public event EventHandler ConfigurationUpdated; + + /// + /// Gets the logger. + /// + /// The logger. + protected ILogger Logger { get; private set; } + /// + /// Gets the XML serializer. + /// + /// The XML serializer. + protected IXmlSerializer XmlSerializer { get; private set; } + + /// + /// Gets or sets the application paths. + /// + /// The application paths. + public IApplicationPaths CommonApplicationPaths { get; private set; } + + /// + /// The _configuration loaded + /// + private bool _configurationLoaded; + /// + /// The _configuration sync lock + /// + private object _configurationSyncLock = new object(); + /// + /// The _configuration + /// + private BaseApplicationConfiguration _configuration; + /// + /// Gets the system configuration + /// + /// The configuration. + public BaseApplicationConfiguration CommonConfiguration + { + get + { + // Lazy load + LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => (BaseApplicationConfiguration)ConfigurationHelper.GetXmlConfiguration(ConfigurationType, CommonApplicationPaths.SystemConfigurationFilePath, XmlSerializer)); + return _configuration; + } + protected set + { + _configuration = value; + + _configurationLoaded = value != null; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// The application paths. + /// The log manager. + /// The XML serializer. + protected BaseConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer) + { + CommonApplicationPaths = applicationPaths; + XmlSerializer = xmlSerializer; + Logger = logManager.GetLogger(GetType().Name); + } + + /// + /// The _save lock + /// + private readonly object _configurationSaveLock = new object(); + + /// + /// Saves the configuration. + /// + public void SaveConfiguration() + { + lock (_configurationSaveLock) + { + XmlSerializer.SerializeToFile(CommonConfiguration, CommonApplicationPaths.SystemConfigurationFilePath); + } + + EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger); + } + + /// + /// Replaces the configuration. + /// + /// The new configuration. + /// newConfiguration + public void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration) + { + if (newConfiguration == null) + { + throw new ArgumentNullException("newConfiguration"); + } + + CommonConfiguration = newConfiguration; + SaveConfiguration(); + } + } +} diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index e01718f45d..f9363e0d90 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.IO; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; diff --git a/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs b/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs index bf487b7603..382183b580 100644 --- a/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs +++ b/MediaBrowser.Common.Implementations/HttpServer/BaseRestService.cs @@ -1,7 +1,5 @@ -using System.Collections.Generic; -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; -using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; using ServiceStack.Common; @@ -9,6 +7,7 @@ using ServiceStack.Common.Web; using ServiceStack.ServiceHost; using ServiceStack.ServiceInterface; using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -22,12 +21,6 @@ namespace MediaBrowser.Common.Implementations.HttpServer /// public class BaseRestService : Service, IRestfulService { - /// - /// Gets or sets the kernel. - /// - /// The kernel. - public IKernel Kernel { get; set; } - /// /// Gets or sets the logger. /// diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index 831b111ec7..84769637a3 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -38,6 +38,9 @@ ..\packages\Alchemy.2.2.1\lib\net40\Alchemy.dll + + ..\ThirdParty\PluginSecurity\Mediabrowser.PluginSecurity.dll + ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll @@ -104,6 +107,7 @@ + @@ -123,6 +127,7 @@ + diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index eada385564..d5adf32658 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs index efd3478a1e..946887303c 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index a9c82c3578..c7a19c0c03 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; using System; @@ -16,10 +16,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks public class DeleteCacheFileTask : IScheduledTask { /// - /// Gets or sets the kernel. + /// Gets or sets the application paths. /// - /// The kernel. - private IKernel Kernel { get; set; } + /// The application paths. + private IApplicationPaths ApplicationPaths { get; set; } /// /// Gets or sets the logger. /// @@ -29,11 +29,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// /// Initializes a new instance of the class. /// - /// The kernel. + /// The app paths. /// The logger. - public DeleteCacheFileTask(IKernel kernel, ILogger logger) + public DeleteCacheFileTask(IApplicationPaths appPaths, ILogger logger) { - Kernel = kernel; + ApplicationPaths = appPaths; Logger = logger; } @@ -60,7 +60,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks { var minDateModified = DateTime.UtcNow.AddMonths(-2); - DeleteCacheFilesFromDirectory(cancellationToken, Kernel.ApplicationPaths.CachePath, minDateModified, progress); + DeleteCacheFilesFromDirectory(cancellationToken, ApplicationPaths.CachePath, minDateModified, progress); }); } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index a7d8a68a04..faeb39735f 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; using System; @@ -16,10 +16,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks public class DeleteLogFileTask : IScheduledTask { /// - /// Gets or sets the kernel. + /// Gets or sets the configuration manager. /// - /// The kernel. - private IKernel Kernel { get; set; } + /// The configuration manager. + private IConfigurationManager ConfigurationManager { get; set; } /// /// Gets or sets the logger. /// @@ -29,11 +29,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// /// Initializes a new instance of the class. /// - /// The kernel. + /// The configuration manager. /// The logger. - public DeleteLogFileTask(IKernel kernel, ILogger logger) + public DeleteLogFileTask(IConfigurationManager configurationManager, ILogger logger) { - Kernel = kernel; + ConfigurationManager = configurationManager; Logger = logger; } @@ -59,9 +59,9 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks return Task.Run(() => { // Delete log files more than n days old - var minDateModified = DateTime.UtcNow.AddDays(-(Kernel.Configuration.LogFileRetentionDays)); + var minDateModified = DateTime.UtcNow.AddDays(-(ConfigurationManager.CommonConfiguration.LogFileRetentionDays)); - var filesToDelete = new DirectoryInfo(Kernel.ApplicationPaths.LogDirectoryPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories) + var filesToDelete = new DirectoryInfo(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories) .Where(f => f.LastWriteTimeUtc < minDateModified) .ToList(); @@ -100,7 +100,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// The description. public string Description { - get { return string.Format("Deletes log files that are more than {0} days old.", Kernel.Configuration.LogFileRetentionDays); } + get { return string.Format("Deletes log files that are more than {0} days old.", ConfigurationManager.CommonConfiguration.LogFileRetentionDays); } } /// diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs index ea1e8b9382..a02f9dec6b 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/ReloadLoggerTask.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; using System; @@ -24,22 +24,22 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks /// The logger. private ILogger Logger { get; set; } /// - /// Gets or sets the kernel. + /// Gets or sets the configuration manager. /// - /// The kernel. - private IKernel Kernel { get; set; } + /// The configuration manager. + private IConfigurationManager ConfigurationManager { get; set; } /// /// Initializes a new instance of the class. /// /// The logManager. /// The logger. - /// The kernel. - public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IKernel kernel) + /// The configuration manager. + public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IConfigurationManager configurationManager) { LogManager = logManager; Logger = logger; - Kernel = kernel; + ConfigurationManager = configurationManager; } /// @@ -65,7 +65,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks progress.Report(0); - return Task.Run(() => LogManager.ReloadLogger(Kernel.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info)); + return Task.Run(() => LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info)); } /// diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs index 0091e14c0e..7da1b9c5a5 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/SystemUpdateTask.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Model.Logging; using System; @@ -19,27 +20,35 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks private readonly IApplicationHost _appHost; /// - /// Gets or sets the kernel. + /// Gets or sets the configuration manager. /// - /// The kernel. - private IKernel Kernel { get; set; } + /// The configuration manager. + private IConfigurationManager ConfigurationManager { get; set; } /// /// Gets or sets the logger. /// /// The logger. private ILogger Logger { get; set; } + /// + /// Gets or sets the kernel. + /// + /// The kernel. + private IKernel Kernel { get; set; } + /// /// Initializes a new instance of the class. /// /// The app host. - /// The kernel. + /// The configuration manager. /// The logger. - public SystemUpdateTask(IApplicationHost appHost, IKernel kernel, ILogger logger) + /// The kernel. + public SystemUpdateTask(IApplicationHost appHost, IConfigurationManager configurationManager, ILogger logger, IKernel kernel) { _appHost = appHost; - Kernel = kernel; + ConfigurationManager = configurationManager; Logger = logger; + Kernel = kernel; } /// @@ -88,7 +97,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Configuration.EnableAutoUpdate) + if (ConfigurationManager.CommonConfiguration.EnableAutoUpdate) { Logger.Info("Update Revision {0} available. Updating...", updateInfo.AvailableVersion); diff --git a/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs similarity index 95% rename from MediaBrowser.Controller/Plugins/PluginSecurityManager.cs rename to MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index 3a097ba1ff..a566373714 100644 --- a/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Security; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Security; using MediaBrowser.Model.Serialization; using Mediabrowser.Model.Entities; using Mediabrowser.PluginSecurity; @@ -8,7 +9,7 @@ using System; using System.Threading; using System.Threading.Tasks; -namespace MediaBrowser.Controller.Plugins +namespace MediaBrowser.Common.Implementations.Security { /// /// Class PluginSecurityManager @@ -68,7 +69,7 @@ namespace MediaBrowser.Controller.Plugins _kernel = kernel; _httpClient = httpClient; _jsonSerializer = jsonSerializer; - MBRegistration.Init(appPaths); + //MBRegistration.Init(appPaths); } /// diff --git a/MediaBrowser.Common.Implementations/ServerManager/ServerManager.cs b/MediaBrowser.Common.Implementations/ServerManager/ServerManager.cs index 31f6922c23..d18971f72e 100644 --- a/MediaBrowser.Common.Implementations/ServerManager/ServerManager.cs +++ b/MediaBrowser.Common.Implementations/ServerManager/ServerManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -77,6 +78,12 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// private readonly IKernel _kernel; + /// + /// Gets or sets the configuration manager. + /// + /// The configuration manager. + private IConfigurationManager ConfigurationManager { get; set; } + /// /// Gets a value indicating whether [supports web socket]. /// @@ -92,14 +99,14 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// The web socket port number. public int WebSocketPortNumber { - get { return SupportsNativeWebSocket ? _kernel.Configuration.HttpServerPortNumber : _kernel.Configuration.LegacyWebSocketPortNumber; } + get { return SupportsNativeWebSocket ? ConfigurationManager.CommonConfiguration.HttpServerPortNumber : ConfigurationManager.CommonConfiguration.LegacyWebSocketPortNumber; } } /// /// Gets the web socket listeners. /// /// The web socket listeners. - private List WebSocketListeners = new List(); + private readonly List _webSocketListeners = new List(); /// /// Initializes a new instance of the class. @@ -109,8 +116,9 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// The network manager. /// The json serializer. /// The logger. + /// The configuration manager. /// applicationHost - public ServerManager(IApplicationHost applicationHost, IKernel kernel, INetworkManager networkManager, IJsonSerializer jsonSerializer, ILogger logger) + public ServerManager(IApplicationHost applicationHost, IKernel kernel, INetworkManager networkManager, IJsonSerializer jsonSerializer, ILogger logger, IConfigurationManager configurationManager) { if (applicationHost == null) { @@ -138,6 +146,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager _kernel = kernel; _applicationHost = applicationHost; _networkManager = networkManager; + ConfigurationManager = configurationManager; } /// @@ -158,7 +167,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager ReloadExternalWebSocketServer(); } - _kernel.ConfigurationUpdated += _kernel_ConfigurationUpdated; + ConfigurationManager.ConfigurationUpdated += _kernel_ConfigurationUpdated; } /// @@ -176,7 +185,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager ExternalWebSocketServer = _applicationHost.Resolve(); - ExternalWebSocketServer.Start(_kernel.Configuration.LegacyWebSocketPortNumber); + ExternalWebSocketServer.Start(ConfigurationManager.CommonConfiguration.LegacyWebSocketPortNumber); ExternalWebSocketServer.WebSocketConnected += HttpServer_WebSocketConnected; } @@ -199,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager try { HttpServer = _applicationHost.Resolve(); - HttpServer.EnableHttpRequestLogging = _kernel.Configuration.EnableHttpLevelLogging; + HttpServer.EnableHttpRequestLogging = ConfigurationManager.CommonConfiguration.EnableHttpLevelLogging; HttpServer.Start(_kernel.HttpServerUrlPrefix); } catch (HttpListenerException ex) @@ -240,7 +249,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// The result. private async void ProcessWebSocketMessageReceived(WebSocketMessageInfo result) { - var tasks = WebSocketListeners.Select(i => Task.Run(async () => + var tasks = _webSocketListeners.Select(i => Task.Run(async () => { try { @@ -435,7 +444,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager private void RegisterServerWithAdministratorAccess() { // Create a temp file path to extract the bat file to - var tmpFile = Path.Combine(_kernel.ApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat"); + var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat"); // Extract the bat file using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.Common.Implementations.ServerManager.RegisterServer.bat")) @@ -450,10 +459,10 @@ namespace MediaBrowser.Common.Implementations.ServerManager { FileName = tmpFile, - Arguments = string.Format("{0} {1} {2} {3}", _kernel.Configuration.HttpServerPortNumber, + Arguments = string.Format("{0} {1} {2} {3}", ConfigurationManager.CommonConfiguration.HttpServerPortNumber, _kernel.HttpServerUrlPrefix, _kernel.UdpServerPortNumber, - _kernel.Configuration.LegacyWebSocketPortNumber), + ConfigurationManager.CommonConfiguration.LegacyWebSocketPortNumber), CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, @@ -508,14 +517,14 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// void _kernel_ConfigurationUpdated(object sender, EventArgs e) { - HttpServer.EnableHttpRequestLogging = _kernel.Configuration.EnableHttpLevelLogging; + HttpServer.EnableHttpRequestLogging = ConfigurationManager.CommonConfiguration.EnableHttpLevelLogging; if (!string.Equals(HttpServer.UrlPrefix, _kernel.HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase)) { ReloadHttpServer(); } - if (!SupportsNativeWebSocket && ExternalWebSocketServer != null && ExternalWebSocketServer.Port != _kernel.Configuration.LegacyWebSocketPortNumber) + if (!SupportsNativeWebSocket && ExternalWebSocketServer != null && ExternalWebSocketServer.Port != ConfigurationManager.CommonConfiguration.LegacyWebSocketPortNumber) { ReloadExternalWebSocketServer(); } @@ -527,7 +536,7 @@ namespace MediaBrowser.Common.Implementations.ServerManager /// The listeners. public void AddWebSocketListeners(IEnumerable listeners) { - WebSocketListeners.AddRange(listeners); + _webSocketListeners.AddRange(listeners); } } } diff --git a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs index cef631e607..f73857da18 100644 --- a/MediaBrowser.Common.Implementations/Updates/PackageManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/PackageManager.cs @@ -1,37 +1,57 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Cryptography; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Common.Security; using MediaBrowser.Common.Updates; -using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Updates; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; namespace MediaBrowser.Common.Implementations.Updates { public class PackageManager : IPackageManager { - public async Task> GetAvailablePackages(IHttpClient client, - INetworkManager networkManager, - ISecurityManager securityManager, - ResourcePool resourcePool, - IJsonSerializer serializer, - CancellationToken cancellationToken) + private readonly ISecurityManager _securityManager; + private readonly INetworkManager _networkManager; + private readonly IHttpClient _httpClient; + private readonly IApplicationPaths _appPaths; + private readonly IJsonSerializer _jsonSerializer; + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// The security manager. + /// The network manager. + /// The HTTP client. + /// The application paths. + /// The json serializer. + /// The logger. + public PackageManager(ISecurityManager securityManager, INetworkManager networkManager, IHttpClient httpClient, IApplicationPaths applicationPaths, IJsonSerializer jsonSerializer, ILogger logger) + { + _securityManager = securityManager; + _networkManager = networkManager; + _httpClient = httpClient; + _appPaths = applicationPaths; + _jsonSerializer = jsonSerializer; + _logger = logger; + } + + public async Task> GetAvailablePackages(CancellationToken cancellationToken) { - var data = new Dictionary { { "key", securityManager.SupporterKey }, { "mac", networkManager.GetMacAddress() } }; + var data = new Dictionary { { "key", _securityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; - using (var json = await client.Post(Constants.Constants.MBAdminUrl + "service/package/retrieveall", data, resourcePool.Mb, cancellationToken).ConfigureAwait(false)) + using (var json = await _httpClient.Post(Constants.Constants.MBAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); - var packages = serializer.DeserializeFromStream>(json).ToList(); + var packages = _jsonSerializer.DeserializeFromStream>(json).ToList(); foreach (var package in packages) { package.versions = package.versions.Where(v => !string.IsNullOrWhiteSpace(v.sourceUrl)) @@ -43,15 +63,15 @@ namespace MediaBrowser.Common.Implementations.Updates } - public async Task InstallPackage(IHttpClient client, ILogger logger, ResourcePool resourcePool, IProgress progress, IApplicationPaths appPaths, PackageVersionInfo package, CancellationToken cancellationToken) + public async Task InstallPackage(IProgress progress, PackageVersionInfo package, CancellationToken cancellationToken) { // Target based on if it is an archive or single assembly // zip archives are assumed to contain directory structures relative to our ProgramDataPath var isArchive = string.Equals(Path.GetExtension(package.targetFilename), ".zip", StringComparison.OrdinalIgnoreCase); - var target = Path.Combine(isArchive ? appPaths.TempUpdatePath : appPaths.PluginsPath, package.targetFilename); + var target = Path.Combine(isArchive ? _appPaths.TempUpdatePath : _appPaths.PluginsPath, package.targetFilename); // Download to temporary file so that, if interrupted, it won't destroy the existing installation - var tempFile = await client.GetTempFile(package.sourceUrl, resourcePool.Mb, cancellationToken, progress).ConfigureAwait(false); + var tempFile = await _httpClient.GetTempFile(package.sourceUrl, cancellationToken, progress).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); @@ -79,7 +99,7 @@ namespace MediaBrowser.Common.Implementations.Updates } catch (IOException e) { - logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target); + _logger.ErrorException("Error attempting to move file from {0} to {1}", e, tempFile, target); throw; } diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs new file mode 100644 index 0000000000..fc74a6a4d0 --- /dev/null +++ b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs @@ -0,0 +1,68 @@ +using MediaBrowser.Model.Serialization; +using System; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Common.Configuration +{ + /// + /// Class ConfigurationHelper + /// + public static class ConfigurationHelper + { + /// + /// Reads an xml configuration file from the file system + /// It will immediately re-serialize and save if new serialization data is available due to property changes + /// + /// The type. + /// The path. + /// The XML serializer. + /// System.Object. + public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer) + { + object configuration; + + byte[] buffer = null; + + // Use try/catch to avoid the extra file system lookup using File.Exists + try + { + buffer = File.ReadAllBytes(path); + + configuration = xmlSerializer.DeserializeFromBytes(type, buffer); + } + catch (FileNotFoundException) + { + configuration = Activator.CreateInstance(type); + } + + // Take the object we just got and serialize it back to bytes + var newBytes = xmlSerializer.SerializeToBytes(configuration); + + // If the file didn't exist before, or if something has changed, re-save + if (buffer == null || !buffer.SequenceEqual(newBytes)) + { + // Save it after load in case we got new items + File.WriteAllBytes(path, newBytes); + } + + return configuration; + } + + + /// + /// Reads an xml configuration file from the file system + /// It will immediately save the configuration after loading it, just + /// in case there are new serializable properties + /// + /// + /// The path. + /// The XML serializer. + /// ``0. + public static T GetXmlConfiguration(string path, IXmlSerializer xmlSerializer) + where T : class + { + return GetXmlConfiguration(typeof(T), path, xmlSerializer) as T; + } + } +} diff --git a/MediaBrowser.Common/Kernel/IApplicationPaths.cs b/MediaBrowser.Common/Configuration/IApplicationPaths.cs similarity index 98% rename from MediaBrowser.Common/Kernel/IApplicationPaths.cs rename to MediaBrowser.Common/Configuration/IApplicationPaths.cs index 52c3b199d8..d2446ce46d 100644 --- a/MediaBrowser.Common/Kernel/IApplicationPaths.cs +++ b/MediaBrowser.Common/Configuration/IApplicationPaths.cs @@ -1,5 +1,5 @@  -namespace MediaBrowser.Common.Kernel +namespace MediaBrowser.Common.Configuration { /// /// Interface IApplicationPaths diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.cs new file mode 100644 index 0000000000..0d0759b666 --- /dev/null +++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs @@ -0,0 +1,36 @@ +using MediaBrowser.Model.Configuration; +using System; + +namespace MediaBrowser.Common.Configuration +{ + public interface IConfigurationManager + { + /// + /// Occurs when [configuration updated]. + /// + event EventHandler ConfigurationUpdated; + + /// + /// Gets or sets the application paths. + /// + /// The application paths. + IApplicationPaths CommonApplicationPaths { get; } + + /// + /// Gets the configuration. + /// + /// The configuration. + BaseApplicationConfiguration CommonConfiguration { get; } + + /// + /// Saves the configuration. + /// + void SaveConfiguration(); + + /// + /// Replaces the configuration. + /// + /// The new configuration. + void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration); + } +} diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs similarity index 93% rename from MediaBrowser.Common/Kernel/IApplicationHost.cs rename to MediaBrowser.Common/IApplicationHost.cs index 38a1cb3180..4bd90e531e 100644 --- a/MediaBrowser.Common/Kernel/IApplicationHost.cs +++ b/MediaBrowser.Common/IApplicationHost.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace MediaBrowser.Common.Kernel +namespace MediaBrowser.Common { /// /// An interface to be implemented by the applications hosting a kernel @@ -17,12 +17,6 @@ namespace MediaBrowser.Common.Kernel /// void Restart(); - /// - /// Configures the auto run at startup. - /// - /// if set to true [autorun]. - void ConfigureAutoRunAtStartup(bool autorun); - /// /// Gets the application version. /// diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 489423d9eb..cf8133e977 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -1,45 +1,21 @@ -using MediaBrowser.Common.Events; -using MediaBrowser.Common.Security; -using MediaBrowser.Model.Configuration; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Events; using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; using System; -using System.IO; -using System.Linq; -using System.Threading; namespace MediaBrowser.Common.Kernel { /// /// Represents a shared base kernel for both the Ui and server apps /// - /// The type of the T configuration type. - /// The type of the T application paths type. - public abstract class BaseKernel : IDisposable, IKernel - where TConfigurationType : BaseApplicationConfiguration, new() - where TApplicationPathsType : IApplicationPaths + public abstract class BaseKernel : IKernel { /// /// Occurs when [has pending restart changed]. /// public event EventHandler HasPendingRestartChanged; - #region ConfigurationUpdated Event - /// - /// Occurs when [configuration updated]. - /// - public event EventHandler ConfigurationUpdated; - - /// - /// Called when [configuration updated]. - /// - internal void OnConfigurationUpdated() - { - EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger); - } - #endregion - #region ApplicationUpdated Event /// /// Occurs when [application updated]. @@ -57,65 +33,12 @@ namespace MediaBrowser.Common.Kernel } #endregion - /// - /// The _configuration loaded - /// - private bool _configurationLoaded; - /// - /// The _configuration sync lock - /// - private object _configurationSyncLock = new object(); - /// - /// The _configuration - /// - private TConfigurationType _configuration; - /// - /// Gets the system configuration - /// - /// The configuration. - public TConfigurationType Configuration - { - get - { - // Lazy load - LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => GetXmlConfiguration(ApplicationPaths.SystemConfigurationFilePath)); - return _configuration; - } - protected set - { - _configuration = value; - - if (value == null) - { - _configurationLoaded = false; - } - } - } - /// /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart. /// /// true if this instance has pending application restart; otherwise, false. public bool HasPendingRestart { get; private set; } - /// - /// Gets the application paths. - /// - /// The application paths. - public TApplicationPathsType ApplicationPaths { get; private set; } - - /// - /// Gets or sets the TCP manager. - /// - /// The TCP manager. - private IServerManager ServerManager { get; set; } - - /// - /// Gets the plug-in security manager. - /// - /// The plug-in security manager. - public ISecurityManager SecurityManager { get; set; } - /// /// Gets the UDP server port number. /// This can't be configurable because then the user would have to configure their client to discover the server. @@ -141,7 +64,7 @@ namespace MediaBrowser.Common.Kernel { get { - return "http://+:" + Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"; + return "http://+:" + _configurationManager.CommonConfiguration.HttpServerPortNumber + "/" + WebApplicationName + "/"; } } @@ -163,25 +86,18 @@ namespace MediaBrowser.Common.Kernel /// The application host. protected IApplicationHost ApplicationHost { get; private set; } - /// - /// The _XML serializer - /// - private readonly IXmlSerializer _xmlSerializer; + private readonly IConfigurationManager _configurationManager; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The app host. - /// The app paths. - /// The XML serializer. - /// The logger. - /// isoManager - protected BaseKernel(IApplicationHost appHost, TApplicationPathsType appPaths, IXmlSerializer xmlSerializer, ILogger logger) + /// The log manager. + protected BaseKernel(IApplicationHost appHost, ILogManager logManager, IConfigurationManager configurationManager) { - ApplicationPaths = appPaths; ApplicationHost = appHost; - _xmlSerializer = xmlSerializer; - Logger = logger; + _configurationManager = configurationManager; + Logger = logManager.GetLogger("Kernel"); } /// @@ -201,7 +117,6 @@ namespace MediaBrowser.Common.Kernel /// Task. protected virtual void ReloadInternal() { - ServerManager = ApplicationHost.Resolve(); } /// @@ -214,24 +129,6 @@ namespace MediaBrowser.Common.Kernel EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger); } - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - - } - /// /// Performs the pending restart. /// @@ -261,108 +158,10 @@ namespace MediaBrowser.Common.Kernel HasPendingRestart = HasPendingRestart, Version = ApplicationHost.ApplicationVersion.ToString(), IsNetworkDeployed = ApplicationHost.CanSelfUpdate, - WebSocketPortNumber = ServerManager.WebSocketPortNumber, - SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket, + WebSocketPortNumber = ApplicationHost.Resolve().WebSocketPortNumber, + SupportsNativeWebSocket = ApplicationHost.Resolve().SupportsNativeWebSocket, FailedPluginAssemblies = ApplicationHost.FailedAssemblies.ToArray() }; } - - /// - /// The _save lock - /// - private readonly object _configurationSaveLock = new object(); - - /// - /// Saves the current configuration - /// - public void SaveConfiguration() - { - lock (_configurationSaveLock) - { - _xmlSerializer.SerializeToFile(Configuration, ApplicationPaths.SystemConfigurationFilePath); - } - - OnConfigurationUpdated(); - } - - /// - /// Gets the application paths. - /// - /// The application paths. - IApplicationPaths IKernel.ApplicationPaths - { - get { return ApplicationPaths; } - } - /// - /// Gets the configuration. - /// - /// The configuration. - BaseApplicationConfiguration IKernel.Configuration - { - get { return Configuration; } - } - - /// - /// Reads an xml configuration file from the file system - /// It will immediately re-serialize and save if new serialization data is available due to property changes - /// - /// The type. - /// The path. - /// System.Object. - public object GetXmlConfiguration(Type type, string path) - { - Logger.Info("Loading {0} at {1}", type.Name, path); - - object configuration; - - byte[] buffer = null; - - // Use try/catch to avoid the extra file system lookup using File.Exists - try - { - buffer = File.ReadAllBytes(path); - - configuration = _xmlSerializer.DeserializeFromBytes(type, buffer); - } - catch (FileNotFoundException) - { - configuration = Activator.CreateInstance(type); - } - - // Take the object we just got and serialize it back to bytes - var newBytes = _xmlSerializer.SerializeToBytes(configuration); - - // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) - { - Logger.Info("Saving {0} to {1}", type.Name, path); - - // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); - } - - return configuration; - } - - - /// - /// Reads an xml configuration file from the file system - /// It will immediately save the configuration after loading it, just - /// in case there are new serializable properties - /// - /// - /// The path. - /// ``0. - private T GetXmlConfiguration(string path) - where T : class - { - return GetXmlConfiguration(typeof(T), path) as T; - } - - /// - /// Limits simultaneous access to various resources - /// - /// The resource pools. - public ResourcePool ResourcePools { get; set; } } } diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs index 1a2d86d7f2..51677677ac 100644 --- a/MediaBrowser.Common/Kernel/IKernel.cs +++ b/MediaBrowser.Common/Kernel/IKernel.cs @@ -1,35 +1,18 @@ -using MediaBrowser.Common.Plugins; -using MediaBrowser.Common.Security; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.System; +using MediaBrowser.Model.System; using System; -using System.Collections.Generic; -using System.Threading.Tasks; namespace MediaBrowser.Common.Kernel { /// /// Interface IKernel /// - public interface IKernel : IDisposable + public interface IKernel { /// /// Occurs when [has pending restart changed]. /// event EventHandler HasPendingRestartChanged; - /// - /// Gets the application paths. - /// - /// The application paths. - IApplicationPaths ApplicationPaths { get; } - - /// - /// Gets the configuration. - /// - /// The configuration. - BaseApplicationConfiguration Configuration { get; } - /// /// Gets the kernel context. /// @@ -83,34 +66,9 @@ namespace MediaBrowser.Common.Kernel /// The HTTP server URL prefix. string HttpServerUrlPrefix { get; } - /// - /// Gets the plug-in security manager. - /// - /// The plug-in security manager. - ISecurityManager SecurityManager { get; set; } - - /// - /// Occurs when [configuration updated]. - /// - event EventHandler ConfigurationUpdated; - /// /// Notifies the pending restart. /// void NotifyPendingRestart(); - - /// - /// Gets the XML configuration. - /// - /// The type. - /// The path. - /// System.Object. - object GetXmlConfiguration(Type type, string path); - - /// - /// Limits simultaneous access to various resources - /// - /// The resource pools. - ResourcePool ResourcePools { get; set; } } } diff --git a/MediaBrowser.Common/Kernel/ResourcePool.cs b/MediaBrowser.Common/Kernel/ResourcePool.cs deleted file mode 100644 index 8a2ab8af8e..0000000000 --- a/MediaBrowser.Common/Kernel/ResourcePool.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Threading; - -namespace MediaBrowser.Common.Kernel -{ - /// - /// This is just a collection of semaphores to control the number of concurrent executions of various resources - /// - public class ResourcePool : IDisposable - { - /// - /// You tube - /// - public readonly SemaphoreSlim YouTube = new SemaphoreSlim(5, 5); - - /// - /// The trakt - /// - public readonly SemaphoreSlim Trakt = new SemaphoreSlim(5, 5); - - /// - /// The tv db - /// - public readonly SemaphoreSlim TvDb = new SemaphoreSlim(5, 5); - - /// - /// The movie db - /// - public readonly SemaphoreSlim MovieDb = new SemaphoreSlim(5, 5); - - /// - /// The fan art - /// - public readonly SemaphoreSlim FanArt = new SemaphoreSlim(5, 5); - - /// - /// The mb - /// - public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5); - - /// - /// Apple doesn't seem to like too many simulataneous requests. - /// - public readonly SemaphoreSlim AppleTrailerVideos = new SemaphoreSlim(1, 1); - - /// - /// The apple trailer images - /// - public readonly SemaphoreSlim AppleTrailerImages = new SemaphoreSlim(1, 1); - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - if (dispose) - { - YouTube.Dispose(); - Trakt.Dispose(); - TvDb.Dispose(); - MovieDb.Dispose(); - FanArt.Dispose(); - Mb.Dispose(); - AppleTrailerVideos.Dispose(); - AppleTrailerImages.Dispose(); - } - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 284649b53d..8b7aae9cb1 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -46,6 +46,8 @@ Properties\SharedVersion.cs + + @@ -58,14 +60,11 @@ - + - + - - - @@ -97,7 +96,6 @@ - diff --git a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs deleted file mode 100644 index 5d26c7e920..0000000000 --- a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs +++ /dev/null @@ -1,808 +0,0 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.Kernel; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Globalization; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net.Handlers -{ - /// - /// Class BaseHandler - /// - public abstract class BaseHandler : IHttpServerHandler - where TKernelType : IKernel - { - /// - /// Initializes the specified kernel. - /// - /// The kernel. - public void Initialize(IKernel kernel) - { - Kernel = (TKernelType)kernel; - } - - /// - /// Gets or sets the kernel. - /// - /// The kernel. - protected TKernelType Kernel { get; private set; } - - /// - /// Gets the URL suffix used to determine if this handler can process a request. - /// - /// The URL suffix. - protected virtual string UrlSuffix - { - get - { - var name = GetType().Name; - - const string srch = "Handler"; - - if (name.EndsWith(srch, StringComparison.OrdinalIgnoreCase)) - { - name = name.Substring(0, name.Length - srch.Length); - } - - return "api/" + name; - } - } - - /// - /// Handleses the request. - /// - /// The request. - /// true if XXXX, false otherwise - public virtual bool HandlesRequest(HttpListenerRequest request) - { - var name = '/' + UrlSuffix.TrimStart('/'); - - var url = Kernel.WebApplicationName + name; - - return request.Url.LocalPath.EndsWith(url, StringComparison.OrdinalIgnoreCase); - } - - /// - /// Gets or sets the compressed stream. - /// - /// The compressed stream. - private Stream CompressedStream { get; set; } - - /// - /// Gets a value indicating whether [use chunked encoding]. - /// - /// null if [use chunked encoding] contains no value, true if [use chunked encoding]; otherwise, false. - public virtual bool? UseChunkedEncoding - { - get - { - return null; - } - } - - /// - /// The original HttpListenerContext - /// - /// The HTTP listener context. - protected HttpListenerContext HttpListenerContext { get; set; } - - /// - /// The _query string - /// - private NameValueCollection _queryString; - /// - /// The original QueryString - /// - /// The query string. - public NameValueCollection QueryString - { - get - { - // HttpListenerContext.Request.QueryString is not decoded properly - return _queryString; - } - } - - /// - /// The _requested ranges - /// - private List> _requestedRanges; - /// - /// Gets the requested ranges. - /// - /// The requested ranges. - protected IEnumerable> RequestedRanges - { - get - { - if (_requestedRanges == null) - { - _requestedRanges = new List>(); - - if (IsRangeRequest) - { - // Example: bytes=0-,32-63 - var ranges = HttpListenerContext.Request.Headers["Range"].Split('=')[1].Split(','); - - foreach (var range in ranges) - { - var vals = range.Split('-'); - - long start = 0; - long? end = null; - - if (!string.IsNullOrEmpty(vals[0])) - { - start = long.Parse(vals[0]); - } - if (!string.IsNullOrEmpty(vals[1])) - { - end = long.Parse(vals[1]); - } - - _requestedRanges.Add(new KeyValuePair(start, end)); - } - } - } - - return _requestedRanges; - } - } - - /// - /// Gets a value indicating whether this instance is range request. - /// - /// true if this instance is range request; otherwise, false. - protected bool IsRangeRequest - { - get - { - return HttpListenerContext.Request.Headers.AllKeys.Contains("Range"); - } - } - - /// - /// Gets a value indicating whether [client supports compression]. - /// - /// true if [client supports compression]; otherwise, false. - protected bool ClientSupportsCompression - { - get - { - var enc = HttpListenerContext.Request.Headers["Accept-Encoding"] ?? string.Empty; - - return enc.Equals("*", StringComparison.OrdinalIgnoreCase) || - enc.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) != -1 || - enc.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) != -1; - } - } - - /// - /// Gets the compression method. - /// - /// The compression method. - private string CompressionMethod - { - get - { - var enc = HttpListenerContext.Request.Headers["Accept-Encoding"] ?? string.Empty; - - if (enc.IndexOf("deflate", StringComparison.OrdinalIgnoreCase) != -1 || enc.Equals("*", StringComparison.OrdinalIgnoreCase)) - { - return "deflate"; - } - if (enc.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) != -1) - { - return "gzip"; - } - - return null; - } - } - - /// - /// Processes the request. - /// - /// The CTX. - /// Task. - public virtual async Task ProcessRequest(HttpListenerContext ctx) - { - HttpListenerContext = ctx; - - ctx.Response.AddHeader("Access-Control-Allow-Origin", "*"); - - ctx.Response.KeepAlive = true; - - try - { - await ProcessRequestInternal(ctx).ConfigureAwait(false); - } - catch (InvalidOperationException ex) - { - HandleException(ctx.Response, ex, 422); - - throw; - } - catch (ResourceNotFoundException ex) - { - HandleException(ctx.Response, ex, 404); - - throw; - } - catch (FileNotFoundException ex) - { - HandleException(ctx.Response, ex, 404); - - throw; - } - catch (DirectoryNotFoundException ex) - { - HandleException(ctx.Response, ex, 404); - - throw; - } - catch (UnauthorizedAccessException ex) - { - HandleException(ctx.Response, ex, 401); - - throw; - } - catch (ArgumentException ex) - { - HandleException(ctx.Response, ex, 400); - - throw; - } - catch (Exception ex) - { - HandleException(ctx.Response, ex, 500); - - throw; - } - finally - { - DisposeResponseStream(); - } - } - - /// - /// Appends the error message. - /// - /// The response. - /// The ex. - /// The status code. - private void HandleException(HttpListenerResponse response, Exception ex, int statusCode) - { - response.StatusCode = statusCode; - - response.Headers.Add("Status", statusCode.ToString(new CultureInfo("en-US"))); - - response.Headers.Remove("Age"); - response.Headers.Remove("Expires"); - response.Headers.Remove("Cache-Control"); - response.Headers.Remove("Etag"); - response.Headers.Remove("Last-Modified"); - - response.ContentType = "text/plain"; - - //Logger.ErrorException("Error processing request", ex); - - if (!string.IsNullOrEmpty(ex.Message)) - { - response.AddHeader("X-Application-Error-Code", ex.Message); - } - - var bytes = Encoding.UTF8.GetBytes(ex.Message); - - var stream = CompressedStream ?? response.OutputStream; - - // This could fail, but try to add the stack trace as the body content - try - { - stream.Write(bytes, 0, bytes.Length); - } - catch (Exception ex1) - { - //Logger.ErrorException("Error dumping stack trace", ex1); - } - } - - /// - /// Processes the request internal. - /// - /// The CTX. - /// Task. - private async Task ProcessRequestInternal(HttpListenerContext ctx) - { - var responseInfo = await GetResponseInfo().ConfigureAwait(false); - - // Let the client know if byte range requests are supported or not - if (responseInfo.SupportsByteRangeRequests) - { - ctx.Response.Headers["Accept-Ranges"] = "bytes"; - } - else if (!responseInfo.SupportsByteRangeRequests) - { - ctx.Response.Headers["Accept-Ranges"] = "none"; - } - - if (responseInfo.IsResponseValid && responseInfo.SupportsByteRangeRequests && IsRangeRequest) - { - // Set the initial status code - // When serving a range request, we need to return status code 206 to indicate a partial response body - responseInfo.StatusCode = 206; - } - - ctx.Response.ContentType = responseInfo.ContentType; - - if (responseInfo.Etag.HasValue) - { - ctx.Response.Headers["ETag"] = responseInfo.Etag.Value.ToString("N"); - } - - var isCacheValid = true; - - // Validate If-Modified-Since - if (ctx.Request.Headers.AllKeys.Contains("If-Modified-Since")) - { - DateTime ifModifiedSince; - - if (DateTime.TryParse(ctx.Request.Headers["If-Modified-Since"], out ifModifiedSince)) - { - isCacheValid = IsCacheValid(ifModifiedSince.ToUniversalTime(), responseInfo.CacheDuration, - responseInfo.DateLastModified); - } - } - - // Validate If-None-Match - if (isCacheValid && - (responseInfo.Etag.HasValue || !string.IsNullOrEmpty(ctx.Request.Headers["If-None-Match"]))) - { - Guid ifNoneMatch; - - if (Guid.TryParse(ctx.Request.Headers["If-None-Match"] ?? string.Empty, out ifNoneMatch)) - { - if (responseInfo.Etag.HasValue && responseInfo.Etag.Value == ifNoneMatch) - { - responseInfo.StatusCode = 304; - } - } - } - - LogResponse(ctx, responseInfo); - - if (responseInfo.IsResponseValid) - { - await OnProcessingRequest(responseInfo).ConfigureAwait(false); - } - - if (responseInfo.IsResponseValid) - { - await ProcessUncachedRequest(ctx, responseInfo).ConfigureAwait(false); - } - else - { - if (responseInfo.StatusCode == 304) - { - AddAgeHeader(ctx.Response, responseInfo); - AddExpiresHeader(ctx.Response, responseInfo); - } - - ctx.Response.StatusCode = responseInfo.StatusCode; - ctx.Response.SendChunked = false; - } - } - - /// - /// The _null task result - /// - private readonly Task _nullTaskResult = Task.FromResult(true); - - /// - /// Called when [processing request]. - /// - /// The response info. - /// Task. - protected virtual Task OnProcessingRequest(ResponseInfo responseInfo) - { - return _nullTaskResult; - } - - /// - /// Logs the response. - /// - /// The CTX. - /// The response info. - private void LogResponse(HttpListenerContext ctx, ResponseInfo responseInfo) - { - // Don't log normal 200's - if (responseInfo.StatusCode == 200) - { - return; - } - - var log = new StringBuilder(); - - log.AppendLine(string.Format("Url: {0}", ctx.Request.Url)); - - log.AppendLine("Headers: " + string.Join(",", ctx.Response.Headers.AllKeys.Select(k => k + "=" + ctx.Response.Headers[k]))); - - var msg = "Http Response Sent (" + responseInfo.StatusCode + ") to " + ctx.Request.RemoteEndPoint; - - if (Kernel.Configuration.EnableHttpLevelLogging) - { - //Logger.LogMultiline(msg, LogSeverity.Debug, log); - } - } - - /// - /// Processes the uncached request. - /// - /// The CTX. - /// The response info. - /// Task. - private async Task ProcessUncachedRequest(HttpListenerContext ctx, ResponseInfo responseInfo) - { - var totalContentLength = GetTotalContentLength(responseInfo); - - // By default, use chunked encoding if we don't know the content length - var useChunkedEncoding = UseChunkedEncoding == null ? (totalContentLength == null) : UseChunkedEncoding.Value; - - // Don't force this to true. HttpListener will default it to true if supported by the client. - if (!useChunkedEncoding) - { - ctx.Response.SendChunked = false; - } - - // Set the content length, if we know it - if (totalContentLength.HasValue) - { - ctx.Response.ContentLength64 = totalContentLength.Value; - } - - var compressResponse = responseInfo.CompressResponse && ClientSupportsCompression; - - // Add the compression header - if (compressResponse) - { - ctx.Response.AddHeader("Content-Encoding", CompressionMethod); - ctx.Response.AddHeader("Vary", "Accept-Encoding"); - } - - // Don't specify both last modified and Etag, unless caching unconditionally. They are redundant - // https://developers.google.com/speed/docs/best-practices/caching#LeverageBrowserCaching - if (responseInfo.DateLastModified.HasValue && (!responseInfo.Etag.HasValue || responseInfo.CacheDuration.Ticks > 0)) - { - ctx.Response.Headers[HttpResponseHeader.LastModified] = responseInfo.DateLastModified.Value.ToString("r"); - AddAgeHeader(ctx.Response, responseInfo); - } - - // Add caching headers - ConfigureCaching(ctx.Response, responseInfo); - - // Set the status code - ctx.Response.StatusCode = responseInfo.StatusCode; - - if (responseInfo.IsResponseValid) - { - // Finally, write the response data - var outputStream = ctx.Response.OutputStream; - - if (compressResponse) - { - if (CompressionMethod.Equals("deflate", StringComparison.OrdinalIgnoreCase)) - { - CompressedStream = new DeflateStream(outputStream, CompressionLevel.Fastest, true); - } - else - { - CompressedStream = new GZipStream(outputStream, CompressionLevel.Fastest, true); - } - - outputStream = CompressedStream; - } - - await WriteResponseToOutputStream(outputStream, responseInfo, totalContentLength).ConfigureAwait(false); - } - else - { - ctx.Response.SendChunked = false; - } - } - - /// - /// Configures the caching. - /// - /// The response. - /// The response info. - private void ConfigureCaching(HttpListenerResponse response, ResponseInfo responseInfo) - { - if (responseInfo.CacheDuration.Ticks > 0) - { - response.Headers[HttpResponseHeader.CacheControl] = "public, max-age=" + Convert.ToInt32(responseInfo.CacheDuration.TotalSeconds); - } - else if (responseInfo.Etag.HasValue) - { - response.Headers[HttpResponseHeader.CacheControl] = "public"; - } - else - { - response.Headers[HttpResponseHeader.CacheControl] = "no-cache, no-store, must-revalidate"; - response.Headers[HttpResponseHeader.Pragma] = "no-cache, no-store, must-revalidate"; - } - - AddExpiresHeader(response, responseInfo); - } - - /// - /// Adds the expires header. - /// - /// The response. - /// The response info. - private void AddExpiresHeader(HttpListenerResponse response, ResponseInfo responseInfo) - { - if (responseInfo.CacheDuration.Ticks > 0) - { - response.Headers[HttpResponseHeader.Expires] = DateTime.UtcNow.Add(responseInfo.CacheDuration).ToString("r"); - } - else if (!responseInfo.Etag.HasValue) - { - response.Headers[HttpResponseHeader.Expires] = "-1"; - } - } - - /// - /// Adds the age header. - /// - /// The response. - /// The response info. - private void AddAgeHeader(HttpListenerResponse response, ResponseInfo responseInfo) - { - if (responseInfo.DateLastModified.HasValue) - { - response.Headers[HttpResponseHeader.Age] = Convert.ToInt32((DateTime.UtcNow - responseInfo.DateLastModified.Value).TotalSeconds).ToString(CultureInfo.InvariantCulture); - } - } - - /// - /// Writes the response to output stream. - /// - /// The stream. - /// The response info. - /// Length of the content. - /// Task. - protected abstract Task WriteResponseToOutputStream(Stream stream, ResponseInfo responseInfo, long? contentLength); - - /// - /// Disposes the response stream. - /// - protected virtual void DisposeResponseStream() - { - if (CompressedStream != null) - { - try - { - CompressedStream.Dispose(); - } - catch (Exception ex) - { - //Logger.ErrorException("Error disposing compressed stream", ex); - } - } - - try - { - //HttpListenerContext.Response.OutputStream.Dispose(); - HttpListenerContext.Response.Close(); - } - catch (Exception ex) - { - //Logger.ErrorException("Error disposing response", ex); - } - } - - /// - /// Determines whether [is cache valid] [the specified if modified since]. - /// - /// If modified since. - /// Duration of the cache. - /// The date modified. - /// true if [is cache valid] [the specified if modified since]; otherwise, false. - private bool IsCacheValid(DateTime ifModifiedSince, TimeSpan cacheDuration, DateTime? dateModified) - { - if (dateModified.HasValue) - { - DateTime lastModified = NormalizeDateForComparison(dateModified.Value); - ifModifiedSince = NormalizeDateForComparison(ifModifiedSince); - - return lastModified <= ifModifiedSince; - } - - DateTime cacheExpirationDate = ifModifiedSince.Add(cacheDuration); - - if (DateTime.UtcNow < cacheExpirationDate) - { - return true; - } - - return false; - } - - /// - /// When the browser sends the IfModifiedDate, it's precision is limited to seconds, so this will account for that - /// - /// The date. - /// DateTime. - private DateTime NormalizeDateForComparison(DateTime date) - { - return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind); - } - - /// - /// Gets the total length of the content. - /// - /// The response info. - /// System.Nullable{System.Int64}. - protected virtual long? GetTotalContentLength(ResponseInfo responseInfo) - { - return null; - } - - /// - /// Gets the response info. - /// - /// Task{ResponseInfo}. - protected abstract Task GetResponseInfo(); - - /// - /// Gets a bool query string param. - /// - /// The name. - /// true if XXXX, false otherwise - protected bool GetBoolQueryStringParam(string name) - { - var val = QueryString[name] ?? string.Empty; - - return val.Equals("1", StringComparison.OrdinalIgnoreCase) || val.Equals("true", StringComparison.OrdinalIgnoreCase); - } - - /// - /// The _form values - /// - private Hashtable _formValues; - - /// - /// Gets a value from form POST data - /// - /// The name. - /// Task{System.String}. - protected async Task GetFormValue(string name) - { - if (_formValues == null) - { - _formValues = await GetFormValues(HttpListenerContext.Request).ConfigureAwait(false); - } - - if (_formValues.ContainsKey(name)) - { - return _formValues[name].ToString(); - } - - return null; - } - - /// - /// Extracts form POST data from a request - /// - /// The request. - /// Task{Hashtable}. - private async Task GetFormValues(HttpListenerRequest request) - { - var formVars = new Hashtable(); - - if (request.HasEntityBody) - { - if (request.ContentType.IndexOf("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase) != -1) - { - using (var requestBody = request.InputStream) - { - using (var reader = new StreamReader(requestBody, request.ContentEncoding)) - { - var s = await reader.ReadToEndAsync().ConfigureAwait(false); - - var pairs = s.Split('&'); - - foreach (var pair in pairs) - { - var index = pair.IndexOf('='); - - if (index != -1) - { - var name = pair.Substring(0, index); - var value = pair.Substring(index + 1); - formVars.Add(name, value); - } - } - } - } - } - } - - return formVars; - } - } - - /// - /// Class ResponseInfo - /// - public class ResponseInfo - { - /// - /// Gets or sets the type of the content. - /// - /// The type of the content. - public string ContentType { get; set; } - /// - /// Gets or sets the etag. - /// - /// The etag. - public Guid? Etag { get; set; } - /// - /// Gets or sets the date last modified. - /// - /// The date last modified. - public DateTime? DateLastModified { get; set; } - /// - /// Gets or sets the duration of the cache. - /// - /// The duration of the cache. - public TimeSpan CacheDuration { get; set; } - /// - /// Gets or sets a value indicating whether [compress response]. - /// - /// true if [compress response]; otherwise, false. - public bool CompressResponse { get; set; } - /// - /// Gets or sets the status code. - /// - /// The status code. - public int StatusCode { get; set; } - /// - /// Gets or sets a value indicating whether [supports byte range requests]. - /// - /// true if [supports byte range requests]; otherwise, false. - public bool SupportsByteRangeRequests { get; set; } - - /// - /// Initializes a new instance of the class. - /// - public ResponseInfo() - { - CacheDuration = TimeSpan.FromTicks(0); - - CompressResponse = true; - - StatusCode = 200; - } - - /// - /// Gets a value indicating whether this instance is response valid. - /// - /// true if this instance is response valid; otherwise, false. - public bool IsResponseValid - { - get - { - return StatusCode >= 200 && StatusCode < 300; - } - } - } -} \ No newline at end of file diff --git a/MediaBrowser.Common/Net/Handlers/IHttpServerHandler.cs b/MediaBrowser.Common/Net/Handlers/IHttpServerHandler.cs deleted file mode 100644 index dadd614737..0000000000 --- a/MediaBrowser.Common/Net/Handlers/IHttpServerHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using MediaBrowser.Common.Kernel; -using System.Net; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net.Handlers -{ - /// - /// Interface IHttpServerHandler - /// - public interface IHttpServerHandler - { - /// - /// Initializes the specified kernel. - /// - /// The kernel. - void Initialize(IKernel kernel); - - /// - /// Handleses the request. - /// - /// The request. - /// true if XXXX, false otherwise - bool HandlesRequest(HttpListenerRequest request); - - /// - /// Processes the request. - /// - /// The CTX. - /// Task. - Task ProcessRequest(HttpListenerContext ctx); - } -} diff --git a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs deleted file mode 100644 index 3967d15c35..0000000000 --- a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs +++ /dev/null @@ -1,264 +0,0 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Common.IO; -using MediaBrowser.Common.Kernel; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net.Handlers -{ - /// - /// Represents an http handler that serves static content - /// - public class StaticFileHandler : BaseHandler - { - /// - /// Initializes a new instance of the class. - /// - /// The kernel. - public StaticFileHandler(IKernel kernel) - { - Initialize(kernel); - } - - /// - /// The _path - /// - private string _path; - /// - /// Gets or sets the path to the static resource - /// - /// The path. - public string Path - { - get - { - if (!string.IsNullOrWhiteSpace(_path)) - { - return _path; - } - - return QueryString["path"]; - } - set - { - _path = value; - } - } - - /// - /// Gets or sets the last date modified of the resource - /// - /// The last date modified. - public DateTime? LastDateModified { get; set; } - - /// - /// Gets or sets the content type of the resource - /// - /// The type of the content. - public string ContentType { get; set; } - - /// - /// Gets or sets the content type of the resource - /// - /// The etag. - public Guid Etag { get; set; } - - /// - /// Gets or sets the source stream of the resource - /// - /// The source stream. - public Stream SourceStream { get; set; } - - /// - /// Shoulds the compress response. - /// - /// Type of the content. - /// true if XXXX, false otherwise - private bool ShouldCompressResponse(string contentType) - { - // It will take some work to support compression with byte range requests - if (IsRangeRequest) - { - return false; - } - - // Don't compress media - if (contentType.StartsWith("audio/", StringComparison.OrdinalIgnoreCase) || contentType.StartsWith("video/", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - // Don't compress images - if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - return true; - } - - /// - /// Gets or sets the duration of the cache. - /// - /// The duration of the cache. - public TimeSpan? CacheDuration { get; set; } - - /// - /// Gets the total length of the content. - /// - /// The response info. - /// System.Nullable{System.Int64}. - protected override long? GetTotalContentLength(ResponseInfo responseInfo) - { - // If we're compressing the response, content length must be the compressed length, which we don't know - if (responseInfo.CompressResponse && ClientSupportsCompression) - { - return null; - } - - return SourceStream.Length; - } - - /// - /// Gets the response info. - /// - /// Task{ResponseInfo}. - protected override Task GetResponseInfo() - { - var info = new ResponseInfo - { - ContentType = ContentType ?? MimeTypes.GetMimeType(Path), - Etag = Etag, - DateLastModified = LastDateModified - }; - - if (SourceStream == null && !string.IsNullOrEmpty(Path)) - { - // FileShare must be ReadWrite in case someone else is currently writing to it. - SourceStream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); - } - - info.CompressResponse = ShouldCompressResponse(info.ContentType); - - info.SupportsByteRangeRequests = !info.CompressResponse || !ClientSupportsCompression; - - if (!info.DateLastModified.HasValue && !string.IsNullOrWhiteSpace(Path)) - { - info.DateLastModified = File.GetLastWriteTimeUtc(Path); - } - - if (CacheDuration.HasValue) - { - info.CacheDuration = CacheDuration.Value; - } - - if (SourceStream == null && string.IsNullOrEmpty(Path)) - { - throw new ResourceNotFoundException(); - } - - return Task.FromResult(info); - } - - /// - /// Writes the response to output stream. - /// - /// The stream. - /// The response info. - /// Total length of the content. - /// Task. - protected override Task WriteResponseToOutputStream(Stream stream, ResponseInfo responseInfo, long? totalContentLength) - { - if (IsRangeRequest && totalContentLength.HasValue) - { - var requestedRange = RequestedRanges.First(); - - // If the requested range is "0-", we can optimize by just doing a stream copy - if (!requestedRange.Value.HasValue) - { - return ServeCompleteRangeRequest(requestedRange, stream, totalContentLength.Value); - } - - // This will have to buffer a portion of the content into memory - return ServePartialRangeRequest(requestedRange.Key, requestedRange.Value.Value, stream, totalContentLength.Value); - } - - return SourceStream.CopyToAsync(stream); - } - - /// - /// Disposes the response stream. - /// - protected override void DisposeResponseStream() - { - if (SourceStream != null) - { - SourceStream.Dispose(); - } - - base.DisposeResponseStream(); - } - - /// - /// Handles a range request of "bytes=0-" - /// This will serve the complete content and add the content-range header - /// - /// The requested range. - /// The response stream. - /// Total length of the content. - /// Task. - private Task ServeCompleteRangeRequest(KeyValuePair requestedRange, Stream responseStream, long totalContentLength) - { - var rangeStart = requestedRange.Key; - var rangeEnd = totalContentLength - 1; - var rangeLength = 1 + rangeEnd - rangeStart; - - // Content-Length is the length of what we're serving, not the original content - HttpListenerContext.Response.ContentLength64 = rangeLength; - HttpListenerContext.Response.Headers["Content-Range"] = string.Format("bytes {0}-{1}/{2}", rangeStart, rangeEnd, totalContentLength); - - if (rangeStart > 0) - { - SourceStream.Position = rangeStart; - } - - return SourceStream.CopyToAsync(responseStream); - } - - /// - /// Serves a partial range request - /// - /// The range start. - /// The range end. - /// The response stream. - /// Total length of the content. - /// Task. - private async Task ServePartialRangeRequest(long rangeStart, long rangeEnd, Stream responseStream, long totalContentLength) - { - var rangeLength = 1 + rangeEnd - rangeStart; - - // Content-Length is the length of what we're serving, not the original content - HttpListenerContext.Response.ContentLength64 = rangeLength; - HttpListenerContext.Response.Headers["Content-Range"] = string.Format("bytes {0}-{1}/{2}", rangeStart, rangeEnd, totalContentLength); - - SourceStream.Position = rangeStart; - - // Fast track to just copy the stream to the end - if (rangeEnd == totalContentLength - 1) - { - await SourceStream.CopyToAsync(responseStream).ConfigureAwait(false); - } - else - { - // Read the bytes we need - var buffer = new byte[Convert.ToInt32(rangeLength)]; - await SourceStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); - - await responseStream.WriteAsync(buffer, 0, Convert.ToInt32(rangeLength)).ConfigureAwait(false); - } - } - } -} diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index c968a65c82..4cff2eeb98 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -1,4 +1,4 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; using System; @@ -17,22 +17,16 @@ namespace MediaBrowser.Common.Plugins where TConfigurationType : BasePluginConfiguration { /// - /// Gets the kernel. + /// Gets the application paths. /// - /// The kernel. - protected IKernel Kernel { get; private set; } + /// The application paths. + protected IApplicationPaths ApplicationPaths { get; private set; } /// /// Gets the XML serializer. /// /// The XML serializer. protected IXmlSerializer XmlSerializer { get; private set; } - - /// - /// Gets or sets the plugin's current context - /// - /// The context. - protected KernelContext Context { get { return Kernel.KernelContext; } } /// /// Gets the name of the plugin @@ -174,7 +168,7 @@ namespace MediaBrowser.Common.Plugins { get { - return Path.Combine(Kernel.ApplicationPaths.PluginsPath, AssemblyFileName); + return Path.Combine(ApplicationPaths.PluginsPath, AssemblyFileName); } } @@ -199,7 +193,7 @@ namespace MediaBrowser.Common.Plugins get { // Lazy load - LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => Kernel.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath) as TConfigurationType); + LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => ConfigurationHelper.GetXmlConfiguration(ConfigurationType, ConfigurationFilePath, XmlSerializer) as TConfigurationType); return _configuration; } protected set @@ -230,7 +224,7 @@ namespace MediaBrowser.Common.Plugins { get { - return Path.Combine(Kernel.ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName); + return Path.Combine(ApplicationPaths.PluginConfigurationsPath, ConfigurationFileName); } } @@ -250,7 +244,7 @@ namespace MediaBrowser.Common.Plugins { // Give the folder name the same name as the config file name // We can always make this configurable if/when needed - _dataFolderPath = Path.Combine(Kernel.ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName)); + _dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName)); if (!Directory.Exists(_dataFolderPath)) { @@ -265,11 +259,11 @@ namespace MediaBrowser.Common.Plugins /// /// Initializes a new instance of the class. /// - /// The kernel. + /// The application paths. /// The XML serializer. - protected BasePlugin(IKernel kernel, IXmlSerializer xmlSerializer) + protected BasePlugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer) { - Kernel = kernel; + ApplicationPaths = applicationPaths; XmlSerializer = xmlSerializer; } @@ -284,11 +278,6 @@ namespace MediaBrowser.Common.Plugins /// Cannot call Plugin.SaveConfiguration from the UI. public virtual void SaveConfiguration() { - if (Kernel.KernelContext != KernelContext.Server) - { - throw new InvalidOperationException("Cannot call Plugin.SaveConfiguration from the UI."); - } - lock (_configurationSaveLock) { XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath); diff --git a/MediaBrowser.Common/Updates/ApplicationUpdater.cs b/MediaBrowser.Common/Updates/ApplicationUpdater.cs index e157c344b7..a796e1bd2d 100644 --- a/MediaBrowser.Common/Updates/ApplicationUpdater.cs +++ b/MediaBrowser.Common/Updates/ApplicationUpdater.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Kernel; namespace MediaBrowser.Common.Updates diff --git a/MediaBrowser.Common/Updates/IPackageManager.cs b/MediaBrowser.Common/Updates/IPackageManager.cs index 1db5ea7066..ecaf9cef83 100644 --- a/MediaBrowser.Common/Updates/IPackageManager.cs +++ b/MediaBrowser.Common/Updates/IPackageManager.cs @@ -1,16 +1,8 @@ -using System; +using MediaBrowser.Model.Updates; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.Kernel; -using MediaBrowser.Common.Net; -using MediaBrowser.Common.Security; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Updates; namespace MediaBrowser.Common.Updates { @@ -19,37 +11,17 @@ namespace MediaBrowser.Common.Updates /// /// Gets all available packages. /// - /// - /// - /// - /// - /// /// The cancellation token. /// Task{List{PackageInfo}}. - Task> GetAvailablePackages(IHttpClient client, - INetworkManager networkManager, - ISecurityManager securityManager, - ResourcePool resourcePool, - IJsonSerializer serializer, - CancellationToken cancellationToken); + Task> GetAvailablePackages(CancellationToken cancellationToken); /// /// Installs a package. /// - /// - /// - /// /// - /// /// The package. /// The cancellation token. /// Task. - Task InstallPackage(IHttpClient client, - ILogger logger, - ResourcePool resourcePool, - IProgress progress, - IApplicationPaths appPaths, - PackageVersionInfo package, - CancellationToken cancellationToken); + Task InstallPackage(IProgress progress, PackageVersionInfo package, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Configuration/IServerConfigurationManager.cs b/MediaBrowser.Controller/Configuration/IServerConfigurationManager.cs new file mode 100644 index 0000000000..810376f6c6 --- /dev/null +++ b/MediaBrowser.Controller/Configuration/IServerConfigurationManager.cs @@ -0,0 +1,23 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; + +namespace MediaBrowser.Controller.Configuration +{ + /// + /// Interface IServerConfigurationManager + /// + public interface IServerConfigurationManager : IConfigurationManager + { + /// + /// Gets the application paths. + /// + /// The application paths. + IServerApplicationPaths ApplicationPaths { get; } + + /// + /// Gets the configuration. + /// + /// The configuration. + ServerConfiguration Configuration { get; } + } +} diff --git a/MediaBrowser.Controller/Drawing/ImageManager.cs b/MediaBrowser.Controller/Drawing/ImageManager.cs index 766d561156..d95f72df70 100644 --- a/MediaBrowser.Controller/Drawing/ImageManager.cs +++ b/MediaBrowser.Controller/Drawing/ImageManager.cs @@ -66,23 +66,23 @@ namespace MediaBrowser.Controller.Drawing /// The _kernel /// private readonly Kernel _kernel; - + /// /// Initializes a new instance of the class. /// /// The kernel. /// The protobuf serializer. /// The logger. - public ImageManager(Kernel kernel, IProtobufSerializer protobufSerializer, ILogger logger) + public ImageManager(Kernel kernel, IProtobufSerializer protobufSerializer, ILogger logger, IServerApplicationPaths appPaths) { _protobufSerializer = protobufSerializer; _logger = logger; _kernel = kernel; - ImageSizeCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "image-sizes")); - ResizedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "resized-images")); - CroppedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "cropped-images")); - EnhancedImageCache = new FileSystemRepository(Path.Combine(_kernel.ApplicationPaths.ImageCachePath, "enhanced-images")); + ImageSizeCache = new FileSystemRepository(Path.Combine(appPaths.ImageCachePath, "image-sizes")); + ResizedImageCache = new FileSystemRepository(Path.Combine(appPaths.ImageCachePath, "resized-images")); + CroppedImageCache = new FileSystemRepository(Path.Combine(appPaths.ImageCachePath, "cropped-images")); + EnhancedImageCache = new FileSystemRepository(Path.Combine(appPaths.ImageCachePath, "enhanced-images")); } /// diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 47c129dea3..e80c3d71f3 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; @@ -96,6 +98,7 @@ namespace MediaBrowser.Controller.Entities /// protected static internal ILogger Logger { get; internal set; } protected static internal ILibraryManager LibraryManager { get; internal set; } + protected static internal IServerConfigurationManager ConfigurationManager { get; internal set; } /// /// Returns a that represents this instance. @@ -311,7 +314,7 @@ namespace MediaBrowser.Controller.Entities // non file-system entries will not have a path if (string.IsNullOrEmpty(path)) { - return new ItemResolveArgs + return new ItemResolveArgs(ConfigurationManager.ApplicationPaths) { FileInfo = new WIN32_FIND_DATA() }; @@ -329,7 +332,7 @@ namespace MediaBrowser.Controller.Entities throw new IOException("Unable to retrieve file system info for " + path); } - var args = new ItemResolveArgs + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths) { FileInfo = pathInfo.Value, Path = path, @@ -997,7 +1000,7 @@ namespace MediaBrowser.Controller.Entities throw new ArgumentNullException(); } - return (DateTime.UtcNow - DateCreated).TotalDays < Kernel.Instance.Configuration.RecentItemDays; + return (DateTime.UtcNow - DateCreated).TotalDays < ConfigurationManager.Configuration.RecentItemDays; } /// @@ -1020,7 +1023,7 @@ namespace MediaBrowser.Controller.Entities return false; } - return (DateTime.UtcNow - data.LastPlayedDate.Value).TotalDays < Kernel.Instance.Configuration.RecentlyPlayedDays; + return (DateTime.UtcNow - data.LastPlayedDate.Value).TotalDays < ConfigurationManager.Configuration.RecentlyPlayedDays; } /// diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index bf77cdc959..ef50a08671 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Configuration; @@ -18,6 +19,7 @@ namespace MediaBrowser.Controller.Entities public class User : BaseItem { internal static IUserManager UserManager { get; set; } + internal static IXmlSerializer XmlSerializer { get; set; } /// /// The _root folder path @@ -45,7 +47,7 @@ namespace MediaBrowser.Controller.Entities } else { - _rootFolderPath = Kernel.Instance.ApplicationPaths.DefaultUserViewsPath; + _rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; } } return _rootFolderPath; @@ -61,7 +63,7 @@ namespace MediaBrowser.Controller.Entities { var safeFolderName = FileSystem.GetValidFilename(username); - return System.IO.Path.Combine(Kernel.Instance.ApplicationPaths.RootFolderPath, safeFolderName); + return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.RootFolderPath, safeFolderName); } /// @@ -171,7 +173,7 @@ namespace MediaBrowser.Controller.Entities get { // Lazy load - LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => (UserConfiguration)Kernel.Instance.GetXmlConfiguration(typeof(UserConfiguration), ConfigurationFilePath)); + LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationInitialized, ref _configurationSyncLock, () => (UserConfiguration)ConfigurationHelper.GetXmlConfiguration(typeof(UserConfiguration), ConfigurationFilePath, XmlSerializer)); return _configuration; } private set @@ -321,7 +323,7 @@ namespace MediaBrowser.Controller.Entities { var safeFolderName = FileSystem.GetValidFilename(username); - return System.IO.Path.Combine(Kernel.Instance.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName); + return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName); } /// @@ -411,7 +413,7 @@ namespace MediaBrowser.Controller.Entities { var userPath = RootFolderPath; - var defaultPath = Kernel.Instance.ApplicationPaths.DefaultUserViewsPath; + var defaultPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; if (userPath.Equals(defaultPath, StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Controller/IO/DirectoryWatchers.cs b/MediaBrowser.Controller/IO/DirectoryWatchers.cs index 991e4ba430..5789c0240a 100644 --- a/MediaBrowser.Controller/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Controller/IO/DirectoryWatchers.cs @@ -1,5 +1,5 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.ScheduledTasks; @@ -74,16 +74,13 @@ namespace MediaBrowser.Controller.IO private ITaskManager TaskManager { get; set; } private ILibraryManager LibraryManager { get; set; } + private IServerConfigurationManager ConfigurationManager { get; set; } /// /// Initializes a new instance of the class. /// - public DirectoryWatchers(ILogger logger, ITaskManager taskManager, ILibraryManager libraryManager) + public DirectoryWatchers(ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager) { - if (logger == null) - { - throw new ArgumentNullException("logger"); - } if (taskManager == null) { throw new ArgumentNullException("taskManager"); @@ -91,7 +88,8 @@ namespace MediaBrowser.Controller.IO LibraryManager = libraryManager; TaskManager = taskManager; - Logger = logger; + Logger = logManager.GetLogger("DirectoryWatchers"); + ConfigurationManager = configurationManager; } /// @@ -335,11 +333,11 @@ namespace MediaBrowser.Controller.IO { if (updateTimer == null) { - updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(Kernel.Instance.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); + updateTimer = new Timer(TimerStopped, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); } else { - updateTimer.Change(TimeSpan.FromSeconds(Kernel.Instance.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); + updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); } } } @@ -356,7 +354,7 @@ namespace MediaBrowser.Controller.IO if (affectedPaths.Any(p => IsFileLocked(p.Key))) { Logger.Info("Timer extended."); - updateTimer.Change(TimeSpan.FromSeconds(Kernel.Instance.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); + updateTimer.Change(TimeSpan.FromSeconds(ConfigurationManager.Configuration.FileWatcherDelay), TimeSpan.FromMilliseconds(-1)); return; } diff --git a/MediaBrowser.Controller/IO/FileSystemManager.cs b/MediaBrowser.Controller/IO/FileSystemManager.cs index b1695e7b5e..4afc8265fc 100644 --- a/MediaBrowser.Controller/IO/FileSystemManager.cs +++ b/MediaBrowser.Controller/IO/FileSystemManager.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.IO; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; @@ -33,14 +34,15 @@ namespace MediaBrowser.Controller.IO /// Initializes a new instance of the class. /// /// The kernel. - /// The logger. + /// The log manager. /// The task manager. /// The library manager. - public FileSystemManager(Kernel kernel, ILogger logger, ITaskManager taskManager, ILibraryManager libraryManager) + /// The configuration manager. + public FileSystemManager(Kernel kernel, ILogManager logManager, ITaskManager taskManager, ILibraryManager libraryManager, IServerConfigurationManager configurationManager) : base(kernel) { - _logger = logger; - DirectoryWatchers = new DirectoryWatchers(logger, taskManager, libraryManager); + _logger = logManager.GetLogger("FileSystemManager"); + DirectoryWatchers = new DirectoryWatchers(logManager, taskManager, libraryManager, configurationManager); } /// diff --git a/MediaBrowser.Controller/IServerApplicationPaths.cs b/MediaBrowser.Controller/IServerApplicationPaths.cs index b5fcdef285..b30120d835 100644 --- a/MediaBrowser.Controller/IServerApplicationPaths.cs +++ b/MediaBrowser.Controller/IServerApplicationPaths.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; namespace MediaBrowser.Controller { diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 5dbb53d0ae..9f97b1719a 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -1,5 +1,7 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; @@ -11,7 +13,6 @@ using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Updates; using MediaBrowser.Controller.Weather; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; @@ -26,7 +27,7 @@ namespace MediaBrowser.Controller /// /// Class Kernel /// - public class Kernel : BaseKernel + public class Kernel : BaseKernel, IDisposable { /// /// Gets the instance. @@ -161,23 +162,34 @@ namespace MediaBrowser.Controller get { return 7359; } } + private readonly IXmlSerializer _xmlSerializer; + + private readonly IServerConfigurationManager _configurationManager; + private readonly ILogManager _logManager; + /// /// Creates a kernel based on a Data path, which is akin to our current programdata path /// /// The app host. - /// The app paths. /// The XML serializer. - /// The logger. + /// The log manager. + /// The configuration manager. /// isoManager - public Kernel(IApplicationHost appHost, IServerApplicationPaths appPaths, IXmlSerializer xmlSerializer, ILogger logger) - : base(appHost, appPaths, xmlSerializer, logger) + public Kernel(IApplicationHost appHost, IXmlSerializer xmlSerializer, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(appHost, logManager, configurationManager) { Instance = this; - // For now there's no real way to inject this properly - BaseItem.Logger = logger; - Ratings.Logger = logger; - LocalizedStrings.Logger = logger; + _configurationManager = configurationManager; + _xmlSerializer = xmlSerializer; + _logManager = logManager; + + // For now there's no real way to inject these properly + BaseItem.Logger = logManager.GetLogger("BaseItem"); + User.XmlSerializer = _xmlSerializer; + Ratings.ConfigurationManager = _configurationManager; + LocalizedStrings.ApplicationPaths = _configurationManager.ApplicationPaths; + BaseItem.ConfigurationManager = configurationManager; } /// @@ -185,14 +197,13 @@ namespace MediaBrowser.Controller /// protected void FindParts() { - // For now there's no real way to inject this properly + // For now there's no real way to inject these properly BaseItem.LibraryManager = ApplicationHost.Resolve(); User.UserManager = ApplicationHost.Resolve(); FFMpegManager = (FFMpegManager)ApplicationHost.CreateInstance(typeof(FFMpegManager)); ImageManager = (ImageManager)ApplicationHost.CreateInstance(typeof(ImageManager)); ProviderManager = (ProviderManager)ApplicationHost.CreateInstance(typeof(ProviderManager)); - SecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager)); UserDataRepositories = ApplicationHost.GetExports(); UserRepositories = ApplicationHost.GetExports(); @@ -217,8 +228,6 @@ namespace MediaBrowser.Controller await LoadRepositories().ConfigureAwait(false); - ReloadResourcePools(); - await ApplicationHost.Resolve().RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false); foreach (var entryPoint in ApplicationHost.GetExports()) @@ -230,42 +239,26 @@ namespace MediaBrowser.Controller } /// - /// Releases unmanaged and - optionally - managed resources. + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool dispose) + public void Dispose() { - if (dispose) - { - DisposeResourcePools(); - - DisposeFileSystemManager(); - } - - base.Dispose(dispose); + Dispose(true); + GC.SuppressFinalize(this); } /// - /// Disposes the resource pools. + /// Releases unmanaged and - optionally - managed resources. /// - private void DisposeResourcePools() + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool dispose) { - if (ResourcePools != null) + if (dispose) { - ResourcePools.Dispose(); - ResourcePools = null; + DisposeFileSystemManager(); } } - /// - /// Reloads the resource pools. - /// - private void ReloadResourcePools() - { - DisposeResourcePools(); - ResourcePools = new ResourcePool(); - } - /// /// Called when [composable parts loaded]. /// @@ -273,19 +266,19 @@ namespace MediaBrowser.Controller protected Task LoadRepositories() { // Get the current item repository - ItemRepository = GetRepository(ItemRepositories, Configuration.ItemRepository); + ItemRepository = GetRepository(ItemRepositories, _configurationManager.Configuration.ItemRepository); var itemRepoTask = ItemRepository.Initialize(); // Get the current user repository - UserRepository = GetRepository(UserRepositories, Configuration.UserRepository); + UserRepository = GetRepository(UserRepositories, _configurationManager.Configuration.UserRepository); var userRepoTask = UserRepository.Initialize(); // Get the current item repository - UserDataRepository = GetRepository(UserDataRepositories, Configuration.UserDataRepository); + UserDataRepository = GetRepository(UserDataRepositories, _configurationManager.Configuration.UserDataRepository); var userDataRepoTask = UserDataRepository.Initialize(); // Get the current display preferences repository - DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, Configuration.DisplayPreferencesRepository); + DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, _configurationManager.Configuration.DisplayPreferencesRepository); var displayPreferencesRepoTask = DisplayPreferencesRepository.Initialize(); return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask); @@ -326,26 +319,10 @@ namespace MediaBrowser.Controller { DisposeFileSystemManager(); - FileSystemManager = new FileSystemManager(this, Logger, ApplicationHost.Resolve(), ApplicationHost.Resolve()); + FileSystemManager = new FileSystemManager(this, _logManager, ApplicationHost.Resolve(), ApplicationHost.Resolve(), _configurationManager); FileSystemManager.StartWatchers(); } - /// - /// Completely overwrites the current configuration with a new copy - /// - /// The config. - public void UpdateConfiguration(ServerConfiguration config) - { - Configuration = config; - SaveConfiguration(); - - // Validate currently executing providers, in the background - Task.Run(() => - { - ProviderManager.ValidateCurrentlyRunningProviders(); - }); - } - /// /// Gets the system info. /// diff --git a/MediaBrowser.Controller/Library/DtoBuilder.cs b/MediaBrowser.Controller/Library/DtoBuilder.cs index 0a892cbfb8..0b14bb9522 100644 --- a/MediaBrowser.Controller/Library/DtoBuilder.cs +++ b/MediaBrowser.Controller/Library/DtoBuilder.cs @@ -474,14 +474,8 @@ namespace MediaBrowser.Controller.Library /// The dto. private static void SetSpecialCounts(Folder folder, User user, BaseItemDto dto) { - var utcNow = DateTime.UtcNow; - var rcentlyAddedItemCount = 0; var recursiveItemCount = 0; - var favoriteItemsCount = 0; - var recentlyAddedUnPlayedItemCount = 0; - var resumableItemCount = 0; - var recentlyPlayedItemCount = 0; double totalPercentPlayed = 0; @@ -498,12 +492,6 @@ namespace MediaBrowser.Controller.Library if (child.IsRecentlyAdded(user)) { rcentlyAddedItemCount++; - - // Check recently added unplayed - if (userdata == null || userdata.PlayCount == 0) - { - recentlyAddedUnPlayedItemCount++; - } } // Incrememt totalPercentPlayed @@ -521,32 +509,10 @@ namespace MediaBrowser.Controller.Library } } } - - if (userdata != null) - { - if (userdata.IsFavorite) - { - favoriteItemsCount++; - } - - if (userdata.PlaybackPositionTicks > 0) - { - resumableItemCount++; - } - - if (userdata.LastPlayedDate.HasValue && (utcNow - userdata.LastPlayedDate.Value).TotalDays < Kernel.Instance.Configuration.RecentlyPlayedDays) - { - recentlyPlayedItemCount++; - } - } } dto.RecursiveItemCount = recursiveItemCount; dto.RecentlyAddedItemCount = rcentlyAddedItemCount; - dto.RecentlyAddedUnPlayedItemCount = recentlyAddedUnPlayedItemCount; - dto.ResumableItemCount = resumableItemCount; - dto.FavoriteItemCount = favoriteItemsCount; - dto.RecentlyPlayedItemCount = recentlyPlayedItemCount; if (recursiveItemCount > 0) { diff --git a/MediaBrowser.Controller/Library/ItemResolveArgs.cs b/MediaBrowser.Controller/Library/ItemResolveArgs.cs index 0979c6845c..2dbbc9d83c 100644 --- a/MediaBrowser.Controller/Library/ItemResolveArgs.cs +++ b/MediaBrowser.Controller/Library/ItemResolveArgs.cs @@ -1,9 +1,9 @@ using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.IO; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using MediaBrowser.Controller.IO; namespace MediaBrowser.Controller.Library { @@ -13,6 +13,20 @@ namespace MediaBrowser.Controller.Library /// public class ItemResolveArgs : EventArgs { + /// + /// The _app paths + /// + private readonly IServerApplicationPaths _appPaths; + + /// + /// Initializes a new instance of the class. + /// + /// The app paths. + public ItemResolveArgs(IServerApplicationPaths appPaths) + { + _appPaths = appPaths; + } + /// /// Gets the file system children. /// @@ -99,9 +113,9 @@ namespace MediaBrowser.Controller.Library } var parentDir = FileInfo.Path != null ? System.IO.Path.GetDirectoryName(FileInfo.Path) ?? string.Empty : string.Empty; - - return (parentDir.Length > Kernel.Instance.ApplicationPaths.RootFolderPath.Length - && parentDir.StartsWith(Kernel.Instance.ApplicationPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase)); + + return (parentDir.Length > _appPaths.RootFolderPath.Length + && parentDir.StartsWith(_appPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase)); } } @@ -114,7 +128,7 @@ namespace MediaBrowser.Controller.Library { get { - return IsDirectory && Path.Equals(Kernel.Instance.ApplicationPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase); + return IsDirectory && Path.Equals(_appPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase); } } diff --git a/MediaBrowser.Controller/Localization/LocalizedStrings.cs b/MediaBrowser.Controller/Localization/LocalizedStrings.cs index 0d583641bd..c7f4755b73 100644 --- a/MediaBrowser.Controller/Localization/LocalizedStrings.cs +++ b/MediaBrowser.Controller/Localization/LocalizedStrings.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Logging; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Logging; using System; using System.Collections.Concurrent; using System.Globalization; @@ -14,10 +15,8 @@ namespace MediaBrowser.Controller.Localization /// public class LocalizedStrings { - /// - /// The logger - /// - static internal ILogger Logger { get; set; } + internal static IServerApplicationPaths ApplicationPaths; + /// /// The base prefix /// @@ -31,17 +30,21 @@ namespace MediaBrowser.Controller.Localization /// private static LocalizedStrings _instance; + private IServerApplicationPaths _appPaths; + /// /// Gets the instance. /// /// The instance. - public static LocalizedStrings Instance { get { return _instance ?? (_instance = new LocalizedStrings()); } } + public static LocalizedStrings Instance { get { return _instance ?? (_instance = new LocalizedStrings(ApplicationPaths)); } } /// /// Initializes a new instance of the class. /// - public LocalizedStrings() + public LocalizedStrings(IServerApplicationPaths appPaths) { + _appPaths = appPaths; + foreach (var stringObject in Kernel.Instance.StringFiles) { AddStringData(LoadFromFile(GetFileName(stringObject),stringObject.GetType())); @@ -55,7 +58,7 @@ namespace MediaBrowser.Controller.Localization /// System.String. protected string GetFileName(LocalizedStringData stringObject) { - var path = Kernel.Instance.ApplicationPaths.LocalizationPath; + var path = _appPaths.LocalizationPath; var name = Path.Combine(path, stringObject.Prefix + "strings-" + CultureInfo.CurrentCulture + ".xml"); if (File.Exists(name)) { @@ -125,17 +128,17 @@ namespace MediaBrowser.Controller.Localization } catch (TargetException ex) { - Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); + //Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); continue; } catch (FieldAccessException ex) { - Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); + //Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); continue; } catch (NotSupportedException ex) { - Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); + //Logger.ErrorException("Error getting value for field: {0}", ex, field.Name); continue; } diff --git a/MediaBrowser.Controller/Localization/Ratings.cs b/MediaBrowser.Controller/Localization/Ratings.cs index 46368a250a..bee7b6e557 100644 --- a/MediaBrowser.Controller/Localization/Ratings.cs +++ b/MediaBrowser.Controller/Localization/Ratings.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Logging; using System.Collections.Generic; using System.IO; @@ -11,7 +12,8 @@ namespace MediaBrowser.Controller.Localization /// public static class Ratings { - static internal ILogger Logger { get; set; } + internal static IServerConfigurationManager ConfigurationManager; + /// /// The ratings def /// @@ -26,7 +28,7 @@ namespace MediaBrowser.Controller.Localization /// The ratings dict. public static Dictionary RatingsDict { - get { return _ratingsDict ?? (_ratingsDict = Initialize(false)); } + get { return _ratingsDict ?? (_ratingsDict = Initialize(false, ConfigurationManager)); } } /// /// The ratings strings @@ -38,17 +40,17 @@ namespace MediaBrowser.Controller.Localization /// /// if set to true [block unrated]. /// Dictionary{System.StringSystem.Int32}. - public static Dictionary Initialize(bool blockUnrated) + public static Dictionary Initialize(bool blockUnrated, IServerConfigurationManager configurationManager) { //build our ratings dictionary from the combined local one and us one - ratingsDef = new RatingsDefinition(Path.Combine(Kernel.Instance.ApplicationPaths.LocalizationPath, "Ratings-" + Kernel.Instance.Configuration.MetadataCountryCode + ".txt"), Logger); + ratingsDef = new RatingsDefinition(Path.Combine(configurationManager.ApplicationPaths.LocalizationPath, "Ratings-" + configurationManager.Configuration.MetadataCountryCode + ".txt"), configurationManager); //global value of None var dict = new Dictionary {{"None", -1}}; foreach (var pair in ratingsDef.RatingsDict) { dict.TryAdd(pair.Key, pair.Value); } - if (Kernel.Instance.Configuration.MetadataCountryCode.ToUpper() != "US") + if (configurationManager.Configuration.MetadataCountryCode.ToUpper() != "US") { foreach (var pair in new USRatingsDictionary()) { diff --git a/MediaBrowser.Controller/Localization/RatingsDefinition.cs b/MediaBrowser.Controller/Localization/RatingsDefinition.cs index e0753da2e0..1162d2389f 100644 --- a/MediaBrowser.Controller/Localization/RatingsDefinition.cs +++ b/MediaBrowser.Controller/Localization/RatingsDefinition.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Logging; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Logging; using System; using System.Collections.Generic; using System.IO; @@ -10,26 +11,18 @@ namespace MediaBrowser.Controller.Localization /// public class RatingsDefinition { - /// - /// Gets or sets the logger. - /// - /// The logger. - private ILogger Logger { get; set; } - /// /// Initializes a new instance of the class. /// /// The file. /// The logger. - public RatingsDefinition(string file, ILogger logger) + /// The configuration manager. + public RatingsDefinition(string file, IServerConfigurationManager configurationManager) { - Logger = logger; - - Logger.Info("Loading Certification Ratings from file " + file); this.file = file; if (!Load()) { - Init(Kernel.Instance.Configuration.MetadataCountryCode.ToUpper()); + Init(configurationManager.Configuration.MetadataCountryCode.ToUpper()); } } @@ -108,7 +101,7 @@ namespace MediaBrowser.Controller.Localization } else { - Logger.Error("Invalid line in ratings file " + file + "(" + line + ")"); + //Logger.Error("Invalid line in ratings file " + file + "(" + line + ")"); } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 319289f94a..f4be79afb1 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -53,9 +53,6 @@ MinimumRecommendedRules.ruleset - - Plugins\Mediabrowser.PluginSecurity.dll - False ..\packages\protobuf-net.2.0.0.621\lib\net40\protobuf-net.dll @@ -74,6 +71,7 @@ Properties\SharedVersion.cs + @@ -135,7 +133,6 @@ - diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs index 0f535208b4..36fab24bb1 100644 --- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs +++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs @@ -67,6 +67,7 @@ namespace MediaBrowser.Controller.MediaInfo /// The _protobuf serializer /// private readonly IProtobufSerializer _protobufSerializer; + private readonly IServerApplicationPaths _appPaths; /// /// Initializes a new instance of the class. @@ -77,7 +78,7 @@ namespace MediaBrowser.Controller.MediaInfo /// The protobuf serializer. /// The logger. /// zipClient - public FFMpegManager(Kernel kernel, IZipClient zipClient, IJsonSerializer jsonSerializer, IProtobufSerializer protobufSerializer, ILogger logger) + public FFMpegManager(Kernel kernel, IZipClient zipClient, IJsonSerializer jsonSerializer, IProtobufSerializer protobufSerializer, ILogManager logManager, IServerApplicationPaths appPaths) { if (kernel == null) { @@ -95,16 +96,13 @@ namespace MediaBrowser.Controller.MediaInfo { throw new ArgumentNullException("protobufSerializer"); } - if (logger == null) - { - throw new ArgumentNullException("logger"); - } _kernel = kernel; _zipClient = zipClient; _jsonSerializer = jsonSerializer; _protobufSerializer = protobufSerializer; - _logger = logger; + _appPaths = appPaths; + _logger = logManager.GetLogger("FFMpegManager"); // Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); @@ -223,7 +221,7 @@ namespace MediaBrowser.Controller.MediaInfo { if (_videoImagesDataPath == null) { - _videoImagesDataPath = Path.Combine(_kernel.ApplicationPaths.DataPath, "ffmpeg-video-images"); + _videoImagesDataPath = Path.Combine(_appPaths.DataPath, "ffmpeg-video-images"); if (!Directory.Exists(_videoImagesDataPath)) { @@ -249,7 +247,7 @@ namespace MediaBrowser.Controller.MediaInfo { if (_audioImagesDataPath == null) { - _audioImagesDataPath = Path.Combine(_kernel.ApplicationPaths.DataPath, "ffmpeg-audio-images"); + _audioImagesDataPath = Path.Combine(_appPaths.DataPath, "ffmpeg-audio-images"); if (!Directory.Exists(_audioImagesDataPath)) { @@ -275,7 +273,7 @@ namespace MediaBrowser.Controller.MediaInfo { if (_subtitleCachePath == null) { - _subtitleCachePath = Path.Combine(_kernel.ApplicationPaths.CachePath, "ffmpeg-subtitles"); + _subtitleCachePath = Path.Combine(_appPaths.CachePath, "ffmpeg-subtitles"); if (!Directory.Exists(_subtitleCachePath)) { @@ -302,7 +300,7 @@ namespace MediaBrowser.Controller.MediaInfo var filename = resource.Substring(resource.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) + prefix.Length); - var versionedDirectoryPath = Path.Combine(_kernel.ApplicationPaths.MediaToolsPath, Path.GetFileNameWithoutExtension(filename)); + var versionedDirectoryPath = Path.Combine(_appPaths.MediaToolsPath, Path.GetFileNameWithoutExtension(filename)); if (!Directory.Exists(versionedDirectoryPath)) { diff --git a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs index f6c6ed3036..a5823c60e2 100644 --- a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs +++ b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs @@ -1,4 +1,6 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; using System; @@ -19,6 +21,12 @@ namespace MediaBrowser.Controller.Providers protected ILogger Logger { get; set; } protected ILogManager LogManager { get; set; } + /// + /// Gets the configuration manager. + /// + /// The configuration manager. + protected IServerConfigurationManager ConfigurationManager { get; private set; } + // Cache these since they will be used a lot /// /// The false task result @@ -103,10 +111,11 @@ namespace MediaBrowser.Controller.Providers /// /// Initializes a new instance of the class. /// - protected BaseMetadataProvider(ILogManager logManager) + protected BaseMetadataProvider(ILogManager logManager, IServerConfigurationManager configurationManager) { Logger = logManager.GetLogger(GetType().Name); LogManager = logManager; + ConfigurationManager = configurationManager; Initialize(); } diff --git a/MediaBrowser.Controller/Providers/FanartBaseProvider.cs b/MediaBrowser.Controller/Providers/FanartBaseProvider.cs index 7a38fbb7a8..548fbd5a69 100644 --- a/MediaBrowser.Controller/Providers/FanartBaseProvider.cs +++ b/MediaBrowser.Controller/Providers/FanartBaseProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using System; using MediaBrowser.Model.Logging; @@ -35,7 +36,7 @@ namespace MediaBrowser.Controller.Providers /// protected const string APIKey = "5c6b04c68e904cfed1e6cbc9a9e683d4"; - protected FanartBaseProvider(ILogManager logManager) : base(logManager) + protected FanartBaseProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } @@ -49,7 +50,7 @@ namespace MediaBrowser.Controller.Providers { if (item.DontFetchMeta) return false; - return DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(Kernel.Instance.Configuration.MetadataRefreshDays)) + return DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays)) && ShouldFetch(item, providerInfo); } diff --git a/MediaBrowser.Controller/Providers/FolderProviderFromXml.cs b/MediaBrowser.Controller/Providers/FolderProviderFromXml.cs index 1baa1ed558..45a47a58da 100644 --- a/MediaBrowser.Controller/Providers/FolderProviderFromXml.cs +++ b/MediaBrowser.Controller/Providers/FolderProviderFromXml.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; using System; using System.IO; @@ -13,7 +14,7 @@ namespace MediaBrowser.Controller.Providers /// public class FolderProviderFromXml : BaseMetadataProvider { - public FolderProviderFromXml(ILogManager logManager) : base(logManager) + public FolderProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs index ddf9e3334c..4b337aadce 100644 --- a/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/ImageFromMediaLocationProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using MediaBrowser.Model.Entities; using System; @@ -16,7 +17,7 @@ namespace MediaBrowser.Controller.Providers /// public class ImageFromMediaLocationProvider : BaseMetadataProvider { - public ImageFromMediaLocationProvider(ILogManager logManager) : base(logManager) + public ImageFromMediaLocationProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs index 1521b514ce..53ff94720e 100644 --- a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs +++ b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using System; using System.Globalization; @@ -13,7 +14,7 @@ namespace MediaBrowser.Controller.Providers /// public class ImagesByNameProvider : ImageFromMediaLocationProvider { - public ImagesByNameProvider(ILogManager logManager) : base(logManager) + public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } @@ -82,7 +83,7 @@ namespace MediaBrowser.Controller.Providers var name = item.Name ?? string.Empty; name = invalid.Aggregate(name, (current, c) => current.Replace(c.ToString(UsCulture), string.Empty)); - return Path.Combine(Kernel.Instance.ApplicationPaths.GeneralPath, name); + return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name); } /// diff --git a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegImageProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegImageProvider.cs index 8ca080e9b8..902fdca27b 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegImageProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegImageProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; namespace MediaBrowser.Controller.Providers.MediaInfo @@ -6,7 +7,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo public abstract class BaseFFMpegImageProvider : BaseFFMpegProvider where T : BaseItem { - protected BaseFFMpegImageProvider(ILogManager logManager) : base(logManager) + protected BaseFFMpegImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegProvider.cs index e3f0d16a74..20f59b22de 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFMpegProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; using System; @@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo public abstract class BaseFFMpegProvider : BaseMetadataProvider where T : BaseItem { - protected BaseFFMpegProvider(ILogManager logManager) : base(logManager) + protected BaseFFMpegProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs index e0633d97dd..9fe2a6c01f 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/BaseFFProbeProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.MediaInfo; using MediaBrowser.Controller.Persistence; @@ -19,7 +20,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo public abstract class BaseFFProbeProvider : BaseFFMpegProvider where T : BaseItem { - protected BaseFFProbeProvider(ILogManager logManager) : base(logManager) + protected BaseFFProbeProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } @@ -35,7 +36,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo protected override void Initialize() { base.Initialize(); - FFProbeCache = new FileSystemRepository(Path.Combine(Kernel.Instance.ApplicationPaths.CachePath, CacheDirectoryName)); + FFProbeCache = new FileSystemRepository(Path.Combine(ConfigurationManager.ApplicationPaths.CachePath, CacheDirectoryName)); } /// diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFMpegAudioImageProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFMpegAudioImageProvider.cs index 581cd4e092..aedd035377 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/FFMpegAudioImageProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/FFMpegAudioImageProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Entities; using System; @@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo /// public class FFMpegAudioImageProvider : BaseFFMpegImageProvider /// The iso manager. - public FfMpegVideoImageProvider(IIsoManager isoManager, ILogManager logManager) - : base(logManager) + /// The log manager. + /// The configuration manager. + public FfMpegVideoImageProvider(IIsoManager isoManager, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { _isoManager = isoManager; } diff --git a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs index 3786763861..603b7dcaae 100644 --- a/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/MediaInfo/FFProbeAudioInfoProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.MediaInfo; @@ -17,7 +18,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo /// public class FFProbeAudioInfoProvider : BaseFFProbeProvider public class FFProbeVideoInfoProvider : BaseFFProbeProvider private readonly IProtobufSerializer _protobufSerializer; - /// - /// Initializes a new instance of the class. - /// - /// The iso manager. - /// The bluray examiner. - /// The protobuf serializer. - /// blurayExaminer - public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IProtobufSerializer protobufSerializer, ILogManager logManager) - : base(logManager) - { - if (isoManager == null) - { - throw new ArgumentNullException("isoManager"); - } - if (blurayExaminer == null) - { - throw new ArgumentNullException("blurayExaminer"); - } - if (protobufSerializer == null) - { - throw new ArgumentNullException("protobufSerializer"); - } - - _blurayExaminer = blurayExaminer; - _isoManager = isoManager; - _protobufSerializer = protobufSerializer; - - BdInfoCache = new FileSystemRepository(Path.Combine(Kernel.Instance.ApplicationPaths.CachePath, "bdinfo")); - } - /// /// Returns true or false indicating if the provider should refresh when the contents of it's directory changes /// diff --git a/MediaBrowser.Controller/Providers/Movies/FanArtMovieProvider.cs b/MediaBrowser.Controller/Providers/Movies/FanArtMovieProvider.cs index 434552be38..d307fe0990 100644 --- a/MediaBrowser.Controller/Providers/Movies/FanArtMovieProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/FanArtMovieProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Model.Entities; @@ -18,14 +19,28 @@ namespace MediaBrowser.Controller.Providers.Movies /// class FanArtMovieProvider : FanartBaseProvider { + /// + /// The fan art + /// + internal readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(5, 5); + + internal static FanArtMovieProvider Current { get; private set; } + /// /// Gets the HTTP client. /// /// The HTTP client. protected IHttpClient HttpClient { get; private set; } - public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager) - : base(logManager) + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client. + /// The log manager. + /// The configuration manager. + /// httpClient + public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (httpClient == null) { @@ -34,6 +49,19 @@ namespace MediaBrowser.Controller.Providers.Movies HttpClient = httpClient; } + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool dispose) + { + if (dispose) + { + FanArtResourcePool.Dispose(); + } + base.Dispose(dispose); + } + /// /// The fan art base URL /// @@ -63,9 +91,9 @@ namespace MediaBrowser.Controller.Providers.Movies var logoExists = item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE); var discExists = item.ResolveArgs.ContainsMetaFileByName(DISC_FILE); - return (!artExists && Kernel.Instance.Configuration.DownloadMovieArt) - || (!logoExists && Kernel.Instance.Configuration.DownloadMovieLogo) - || (!discExists && Kernel.Instance.Configuration.DownloadMovieDisc); + return (!artExists && ConfigurationManager.Configuration.DownloadMovieArt) + || (!logoExists && ConfigurationManager.Configuration.DownloadMovieLogo) + || (!discExists && ConfigurationManager.Configuration.DownloadMovieDisc); } /// @@ -82,13 +110,13 @@ namespace MediaBrowser.Controller.Providers.Movies var movie = item; if (ShouldFetch(movie, movie.ProviderData.GetValueOrDefault(Id, new BaseProviderInfo { ProviderId = Id }))) { - var language = Kernel.Instance.Configuration.PreferredMetadataLanguage.ToLower(); + var language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower(); var url = string.Format(FanArtBaseUrl, APIKey, movie.GetProviderId(MetadataProviders.Tmdb)); var doc = new XmlDocument(); try { - using (var xml = await HttpClient.Get(url, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)) + using (var xml = await HttpClient.Get(url, FanArtResourcePool, cancellationToken).ConfigureAwait(false)) { doc.Load(xml); } @@ -102,8 +130,8 @@ namespace MediaBrowser.Controller.Providers.Movies if (doc.HasChildNodes) { string path; - var hd = Kernel.Instance.Configuration.DownloadHDFanArt ? "hd" : ""; - if (Kernel.Instance.Configuration.DownloadMovieLogo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) + var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : ""; + if (ConfigurationManager.Configuration.DownloadMovieLogo && !item.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) { var node = doc.SelectSingleNode("//fanart/movie/movielogos/" + hd + "movielogo[@lang = \"" + language + "\"]/@url") ?? @@ -119,7 +147,7 @@ namespace MediaBrowser.Controller.Providers.Movies Logger.Debug("FanArtProvider getting ClearLogo for " + movie.Name); try { - movie.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, LOGO_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + movie.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, LOGO_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -132,7 +160,7 @@ namespace MediaBrowser.Controller.Providers.Movies } cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadMovieArt && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE)) + if (ConfigurationManager.Configuration.DownloadMovieArt && !item.ResolveArgs.ContainsMetaFileByName(ART_FILE)) { var node = doc.SelectSingleNode("//fanart/movie/moviearts/" + hd + "movieart[@lang = \"" + language + "\"]/@url") ?? @@ -145,7 +173,7 @@ namespace MediaBrowser.Controller.Providers.Movies Logger.Debug("FanArtProvider getting ClearArt for " + movie.Name); try { - movie.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, ART_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + movie.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, ART_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -158,7 +186,7 @@ namespace MediaBrowser.Controller.Providers.Movies } cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadMovieDisc && !item.ResolveArgs.ContainsMetaFileByName(DISC_FILE)) + if (ConfigurationManager.Configuration.DownloadMovieDisc && !item.ResolveArgs.ContainsMetaFileByName(DISC_FILE)) { var node = doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/movie/moviediscs/moviedisc/@url"); @@ -168,7 +196,7 @@ namespace MediaBrowser.Controller.Providers.Movies Logger.Debug("FanArtProvider getting DiscArt for " + movie.Name); try { - movie.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, DISC_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + movie.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, DISC_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -182,7 +210,7 @@ namespace MediaBrowser.Controller.Providers.Movies cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadMovieBanner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE)) + if (ConfigurationManager.Configuration.DownloadMovieBanner && !item.ResolveArgs.ContainsMetaFileByName(BANNER_FILE)) { var node = doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/movie/moviebanners/moviebanner/@url"); @@ -192,7 +220,7 @@ namespace MediaBrowser.Controller.Providers.Movies Logger.Debug("FanArtProvider getting Banner for " + movie.Name); try { - movie.SetImage(ImageType.Banner, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, BANNER_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + movie.SetImage(ImageType.Banner, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, BANNER_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -206,7 +234,7 @@ namespace MediaBrowser.Controller.Providers.Movies cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadMovieThumb && !item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE)) + if (ConfigurationManager.Configuration.DownloadMovieThumb && !item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE)) { var node = doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/movie/moviethumbs/moviethumb/@url"); @@ -216,7 +244,7 @@ namespace MediaBrowser.Controller.Providers.Movies Logger.Debug("FanArtProvider getting Banner for " + movie.Name); try { - movie.SetImage(ImageType.Thumb, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, THUMB_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + movie.SetImage(ImageType.Thumb, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(movie, path, THUMB_FILE, FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { diff --git a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs index 34435402fb..8d004a5744 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs @@ -1,21 +1,22 @@ -using System.Net; -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; +using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Serialization; namespace MediaBrowser.Controller.Providers.Movies { @@ -31,6 +32,13 @@ namespace MediaBrowser.Controller.Providers.Movies /// public class MovieDbProvider : BaseMetadataProvider { + /// + /// The movie db + /// + internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(5, 5); + + internal static MovieDbProvider Current { get; private set; } + /// /// Gets the json serializer. /// @@ -46,23 +54,29 @@ namespace MediaBrowser.Controller.Providers.Movies /// /// Initializes a new instance of the class. /// + /// The log manager. + /// The configuration manager. /// The json serializer. /// The HTTP client. - /// The Log manager - /// jsonSerializer - public MovieDbProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(logManager) + public MovieDbProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient) + : base(logManager, configurationManager) { - if (jsonSerializer == null) - { - throw new ArgumentNullException("jsonSerializer"); - } - if (httpClient == null) - { - throw new ArgumentNullException("httpClient"); - } JsonSerializer = jsonSerializer; HttpClient = httpClient; + Current = this; + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool dispose) + { + if (dispose) + { + MovieDbResourcePool.Dispose(); + } + base.Dispose(dispose); } /// @@ -103,7 +117,7 @@ namespace MediaBrowser.Controller.Providers.Movies { get { - return Kernel.Instance.Configuration.SaveLocalMeta; + return ConfigurationManager.Configuration.SaveLocalMeta; } } @@ -141,7 +155,7 @@ namespace MediaBrowser.Controller.Providers.Movies { try { - using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), Kernel.Instance.ResourcePools.MovieDb, CancellationToken.None).ConfigureAwait(false)) + using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), MovieDbProvider.Current.MovieDbResourcePool, CancellationToken.None).ConfigureAwait(false)) { return jsonSerializer.DeserializeFromStream(json); } @@ -200,11 +214,11 @@ namespace MediaBrowser.Controller.Providers.Movies { base.SetLastRefreshed(item, value, status); - if (Kernel.Instance.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta) { //in addition to ours, we need to set the last refreshed time for the local data provider //so it won't see the new files we download and process them all over again - if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(HttpClient, JsonSerializer, LogManager); + if (JsonProvider == null) JsonProvider = new MovieProviderFromJson(LogManager, ConfigurationManager, JsonSerializer, HttpClient); var data = item.ProviderData.GetValueOrDefault(JsonProvider.Id, new BaseProviderInfo { ProviderId = JsonProvider.Id }); data.LastRefreshed = value; item.ProviderData[JsonProvider.Id] = data; @@ -233,7 +247,7 @@ namespace MediaBrowser.Controller.Providers.Movies { if (item.DontFetchMeta) return false; - if (Kernel.Instance.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo)) + if (ConfigurationManager.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo)) { //If they deleted something from file system, chances are, this item was mis-identified the first time item.SetProviderId(MetadataProviders.Tmdb, null); @@ -250,7 +264,7 @@ namespace MediaBrowser.Controller.Providers.Movies var downloadDate = providerInfo.LastRefreshed; - if (Kernel.Instance.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) + if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) { return false; } @@ -258,7 +272,7 @@ namespace MediaBrowser.Controller.Providers.Movies if (DateTime.Today.Subtract(item.DateCreated).TotalDays > 180 && downloadDate != DateTime.MinValue) return false; // don't trigger a refresh data for item that are more than 6 months old and have been refreshed before - if (DateTime.Today.Subtract(downloadDate).TotalDays < Kernel.Instance.Configuration.MetadataRefreshDays) // only refresh every n days + if (DateTime.Today.Subtract(downloadDate).TotalDays < ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days return false; if (HasAltMeta(item)) @@ -266,7 +280,7 @@ namespace MediaBrowser.Controller.Providers.Movies - Logger.Debug("MovieDbProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + Kernel.Instance.Configuration.MetadataRefreshDays); + Logger.Debug("MovieDbProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + ConfigurationManager.Configuration.MetadataRefreshDays); return true; } @@ -293,7 +307,7 @@ namespace MediaBrowser.Controller.Providers.Movies cancellationToken.ThrowIfCancellationRequested(); - if (!Kernel.Instance.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item))) + if (!ConfigurationManager.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item))) { try { @@ -407,7 +421,7 @@ namespace MediaBrowser.Controller.Providers.Movies } Logger.Info("MovieDbProvider: Finding id for movie: " + name); - string language = Kernel.Instance.Configuration.PreferredMetadataLanguage.ToLower(); + string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower(); //if we are a boxset - look at our first child var boxset = item as BoxSet; @@ -478,7 +492,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url3, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -510,7 +524,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (var json = await HttpClient.Get(url3, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -545,11 +559,11 @@ namespace MediaBrowser.Controller.Providers.Movies if (matchedName == null) { //that title didn't match - look for alternatives - url3 = string.Format(AltTitleSearch, id, ApiKey, Kernel.Instance.Configuration.MetadataCountryCode); + url3 = string.Format(AltTitleSearch, id, ApiKey, ConfigurationManager.Configuration.MetadataCountryCode); try { - using (var json = await HttpClient.Get(url3, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { var response = JsonSerializer.DeserializeFromStream(json); @@ -630,7 +644,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { var movieResult = JsonSerializer.DeserializeFromStream(json); @@ -703,7 +717,7 @@ namespace MediaBrowser.Controller.Providers.Movies } //and save locally - if (Kernel.Instance.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta) { var ms = new MemoryStream(); JsonSerializer.SerializeToStream(mainResult, ms); @@ -724,14 +738,14 @@ namespace MediaBrowser.Controller.Providers.Movies protected async Task FetchMainResult(BaseItem item, string id, CancellationToken cancellationToken) { ItemType = item is BoxSet ? "collection" : "movie"; - string url = string.Format(GetInfo3, id, ApiKey, Kernel.Instance.Configuration.PreferredMetadataLanguage, ItemType); + string url = string.Format(GetInfo3, id, ApiKey, ConfigurationManager.Configuration.PreferredMetadataLanguage, ItemType); CompleteMovieData mainResult; cancellationToken.ThrowIfCancellationRequested(); try { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { mainResult = JsonSerializer.DeserializeFromStream(json); } @@ -756,14 +770,14 @@ namespace MediaBrowser.Controller.Providers.Movies if (mainResult != null && string.IsNullOrEmpty(mainResult.overview)) { - if (Kernel.Instance.Configuration.PreferredMetadataLanguage.ToLower() != "en") + if (ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower() != "en") { - Logger.Info("MovieDbProvider couldn't find meta for language " + Kernel.Instance.Configuration.PreferredMetadataLanguage + ". Trying English..."); + Logger.Info("MovieDbProvider couldn't find meta for language " + ConfigurationManager.Configuration.PreferredMetadataLanguage + ". Trying English..."); url = string.Format(GetInfo3, id, ApiKey, "en", ItemType); try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { mainResult = JsonSerializer.DeserializeFromStream(json); } @@ -799,7 +813,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { cast = JsonSerializer.DeserializeFromStream(json); } @@ -826,7 +840,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { releases = JsonSerializer.DeserializeFromStream(json); } @@ -855,7 +869,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { images = JsonSerializer.DeserializeFromStream(json); } @@ -883,7 +897,7 @@ namespace MediaBrowser.Controller.Providers.Movies movie.SetProviderId(MetadataProviders.Imdb, movieData.imdb_id); float rating; string voteAvg = movieData.vote_average.ToString(); - string cultureStr = Kernel.Instance.Configuration.PreferredMetadataLanguage + "-" + Kernel.Instance.Configuration.MetadataCountryCode; + string cultureStr = ConfigurationManager.Configuration.PreferredMetadataLanguage + "-" + ConfigurationManager.Configuration.MetadataCountryCode; CultureInfo culture; try { @@ -900,7 +914,7 @@ namespace MediaBrowser.Controller.Providers.Movies //release date and certification are retrieved based on configured country and we fall back on US if not there if (movieData.countries != null) { - var ourRelease = movieData.countries.FirstOrDefault(c => c.iso_3166_1.Equals(Kernel.Instance.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country(); + var ourRelease = movieData.countries.FirstOrDefault(c => c.iso_3166_1.Equals(ConfigurationManager.Configuration.MetadataCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new Country(); var usRelease = movieData.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new Country(); movie.OfficialRating = ourRelease.certification ?? usRelease.certification; @@ -975,17 +989,17 @@ namespace MediaBrowser.Controller.Providers.Movies cancellationToken.ThrowIfCancellationRequested(); // poster - if (images.posters != null && images.posters.Count > 0 && (Kernel.Instance.Configuration.RefreshItemImages || !item.HasLocalImage("folder"))) + if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage("folder"))) { var tmdbSettings = await TmdbSettings.ConfigureAwait(false); - var tmdbImageUrl = tmdbSettings.images.base_url + Kernel.Instance.Configuration.TmdbFetchedPosterSize; + var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedPosterSize; // get highest rated poster for our language var postersSortedByVote = images.posters.OrderByDescending(i => i.vote_average); - var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(Kernel.Instance.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); - if (poster == null && !Kernel.Instance.Configuration.PreferredMetadataLanguage.Equals("en")) + var poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); + if (poster == null && !ConfigurationManager.Configuration.PreferredMetadataLanguage.Equals("en")) { // couldn't find our specific language, find english (if that wasn't our language) poster = postersSortedByVote.FirstOrDefault(p => p.iso_639_1 != null && p.iso_639_1.Equals("en", StringComparison.OrdinalIgnoreCase)); @@ -1004,7 +1018,7 @@ namespace MediaBrowser.Controller.Providers.Movies { try { - item.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false); + item.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false); } catch (HttpException) { @@ -1025,18 +1039,18 @@ namespace MediaBrowser.Controller.Providers.Movies var tmdbSettings = await TmdbSettings.ConfigureAwait(false); - var tmdbImageUrl = tmdbSettings.images.base_url + Kernel.Instance.Configuration.TmdbFetchedBackdropSize; + var tmdbImageUrl = tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedBackdropSize; //backdrops should be in order of rating. get first n ones - var numToFetch = Math.Min(Kernel.Instance.Configuration.MaxBackdrops, images.backdrops.Count); + var numToFetch = Math.Min(ConfigurationManager.Configuration.MaxBackdrops, images.backdrops.Count); for (var i = 0; i < numToFetch; i++) { var bdName = "backdrop" + (i == 0 ? "" : i.ToString()); - if (Kernel.Instance.Configuration.RefreshItemImages || !item.HasLocalImage(bdName)) + if (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage(bdName)) { try { - item.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)); + item.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), MovieDbResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { diff --git a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs index aa507d02ec..2a7a09625f 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -14,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Movies /// public class MovieProviderFromJson : MovieDbProvider { - public MovieProviderFromJson(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager) - : base(jsonSerializer, httpClient, logManager) + public MovieProviderFromJson(ILogManager logManager, IServerConfigurationManager configurationManager, IJsonSerializer jsonSerializer, IHttpClient httpClient) : + base(logManager, configurationManager, jsonSerializer, httpClient) { } diff --git a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromXml.cs b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromXml.cs index 555017e28e..3e5a6fe8d7 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromXml.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromXml.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using System; using System.IO; @@ -13,7 +14,7 @@ namespace MediaBrowser.Controller.Providers.Movies /// public class MovieProviderFromXml : BaseMetadataProvider { - public MovieProviderFromXml(ILogManager logManager) : base(logManager) + public MovieProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/Movies/PersonProviderFromJson.cs b/MediaBrowser.Controller/Providers/Movies/PersonProviderFromJson.cs index 1004eaeae0..278d672617 100644 --- a/MediaBrowser.Controller/Providers/Movies/PersonProviderFromJson.cs +++ b/MediaBrowser.Controller/Providers/Movies/PersonProviderFromJson.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -14,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Movies /// class PersonProviderFromJson : TmdbPersonProvider { - public PersonProviderFromJson(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager) - : base(httpClient, jsonSerializer, logManager) + public PersonProviderFromJson(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager) : + base(httpClient, jsonSerializer, logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs b/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs index 3c4ac6076f..5c977a928c 100644 --- a/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -25,26 +26,8 @@ namespace MediaBrowser.Controller.Providers.Movies /// protected const string MetaFileName = "MBPerson.json"; - /// - /// Gets the json serializer. - /// - /// The json serializer. - protected IJsonSerializer JsonSerializer { get; private set; } - - /// - /// Gets the HTTP client. - /// - /// The HTTP client. - protected IHttpClient HttpClient { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// The HTTP client. - /// The json serializer. - /// jsonSerializer - public TmdbPersonProvider(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager) - : base(logManager) + public TmdbPersonProvider(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (jsonSerializer == null) { @@ -58,6 +41,18 @@ namespace MediaBrowser.Controller.Providers.Movies JsonSerializer = jsonSerializer; } + /// + /// Gets the json serializer. + /// + /// The json serializer. + protected IJsonSerializer JsonSerializer { get; private set; } + + /// + /// Gets the HTTP client. + /// + /// The HTTP client. + protected IHttpClient HttpClient { get; private set; } + /// /// Supportses the specified item. /// @@ -78,7 +73,7 @@ namespace MediaBrowser.Controller.Providers.Movies { //we fetch if either info or image needed and haven't already tried recently return (string.IsNullOrEmpty(item.PrimaryImagePath) || !item.ResolveArgs.ContainsMetaFileByName(MetaFileName)) - && DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > Kernel.Instance.Configuration.MetadataRefreshDays; + && DateTime.Today.Subtract(providerInfo.LastRefreshed).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays; } /// @@ -165,7 +160,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -191,7 +186,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { if (json != null) { @@ -254,7 +249,7 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { if (json != null) { @@ -273,7 +268,7 @@ namespace MediaBrowser.Controller.Providers.Movies searchResult.Profiles.FirstOrDefault( p => !string.IsNullOrEmpty(p.Iso_639_1) && - p.Iso_639_1.Equals(Kernel.Instance.Configuration.PreferredMetadataLanguage, + p.Iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); if (profile == null) { @@ -282,7 +277,7 @@ namespace MediaBrowser.Controller.Providers.Movies searchResult.Profiles.FirstOrDefault( p => !string.IsNullOrEmpty(p.Iso_639_1) && - p.Iso_639_1.Equals(Kernel.Instance.Configuration.PreferredMetadataLanguage, + p.Iso_639_1.Equals(ConfigurationManager.Configuration.PreferredMetadataLanguage, StringComparison.OrdinalIgnoreCase)); } @@ -295,7 +290,7 @@ namespace MediaBrowser.Controller.Providers.Movies { var tmdbSettings = await Kernel.Instance.MetadataProviders.OfType().First().TmdbSettings.ConfigureAwait(false); - var img = await DownloadAndSaveImage(person, tmdbSettings.images.base_url + Kernel.Instance.Configuration.TmdbFetchedProfileSize + profile.File_Path, + var img = await DownloadAndSaveImage(person, tmdbSettings.images.base_url + ConfigurationManager.Configuration.TmdbFetchedProfileSize + profile.File_Path, "folder" + Path.GetExtension(profile.File_Path), cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(img)) @@ -322,7 +317,7 @@ namespace MediaBrowser.Controller.Providers.Movies var localPath = Path.Combine(item.MetaLocation, targetName); if (!item.ResolveArgs.ContainsMetaFileByName(targetName)) { - using (var sourceStream = await HttpClient.GetMemoryStream(source, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var sourceStream = await HttpClient.GetMemoryStream(source, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) { await Kernel.Instance.FileSystemManager.SaveToLibraryFilesystem(item, localPath, sourceStream, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs index 364986130f..c73321e552 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseProvider.cs @@ -1,5 +1,6 @@ using System.Net; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -23,32 +24,16 @@ namespace MediaBrowser.Controller.Providers.Music /// public abstract class LastfmBaseProvider : BaseMetadataProvider { - /// - /// Gets the json serializer. - /// - /// The json serializer. - protected IJsonSerializer JsonSerializer { get; private set; } - - /// - /// Gets the HTTP client. - /// - /// The HTTP client. - protected IHttpClient HttpClient { get; private set; } - - /// - /// The name of the local json meta file for this item type - /// - protected string LocalMetaFileName { get; set; } - /// /// Initializes a new instance of the class. /// /// The json serializer. /// The HTTP client. - /// The Log manager + /// The log manager. + /// The configuration manager. /// jsonSerializer - public LastfmBaseProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(logManager) + protected LastfmBaseProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (jsonSerializer == null) { @@ -62,6 +47,23 @@ namespace MediaBrowser.Controller.Providers.Music HttpClient = httpClient; } + /// + /// Gets the json serializer. + /// + /// The json serializer. + protected IJsonSerializer JsonSerializer { get; private set; } + + /// + /// Gets the HTTP client. + /// + /// The HTTP client. + protected IHttpClient HttpClient { get; private set; } + + /// + /// The name of the local json meta file for this item type + /// + protected string LocalMetaFileName { get; set; } + /// /// Gets the priority. /// @@ -90,7 +92,7 @@ namespace MediaBrowser.Controller.Providers.Music { get { - return Kernel.Instance.Configuration.SaveLocalMeta; + return ConfigurationManager.Configuration.SaveLocalMeta; } } @@ -101,7 +103,7 @@ namespace MediaBrowser.Controller.Providers.Music { if (item.DontFetchMeta) return false; - if (Kernel.Instance.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo)) + if (ConfigurationManager.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo)) { //If they deleted something from file system, chances are, this item was mis-identified the first time item.SetProviderId(MetadataProviders.Musicbrainz, null); @@ -118,7 +120,7 @@ namespace MediaBrowser.Controller.Providers.Music var downloadDate = providerInfo.LastRefreshed; - if (Kernel.Instance.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) + if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) { return false; } @@ -126,11 +128,11 @@ namespace MediaBrowser.Controller.Providers.Music if (DateTime.Today.Subtract(item.DateCreated).TotalDays > 180 && downloadDate != DateTime.MinValue) return false; // don't trigger a refresh data for item that are more than 6 months old and have been refreshed before - if (DateTime.Today.Subtract(downloadDate).TotalDays < Kernel.Instance.Configuration.MetadataRefreshDays) // only refresh every n days + if (DateTime.Today.Subtract(downloadDate).TotalDays < ConfigurationManager.Configuration.MetadataRefreshDays) // only refresh every n days return false; - Logger.Debug("LastfmProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + Kernel.Instance.Configuration.MetadataRefreshDays); + Logger.Debug("LastfmProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + ConfigurationManager.Configuration.MetadataRefreshDays); return true; } @@ -151,7 +153,7 @@ namespace MediaBrowser.Controller.Providers.Music cancellationToken.ThrowIfCancellationRequested(); - if (!Kernel.Instance.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item))) + if (!ConfigurationManager.Configuration.SaveLocalMeta || !HasLocalMeta(item) || (force && !HasLocalMeta(item))) { try { diff --git a/MediaBrowser.Controller/Providers/ProviderManager.cs b/MediaBrowser.Controller/Providers/ProviderManager.cs index 0f7198756a..16e862fb91 100644 --- a/MediaBrowser.Controller/Providers/ProviderManager.cs +++ b/MediaBrowser.Controller/Providers/ProviderManager.cs @@ -1,6 +1,8 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; using System; @@ -39,18 +41,37 @@ namespace MediaBrowser.Controller.Providers /// private readonly IHttpClient _httpClient; + private IServerConfigurationManager ConfigurationManager { get; set; } + /// /// Initializes a new instance of the class. /// /// The kernel. /// The HTTP client. /// The logger. - public ProviderManager(Kernel kernel, IHttpClient httpClient, ILogger logger) + public ProviderManager(Kernel kernel, IHttpClient httpClient, ILogger logger, IServerConfigurationManager configurationManager) : base(kernel) { _logger = logger; _httpClient = httpClient; + ConfigurationManager = configurationManager; _remoteImageCache = new FileSystemRepository(ImagesDataPath); + + configurationManager.ConfigurationUpdated += configurationManager_ConfigurationUpdated; + } + + /// + /// Handles the ConfigurationUpdated event of the configurationManager control. + /// + /// The source of the event. + /// The instance containing the event data. + void configurationManager_ConfigurationUpdated(object sender, EventArgs e) + { + // Validate currently executing providers, in the background + Task.Run(() => + { + ValidateCurrentlyRunningProviders(); + }); } /// @@ -67,7 +88,7 @@ namespace MediaBrowser.Controller.Providers { if (_imagesDataPath == null) { - _imagesDataPath = Path.Combine(Kernel.ApplicationPaths.DataPath, "remote-images"); + _imagesDataPath = Path.Combine(ConfigurationManager.ApplicationPaths.DataPath, "remote-images"); if (!Directory.Exists(_imagesDataPath)) { @@ -145,7 +166,7 @@ namespace MediaBrowser.Controller.Providers cancellationToken.ThrowIfCancellationRequested(); // Skip if internet providers are currently disabled - if (provider.RequiresInternet && !Kernel.Configuration.EnableInternetProviders) + if (provider.RequiresInternet && !ConfigurationManager.Configuration.EnableInternetProviders) { continue; } @@ -157,7 +178,7 @@ namespace MediaBrowser.Controller.Providers } // Skip if internet provider and this type is not allowed - if (provider.RequiresInternet && Kernel.Configuration.EnableInternetProviders && Kernel.Configuration.InternetProviderExcludeTypes.Contains(item.GetType().Name, StringComparer.OrdinalIgnoreCase)) + if (provider.RequiresInternet && ConfigurationManager.Configuration.EnableInternetProviders && ConfigurationManager.Configuration.InternetProviderExcludeTypes.Contains(item.GetType().Name, StringComparer.OrdinalIgnoreCase)) { continue; } @@ -249,8 +270,8 @@ namespace MediaBrowser.Controller.Providers { _logger.Info("Validing currently running providers"); - var enableInternetProviders = Kernel.Configuration.EnableInternetProviders; - var internetProviderExcludeTypes = Kernel.Configuration.InternetProviderExcludeTypes; + var enableInternetProviders = ConfigurationManager.Configuration.EnableInternetProviders; + var internetProviderExcludeTypes = ConfigurationManager.Configuration.InternetProviderExcludeTypes; foreach (var tuple in _currentlyRunningProviders.Values .Where(p => p.Item1.RequiresInternet && (!enableInternetProviders || internetProviderExcludeTypes.Contains(p.Item2.GetType().Name, StringComparer.OrdinalIgnoreCase))) @@ -290,13 +311,13 @@ namespace MediaBrowser.Controller.Providers } //download and save locally - var localPath = Kernel.Configuration.SaveLocalMeta ? + var localPath = ConfigurationManager.Configuration.SaveLocalMeta ? Path.Combine(item.MetaLocation, targetName) : _remoteImageCache.GetResourcePath(item.GetType().FullName + item.Path.ToLower(), targetName); var img = await _httpClient.GetMemoryStream(source, resourcePool, cancellationToken).ConfigureAwait(false); - if (Kernel.Configuration.SaveLocalMeta) // queue to media directories + if (ConfigurationManager.Configuration.SaveLocalMeta) // queue to media directories { await Kernel.FileSystemManager.SaveToLibraryFilesystem(item, localPath, img, cancellationToken).ConfigureAwait(false); } diff --git a/MediaBrowser.Controller/Providers/SortNameProvider.cs b/MediaBrowser.Controller/Providers/SortNameProvider.cs index 407db4c8e8..2214d8a080 100644 --- a/MediaBrowser.Controller/Providers/SortNameProvider.cs +++ b/MediaBrowser.Controller/Providers/SortNameProvider.cs @@ -1,10 +1,11 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Model.Logging; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Logging; namespace MediaBrowser.Controller.Providers { @@ -13,7 +14,8 @@ namespace MediaBrowser.Controller.Providers /// public class SortNameProvider : BaseMetadataProvider { - public SortNameProvider(ILogManager logManager) : base(logManager) + public SortNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { } @@ -99,14 +101,14 @@ namespace MediaBrowser.Controller.Providers if (item.Name == null) return false; //some items may not have name filled in properly var sortable = item.Name.Trim().ToLower(); - sortable = Kernel.Instance.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty)); + sortable = ConfigurationManager.Configuration.SortRemoveCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), string.Empty)); - sortable = Kernel.Instance.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " ")); + sortable = ConfigurationManager.Configuration.SortReplaceCharacters.Aggregate(sortable, (current, search) => current.Replace(search.ToLower(), " ")); - foreach (var search in Kernel.Instance.Configuration.SortRemoveWords) + foreach (var search in ConfigurationManager.Configuration.SortRemoveWords) { cancellationToken.ThrowIfCancellationRequested(); - + var searchLower = search.ToLower(); // Remove from beginning if a space follows if (sortable.StartsWith(searchLower + " ")) diff --git a/MediaBrowser.Controller/Providers/TV/EpisodeImageFromMediaLocationProvider.cs b/MediaBrowser.Controller/Providers/TV/EpisodeImageFromMediaLocationProvider.cs index 9c50091f19..e4ef738925 100644 --- a/MediaBrowser.Controller/Providers/TV/EpisodeImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/EpisodeImageFromMediaLocationProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Entities; using System; @@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Providers.TV /// public class EpisodeImageFromMediaLocationProvider : BaseMetadataProvider { - public EpisodeImageFromMediaLocationProvider(ILogManager logManager) : base(logManager) + public EpisodeImageFromMediaLocationProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/TV/EpisodeProviderFromXml.cs b/MediaBrowser.Controller/Providers/TV/EpisodeProviderFromXml.cs index 89f6810897..1913397d47 100644 --- a/MediaBrowser.Controller/Providers/TV/EpisodeProviderFromXml.cs +++ b/MediaBrowser.Controller/Providers/TV/EpisodeProviderFromXml.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Entities; using System; @@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Providers.TV /// public class EpisodeProviderFromXml : BaseMetadataProvider { - public EpisodeProviderFromXml(ILogManager logManager) : base(logManager) + public EpisodeProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs b/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs index 9769d7a3bc..d89545a8d1 100644 --- a/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/FanArtTVProvider.cs @@ -1,7 +1,9 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Providers.Movies; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; @@ -23,8 +25,8 @@ namespace MediaBrowser.Controller.Providers.TV /// The HTTP client. protected IHttpClient HttpClient { get; private set; } - public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager) - : base(logManager) + public FanArtTvProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (httpClient == null) { @@ -46,9 +48,9 @@ namespace MediaBrowser.Controller.Providers.TV var thumbExists = item.ResolveArgs.ContainsMetaFileByName(THUMB_FILE); - return (!artExists && Kernel.Instance.Configuration.DownloadTVArt) - || (!logoExists && Kernel.Instance.Configuration.DownloadTVLogo) - || (!thumbExists && Kernel.Instance.Configuration.DownloadTVThumb); + return (!artExists && ConfigurationManager.Configuration.DownloadTVArt) + || (!logoExists && ConfigurationManager.Configuration.DownloadTVLogo) + || (!thumbExists && ConfigurationManager.Configuration.DownloadTVThumb); } protected override async Task FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken) @@ -58,13 +60,13 @@ namespace MediaBrowser.Controller.Providers.TV var series = (Series)item; if (ShouldFetch(series, series.ProviderData.GetValueOrDefault(Id, new BaseProviderInfo { ProviderId = Id }))) { - string language = Kernel.Instance.Configuration.PreferredMetadataLanguage.ToLower(); + string language = ConfigurationManager.Configuration.PreferredMetadataLanguage.ToLower(); string url = string.Format(FanArtBaseUrl, APIKey, series.GetProviderId(MetadataProviders.Tvdb)); var doc = new XmlDocument(); try { - using (var xml = await HttpClient.Get(url, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)) + using (var xml = await HttpClient.Get(url, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false)) { doc.Load(xml); } @@ -78,7 +80,7 @@ namespace MediaBrowser.Controller.Providers.TV if (doc.HasChildNodes) { string path; - if (Kernel.Instance.Configuration.DownloadTVLogo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) + if (ConfigurationManager.Configuration.DownloadTVLogo && !series.ResolveArgs.ContainsMetaFileByName(LOGO_FILE)) { var node = doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/series/clearlogos/clearlogo/@url"); @@ -88,7 +90,7 @@ namespace MediaBrowser.Controller.Providers.TV Logger.Debug("FanArtProvider getting ClearLogo for " + series.Name); try { - series.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, LOGO_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + series.SetImage(ImageType.Logo, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, LOGO_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -102,7 +104,7 @@ namespace MediaBrowser.Controller.Providers.TV cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadTVArt && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE)) + if (ConfigurationManager.Configuration.DownloadTVArt && !series.ResolveArgs.ContainsMetaFileByName(ART_FILE)) { var node = doc.SelectSingleNode("//fanart/series/cleararts/clearart[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/series/cleararts/clearart/@url"); @@ -112,7 +114,7 @@ namespace MediaBrowser.Controller.Providers.TV Logger.Debug("FanArtProvider getting ClearArt for " + series.Name); try { - series.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, ART_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + series.SetImage(ImageType.Art, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, ART_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -126,7 +128,7 @@ namespace MediaBrowser.Controller.Providers.TV cancellationToken.ThrowIfCancellationRequested(); - if (Kernel.Instance.Configuration.DownloadTVThumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE)) + if (ConfigurationManager.Configuration.DownloadTVThumb && !series.ResolveArgs.ContainsMetaFileByName(THUMB_FILE)) { var node = doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb[@lang = \"" + language + "\"]/@url") ?? doc.SelectSingleNode("//fanart/series/tvthumbs/tvthumb/@url"); @@ -136,7 +138,7 @@ namespace MediaBrowser.Controller.Providers.TV Logger.Debug("FanArtProvider getting ThumbArt for " + series.Name); try { - series.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, THUMB_FILE, Kernel.Instance.ResourcePools.FanArt, cancellationToken).ConfigureAwait(false)); + series.SetImage(ImageType.Disc, await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, path, THUMB_FILE, FanArtMovieProvider.Current.FanArtResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { diff --git a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs index 8056ea5c0f..eee43016c6 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Extensions; @@ -27,13 +28,15 @@ namespace MediaBrowser.Controller.Providers.TV /// The HTTP client. protected IHttpClient HttpClient { get; private set; } - public RemoteEpisodeProvider(IHttpClient httpClient, ILogManager logManager) - : base(logManager) + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client. + /// The log manager. + /// The configuration manager. + public RemoteEpisodeProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { - if (httpClient == null) - { - throw new ArgumentNullException("httpClient"); - } HttpClient = httpClient; } @@ -94,15 +97,15 @@ namespace MediaBrowser.Controller.Providers.TV var episode = (Episode)item; var downloadDate = providerInfo.LastRefreshed; - if (Kernel.Instance.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) + if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) { return false; } if (!item.DontFetchMeta && !HasLocalMeta(episode)) { - fetch = Kernel.Instance.Configuration.MetadataRefreshDays != -1 && - DateTime.Today.Subtract(downloadDate).TotalDays > Kernel.Instance.Configuration.MetadataRefreshDays; + fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 && + DateTime.Today.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays; } return fetch; @@ -183,12 +186,12 @@ namespace MediaBrowser.Controller.Providers.TV seasonNumber = "0"; // Specials } - var url = string.Format(episodeQuery, TVUtils.TVDBApiKey, seriesId, seasonNumber, episodeNumber, Kernel.Instance.Configuration.PreferredMetadataLanguage); + var url = string.Format(episodeQuery, TVUtils.TVDBApiKey, seriesId, seasonNumber, episodeNumber, ConfigurationManager.Configuration.PreferredMetadataLanguage); var doc = new XmlDocument(); try { - using (var result = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var result = await HttpClient.Get(url, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { doc.Load(result); } @@ -202,11 +205,11 @@ namespace MediaBrowser.Controller.Providers.TV //this is basicly just for anime. if (!doc.HasChildNodes && Int32.Parse(seasonNumber) == 1) { - url = string.Format(absEpisodeQuery, TVUtils.TVDBApiKey, seriesId, episodeNumber, Kernel.Instance.Configuration.PreferredMetadataLanguage); + url = string.Format(absEpisodeQuery, TVUtils.TVDBApiKey, seriesId, episodeNumber, ConfigurationManager.Configuration.PreferredMetadataLanguage); try { - using (var result = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var result = await HttpClient.Get(url, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { if (result != null) doc.Load(result); usingAbsoluteData = true; @@ -226,7 +229,7 @@ namespace MediaBrowser.Controller.Providers.TV try { - episode.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(episode, TVUtils.BannerUrl + p, Path.GetFileName(p), Kernel.Instance.ResourcePools.TvDb, cancellationToken); + episode.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(episode, TVUtils.BannerUrl + p, Path.GetFileName(p), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken); } catch (HttpException) { @@ -273,7 +276,7 @@ namespace MediaBrowser.Controller.Providers.TV episode.AddPeople(writers.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = "Writer", Name = str })); } - if (Kernel.Instance.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta) { if (!Directory.Exists(episode.MetaLocation)) Directory.CreateDirectory(episode.MetaLocation); var ms = new MemoryStream(); diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs index ac79817754..71741d2259 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteSeasonProvider.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; @@ -24,9 +25,9 @@ namespace MediaBrowser.Controller.Providers.TV /// /// The HTTP client. protected IHttpClient HttpClient { get; private set; } - - public RemoteSeasonProvider(IHttpClient httpClient, ILogManager logManager) - : base(logManager) + + public RemoteSeasonProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (httpClient == null) { @@ -77,13 +78,13 @@ namespace MediaBrowser.Controller.Providers.TV bool fetch = false; var downloadDate = providerInfo.LastRefreshed; - if (Kernel.Instance.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) + if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) return false; if (!HasLocalMeta(item)) { - fetch = Kernel.Instance.Configuration.MetadataRefreshDays != -1 && - DateTime.UtcNow.Subtract(downloadDate).TotalDays > Kernel.Instance.Configuration.MetadataRefreshDays; + fetch = ConfigurationManager.Configuration.MetadataRefreshDays != -1 && + DateTime.UtcNow.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays; } return fetch; @@ -152,7 +153,7 @@ namespace MediaBrowser.Controller.Providers.TV try { - using (var imgs = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var imgs = await HttpClient.Get(url, RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { images.Load(imgs); } @@ -163,7 +164,7 @@ namespace MediaBrowser.Controller.Providers.TV if (images.HasChildNodes) { - if (Kernel.Instance.Configuration.RefreshItemImages || !season.HasLocalImage("folder")) + if (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("folder")) { var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='season'][Season='" + seasonNumber + "']"); if (n != null) @@ -173,7 +174,7 @@ namespace MediaBrowser.Controller.Providers.TV try { if (n != null) - season.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false); + season.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false); } catch (HttpException) { @@ -185,7 +186,7 @@ namespace MediaBrowser.Controller.Providers.TV } } - if (Kernel.Instance.Configuration.DownloadTVSeasonBanner && (Kernel.Instance.Configuration.RefreshItemImages || !season.HasLocalImage("banner"))) + if (ConfigurationManager.Configuration.DownloadTVSeasonBanner && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("banner"))) { var n = images.SelectSingleNode("//Banner[BannerType='season'][BannerType2='seasonwide'][Season='" + seasonNumber + "']"); if (n != null) @@ -201,7 +202,7 @@ namespace MediaBrowser.Controller.Providers.TV TVUtils.BannerUrl + n.InnerText, "banner" + Path.GetExtension(n.InnerText), - Kernel.Instance.ResourcePools.TvDb, cancellationToken). + RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken). ConfigureAwait(false); season.SetImage(ImageType.Banner, bannerImagePath); @@ -217,7 +218,7 @@ namespace MediaBrowser.Controller.Providers.TV } } - if (Kernel.Instance.Configuration.DownloadTVSeasonBackdrops && (Kernel.Instance.Configuration.RefreshItemImages || !season.HasLocalImage("backdrop"))) + if (ConfigurationManager.Configuration.DownloadTVSeasonBackdrops && (ConfigurationManager.Configuration.RefreshItemImages || !season.HasLocalImage("backdrop"))) { var n = images.SelectSingleNode("//Banner[BannerType='fanart'][Season='" + seasonNumber + "']"); if (n != null) @@ -228,7 +229,7 @@ namespace MediaBrowser.Controller.Providers.TV try { if (season.BackdropImagePaths == null) season.BackdropImagePaths = new List(); - season.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "backdrop" + Path.GetExtension(n.InnerText), Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)); + season.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(season, TVUtils.BannerUrl + n.InnerText, "backdrop" + Path.GetExtension(n.InnerText), RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -239,7 +240,7 @@ namespace MediaBrowser.Controller.Providers.TV } } } - else if (!Kernel.Instance.Configuration.SaveLocalMeta) //if saving local - season will inherit from series + else if (!ConfigurationManager.Configuration.SaveLocalMeta) //if saving local - season will inherit from series { // not necessarily accurate but will give a different bit of art to each season var lst = images.SelectNodes("//Banner[BannerType='fanart']"); @@ -263,7 +264,7 @@ namespace MediaBrowser.Controller.Providers.TV "backdrop" + Path.GetExtension( n.InnerText), - Kernel.Instance.ResourcePools.TvDb, cancellationToken) + RemoteSeriesProvider.Current.TvDbResourcePool, cancellationToken) .ConfigureAwait(false)); } catch (HttpException) diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs index 7c65136b61..1d4063cdde 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Extensions; @@ -23,20 +24,48 @@ namespace MediaBrowser.Controller.Providers.TV /// class RemoteSeriesProvider : BaseMetadataProvider { + /// + /// The tv db + /// + internal readonly SemaphoreSlim TvDbResourcePool = new SemaphoreSlim(5, 5); + + internal static RemoteSeriesProvider Current { get; private set; } + /// /// Gets the HTTP client. /// /// The HTTP client. protected IHttpClient HttpClient { get; private set; } - public RemoteSeriesProvider(IHttpClient httpClient, ILogManager logManager) - : base(logManager) + /// + /// Initializes a new instance of the class. + /// + /// The HTTP client. + /// The log manager. + /// The configuration manager. + /// httpClient + public RemoteSeriesProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) { if (httpClient == null) { throw new ArgumentNullException("httpClient"); } HttpClient = httpClient; + Current = this; + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool dispose) + { + if (dispose) + { + TvDbResourcePool.Dispose(); + } + base.Dispose(dispose); } /// @@ -102,15 +131,15 @@ namespace MediaBrowser.Controller.Providers.TV { var downloadDate = providerInfo.LastRefreshed; - if (Kernel.Instance.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) + if (ConfigurationManager.Configuration.MetadataRefreshDays == -1 && downloadDate != DateTime.MinValue) { return false; } if (item.DontFetchMeta) return false; - return !HasLocalMeta(item) && (Kernel.Instance.Configuration.MetadataRefreshDays != -1 && - DateTime.UtcNow.Subtract(downloadDate).TotalDays > Kernel.Instance.Configuration.MetadataRefreshDays); + return !HasLocalMeta(item) && (ConfigurationManager.Configuration.MetadataRefreshDays != -1 && + DateTime.UtcNow.Subtract(downloadDate).TotalDays > ConfigurationManager.Configuration.MetadataRefreshDays); } /// @@ -165,12 +194,12 @@ namespace MediaBrowser.Controller.Providers.TV if (!string.IsNullOrEmpty(seriesId)) { - string url = string.Format(seriesGet, TVUtils.TVDBApiKey, seriesId, Kernel.Instance.Configuration.PreferredMetadataLanguage); + string url = string.Format(seriesGet, TVUtils.TVDBApiKey, seriesId, ConfigurationManager.Configuration.PreferredMetadataLanguage); var doc = new XmlDocument(); try { - using (var xml = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var xml = await HttpClient.Get(url, TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { doc.Load(xml); } @@ -219,7 +248,7 @@ namespace MediaBrowser.Controller.Providers.TV //wait for other tasks await Task.WhenAll(actorTask, imageTask).ConfigureAwait(false); - if (Kernel.Instance.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta) { var ms = new MemoryStream(); doc.Save(ms); @@ -249,7 +278,7 @@ namespace MediaBrowser.Controller.Providers.TV try { - using (var actors = await HttpClient.Get(urlActors, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var actors = await HttpClient.Get(urlActors, TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { docActors.Load(actors); } @@ -261,7 +290,7 @@ namespace MediaBrowser.Controller.Providers.TV if (docActors.HasChildNodes) { XmlNode actorsNode = null; - if (Kernel.Instance.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta) { //add to the main doc for saving var seriesNode = doc.SelectSingleNode("//Series"); @@ -282,7 +311,7 @@ namespace MediaBrowser.Controller.Providers.TV { series.AddPerson(new PersonInfo { Type = PersonType.Actor, Name = actorName, Role = actorRole }); - if (Kernel.Instance.Configuration.SaveLocalMeta && actorsNode != null) + if (ConfigurationManager.Configuration.SaveLocalMeta && actorsNode != null) { //create in main doc var personNode = doc.CreateNode(XmlNodeType.Element, "Person", null); @@ -316,7 +345,7 @@ namespace MediaBrowser.Controller.Providers.TV try { - using (var imgs = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var imgs = await HttpClient.Get(url, TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { images.Load(imgs); } @@ -327,7 +356,7 @@ namespace MediaBrowser.Controller.Providers.TV if (images.HasChildNodes) { - if (Kernel.Instance.Configuration.RefreshItemImages || !series.HasLocalImage("folder")) + if (ConfigurationManager.Configuration.RefreshItemImages || !series.HasLocalImage("folder")) { var n = images.SelectSingleNode("//Banner[BannerType='poster']"); if (n != null) @@ -337,7 +366,7 @@ namespace MediaBrowser.Controller.Providers.TV { try { - series.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false); + series.PrimaryImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "folder" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false); } catch (HttpException) { @@ -350,7 +379,7 @@ namespace MediaBrowser.Controller.Providers.TV } } - if (Kernel.Instance.Configuration.DownloadTVBanner && (Kernel.Instance.Configuration.RefreshItemImages || !series.HasLocalImage("banner"))) + if (ConfigurationManager.Configuration.DownloadTVBanner && (ConfigurationManager.Configuration.RefreshItemImages || !series.HasLocalImage("banner"))) { var n = images.SelectSingleNode("//Banner[BannerType='series']"); if (n != null) @@ -360,7 +389,7 @@ namespace MediaBrowser.Controller.Providers.TV { try { - var bannerImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "banner" + Path.GetExtension(n.InnerText), Kernel.Instance.ResourcePools.TvDb, cancellationToken); + var bannerImagePath = await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + n.InnerText, "banner" + Path.GetExtension(n.InnerText), TvDbResourcePool, cancellationToken); series.SetImage(ImageType.Banner, bannerImagePath); } @@ -385,11 +414,11 @@ namespace MediaBrowser.Controller.Providers.TV if (p != null) { var bdName = "backdrop" + (bdNo > 0 ? bdNo.ToString() : ""); - if (Kernel.Instance.Configuration.RefreshItemImages || !series.HasLocalImage(bdName)) + if (ConfigurationManager.Configuration.RefreshItemImages || !series.HasLocalImage(bdName)) { try { - series.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + p.InnerText, bdName + Path.GetExtension(p.InnerText), Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)); + series.BackdropImagePaths.Add(await Kernel.Instance.ProviderManager.DownloadAndSaveImage(series, TVUtils.BannerUrl + p.InnerText, bdName + Path.GetExtension(p.InnerText), TvDbResourcePool, cancellationToken).ConfigureAwait(false)); } catch (HttpException) { @@ -400,7 +429,7 @@ namespace MediaBrowser.Controller.Providers.TV } } bdNo++; - if (bdNo >= Kernel.Instance.Configuration.MaxBackdrops) break; + if (bdNo >= ConfigurationManager.Configuration.MaxBackdrops) break; } } } @@ -463,7 +492,7 @@ namespace MediaBrowser.Controller.Providers.TV try { - using (var results = await HttpClient.Get(url, Kernel.Instance.ResourcePools.TvDb, cancellationToken).ConfigureAwait(false)) + using (var results = await HttpClient.Get(url, TvDbResourcePool, cancellationToken).ConfigureAwait(false)) { doc.Load(results); } diff --git a/MediaBrowser.Controller/Providers/TV/SeriesProviderFromXml.cs b/MediaBrowser.Controller/Providers/TV/SeriesProviderFromXml.cs index 450c36e515..f9d409c184 100644 --- a/MediaBrowser.Controller/Providers/TV/SeriesProviderFromXml.cs +++ b/MediaBrowser.Controller/Providers/TV/SeriesProviderFromXml.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Entities; using System; @@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.Providers.TV /// public class SeriesProviderFromXml : BaseMetadataProvider { - public SeriesProviderFromXml(ILogManager logManager) : base(logManager) + public SeriesProviderFromXml(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager) { } diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs index f67f690aed..9a2733ce03 100644 --- a/MediaBrowser.Controller/Updates/InstallationManager.cs +++ b/MediaBrowser.Controller/Updates/InstallationManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Events; +using MediaBrowser.Common; +using MediaBrowser.Common.Events; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; @@ -182,7 +183,7 @@ namespace MediaBrowser.Controller.Updates PackageType? packageType = null, Version applicationVersion = null) { - var packages = (await _packageManager.GetAvailablePackages(HttpClient, _networkManager, Kernel.SecurityManager, Kernel.ResourcePools, JsonSerializer, cancellationToken).ConfigureAwait(false)).ToList(); + var packages = (await _packageManager.GetAvailablePackages(cancellationToken).ConfigureAwait(false)).ToList(); if (packageType.HasValue) { @@ -418,7 +419,7 @@ namespace MediaBrowser.Controller.Updates private async Task InstallPackageInternal(PackageVersionInfo package, IProgress progress, CancellationToken cancellationToken) { // Do the install - await _packageManager.InstallPackage(HttpClient, _logger, Kernel.ResourcePools, progress, Kernel.ApplicationPaths, package, cancellationToken).ConfigureAwait(false); + await _packageManager.InstallPackage(progress, package, cancellationToken).ConfigureAwait(false); // Do plugin-specific processing if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Model/DTO/BaseItemDto.cs b/MediaBrowser.Model/DTO/BaseItemDto.cs index c72613d1a8..67c7dabf60 100644 --- a/MediaBrowser.Model/DTO/BaseItemDto.cs +++ b/MediaBrowser.Model/DTO/BaseItemDto.cs @@ -245,20 +245,6 @@ namespace MediaBrowser.Model.Dto [ProtoMember(38)] public int? RecentlyAddedItemCount { get; set; } - /// - /// Gets or sets the recently added un played item count. - /// - /// The recently added un played item count. - [ProtoMember(39)] - public int? RecentlyAddedUnPlayedItemCount { get; set; } - - /// - /// Gets or sets the resumable item count. - /// - /// The resumable item count. - [ProtoMember(40)] - public int? ResumableItemCount { get; set; } - /// /// Gets or sets the played percentage. /// @@ -273,13 +259,6 @@ namespace MediaBrowser.Model.Dto [ProtoMember(42)] public int? RecursiveItemCount { get; set; } - /// - /// Gets or sets the favorite item count. - /// - /// The favorite item count. - [ProtoMember(43)] - public int? FavoriteItemCount { get; set; } - /// /// Gets or sets the child count. /// @@ -301,13 +280,6 @@ namespace MediaBrowser.Model.Dto [ProtoMember(46)] public string SeriesId { get; set; } - /// - /// Gets or sets the recently played item count. - /// - /// The recently played item count. - [ProtoMember(47)] - public int? RecentlyPlayedItemCount { get; set; } - /// /// Gets or sets the special feature count. /// diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs new file mode 100644 index 0000000000..cb4c5a6cdd --- /dev/null +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -0,0 +1,55 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Implementations.Configuration; +using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; +using System; + +namespace MediaBrowser.Server.Implementations.Configuration +{ + /// + /// Class ServerConfigurationManager + /// + public class ServerConfigurationManager : BaseConfigurationManager, IServerConfigurationManager + { + /// + /// Initializes a new instance of the class. + /// + /// The application paths. + /// The log manager. + /// The XML serializer. + public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer) + : base(applicationPaths, logManager, xmlSerializer) + { + } + + /// + /// Gets the type of the configuration. + /// + /// The type of the configuration. + protected override Type ConfigurationType + { + get { return typeof(ServerConfiguration); } + } + + /// + /// Gets the application paths. + /// + /// The application paths. + public IServerApplicationPaths ApplicationPaths + { + get { return (IServerApplicationPaths)CommonApplicationPaths; } + } + + /// + /// Gets the configuration. + /// + /// The configuration. + public ServerConfiguration Configuration + { + get { return (ServerConfiguration)CommonConfiguration; } + } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index b6e9fec170..c3c48f0993 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -3,6 +3,7 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; @@ -90,6 +91,12 @@ namespace MediaBrowser.Server.Implementations.Library /// The kernel. private Kernel Kernel { get; set; } + /// + /// Gets or sets the configuration manager. + /// + /// The configuration manager. + private IServerConfigurationManager ConfigurationManager { get; set; } + /// /// Initializes a new instance of the class. /// @@ -97,14 +104,16 @@ namespace MediaBrowser.Server.Implementations.Library /// The logger. /// The task manager. /// The user manager. - public LibraryManager(Kernel kernel, ILogger logger, ITaskManager taskManager, IUserManager userManager) + /// The configuration manager. + public LibraryManager(Kernel kernel, ILogger logger, ITaskManager taskManager, IUserManager userManager, IServerConfigurationManager configurationManager) { Kernel = kernel; _logger = logger; _taskManager = taskManager; _userManager = userManager; + ConfigurationManager = configurationManager; - kernel.ConfigurationUpdated += kernel_ConfigurationUpdated; + ConfigurationManager.ConfigurationUpdated += kernel_ConfigurationUpdated; } /// @@ -222,7 +231,7 @@ namespace MediaBrowser.Server.Implementations.Library return null; } - var args = new ItemResolveArgs + var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths) { Parent = parent, Path = path, @@ -306,7 +315,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Cannot create the root folder until plugins have loaded public AggregateFolder CreateRootFolder() { - var rootFolderPath = Kernel.ApplicationPaths.RootFolderPath; + var rootFolderPath = ConfigurationManager.ApplicationPaths.RootFolderPath; var rootFolder = Kernel.ItemRepository.RetrieveItem(rootFolderPath.GetMBId(typeof(AggregateFolder))) as AggregateFolder ?? (AggregateFolder)ResolvePath(rootFolderPath); // Add in the plug-in folders @@ -338,7 +347,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task{Person}. private Task GetPerson(string name, CancellationToken cancellationToken, bool allowSlowProviders = false) { - return GetImagesByNameItem(Kernel.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders); + return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders); } /// @@ -349,7 +358,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task{Studio}. public Task GetStudio(string name, bool allowSlowProviders = false) { - return GetImagesByNameItem(Kernel.ApplicationPaths.StudioPath, name, CancellationToken.None, allowSlowProviders); + return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.StudioPath, name, CancellationToken.None, allowSlowProviders); } /// @@ -360,7 +369,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task{Genre}. public Task GetGenre(string name, bool allowSlowProviders = false) { - return GetImagesByNameItem(Kernel.ApplicationPaths.GenrePath, name, CancellationToken.None, allowSlowProviders); + return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.GenrePath, name, CancellationToken.None, allowSlowProviders); } /// @@ -382,7 +391,7 @@ namespace MediaBrowser.Server.Implementations.Library throw new ArgumentOutOfRangeException(); } - return GetImagesByNameItem(Kernel.ApplicationPaths.YearPath, value.ToString(UsCulture), CancellationToken.None, allowSlowProviders); + return GetImagesByNameItem(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture), CancellationToken.None, allowSlowProviders); } /// @@ -612,7 +621,7 @@ namespace MediaBrowser.Server.Implementations.Library /// IEnumerable{VirtualFolderInfo}. public IEnumerable GetDefaultVirtualFolders() { - return GetView(Kernel.ApplicationPaths.DefaultUserViewsPath); + return GetView(ConfigurationManager.ApplicationPaths.DefaultUserViewsPath); } /// diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 4dd7aceb44..61ca82f95c 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; @@ -16,6 +17,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// public class MovieResolver : BaseVideoResolver { + private IServerApplicationPaths ApplicationPaths { get; set; } + + public MovieResolver(IServerApplicationPaths appPaths) + { + ApplicationPaths = appPaths; + } + /// /// Gets the priority. /// @@ -149,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies continue; } - var childArgs = new ItemResolveArgs + var childArgs = new ItemResolveArgs(ApplicationPaths) { FileInfo = child, Path = child.Path diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 0490a9cf03..a3a24fb344 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Connectivity; @@ -89,15 +90,23 @@ namespace MediaBrowser.Server.Implementations.Library /// The kernel. private Kernel Kernel { get; set; } + /// + /// Gets or sets the configuration manager. + /// + /// The configuration manager. + private IServerConfigurationManager ConfigurationManager { get; set; } + /// /// Initializes a new instance of the class. /// /// The kernel. /// The logger. - public UserManager(Kernel kernel, ILogger logger) + /// The configuration manager. + public UserManager(Kernel kernel, ILogger logger, IServerConfigurationManager configurationManager) { _logger = logger; Kernel = kernel; + ConfigurationManager = configurationManager; } #region Events @@ -596,14 +605,14 @@ namespace MediaBrowser.Server.Implementations.Library var pctIn = Decimal.Divide(positionTicks, item.RunTimeTicks.Value) * 100; // Don't track in very beginning - if (pctIn < Kernel.Configuration.MinResumePct) + if (pctIn < ConfigurationManager.Configuration.MinResumePct) { positionTicks = 0; incrementPlayCount = false; } // If we're at the end, assume completed - else if (pctIn > Kernel.Configuration.MaxResumePct || positionTicks >= item.RunTimeTicks.Value) + else if (pctIn > ConfigurationManager.Configuration.MaxResumePct || positionTicks >= item.RunTimeTicks.Value) { positionTicks = 0; data.Played = true; @@ -614,7 +623,7 @@ namespace MediaBrowser.Server.Implementations.Library // Enforce MinResumeDuration var durationSeconds = TimeSpan.FromTicks(item.RunTimeTicks.Value).TotalSeconds; - if (durationSeconds < Kernel.Configuration.MinResumeDurationSeconds) + if (durationSeconds < ConfigurationManager.Configuration.MinResumeDurationSeconds) { positionTicks = 0; data.Played = true; diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 05fe1d3abf..bf6046393a 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -58,6 +58,7 @@ Properties\SharedVersion.cs + diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs index 53a467c1a0..d6a0858afd 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteDisplayPreferencesRepository.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs index 24de081f93..87cce1785d 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteItemRepository.cs @@ -1,3 +1,4 @@ +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Persistence; diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs index 5787a614a7..64ba4d1e2c 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserDataRepository.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Logging; diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs index 1e6f370ebf..89d2900dd2 100644 --- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs +++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteUserRepository.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Kernel; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Logging; diff --git a/MediaBrowser.Server.Implementations/WorldWeatherOnline/WeatherProvider.cs b/MediaBrowser.Server.Implementations/WorldWeatherOnline/WeatherProvider.cs index 39ac203fc9..ae8b1ff974 100644 --- a/MediaBrowser.Server.Implementations/WorldWeatherOnline/WeatherProvider.cs +++ b/MediaBrowser.Server.Implementations/WorldWeatherOnline/WeatherProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Net; -using MediaBrowser.Controller; using MediaBrowser.Controller.Weather; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index d79b2ff437..470b7fc558 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -1,4 +1,5 @@ using System.IO; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Constants; using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Updates; @@ -71,12 +72,6 @@ namespace MediaBrowser.ServerApplication /// private Mutex SingleInstanceMutex; - /// - /// Gets or sets the kernel. - /// - /// The kernel. - protected IKernel Kernel { get; set; } - /// /// Gets or sets the logger. /// @@ -107,12 +102,6 @@ namespace MediaBrowser.ServerApplication get { return "MediaBrowser.Server.Uninstall.exe"; } } - /// - /// Gets or sets a value indicating whether [last run at startup value]. - /// - /// null if [last run at startup value] contains no value, true if [last run at startup value]; otherwise, false. - private bool? LastRunAtStartupValue { get; set; } - /// /// Raises the event. /// @@ -164,26 +153,17 @@ namespace MediaBrowser.ServerApplication /// protected async void LoadKernel() { - CompositionRoot = new ApplicationHost(); - await CompositionRoot.Init(); - - Logger = CompositionRoot.Logger; - Kernel = CompositionRoot.Kernel; - try { - var win = (MainWindow)CompositionRoot.CreateInstance(typeof(MainWindow)); - - win.Show(); + CompositionRoot = new ApplicationHost(); - var now = DateTime.UtcNow; + var win = new MainWindow(CompositionRoot.LogManager, CompositionRoot, CompositionRoot.ServerConfigurationManager); - Kernel.Init(); + Logger = CompositionRoot.LogManager.GetLogger("App"); - var done = (DateTime.UtcNow - now); - Logger.Info("Kernel.Init completed in {0}{1} minutes and {2} seconds.", done.Hours > 0 ? done.Hours + " Hours " : "", done.Minutes, done.Seconds); + win.Show(); - await OnKernelLoaded(); + await CompositionRoot.Init(); } catch (Exception ex) { @@ -196,41 +176,6 @@ namespace MediaBrowser.ServerApplication } } - /// - /// Called when [kernel loaded]. - /// - /// Task. - protected Task OnKernelLoaded() - { - return Task.Run(() => - { - Kernel.ConfigurationUpdated += Kernel_ConfigurationUpdated; - - ConfigureAutoRun(); - }); - } - - /// - /// Handles the ConfigurationUpdated event of the Kernel control. - /// - /// The source of the event. - /// The instance containing the event data. - void Kernel_ConfigurationUpdated(object sender, EventArgs e) - { - if (!LastRunAtStartupValue.HasValue || LastRunAtStartupValue.Value != Kernel.Configuration.RunAtStartup) - { - ConfigureAutoRun(); - } - } - - /// - /// Configures the click once startup. - /// - private void ConfigureAutoRun() - { - CompositionRoot.ConfigureAutoRunAtStartup(Kernel.Configuration.RunAtStartup); - } - /// /// Raises the event. /// @@ -260,22 +205,14 @@ namespace MediaBrowser.ServerApplication SingleInstanceMutex = null; } - /// - /// Opens the dashboard. - /// - public static void OpenDashboard(User loggedInUser) - { - OpenDashboardPage("dashboard.html", loggedInUser); - } - /// /// Opens the dashboard page. /// /// The page. - public static void OpenDashboardPage(string page, User loggedInUser) + public static void OpenDashboardPage(string page, User loggedInUser, IConfigurationManager configurationManager) { - var url = "http://localhost:" + Controller.Kernel.Instance.Configuration.HttpServerPortNumber + "/" + - Controller.Kernel.Instance.WebApplicationName + "/dashboard/" + page; + var url = "http://localhost:" + configurationManager.CommonConfiguration.HttpServerPortNumber + "/" + + Kernel.Instance.WebApplicationName + "/dashboard/" + page; if (loggedInUser != null) { diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index fa9ba2b8f0..c36e0fa7fa 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -1,18 +1,16 @@ using MediaBrowser.Api; +using MediaBrowser.Common; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Constants; using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.HttpServer; using MediaBrowser.Common.Implementations.Logging; -using MediaBrowser.Common.Implementations.NetworkManagement; using MediaBrowser.Common.Implementations.ScheduledTasks; -using MediaBrowser.Common.Implementations.Serialization; -using MediaBrowser.Common.Implementations.ServerManager; using MediaBrowser.Common.IO; using MediaBrowser.Common.Kernel; -using MediaBrowser.Common.Net; -using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; @@ -21,13 +19,12 @@ using MediaBrowser.IsoMounter; using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; -using MediaBrowser.Model.Serialization; using MediaBrowser.Model.System; using MediaBrowser.Model.Updates; using MediaBrowser.Server.Implementations; using MediaBrowser.Server.Implementations.BdInfo; +using MediaBrowser.Server.Implementations.Configuration; using MediaBrowser.Server.Implementations.Library; -using MediaBrowser.Server.Implementations.Library.Resolvers; using MediaBrowser.ServerApplication.Implementations; using MediaBrowser.WebDashboard.Api; using System; @@ -43,112 +40,80 @@ namespace MediaBrowser.ServerApplication /// /// Class CompositionRoot /// - public class ApplicationHost : BaseApplicationHost, IApplicationHost + public class ApplicationHost : BaseApplicationHost { /// - /// Gets or sets the kernel. + /// The _web socket events /// - /// The kernel. - internal Kernel Kernel { get; private set; } - - /// - /// The json serializer - /// - private readonly IJsonSerializer _jsonSerializer = new JsonSerializer(); - - /// - /// The _XML serializer - /// - private readonly IXmlSerializer _xmlSerializer = new XmlSerializer(); - private WebSocketEvents _webSocketEvents; /// - /// Gets the server application paths. + /// Gets the server kernel. /// - /// The server application paths. - protected IServerApplicationPaths ServerApplicationPaths + /// The server kernel. + protected Kernel ServerKernel { - get { return (IServerApplicationPaths)ApplicationPaths; } + get { return (Kernel)Kernel; } } /// - /// Initializes a new instance of the class. + /// Gets the server configuration manager. /// - /// The logger. - public ApplicationHost() - : base() + /// The server configuration manager. + public IServerConfigurationManager ServerConfigurationManager { + get { return (IServerConfigurationManager)ConfigurationManager; } } /// - /// Inits this instance. + /// Gets the kernel. /// - /// Task. - public override async Task Init() + /// IKernel. + protected override IKernel GetKernel() { - await base.Init().ConfigureAwait(false); - - Kernel = new Kernel(this, ServerApplicationPaths, _xmlSerializer, Logger); - - var networkManager = new NetworkManager(); - - var serverManager = new ServerManager(this, Kernel, networkManager, _jsonSerializer, Logger); - - var taskManager = new TaskManager(ApplicationPaths, _jsonSerializer, Logger, serverManager); - - LogManager.ReloadLogger(Kernel.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); - - Logger.Info("Version {0} initializing", ApplicationVersion); - - RegisterResources(taskManager, networkManager, serverManager); - - FindParts(); + return new Kernel(this, XmlSerializer, LogManager, ServerConfigurationManager); } /// - /// Gets the application paths. + /// Gets the name of the log file prefix. /// - /// IApplicationPaths. - protected override IApplicationPaths GetApplicationPaths() + /// The name of the log file prefix. + protected override string LogFilePrefixName { - return new ServerApplicationPaths(); + get { return "Server"; } } /// - /// Gets the log manager. + /// Gets the configuration manager. /// - /// ILogManager. - protected override ILogManager GetLogManager() + /// IConfigurationManager. + protected override IConfigurationManager GetConfigurationManager() { - return new NlogManager(ApplicationPaths.LogDirectoryPath, "Server"); + return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer); } /// /// Registers resources that classes will depend on /// - protected override void RegisterResources(ITaskManager taskManager, INetworkManager networkManager, IServerManager serverManager) + protected override void RegisterResources() { - base.RegisterResources(taskManager, networkManager, serverManager); - - RegisterSingleInstance(Kernel); - RegisterSingleInstance(Kernel); + base.RegisterResources(); - RegisterSingleInstance(this); + RegisterSingleInstance(ApplicationPaths); + + RegisterSingleInstance(ServerKernel); + RegisterSingleInstance(ServerConfigurationManager); - - RegisterSingleInstance(ServerApplicationPaths); RegisterSingleInstance(new PismoIsoManager(Logger)); RegisterSingleInstance(new BdInfoExaminer()); RegisterSingleInstance(new DotNetZipClient()); - RegisterSingleInstance(_jsonSerializer); - RegisterSingleInstance(_xmlSerializer); RegisterSingleInstance(ServerFactory.CreateServer(this, ProtobufSerializer, Logger, "Media Browser", "index.html"), false); - var userManager = new UserManager(Kernel, Logger); + var userManager = new UserManager(ServerKernel, Logger, ServerConfigurationManager); + RegisterSingleInstance(userManager); - RegisterSingleInstance(new LibraryManager(Kernel, Logger, taskManager, userManager)); + RegisterSingleInstance(new LibraryManager(ServerKernel, Logger, TaskManager, userManager, ServerConfigurationManager)); } /// @@ -160,15 +125,15 @@ namespace MediaBrowser.ServerApplication Resolve().AddParts(GetExports(), GetExports(), GetExports(), GetExports()); - Kernel.InstallationManager = (InstallationManager)CreateInstance(typeof(InstallationManager)); + ServerKernel.InstallationManager = (InstallationManager)CreateInstance(typeof(InstallationManager)); - _webSocketEvents = new WebSocketEvents(Resolve(), Resolve(), Resolve(), Resolve(), Resolve(), Kernel.InstallationManager); + _webSocketEvents = new WebSocketEvents(Resolve(), Resolve(), Resolve(), Resolve(), Resolve(), ServerKernel.InstallationManager); } /// /// Restarts this instance. /// - public void Restart() + public override void Restart() { App.Instance.Restart(); } @@ -177,9 +142,9 @@ namespace MediaBrowser.ServerApplication /// Gets or sets a value indicating whether this instance can self update. /// /// true if this instance can self update; otherwise, false. - public bool CanSelfUpdate + public override bool CanSelfUpdate { - get { return Kernel.Configuration.EnableAutoUpdate; } + get { return ConfigurationManager.CommonConfiguration.EnableAutoUpdate; } } /// @@ -188,11 +153,11 @@ namespace MediaBrowser.ServerApplication /// The cancellation token. /// The progress. /// Task{CheckForUpdateResult}. - public async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) + public async override Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) { var pkgManager = Resolve(); - var availablePackages = await pkgManager.GetAvailablePackages(Resolve(), Resolve(), Kernel.SecurityManager, Kernel.ResourcePools, Resolve(), CancellationToken.None).ConfigureAwait(false); - var version = Kernel.InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MBServerPkgName, Kernel.Configuration.SystemUpdateLevel); + var availablePackages = await pkgManager.GetAvailablePackages(CancellationToken.None).ConfigureAwait(false); + var version = ServerKernel.InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MBServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; @@ -205,10 +170,10 @@ namespace MediaBrowser.ServerApplication /// The cancellation token. /// The progress. /// Task. - public Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress progress) + public override Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress progress) { var pkgManager = Resolve(); - return pkgManager.InstallPackage(Resolve(), Resolve(), Kernel.ResourcePools, progress, Kernel.ApplicationPaths, package, cancellationToken); + return pkgManager.InstallPackage(progress, package, cancellationToken); } /// @@ -254,7 +219,7 @@ namespace MediaBrowser.ServerApplication /// /// Shuts down. /// - public void Shutdown() + public override void Shutdown() { App.Instance.Dispatcher.Invoke(App.Instance.Shutdown); } diff --git a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs index 2c07effde3..d15865485b 100644 --- a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs +++ b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Kernel; -using MediaBrowser.Controller; +using MediaBrowser.Common; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; @@ -78,11 +77,10 @@ namespace MediaBrowser.ServerApplication //this whole async thing doesn't really work in this instance since all my work pretty much needs to be on the UI thread... Cursor = Cursors.Wait; await Task.Run(() => - { - IEnumerable children; - children = CurrentUser.Name == "Physical" ? _libraryManager.RootFolder.Children.OrderBy(i => i.SortName) : _libraryManager.RootFolder.GetChildren(CurrentUser, sortBy: LocalizedStrings.Instance.GetString("NameDispPref")); + { + IEnumerable children = CurrentUser.Name == "Physical" ? _libraryManager.RootFolder.Children.OrderBy(i => i.SortName) : _libraryManager.RootFolder.GetChildren(CurrentUser, sortBy: LocalizedStrings.Instance.GetString("NameDispPref")); - foreach (Folder folder in children) + foreach (Folder folder in children) { var currentFolder = folder; @@ -96,7 +94,7 @@ namespace MediaBrowser.ServerApplication tvwLibrary.Items.Add(node); }, CancellationToken.None, TaskCreationOptions.None, ui); } - }); + }); lblLoading.Visibility = Visibility.Hidden; Cursor = Cursors.Arrow; diff --git a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs index fca9784861..75ef69924b 100644 --- a/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs +++ b/MediaBrowser.ServerApplication/Logging/LogWindow.xaml.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Kernel; -using NLog; +using NLog; using NLog.Config; using NLog.Targets; using System.ComponentModel; @@ -18,20 +17,15 @@ namespace MediaBrowser.ServerApplication.Logging /// The _ui thread /// private readonly TaskScheduler _uiThread; - /// - /// The _kernel - /// - private readonly IKernel _kernel; /// /// Initializes a new instance of the class. /// /// The kernel. - public LogWindow(IKernel kernel) + public LogWindow() { InitializeComponent(); _uiThread = TaskScheduler.FromCurrentSynchronizationContext(); - _kernel = kernel; Loaded += LogWindow_Loaded; } @@ -94,7 +88,7 @@ namespace MediaBrowser.ServerApplication.Logging target.Name = name; config.AddTarget(name, target); - var level = _kernel.Configuration.EnableDebugLevelLogging ? LogLevel.Debug : LogLevel.Info; + var level = LogLevel.Debug; var rule = new LoggingRule("*", level, target); config.LoggingRules.Add(rule); diff --git a/MediaBrowser.ServerApplication/MainWindow.xaml.cs b/MediaBrowser.ServerApplication/MainWindow.xaml.cs index 0d0d2d54bb..9043e007f2 100644 --- a/MediaBrowser.ServerApplication/MainWindow.xaml.cs +++ b/MediaBrowser.ServerApplication/MainWindow.xaml.cs @@ -1,5 +1,7 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using MediaBrowser.ServerApplication.Logging; @@ -31,6 +33,11 @@ namespace MediaBrowser.ServerApplication /// The _log manager /// private readonly ILogManager _logManager; + + /// + /// The _configuration manager + /// + private readonly IServerConfigurationManager _configurationManager; /// /// Initializes a new instance of the class. @@ -39,16 +46,25 @@ namespace MediaBrowser.ServerApplication /// The logger. /// The app host. /// logger - public MainWindow(ILogManager logManager, IApplicationHost appHost) + public MainWindow(ILogManager logManager, IApplicationHost appHost, IServerConfigurationManager configurationManager) { if (logManager == null) { throw new ArgumentNullException("logManager"); } + if (appHost == null) + { + throw new ArgumentNullException("appHost"); + } + if (configurationManager == null) + { + throw new ArgumentNullException("configurationManager"); + } _logger = logManager.GetLogger("MainWindow"); _appHost = appHost; _logManager = logManager; + _configurationManager = configurationManager; InitializeComponent(); @@ -67,7 +83,7 @@ namespace MediaBrowser.ServerApplication Instance_ConfigurationUpdated(null, EventArgs.Empty); _logManager.LoggerLoaded += LoadLogWindow; - Kernel.Instance.ConfigurationUpdated += Instance_ConfigurationUpdated; + _configurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated; } /// @@ -79,7 +95,7 @@ namespace MediaBrowser.ServerApplication { Dispatcher.InvokeAsync(() => { - var developerToolsVisibility = Kernel.Instance.Configuration.EnableDeveloperTools + var developerToolsVisibility = _configurationManager.Configuration.EnableDeveloperTools ? Visibility.Visible : Visibility.Collapsed; @@ -89,9 +105,9 @@ namespace MediaBrowser.ServerApplication var logWindow = App.Instance.Windows.OfType().FirstOrDefault(); - if ((logWindow == null && Kernel.Instance.Configuration.ShowLogWindow) || (logWindow != null && !Kernel.Instance.Configuration.ShowLogWindow)) + if ((logWindow == null && _configurationManager.Configuration.ShowLogWindow) || (logWindow != null && !_configurationManager.Configuration.ShowLogWindow)) { - _logManager.ReloadLogger(Kernel.Instance.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); + _logManager.ReloadLogger(_configurationManager.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); } }); } @@ -107,16 +123,16 @@ namespace MediaBrowser.ServerApplication Dispatcher.InvokeAsync(() => { // Add our log window if specified - if (Kernel.Instance.Configuration.ShowLogWindow) + if (_configurationManager.Configuration.ShowLogWindow) { - Trace.Listeners.Add(new WindowTraceListener(new LogWindow(Kernel.Instance))); + Trace.Listeners.Add(new WindowTraceListener(new LogWindow())); } else { Trace.Listeners.Remove("MBLogWindow"); } // Set menu option indicator - cmShowLogWindow.IsChecked = Kernel.Instance.Configuration.ShowLogWindow; + cmShowLogWindow.IsChecked = _configurationManager.Configuration.ShowLogWindow; }, DispatcherPriority.Normal); } @@ -142,7 +158,7 @@ namespace MediaBrowser.ServerApplication /// The instance containing the event data. void cmdApiDocs_Click(object sender, EventArgs e) { - App.OpenUrl("http://localhost:" + Kernel.Instance.Configuration.HttpServerPortNumber + "/" + + App.OpenUrl("http://localhost:" + _configurationManager.Configuration.HttpServerPortNumber + "/" + Kernel.Instance.WebApplicationName + "/metadata"); } @@ -190,9 +206,17 @@ namespace MediaBrowser.ServerApplication private void cmOpenDashboard_click(object sender, RoutedEventArgs e) { var user = _appHost.Resolve().Users.FirstOrDefault(u => u.Configuration.IsAdministrator); - App.OpenDashboard(user); + OpenDashboard(user); } + /// + /// Opens the dashboard. + /// + private void OpenDashboard(User loggedInUser) + { + App.OpenDashboardPage("dashboard.html", loggedInUser, _configurationManager); + } + /// /// Handles the click event of the cmVisitCT control. /// @@ -211,7 +235,7 @@ namespace MediaBrowser.ServerApplication private void cmdBrowseLibrary_click(object sender, RoutedEventArgs e) { var user = _appHost.Resolve().Users.FirstOrDefault(u => u.Configuration.IsAdministrator); - App.OpenDashboardPage("index.html", user); + App.OpenDashboardPage("index.html", user, _configurationManager); } /// @@ -241,8 +265,8 @@ namespace MediaBrowser.ServerApplication /// The instance containing the event data. private void CmShowLogWindow_click(object sender, RoutedEventArgs e) { - Kernel.Instance.Configuration.ShowLogWindow = !Kernel.Instance.Configuration.ShowLogWindow; - Kernel.Instance.SaveConfiguration(); + _configurationManager.Configuration.ShowLogWindow = !_configurationManager.Configuration.ShowLogWindow; + _configurationManager.SaveConfiguration(); LoadLogWindow(sender, e); } diff --git a/MediaBrowser.ServerApplication/StartupWizard.cs b/MediaBrowser.ServerApplication/StartupWizard.cs index c5e8c1c993..57a90ea814 100644 --- a/MediaBrowser.ServerApplication/StartupWizard.cs +++ b/MediaBrowser.ServerApplication/StartupWizard.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common; +using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using System.Linq; @@ -19,15 +20,18 @@ namespace MediaBrowser.ServerApplication /// private readonly IUserManager _userManager; + private readonly IConfigurationManager _configurationManager; + /// /// Initializes a new instance of the class. /// /// The app host. /// The user manager. - public StartupWizard(IApplicationHost appHost, IUserManager userManager) + public StartupWizard(IApplicationHost appHost, IUserManager userManager, IConfigurationManager configurationManager) { _appHost = appHost; _userManager = userManager; + _configurationManager = configurationManager; } /// @@ -48,7 +52,7 @@ namespace MediaBrowser.ServerApplication { var user = _userManager.Users.FirstOrDefault(u => u.Configuration.IsAdministrator); - App.OpenDashboardPage("wizardStart.html", user); + App.OpenDashboardPage("wizardStart.html", user, _configurationManager); } /// diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 18ca7ef24e..7cf6b28738 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -107,9 +107,7 @@ namespace MediaBrowser.WebDashboard.Api /// System.Object. public object Get(GetDashboardInfo request) { - var kernel = (Kernel)Kernel; - - return GetDashboardInfo(kernel, Logger, _taskManager, _userManager); + return GetDashboardInfo(Kernel.Instance, Logger, _taskManager, _userManager); } /// @@ -149,9 +147,7 @@ namespace MediaBrowser.WebDashboard.Api /// System.Object. public object Get(GetDashboardConfigurationPage request) { - var kernel = (Kernel)Kernel; - - var page = kernel.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); + var page = Kernel.Instance.PluginConfigurationPages.First(p => p.Name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); return ToStaticResult(page.Version.GetMD5(), page.DateLastModified, null, MimeTypes.GetMimeType("page.html"), () => ModifyHtml(page.GetHtmlStream())); } @@ -163,9 +159,7 @@ namespace MediaBrowser.WebDashboard.Api /// System.Object. public object Get(GetDashboardConfigurationPages request) { - var kernel = (Kernel)Kernel; - - var pages = kernel.PluginConfigurationPages; + var pages = Kernel.Instance.PluginConfigurationPages; if (request.PageType.HasValue) { From 9cdda84b062d990af285d7f25507c892ce05e180 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 01:06:38 -0500 Subject: [PATCH 3/4] updated plugin security --- .../Security/PluginSecurityManager.cs | 2 +- .../Providers/Music/LastfmArtistProvider.cs | 11 +++++++---- .../Providers/Music/LastfmBaseArtistProvider.cs | 5 +++-- Nuget/MediaBrowser.Common.Internal.nuspec | 4 ++-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index a566373714..d1a4940ef4 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -69,7 +69,7 @@ namespace MediaBrowser.Common.Implementations.Security _kernel = kernel; _httpClient = httpClient; _jsonSerializer = jsonSerializer; - //MBRegistration.Init(appPaths); + MBRegistration.Init(appPaths); } /// diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs index 5203b6f06b..ba32ba9e6f 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Logging; @@ -16,8 +17,10 @@ namespace MediaBrowser.Controller.Providers.Music { public class LastfmArtistProvider : LastfmBaseArtistProvider { - public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(jsonSerializer, httpClient, logManager) + internal readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(5, 5); + + public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(jsonSerializer, httpClient, logManager, configurationManager) { } @@ -30,7 +33,7 @@ namespace MediaBrowser.Controller.Providers.Music try { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -61,7 +64,7 @@ namespace MediaBrowser.Controller.Providers.Music try { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.Lastfm, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false)) { result = JsonSerializer.DeserializeFromStream(json); } diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs index 85f141a56f..444c0fefd5 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs @@ -5,6 +5,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; @@ -14,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Music { public abstract class LastfmBaseArtistProvider : LastfmBaseProvider { - protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(jsonSerializer, httpClient, logManager) + protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(jsonSerializer, httpClient, logManager, configurationManager) { LocalMetaFileName = "MBArtist.json"; } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index b74f7a55ff..e3f8d15a12 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.26 + 3.0.28 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index bdc5645929..725057b947 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.26 + 3.0.28 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 2d127a8903..ce44452039 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.26 + 3.0.28 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - + From d3b9afef2f3895daf91056938a92d6f51c8c834b Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 02:19:04 -0500 Subject: [PATCH 4/4] removed the clickonce assembly --- .../ApplicationUpdateCheck.cs | 106 -------- MediaBrowser.ClickOnce/ApplicationUpdater.cs | 92 ------- MediaBrowser.ClickOnce/ClickOnceHelper.cs | 255 ------------------ .../MediaBrowser.ClickOnce.csproj | 66 ----- .../Properties/AssemblyInfo.cs | 31 --- .../MediaBrowser.ServerApplication.csproj | 4 - MediaBrowser.sln | 16 -- Nuget/MediaBrowser.Common.Internal.nuspec | 5 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 10 files changed, 5 insertions(+), 576 deletions(-) delete mode 100644 MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs delete mode 100644 MediaBrowser.ClickOnce/ApplicationUpdater.cs delete mode 100644 MediaBrowser.ClickOnce/ClickOnceHelper.cs delete mode 100644 MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj delete mode 100644 MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs diff --git a/MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs b/MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs deleted file mode 100644 index 72c42f5866..0000000000 --- a/MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs +++ /dev/null @@ -1,106 +0,0 @@ -using MediaBrowser.Model.Updates; -using System; -using System.Deployment.Application; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.ClickOnce -{ - /// - /// Class ApplicationUpdateCheck - /// - public class ApplicationUpdateCheck - { - /// - /// The _task completion source - /// - private TaskCompletionSource _taskCompletionSource; - - /// - /// The _progress - /// - private IProgress _progress; - - /// - /// Checks for application update. - /// - /// The cancellation token. - /// The progress. - /// Task{CheckForUpdateCompletedEventArgs}. - /// Current deployment is not a ClickOnce deployment - public Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) - { - if (!ApplicationDeployment.IsNetworkDeployed) - { - throw new InvalidOperationException("Current deployment is not network deployed."); - } - - _progress = progress; - - _taskCompletionSource = new TaskCompletionSource(); - - var deployment = ApplicationDeployment.CurrentDeployment; - - cancellationToken.Register(deployment.CheckForUpdateAsyncCancel); - - cancellationToken.ThrowIfCancellationRequested(); - - deployment.CheckForUpdateCompleted += deployment_CheckForUpdateCompleted; - deployment.CheckForUpdateProgressChanged += deployment_CheckForUpdateProgressChanged; - - deployment.CheckForUpdateAsync(); - - return _taskCompletionSource.Task; - } - - /// - /// To the result. - /// - /// The instance containing the event data. - /// CheckForUpdateResult. - private CheckForUpdateResult ToResult(CheckForUpdateCompletedEventArgs args) - { - return new CheckForUpdateResult - { - AvailableVersion = args.AvailableVersion, - IsUpdateAvailable = args.UpdateAvailable - }; - } - - /// - /// Handles the CheckForUpdateCompleted event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_CheckForUpdateCompleted(object sender, CheckForUpdateCompletedEventArgs e) - { - var deployment = ApplicationDeployment.CurrentDeployment; - - deployment.CheckForUpdateCompleted -= deployment_CheckForUpdateCompleted; - deployment.CheckForUpdateProgressChanged -= deployment_CheckForUpdateProgressChanged; - - if (e.Error != null) - { - _taskCompletionSource.SetException(e.Error); - } - else if (e.Cancelled) - { - _taskCompletionSource.SetCanceled(); - } - else - { - _taskCompletionSource.SetResult(ToResult(e)); - } - } - - /// - /// Handles the CheckForUpdateProgressChanged event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_CheckForUpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) - { - _progress.Report(e.ProgressPercentage); - } - } -} diff --git a/MediaBrowser.ClickOnce/ApplicationUpdater.cs b/MediaBrowser.ClickOnce/ApplicationUpdater.cs deleted file mode 100644 index 29af406f1e..0000000000 --- a/MediaBrowser.ClickOnce/ApplicationUpdater.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.ComponentModel; -using System.Deployment.Application; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.ClickOnce -{ - /// - /// Class ApplicationUpdater - /// - public class ApplicationUpdater - { - /// - /// The _task completion source - /// - private TaskCompletionSource _taskCompletionSource; - - /// - /// The _progress - /// - private IProgress _progress; - - /// - /// Updates the application - /// - /// The cancellation token. - /// The progress. - /// Task{AsyncCompletedEventArgs}. - /// Current deployment is not network deployed. - public Task UpdateApplication(CancellationToken cancellationToken, IProgress progress) - { - if (!ApplicationDeployment.IsNetworkDeployed) - { - throw new InvalidOperationException("Current deployment is not network deployed."); - } - - _progress = progress; - - _taskCompletionSource = new TaskCompletionSource(); - - var deployment = ApplicationDeployment.CurrentDeployment; - - cancellationToken.Register(deployment.UpdateAsyncCancel); - - cancellationToken.ThrowIfCancellationRequested(); - - deployment.UpdateCompleted += deployment_UpdateCompleted; - deployment.UpdateProgressChanged += deployment_UpdateProgressChanged; - - deployment.UpdateAsync(); - - return _taskCompletionSource.Task; - } - - /// - /// Handles the UpdateCompleted event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_UpdateCompleted(object sender, AsyncCompletedEventArgs e) - { - var deployment = ApplicationDeployment.CurrentDeployment; - - deployment.UpdateCompleted -= deployment_UpdateCompleted; - deployment.UpdateProgressChanged -= deployment_UpdateProgressChanged; - - if (e.Error != null) - { - _taskCompletionSource.SetException(e.Error); - } - else if (e.Cancelled) - { - _taskCompletionSource.SetCanceled(); - } - else - { - _taskCompletionSource.SetResult(e); - } - } - - /// - /// Handles the UpdateProgressChanged event of the deployment control. - /// - /// The source of the event. - /// The instance containing the event data. - void deployment_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) - { - _progress.Report(e.ProgressPercentage); - } - } -} diff --git a/MediaBrowser.ClickOnce/ClickOnceHelper.cs b/MediaBrowser.ClickOnce/ClickOnceHelper.cs deleted file mode 100644 index c86332ccf0..0000000000 --- a/MediaBrowser.ClickOnce/ClickOnceHelper.cs +++ /dev/null @@ -1,255 +0,0 @@ -using System.Deployment.Application; -using Microsoft.Win32; -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Security.AccessControl; - -namespace MediaBrowser.ClickOnce -{ - /// - /// Class ClickOnceHelper - /// - public class ClickOnceHelper - { - /// - /// The uninstall string - /// - private const string UninstallString = "UninstallString"; - /// - /// The display name key - /// - private const string DisplayNameKey = "DisplayName"; - /// - /// The uninstall string file - /// - private const string UninstallStringFile = "UninstallString.bat"; - /// - /// The appref extension - /// - private const string ApprefExtension = ".appref-ms"; - /// - /// The uninstall registry key - /// - private readonly RegistryKey UninstallRegistryKey; - - /// - /// Gets the location. - /// - /// The location. - private static string Location - { - get { return Assembly.GetExecutingAssembly().Location; } - } - - /// - /// Gets a value indicating whether this instance is network deployed. - /// - /// true if this instance is network deployed; otherwise, false. - public static bool IsNetworkDeployed - { - get { return ApplicationDeployment.IsNetworkDeployed; } - } - - /// - /// Gets the name of the publisher. - /// - /// The name of the publisher. - public string PublisherName { get; private set; } - /// - /// Gets the name of the product. - /// - /// The name of the product. - public string ProductName { get; private set; } - /// - /// Gets the uninstall file. - /// - /// The uninstall file. - public string UninstallFile { get; private set; } - /// - /// Gets the name of the suite. - /// - /// The name of the suite. - public string SuiteName { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Name of the publisher. - /// Name of the product. - /// Name of the suite. - public ClickOnceHelper(string publisherName, string productName, string suiteName) - { - PublisherName = publisherName; - ProductName = productName; - SuiteName = suiteName; - - var publisherFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), PublisherName); - - if (!Directory.Exists(publisherFolder)) - { - Directory.CreateDirectory(publisherFolder); - } - - UninstallFile = Path.Combine(publisherFolder, UninstallStringFile); - - UninstallRegistryKey = GetUninstallRegistryKeyByProductName(ProductName); - } - - /// - /// Gets the shortcut path. - /// - /// System.String. - private string GetShortcutPath() - { - var allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs); - - var shortcutPath = Path.Combine(allProgramsPath, PublisherName); - - if (!string.IsNullOrEmpty(SuiteName)) - { - shortcutPath = Path.Combine(shortcutPath, SuiteName); - } - - return Path.Combine(shortcutPath, ProductName) + ApprefExtension; - } - - /// - /// Gets the startup shortcut path. - /// - /// System.String. - private string GetStartupShortcutPath() - { - var startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); - - return Path.Combine(startupPath, ProductName) + ApprefExtension; - } - - /// - /// Adds the shortcut to startup. - /// - public void AddShortcutToStartup() - { - var startupPath = GetStartupShortcutPath(); - - if (!File.Exists(startupPath)) - { - File.Copy(GetShortcutPath(), startupPath); - } - } - - /// - /// Removes the shortcut from startup. - /// - public void RemoveShortcutFromStartup() - { - var startupPath = GetStartupShortcutPath(); - - if (File.Exists(startupPath)) - { - File.Delete(startupPath); - } - } - - /// - /// Updates the uninstall parameters. - /// - /// Name of the uninstaller file. - public void UpdateUninstallParameters(string uninstallerFileName) - { - if (UninstallRegistryKey != null) - { - UpdateUninstallString(uninstallerFileName); - } - } - - /// - /// Gets the name of the uninstall registry key by product. - /// - /// Name of the product. - /// RegistryKey. - private RegistryKey GetUninstallRegistryKeyByProductName(string productName) - { - var subKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"); - - if (subKey == null) - { - return null; - } - - return subKey.GetSubKeyNames() - .Select(name => subKey.OpenSubKey(name, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.QueryValues | RegistryRights.ReadKey | RegistryRights.SetValue)) - .Where(application => application != null) - .FirstOrDefault(application => application.GetValueNames().Where(appKey => appKey.Equals(DisplayNameKey)).Any(appKey => application.GetValue(appKey).Equals(productName))); - } - - /// - /// Updates the uninstall string. - /// - /// Name of the uninstaller file. - private void UpdateUninstallString(string uninstallerFileName) - { - var uninstallString = (string)UninstallRegistryKey.GetValue(UninstallString); - - if (!string.IsNullOrEmpty(UninstallFile) && uninstallString.StartsWith("rundll32.exe", StringComparison.OrdinalIgnoreCase)) - { - File.WriteAllText(UninstallFile, uninstallString); - } - - var str = String.Format("\"{0}\" uninstall", Path.Combine(Path.GetDirectoryName(Location), uninstallerFileName)); - - UninstallRegistryKey.SetValue(UninstallString, str); - } - - /// - /// Uninstalls this instance. - /// - public void Uninstall() - { - RemoveShortcutFromStartup(); - - var uninstallString = File.ReadAllText(UninstallFile); - - new Process - { - StartInfo = - { - Arguments = uninstallString.Substring(uninstallString.IndexOf(" ", StringComparison.OrdinalIgnoreCase) + 1), - FileName = uninstallString.Substring(0, uninstallString.IndexOf(" ", StringComparison.OrdinalIgnoreCase)), - UseShellExecute = false - } - - }.Start(); - } - - /// - /// Configures the click once startup. - /// - /// Name of the publisher. - /// Name of the product. - /// Name of the suite. - /// if set to true [run at startup]. - /// The uninstaller filename. - public static void ConfigureClickOnceStartupIfInstalled(string publisherName, string productName, string suiteName, bool runAtStartup, string uninstallerFilename) - { - if (!ApplicationDeployment.IsNetworkDeployed) - { - return; - } - - var clickOnceHelper = new ClickOnceHelper(publisherName, productName, suiteName); - - if (runAtStartup) - { - clickOnceHelper.UpdateUninstallParameters(uninstallerFilename); - clickOnceHelper.AddShortcutToStartup(); - } - else - { - clickOnceHelper.RemoveShortcutFromStartup(); - } - } - } -} diff --git a/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj b/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj deleted file mode 100644 index eb566fd7fd..0000000000 --- a/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Debug - AnyCPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84} - Library - Properties - MediaBrowser.ClickOnce - MediaBrowser.ClickOnce - v4.5 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - Properties\SharedVersion.cs - - - - - - - - - {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} - MediaBrowser.Model - - - - - if $(ConfigurationName) == Release ( -xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i -) - - - \ No newline at end of file diff --git a/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs b/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs deleted file mode 100644 index c3947b6486..0000000000 --- a/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.ClickOnce")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.ClickOnce")] -[assembly: AssemblyCopyright("Copyright © 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("16e62c11-5009-4212-8c96-fd692479fc5d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 00b68e2546..4ca2c6f96b 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -248,10 +248,6 @@ {4fd51ac5-2c16-4308-a993-c3a84f3b4582} MediaBrowser.Api - - {cc96bf3e-0bda-4809-bc4b-bb6d418f4a84} - MediaBrowser.ClickOnce - {c4d2573a-3fd3-441f-81af-174ac4cd4e1d} MediaBrowser.Common.Implementations diff --git a/MediaBrowser.sln b/MediaBrowser.sln index b473b20625..16caa617d6 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -31,8 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.IsoMounter", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Installer", "MediaBrowser.Installer\MediaBrowser.Installer.csproj", "{3879F78A-D6F6-45E5-B2A8-D8DCF2DABB74}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.ClickOnce", "MediaBrowser.ClickOnce\MediaBrowser.ClickOnce.csproj", "{CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Common.Implementations", "MediaBrowser.Common.Implementations\MediaBrowser.Common.Implementations.csproj", "{C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Server.Implementations", "MediaBrowser.Server.Implementations\MediaBrowser.Server.Implementations.csproj", "{2E781478-814D-4A48-9D80-BFF206441A65}" @@ -179,20 +177,6 @@ Global {3879F78A-D6F6-45E5-B2A8-D8DCF2DABB74}.Release|Win32.ActiveCfg = Release|Any CPU {3879F78A-D6F6-45E5-B2A8-D8DCF2DABB74}.Release|x64.ActiveCfg = Release|Any CPU {3879F78A-D6F6-45E5-B2A8-D8DCF2DABB74}.Release|x86.ActiveCfg = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|Win32.ActiveCfg = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|x64.ActiveCfg = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Debug|x86.ActiveCfg = Debug|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|Any CPU.Build.0 = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|Win32.ActiveCfg = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|x64.ActiveCfg = Release|Any CPU - {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84}.Release|x86.ActiveCfg = Release|Any CPU {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Debug|Any CPU.Build.0 = Debug|Any CPU {C4D2573A-3FD3-441F-81AF-174AC4CD4E1D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index e3f8d15a12..e8a6fbedd2 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.28 + 3.0.29 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + @@ -21,7 +21,6 @@ - diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 725057b947..745c7076ef 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.28 + 3.0.29 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index ce44452039..8f82654c72 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.28 + 3.0.29 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +