From 119dfc3ac70db7536e86191eb3c89ffa1fd4f576 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 20 Sep 2012 11:25:22 -0400 Subject: Adding the UI to the same repo. Made some default theme progress --- MediaBrowser.UI/Controller/UIKernel.cs | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 MediaBrowser.UI/Controller/UIKernel.cs (limited to 'MediaBrowser.UI/Controller/UIKernel.cs') diff --git a/MediaBrowser.UI/Controller/UIKernel.cs b/MediaBrowser.UI/Controller/UIKernel.cs new file mode 100644 index 000000000..ca24b7852 --- /dev/null +++ b/MediaBrowser.UI/Controller/UIKernel.cs @@ -0,0 +1,97 @@ +using MediaBrowser.ApiInteraction; +using MediaBrowser.Common.Kernel; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.DTO; +using MediaBrowser.Model.Progress; +using MediaBrowser.UI.Configuration; +using System; +using System.Threading.Tasks; + +namespace MediaBrowser.UI.Controller +{ + /// + /// This controls application logic as well as server interaction within the UI. + /// + public class UIKernel : BaseKernel + { + public static UIKernel Instance { get; private set; } + + public ApiClient ApiClient { get; private set; } + public DtoUser CurrentUser { get; set; } + public ServerConfiguration ServerConfiguration { get; set; } + + public UIKernel() + : base() + { + Instance = this; + } + + public override KernelContext KernelContext + { + get { return KernelContext.Ui; } + } + + /// + /// Give the UI a different url prefix so that they can share the same port, in case they are installed on the same machine. + /// + protected override string HttpServerUrlPrefix + { + get + { + return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/ui/"; + } + } + + /// + /// Performs initializations that can be reloaded at anytime + /// + protected override async Task ReloadInternal(IProgress progress) + { + ReloadApiClient(); + + await new PluginUpdater().UpdatePlugins().ConfigureAwait(false); + + await base.ReloadInternal(progress).ConfigureAwait(false); + } + + /// + /// Updates and installs new plugin assemblies and configurations from the server + /// + protected async Task UpdatePlugins() + { + return await new PluginUpdater().UpdatePlugins().ConfigureAwait(false); + } + + /// + /// Disposes the current ApiClient and creates a new one + /// + private void ReloadApiClient() + { + DisposeApiClient(); + + ApiClient = new ApiClient + { + ServerHostName = Configuration.ServerHostName, + ServerApiPort = Configuration.ServerApiPort + }; + } + + /// + /// Disposes the current ApiClient + /// + private void DisposeApiClient() + { + if (ApiClient != null) + { + ApiClient.Dispose(); + } + } + + public override void Dispose() + { + base.Dispose(); + + DisposeApiClient(); + } + } +} -- cgit v1.2.3