/// <summary>
        /// Updates the plugins.
        /// </summary>
        /// <returns>Task{PluginUpdateResult}.</returns>
        public async Task<PluginUpdateResult> UpdatePlugins()
        {
            _logger.Info("Downloading list of installed plugins");
            var allInstalledPlugins = await _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;
        }
        /// <summary>
        /// Downloads plugin assemblies from the server, if they need to be installed or updated.
        /// </summary>
        /// <param name="uiPlugins">The UI plugins.</param>
        /// <param name="result">The result.</param>
        /// <returns>Task.</returns>
        private async Task DownloadPluginAssemblies(IEnumerable<PluginInfo> uiPlugins, PluginUpdateResult result)
        {
            var newlyInstalledPlugins = new List<PluginInfo>();
            var updatedPlugins = new List<PluginInfo>();

            // 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(_appPaths.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 (_appHost.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;
        }