diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-03-07 00:34:00 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-03-07 00:34:00 -0500 |
| commit | 4f67fc4aefc11c1a4293227c70de922dbe03c652 (patch) | |
| tree | 67af7ffa36b002969968e06467c624def3e97dc6 /MediaBrowser.ServerApplication | |
| parent | 60545c433b7d383147adb57bb91e720c3b547054 (diff) | |
removed base kernel and ikernel
Diffstat (limited to 'MediaBrowser.ServerApplication')
| -rw-r--r-- | MediaBrowser.ServerApplication/App.xaml.cs | 13 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 89 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/StartupWizard.cs | 6 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/WebSocketEvents.cs | 36 |
4 files changed, 91 insertions, 53 deletions
diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index 470b7fc55..a3e273438 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -1,18 +1,17 @@ -using System.IO; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Constants; -using MediaBrowser.Common.Kernel; -using MediaBrowser.Common.Updates; +using MediaBrowser.Common.Implementations.Updates; using MediaBrowser.Controller; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations; using Microsoft.Win32; using System; using System.Diagnostics; +using System.IO; using System.Net.Cache; using System.Threading; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -209,9 +208,9 @@ namespace MediaBrowser.ServerApplication /// Opens the dashboard page. /// </summary> /// <param name="page">The page.</param> - public static void OpenDashboardPage(string page, User loggedInUser, IConfigurationManager configurationManager) + public static void OpenDashboardPage(string page, User loggedInUser, IServerConfigurationManager configurationManager) { - var url = "http://localhost:" + configurationManager.CommonConfiguration.HttpServerPortNumber + "/" + + var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" + Kernel.Instance.WebApplicationName + "/dashboard/" + page; if (loggedInUser != null) diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index d22c522e7..df3765818 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -2,12 +2,11 @@ using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Constants; +using MediaBrowser.Common.Events; using MediaBrowser.Common.Implementations; -using MediaBrowser.Common.Implementations.HttpServer; -using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.IO; -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Net; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -17,15 +16,18 @@ using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Updates; using MediaBrowser.IsoMounter; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; 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.HttpServer; using MediaBrowser.Server.Implementations.Library; +using MediaBrowser.Server.Implementations.ServerManager; +using MediaBrowser.Server.Implementations.Udp; using MediaBrowser.Server.Implementations.Updates; +using MediaBrowser.Server.Implementations.WebSocket; using MediaBrowser.ServerApplication.Implementations; using MediaBrowser.WebDashboard.Api; using System; @@ -41,16 +43,13 @@ namespace MediaBrowser.ServerApplication /// <summary> /// Class CompositionRoot /// </summary> - public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths> + public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost { /// <summary> /// Gets the server kernel. /// </summary> /// <value>The server kernel.</value> - protected Kernel ServerKernel - { - get { return (Kernel)Kernel; } - } + protected Kernel ServerKernel { get; set; } /// <summary> /// Gets the server configuration manager. @@ -62,15 +61,6 @@ namespace MediaBrowser.ServerApplication } /// <summary> - /// Gets the kernel. - /// </summary> - /// <returns>IKernel.</returns> - protected override IKernel GetKernel() - { - return new Kernel(this, XmlSerializer, LogManager, ServerConfigurationManager); - } - - /// <summary> /// Gets the name of the log file prefix. /// </summary> /// <value>The name of the log file prefix.</value> @@ -88,30 +78,50 @@ namespace MediaBrowser.ServerApplication return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer); } + private IInstallationManager InstallationManager { get; set; } + private IServerManager ServerManager { get; set; } + + public override async Task Init() + { + await base.Init().ConfigureAwait(false); + + await ServerKernel.Init().ConfigureAwait(false); + } + /// <summary> /// Registers resources that classes will depend on /// </summary> protected override async Task RegisterResources() { + ServerKernel = new Kernel(this, XmlSerializer, LogManager, ServerConfigurationManager); + await base.RegisterResources().ConfigureAwait(false); + RegisterSingleInstance<IServerApplicationHost>(this); RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths); - + RegisterSingleInstance(ServerKernel); RegisterSingleInstance(ServerConfigurationManager); + RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger)); + RegisterSingleInstance<IUdpServer>(new UdpServer(Logger), false); + RegisterSingleInstance<IIsoManager>(new PismoIsoManager(Logger)); RegisterSingleInstance<IBlurayExaminer>(new BdInfoExaminer()); RegisterSingleInstance<IZipClient>(new DotNetZipClient()); RegisterSingleInstance(ServerFactory.CreateServer(this, ProtobufSerializer, Logger, "Media Browser", "index.html"), false); + ServerManager = new ServerManager(this, NetworkManager, JsonSerializer, Logger, ServerConfigurationManager, ServerKernel); + RegisterSingleInstance(ServerManager); + var userManager = new UserManager(ServerKernel, Logger, ServerConfigurationManager); RegisterSingleInstance<IUserManager>(userManager); RegisterSingleInstance<ILibraryManager>(new LibraryManager(ServerKernel, Logger, TaskManager, userManager, ServerConfigurationManager)); - RegisterSingleInstance<IInstallationManager>(new InstallationManager(Kernel, HttpClient, PackageManager, JsonSerializer, Logger, this)); + InstallationManager = new InstallationManager(HttpClient, PackageManager, JsonSerializer, Logger, this); + RegisterSingleInstance(InstallationManager); } /// <summary> @@ -121,6 +131,11 @@ namespace MediaBrowser.ServerApplication { base.FindParts(); + Resolve<IHttpServer>().Init(GetExports<IRestfulService>(false)); + Resolve<IServerManager>().AddWebSocketListeners(GetExports<IWebSocketListener>(false)); + + Resolve<IServerManager>().Start(); + Resolve<ILibraryManager>().AddParts(GetExports<IResolverIgnoreRule>(), GetExports<IVirtualFolderCreator>(), GetExports<IItemResolver>(), GetExports<IIntroProvider>()); } @@ -158,19 +173,6 @@ namespace MediaBrowser.ServerApplication } /// <summary> - /// Updates the application. - /// </summary> - /// <param name="package">The package that contains the update</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <param name="progress">The progress.</param> - /// <returns>Task.</returns> - public override Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress) - { - var pkgManager = Resolve<IPackageManager>(); - return pkgManager.InstallPackage(progress, package, cancellationToken); - } - - /// <summary> /// Gets the composable part assemblies. /// </summary> /// <returns>IEnumerable{Assembly}.</returns> @@ -195,7 +197,7 @@ namespace MediaBrowser.ServerApplication yield return typeof(SystemInfo).Assembly; // Include composable parts in the Common assembly - yield return typeof(IKernel).Assembly; + yield return typeof(IApplicationHost).Assembly; // Include composable parts in the Controller assembly yield return typeof(Kernel).Assembly; @@ -211,6 +213,25 @@ namespace MediaBrowser.ServerApplication } /// <summary> + /// Gets the system status. + /// </summary> + /// <returns>SystemInfo.</returns> + public virtual SystemInfo GetSystemInfo() + { + return new SystemInfo + { + HasPendingRestart = HasPendingRestart, + Version = ApplicationVersion.ToString(), + IsNetworkDeployed = CanSelfUpdate, + WebSocketPortNumber = ServerManager.WebSocketPortNumber, + SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket, + FailedPluginAssemblies = FailedAssemblies.ToArray(), + InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToArray(), + CompletedInstallations = InstallationManager.CompletedInstallations.ToArray() + }; + } + + /// <summary> /// Shuts down. /// </summary> public override void Shutdown() diff --git a/MediaBrowser.ServerApplication/StartupWizard.cs b/MediaBrowser.ServerApplication/StartupWizard.cs index 57a90ea81..f7946c711 100644 --- a/MediaBrowser.ServerApplication/StartupWizard.cs +++ b/MediaBrowser.ServerApplication/StartupWizard.cs @@ -1,5 +1,5 @@ using MediaBrowser.Common; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using System.Linq; @@ -20,14 +20,14 @@ namespace MediaBrowser.ServerApplication /// </summary> private readonly IUserManager _userManager; - private readonly IConfigurationManager _configurationManager; + private readonly IServerConfigurationManager _configurationManager; /// <summary> /// Initializes a new instance of the <see cref="StartupWizard" /> class. /// </summary> /// <param name="appHost">The app host.</param> /// <param name="userManager">The user manager.</param> - public StartupWizard(IApplicationHost appHost, IUserManager userManager, IConfigurationManager configurationManager) + public StartupWizard(IApplicationHost appHost, IUserManager userManager, IServerConfigurationManager configurationManager) { _appHost = appHost; _userManager = userManager; diff --git a/MediaBrowser.ServerApplication/WebSocketEvents.cs b/MediaBrowser.ServerApplication/WebSocketEvents.cs index caa4ca2ab..43972bafc 100644 --- a/MediaBrowser.ServerApplication/WebSocketEvents.cs +++ b/MediaBrowser.ServerApplication/WebSocketEvents.cs @@ -1,11 +1,14 @@ using MediaBrowser.Common.Events; -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Updates; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Updates; using System; @@ -43,7 +46,9 @@ namespace MediaBrowser.ServerApplication /// <summary> /// The _kernel /// </summary> - private readonly IKernel _kernel; + private readonly IServerApplicationHost _appHost; + + private readonly ITaskManager _taskManager; /// <summary> /// Initializes a new instance of the <see cref="WebSocketEvents" /> class. @@ -51,14 +56,15 @@ namespace MediaBrowser.ServerApplication /// <param name="serverManager">The server manager.</param> /// <param name="logger">The logger.</param> /// <param name="userManager">The user manager.</param> - public WebSocketEvents(IServerManager serverManager, IKernel kernel, ILogger logger, IUserManager userManager, ILibraryManager libraryManager, IInstallationManager installationManager) + public WebSocketEvents(IServerManager serverManager, IServerApplicationHost appHost, ILogger logger, IUserManager userManager, ILibraryManager libraryManager, IInstallationManager installationManager, ITaskManager taskManager) { _serverManager = serverManager; _logger = logger; _userManager = userManager; _libraryManager = libraryManager; _installationManager = installationManager; - _kernel = kernel; + _appHost = appHost; + _taskManager = taskManager; } public void Run() @@ -68,13 +74,27 @@ namespace MediaBrowser.ServerApplication _libraryManager.LibraryChanged += libraryManager_LibraryChanged; - _kernel.HasPendingRestartChanged += kernel_HasPendingRestartChanged; + _appHost.HasPendingRestartChanged += kernel_HasPendingRestartChanged; _installationManager.PluginUninstalled += InstallationManager_PluginUninstalled; _installationManager.PackageInstalling += installationManager_PackageInstalling; _installationManager.PackageInstallationCancelled += installationManager_PackageInstallationCancelled; _installationManager.PackageInstallationCompleted += installationManager_PackageInstallationCompleted; _installationManager.PackageInstallationFailed += installationManager_PackageInstallationFailed; + + _taskManager.TaskExecuting += _taskManager_TaskExecuting; + _taskManager.TaskCompleted += _taskManager_TaskCompleted; + } + + void _taskManager_TaskCompleted(object sender, GenericEventArgs<TaskResult> e) + { + _serverManager.SendWebSocketMessage("ScheduledTaskEndExecute", e.Argument); + } + + void _taskManager_TaskExecuting(object sender, EventArgs e) + { + var task = (IScheduledTask) sender; + _serverManager.SendWebSocketMessage("ScheduledTaskBeginExecute", task.Name); } /// <summary> @@ -144,9 +164,7 @@ namespace MediaBrowser.ServerApplication /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> void kernel_HasPendingRestartChanged(object sender, EventArgs e) { - var kernel = (IKernel)sender; - - _serverManager.SendWebSocketMessage("HasPendingRestartChanged", kernel.GetSystemInfo()); + _serverManager.SendWebSocketMessage("HasPendingRestartChanged", _appHost.GetSystemInfo()); } /// <summary> @@ -196,7 +214,7 @@ namespace MediaBrowser.ServerApplication _installationManager.PackageInstallationCompleted -= installationManager_PackageInstallationCompleted; _installationManager.PackageInstallationFailed -= installationManager_PackageInstallationFailed; - _kernel.HasPendingRestartChanged -= kernel_HasPendingRestartChanged; + _appHost.HasPendingRestartChanged -= kernel_HasPendingRestartChanged; } } } |
