2013-02-21 04:37:50 +00:00
|
|
|
|
using MediaBrowser.ApiInteraction;
|
|
|
|
|
using MediaBrowser.Common.IO;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Common.Kernel;
|
|
|
|
|
using MediaBrowser.Model.Connectivity;
|
2013-02-21 21:06:23 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
using MediaBrowser.UI.Configuration;
|
|
|
|
|
using MediaBrowser.UI.Playback;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.Composition;
|
2013-02-21 04:37:50 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Cache;
|
|
|
|
|
using System.Net.Http;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
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>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The instance.</value>
|
|
|
|
|
public static UIKernel Instance { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the API client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The API client.</value>
|
|
|
|
|
public ApiClient ApiClient { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the playback manager.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The playback manager.</value>
|
|
|
|
|
public PlaybackManager PlaybackManager { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UIKernel" /> class.
|
|
|
|
|
/// </summary>
|
2013-02-22 01:26:35 +00:00
|
|
|
|
public UIKernel(IApplicationHost appHost, IIsoManager isoManager, ILogger logger)
|
|
|
|
|
: base(appHost, isoManager, logger)
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the media players.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The media players.</value>
|
|
|
|
|
[ImportMany(typeof(BaseMediaPlayer))]
|
|
|
|
|
public IEnumerable<BaseMediaPlayer> MediaPlayers { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the list of currently loaded themes
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The themes.</value>
|
|
|
|
|
[ImportMany(typeof(BaseTheme))]
|
|
|
|
|
public IEnumerable<BaseTheme> Themes { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the kernel context.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The kernel context.</value>
|
|
|
|
|
public override KernelContext KernelContext
|
|
|
|
|
{
|
|
|
|
|
get { return KernelContext.Ui; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the UDP server port number.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The UDP server port number.</value>
|
|
|
|
|
public override int UdpServerPortNumber
|
|
|
|
|
{
|
|
|
|
|
get { return 7360; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
/// <value>The HTTP server URL prefix.</value>
|
|
|
|
|
public override string HttpServerUrlPrefix
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowserui/";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reload api client and update plugins after loading configuration
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
protected override async Task OnConfigurationLoaded()
|
|
|
|
|
{
|
|
|
|
|
ReloadApiClient();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-02-21 20:36:36 +00:00
|
|
|
|
await new PluginUpdater(Logger).UpdatePlugins().ConfigureAwait(false);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error updating plugins from the server", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Disposes the current ApiClient and creates a new one
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReloadApiClient()
|
|
|
|
|
{
|
|
|
|
|
DisposeApiClient();
|
|
|
|
|
|
2013-02-22 01:26:35 +00:00
|
|
|
|
ApiClient = new ApiClient(Logger, new AsyncHttpClient(new WebRequestHandler
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
AutomaticDecompression = DecompressionMethods.Deflate,
|
|
|
|
|
CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate)
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
ServerHostName = Configuration.ServerHostName,
|
|
|
|
|
ServerApiPort = Configuration.ServerApiPort,
|
|
|
|
|
ClientType = ClientType.Pc,
|
|
|
|
|
DeviceName = Environment.MachineName,
|
|
|
|
|
SerializationFormat = SerializationFormats.Json
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reloads the internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
protected override Task ReloadInternal()
|
|
|
|
|
{
|
2013-02-21 21:39:53 +00:00
|
|
|
|
PlaybackManager = new PlaybackManager(this, Logger);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
return base.ReloadInternal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when [composable parts loaded].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
protected override async Task OnComposablePartsLoaded()
|
|
|
|
|
{
|
|
|
|
|
await base.OnComposablePartsLoaded().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
// Once plugins have loaded give the api a reference to our protobuf serializer
|
|
|
|
|
DataSerializer.DynamicSerializer = ProtobufSerializer.TypeModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Disposes the current ApiClient
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DisposeApiClient()
|
|
|
|
|
{
|
|
|
|
|
if (ApiClient != null)
|
|
|
|
|
{
|
|
|
|
|
ApiClient.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Releases unmanaged and - optionally - managed resources.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
|
|
|
|
protected override void Dispose(bool dispose)
|
|
|
|
|
{
|
|
|
|
|
if (dispose)
|
|
|
|
|
{
|
|
|
|
|
DisposeApiClient();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose(dispose);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|