From 17c1fd576057bdd2d6aea517d733fe8af6e6b2ba Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 23 Feb 2013 10:58:08 -0500 Subject: moved ui to it's own repo --- MediaBrowser.UI/Controller/BaseTheme.cs | 60 ------ MediaBrowser.UI/Controller/PluginUpdater.cs | 313 ---------------------------- MediaBrowser.UI/Controller/UIKernel.cs | 181 ---------------- 3 files changed, 554 deletions(-) delete mode 100644 MediaBrowser.UI/Controller/BaseTheme.cs delete mode 100644 MediaBrowser.UI/Controller/PluginUpdater.cs delete mode 100644 MediaBrowser.UI/Controller/UIKernel.cs (limited to 'MediaBrowser.UI/Controller') diff --git a/MediaBrowser.UI/Controller/BaseTheme.cs b/MediaBrowser.UI/Controller/BaseTheme.cs deleted file mode 100644 index bcf882f689..0000000000 --- a/MediaBrowser.UI/Controller/BaseTheme.cs +++ /dev/null @@ -1,60 +0,0 @@ -using MediaBrowser.Model.Dto; -using System; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Controls; - -namespace MediaBrowser.UI.Controller -{ - /// - /// Class BaseTheme - /// - public abstract class BaseTheme : IDisposable - { - /// - /// Gets the global resources. - /// - /// IEnumerable{ResourceDictionary}. - public abstract IEnumerable GetGlobalResources(); - - /// - /// Gets the list page. - /// - /// The item. - /// Page. - public abstract Page GetListPage(BaseItemDto item); - /// - /// Gets the detail page. - /// - /// The item. - /// Page. - public abstract Page GetDetailPage(BaseItemDto item); - /// - /// Gets the home page. - /// - /// Page. - public abstract Page GetHomePage(); - /// - /// Gets the login page. - /// - /// Page. - public abstract Page GetLoginPage(); - /// - /// Gets the internal player page. - /// - /// Page. - public abstract Page GetInternalPlayerPage(); - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public virtual void Dispose() - { - } - - /// - /// Displays the weather. - /// - public abstract void DisplayWeather(); - } -} diff --git a/MediaBrowser.UI/Controller/PluginUpdater.cs b/MediaBrowser.UI/Controller/PluginUpdater.cs deleted file mode 100644 index e56b6f54f2..0000000000 --- a/MediaBrowser.UI/Controller/PluginUpdater.cs +++ /dev/null @@ -1,313 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; -using MediaBrowser.Model.Plugins; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace MediaBrowser.UI.Controller -{ - /// - /// This keeps ui plugin assemblies in sync with plugins installed on the server - /// - public class PluginUpdater - { - private readonly ILogger _logger; - - public PluginUpdater(ILogger logger) - { - _logger = logger; - } - - /// - /// Updates the plugins. - /// - /// Task{PluginUpdateResult}. - public async Task UpdatePlugins() - { - _logger.Info("Downloading list of installed plugins"); - var allInstalledPlugins = await UIKernel.Instance.ApiClient.GetInstalledPluginsAsync().ConfigureAwait(false); - - var uiPlugins = allInstalledPlugins.Where(p => p.DownloadToUI).ToList(); - - var result = new PluginUpdateResult { }; - - result.DeletedPlugins = DeleteUninstalledPlugins(uiPlugins); - - await DownloadPluginAssemblies(uiPlugins, result).ConfigureAwait(false); - - result.UpdatedConfigurations = await DownloadPluginConfigurations(uiPlugins).ConfigureAwait(false); - - return result; - } - - /// - /// Downloads plugin assemblies from the server, if they need to be installed or updated. - /// - /// The UI plugins. - /// The result. - /// Task. - private async Task DownloadPluginAssemblies(IEnumerable uiPlugins, PluginUpdateResult result) - { - var newlyInstalledPlugins = new List(); - var updatedPlugins = new List(); - - // Loop through the list of plugins that are on the server - foreach (var pluginInfo in uiPlugins) - { - // See if it is already installed in the UI - var currentAssemblyPath = Path.Combine(UIKernel.Instance.ApplicationPaths.PluginsPath, pluginInfo.AssemblyFileName); - - var isPluginInstalled = File.Exists(currentAssemblyPath); - - // Download the plugin if it is not present, or if the current version is out of date - bool downloadPlugin; - - if (!isPluginInstalled) - { - downloadPlugin = true; - _logger.Info("{0} is not installed and needs to be downloaded.", pluginInfo.Name); - } - else - { - var serverVersion = Version.Parse(pluginInfo.Version); - - var fileVersion = FileVersionInfo.GetVersionInfo(currentAssemblyPath).FileVersion ?? string.Empty; - - downloadPlugin = string.IsNullOrEmpty(fileVersion) || Version.Parse(fileVersion) < serverVersion; - - if (downloadPlugin) - { - _logger.Info("{0} has an updated version on the server and needs to be downloaded. Server version: {1}, UI version: {2}", pluginInfo.Name, serverVersion, fileVersion); - } - } - - if (downloadPlugin) - { - if (UIKernel.Instance.ApplicationVersion < Version.Parse(pluginInfo.MinimumRequiredUIVersion)) - { - _logger.Warn("Can't download new version of {0} because the application needs to be updated first.", pluginInfo.Name); - continue; - } - - try - { - await DownloadPlugin(pluginInfo).ConfigureAwait(false); - - if (isPluginInstalled) - { - updatedPlugins.Add(pluginInfo); - } - else - { - newlyInstalledPlugins.Add(pluginInfo); - } - } - catch (HttpException ex) - { - _logger.ErrorException("Error downloading {0} configuration", ex, pluginInfo.Name); - } - catch (IOException ex) - { - _logger.ErrorException("Error saving plugin assembly for {0}", ex, pluginInfo.Name); - } - } - } - - result.NewlyInstalledPlugins = newlyInstalledPlugins; - result.UpdatedPlugins = updatedPlugins; - } - - /// - /// Downloads plugin configurations from the server. - /// - /// The UI plugins. - /// Task{List{PluginInfo}}. - private async Task> DownloadPluginConfigurations(IEnumerable uiPlugins) - { - var updatedPlugins = new List(); - - // Loop through the list of plugins that are on the server - foreach (var pluginInfo in uiPlugins - .Where(p => UIKernel.Instance.ApplicationVersion >= Version.Parse(p.MinimumRequiredUIVersion))) - { - // See if it is already installed in the UI - var path = Path.Combine(UIKernel.Instance.ApplicationPaths.PluginConfigurationsPath, pluginInfo.ConfigurationFileName); - - var download = false; - - if (!File.Exists(path)) - { - download = true; - _logger.Info("{0} configuration was not found needs to be downloaded.", pluginInfo.Name); - } - else if (File.GetLastWriteTimeUtc(path) < pluginInfo.ConfigurationDateLastModified) - { - download = true; - _logger.Info("{0} has an updated configuration on the server and needs to be downloaded.", pluginInfo.Name); - } - - if (download) - { - if (UIKernel.Instance.ApplicationVersion < Version.Parse(pluginInfo.MinimumRequiredUIVersion)) - { - _logger.Warn("Can't download updated configuration of {0} because the application needs to be updated first.", pluginInfo.Name); - continue; - } - - try - { - await DownloadPluginConfiguration(pluginInfo, path).ConfigureAwait(false); - - updatedPlugins.Add(pluginInfo); - } - catch (HttpException ex) - { - _logger.ErrorException("Error downloading {0} configuration", ex, pluginInfo.Name); - } - catch (IOException ex) - { - _logger.ErrorException("Error saving plugin configuration to {0}", ex, path); - } - } - } - - return updatedPlugins; - } - - /// - /// Downloads a plugin assembly from the server - /// - /// The plugin. - /// Task. - private async Task DownloadPlugin(PluginInfo plugin) - { - _logger.Info("Downloading {0} Plugin", plugin.Name); - - var path = Path.Combine(UIKernel.Instance.ApplicationPaths.PluginsPath, plugin.AssemblyFileName); - - // First download to a MemoryStream. This way if the download is cut off, we won't be left with a partial file - using (var memoryStream = new MemoryStream()) - { - var assemblyStream = await UIKernel.Instance.ApiClient.GetPluginAssemblyAsync(plugin).ConfigureAwait(false); - - await assemblyStream.CopyToAsync(memoryStream).ConfigureAwait(false); - - memoryStream.Position = 0; - - using (var fileStream = new FileStream(path, FileMode.Create)) - { - await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false); - } - } - } - - /// - /// Downloads the latest configuration for a plugin - /// - /// The plugin info. - /// The path. - /// Task. - private async Task DownloadPluginConfiguration(PluginInfo pluginInfo, string path) - { - _logger.Info("Downloading {0} Configuration", pluginInfo.Name); - - // First download to a MemoryStream. This way if the download is cut off, we won't be left with a partial file - using (var stream = await UIKernel.Instance.ApiClient.GetPluginConfigurationFileAsync(pluginInfo.Id).ConfigureAwait(false)) - { - using (var memoryStream = new MemoryStream()) - { - await stream.CopyToAsync(memoryStream).ConfigureAwait(false); - - memoryStream.Position = 0; - - using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, true)) - { - await memoryStream.CopyToAsync(fs).ConfigureAwait(false); - } - } - } - - File.SetLastWriteTimeUtc(path, pluginInfo.ConfigurationDateLastModified); - } - - /// - /// Deletes any plugins that have been uninstalled from the server - /// - /// The UI plugins. - /// IEnumerable{System.String}. - private IEnumerable DeleteUninstalledPlugins(IEnumerable uiPlugins) - { - var deletedPlugins = new List(); - - foreach (var plugin in Directory.EnumerateFiles(UIKernel.Instance.ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly) - .Select(Path.GetFileName) - .ToList()) - { - var serverPlugin = uiPlugins.FirstOrDefault(p => p.AssemblyFileName.Equals(plugin, StringComparison.OrdinalIgnoreCase)); - - if (serverPlugin == null) - { - try - { - DeletePlugin(plugin); - - deletedPlugins.Add(plugin); - } - catch (IOException ex) - { - _logger.ErrorException("Error deleting plugin assembly {0}", ex, plugin); - } - } - } - - return deletedPlugins; - } - - /// - /// Deletes an installed ui plugin. - /// Leaves config and data behind in the event it is later re-installed - /// - /// The plugin. - private void DeletePlugin(string plugin) - { - _logger.Info("Deleting {0} Plugin", plugin); - - if (File.Exists(plugin)) - { - File.Delete(plugin); - } - } - } - - /// - /// Class PluginUpdateResult - /// - public class PluginUpdateResult - { - /// - /// Gets or sets the deleted plugins. - /// - /// The deleted plugins. - public IEnumerable DeletedPlugins { get; set; } - /// - /// Gets or sets the newly installed plugins. - /// - /// The newly installed plugins. - public IEnumerable NewlyInstalledPlugins { get; set; } - /// - /// Gets or sets the updated plugins. - /// - /// The updated plugins. - public IEnumerable UpdatedPlugins { get; set; } - /// - /// Gets or sets the updated configurations. - /// - /// The updated configurations. - public IEnumerable UpdatedConfigurations { get; set; } - } -} diff --git a/MediaBrowser.UI/Controller/UIKernel.cs b/MediaBrowser.UI/Controller/UIKernel.cs deleted file mode 100644 index 118067140f..0000000000 --- a/MediaBrowser.UI/Controller/UIKernel.cs +++ /dev/null @@ -1,181 +0,0 @@ -using MediaBrowser.ApiInteraction; -using MediaBrowser.Common.Kernel; -using MediaBrowser.Model.Connectivity; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Net; -using MediaBrowser.UI.Configuration; -using MediaBrowser.UI.Playback; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Cache; -using System.Net.Http; -using System.Threading.Tasks; - -namespace MediaBrowser.UI.Controller -{ - /// - /// This controls application logic as well as server interaction within the UI. - /// - public class UIKernel : BaseKernel - { - /// - /// Gets the instance. - /// - /// The instance. - public static UIKernel Instance { get; private set; } - - /// - /// Gets the API client. - /// - /// The API client. - public ApiClient ApiClient { get; private set; } - - /// - /// Gets the playback manager. - /// - /// The playback manager. - public PlaybackManager PlaybackManager { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - public UIKernel(IApplicationHost appHost, ILogger logger) - : base(appHost, logger) - { - Instance = this; - } - - /// - /// Gets the media players. - /// - /// The media players. - public IEnumerable MediaPlayers { get; private set; } - - /// - /// Gets the list of currently loaded themes - /// - /// The themes. - public IEnumerable Themes { get; private set; } - - /// - /// Gets the kernel context. - /// - /// The kernel context. - public override KernelContext KernelContext - { - get { return KernelContext.Ui; } - } - - /// - /// Gets the UDP server port number. - /// - /// The UDP server port number. - public override int UdpServerPortNumber - { - get { return 7360; } - } - - /// - /// Give the UI a different url prefix so that they can share the same port, in case they are installed on the same machine. - /// - /// The HTTP server URL prefix. - public override string HttpServerUrlPrefix - { - get - { - return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowserui/"; - } - } - - /// - /// Reload api client and update plugins after loading configuration - /// - /// Task. - protected override async Task OnConfigurationLoaded() - { - ReloadApiClient(); - - try - { - await new PluginUpdater(Logger).UpdatePlugins().ConfigureAwait(false); - } - catch (HttpException ex) - { - Logger.ErrorException("Error updating plugins from the server", ex); - } - } - - /// - /// Disposes the current ApiClient and creates a new one - /// - private void ReloadApiClient() - { - DisposeApiClient(); - - ApiClient = new ApiClient(Logger, new AsyncHttpClient(new WebRequestHandler - { - AutomaticDecompression = DecompressionMethods.Deflate, - CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate) - })) - { - ServerHostName = Configuration.ServerHostName, - ServerApiPort = Configuration.ServerApiPort, - ClientType = ClientType.Pc, - DeviceName = Environment.MachineName, - SerializationFormat = SerializationFormats.Json - }; - } - - /// - /// Finds the parts. - /// - /// All types. - protected override void FindParts(Type[] allTypes) - { - PlaybackManager = (PlaybackManager)ApplicationHost.CreateInstance(typeof(PlaybackManager)); - - base.FindParts(allTypes); - - Themes = GetExports(allTypes); - MediaPlayers = GetExports(allTypes); - } - - /// - /// Called when [composable parts loaded]. - /// - /// Task. - 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; - } - - /// - /// Disposes the current ApiClient - /// - private void DisposeApiClient() - { - if (ApiClient != null) - { - ApiClient.Dispose(); - } - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool dispose) - { - if (dispose) - { - DisposeApiClient(); - } - - base.Dispose(dispose); - } - } -} -- cgit v1.2.3