diff options
| author | ebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com> | 2012-09-20 13:54:37 -0400 |
|---|---|---|
| committer | ebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com> | 2012-09-20 13:54:37 -0400 |
| commit | 7ed11c0bbae55cd2d5c559a2ef6af8f20edebeef (patch) | |
| tree | f96d8d2ba2b3ba71b7b31f012fcdd80ae09f0868 /MediaBrowser.UI/Controller/UIKernel.cs | |
| parent | da618f13e23cbef6ca71c8c0099dfd563a394fa5 (diff) | |
| parent | 119dfc3ac70db7536e86191eb3c89ffa1fd4f576 (diff) | |
Merge with default
Diffstat (limited to 'MediaBrowser.UI/Controller/UIKernel.cs')
| -rw-r--r-- | MediaBrowser.UI/Controller/UIKernel.cs | 97 |
1 files changed, 97 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// This controls application logic as well as server interaction within the UI.
+ /// </summary>
+ public class UIKernel : BaseKernel<UIApplicationConfiguration, UIApplicationPaths>
+ {
+ 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; }
+ }
+
+ /// <summary>
+ /// Give the UI a different url prefix so that they can share the same port, in case they are installed on the same machine.
+ /// </summary>
+ protected override string HttpServerUrlPrefix
+ {
+ get
+ {
+ return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/ui/";
+ }
+ }
+
+ /// <summary>
+ /// Performs initializations that can be reloaded at anytime
+ /// </summary>
+ protected override async Task ReloadInternal(IProgress<TaskProgress> progress)
+ {
+ ReloadApiClient();
+
+ await new PluginUpdater().UpdatePlugins().ConfigureAwait(false);
+
+ await base.ReloadInternal(progress).ConfigureAwait(false);
+ }
+
+ /// <summary>
+ /// Updates and installs new plugin assemblies and configurations from the server
+ /// </summary>
+ protected async Task<PluginUpdateResult> UpdatePlugins()
+ {
+ return await new PluginUpdater().UpdatePlugins().ConfigureAwait(false);
+ }
+
+ /// <summary>
+ /// Disposes the current ApiClient and creates a new one
+ /// </summary>
+ private void ReloadApiClient()
+ {
+ DisposeApiClient();
+
+ ApiClient = new ApiClient
+ {
+ ServerHostName = Configuration.ServerHostName,
+ ServerApiPort = Configuration.ServerApiPort
+ };
+ }
+
+ /// <summary>
+ /// Disposes the current ApiClient
+ /// </summary>
+ private void DisposeApiClient()
+ {
+ if (ApiClient != null)
+ {
+ ApiClient.Dispose();
+ }
+ }
+
+ public override void Dispose()
+ {
+ base.Dispose();
+
+ DisposeApiClient();
+ }
+ }
+}
|
