From 2ca4b7d03adfa3cc7c9c6a597a11762142d5b34b Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 00:43:06 -0500 Subject: Created IConfigurationManager --- .../BaseApplicationHost.cs | 125 ++++++++++++++++----- 1 file changed, 98 insertions(+), 27 deletions(-) (limited to 'MediaBrowser.Common.Implementations/BaseApplicationHost.cs') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 4e1b4634e..b25c1808d 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(); } } -- cgit v1.2.3