diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index a9c73d0e9..1950c1428 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -13,7 +13,6 @@ using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
-using MediaBrowser.Model.System;
using MediaBrowser.Model.Updates;
using SimpleInjector;
using System;
@@ -26,6 +25,10 @@ using System.Threading.Tasks;
namespace MediaBrowser.Common.Implementations
{
+ ///
+ /// Class BaseApplicationHost
+ ///
+ /// The type of the T application paths type.
public abstract class BaseApplicationHost : IApplicationHost
where TApplicationPathsType : class, IApplicationPaths, new()
{
@@ -87,6 +90,7 @@ namespace MediaBrowser.Common.Implementations
///
/// Gets assemblies that failed to load
///
+ /// The failed assemblies.
public List FailedAssemblies { get; protected set; }
///
@@ -148,11 +152,31 @@ namespace MediaBrowser.Common.Implementations
///
/// The kernel.
protected ITaskManager TaskManager { get; private set; }
+ ///
+ /// Gets the security manager.
+ ///
+ /// The security manager.
protected ISecurityManager SecurityManager { get; private set; }
+ ///
+ /// Gets the package manager.
+ ///
+ /// The package manager.
protected IPackageManager PackageManager { get; private set; }
+ ///
+ /// Gets the HTTP client.
+ ///
+ /// The HTTP client.
protected IHttpClient HttpClient { get; private set; }
+ ///
+ /// Gets the network manager.
+ ///
+ /// The network manager.
protected INetworkManager NetworkManager { get; private set; }
+ ///
+ /// Gets the configuration manager.
+ ///
+ /// The configuration manager.
protected IConfigurationManager ConfigurationManager { get; private set; }
///
@@ -187,7 +211,21 @@ namespace MediaBrowser.Common.Implementations
FindParts();
- Task.Run(() => ConfigureAutoRunAtStartup());
+ await RunStartupTasks().ConfigureAwait(false);
+ }
+
+ ///
+ /// Runs the startup tasks.
+ ///
+ /// Task.
+ protected virtual Task RunStartupTasks()
+ {
+ return Task.Run(() =>
+ {
+ Resolve().AddTasks(GetExports(false));
+
+ Task.Run(() => ConfigureAutoRunAtStartup());
+ });
}
///
@@ -202,6 +240,10 @@ namespace MediaBrowser.Common.Implementations
/// The name of the log file prefix.
protected abstract string LogFilePrefixName { get; }
+ ///
+ /// Gets the configuration manager.
+ ///
+ /// IConfigurationManager.
protected abstract IConfigurationManager GetConfigurationManager();
///
@@ -210,8 +252,6 @@ namespace MediaBrowser.Common.Implementations
protected virtual void FindParts()
{
Plugins = GetExports();
-
- Resolve().AddTasks(GetExports(false));
}
///
@@ -236,6 +276,7 @@ namespace MediaBrowser.Common.Implementations
///
/// Registers resources that classes will depend on
///
+ /// Task.
protected virtual Task RegisterResources()
{
return Task.Run(() =>
@@ -509,10 +550,23 @@ namespace MediaBrowser.Common.Implementations
}
}
+ ///
+ /// Restarts this instance.
+ ///
public abstract void Restart();
+ ///
+ /// Gets or sets a value indicating whether this instance can self update.
+ ///
+ /// true if this instance can self update; otherwise, false.
public abstract bool CanSelfUpdate { get; }
+ ///
+ /// Checks for update.
+ ///
+ /// The cancellation token.
+ /// The progress.
+ /// Task{CheckForUpdateResult}.
public abstract Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress);
///
@@ -529,6 +583,9 @@ namespace MediaBrowser.Common.Implementations
EventHelper.QueueEventIfNotNull(ApplicationUpdated, this, new GenericEventArgs { Argument = package.version }, Logger);
}
+ ///
+ /// Shuts down.
+ ///
public abstract void Shutdown();
}
}
diff --git a/MediaBrowser.Server.Implementations/Udp/UdpServer.cs b/MediaBrowser.Server.Implementations/Udp/UdpServer.cs
index c6869c12d..8315b2000 100644
--- a/MediaBrowser.Server.Implementations/Udp/UdpServer.cs
+++ b/MediaBrowser.Server.Implementations/Udp/UdpServer.cs
@@ -127,7 +127,10 @@ namespace MediaBrowser.Server.Implementations.Udp
///
public void Stop()
{
- _udpClient.Close();
+ if (_udpClient != null)
+ {
+ _udpClient.Close();
+ }
}
///
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index e156c465b..d5a505792 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -127,23 +127,21 @@ namespace MediaBrowser.ServerApplication
///
/// The HTTP server.
private IHttpServer HttpServer { get; set; }
-
+
///
- /// Inits this instance.
+ /// Runs the startup tasks.
///
/// Task.
- public override async Task Init()
+ protected override async Task RunStartupTasks()
{
- await base.Init().ConfigureAwait(false);
+ // Do these before allowing the base method to run, which will invoke startup scheduled tasks
+ await ServerKernel.LoadRepositories(ServerConfigurationManager).ConfigureAwait(false);
- Task.Run(async () =>
- {
- await ServerKernel.LoadRepositories(ServerConfigurationManager).ConfigureAwait(false);
+ await base.RunStartupTasks().ConfigureAwait(false);
- DirectoryWatchers.Start();
+ DirectoryWatchers.Start();
- Parallel.ForEach(GetExports(), entryPoint => entryPoint.Run());
- });
+ Parallel.ForEach(GetExports(), entryPoint => entryPoint.Run());
}
///
@@ -206,13 +204,15 @@ namespace MediaBrowser.ServerApplication
ServerKernel.FFMpegManager = new FFMpegManager(ServerKernel, ZipClient, JsonSerializer, ProtobufSerializer, LogManager, ApplicationPaths);
ServerKernel.ImageManager = new ImageManager(ServerKernel, ProtobufSerializer, LogManager.GetLogger("ImageManager"), ApplicationPaths);
- ServerKernel.UserDataRepositories = GetExports();
- ServerKernel.UserRepositories = GetExports();
- ServerKernel.DisplayPreferencesRepositories = GetExports();
- ServerKernel.ItemRepositories = GetExports();
- ServerKernel.WeatherProviders = GetExports();
- ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray();
- ServerKernel.StringFiles = GetExports();
+ Parallel.Invoke(
+ () => ServerKernel.UserDataRepositories = GetExports(),
+ () => ServerKernel.UserRepositories = GetExports(),
+ () => ServerKernel.DisplayPreferencesRepositories = GetExports(),
+ () => ServerKernel.ItemRepositories = GetExports(),
+ () => ServerKernel.WeatherProviders = GetExports(),
+ () => ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray(),
+ () => ServerKernel.StringFiles = GetExports()
+ );
}
///
@@ -238,14 +238,20 @@ namespace MediaBrowser.ServerApplication
{
base.FindParts();
- HttpServer.Init(GetExports(false));
+ Parallel.Invoke(
+
+ () =>
+ {
+ HttpServer.Init(GetExports(false));
- ServerManager.AddWebSocketListeners(GetExports(false));
- ServerManager.Start();
+ ServerManager.AddWebSocketListeners(GetExports(false));
+ ServerManager.Start();
+ },
- LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports());
+ () => LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports()),
- ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray());
+ () => ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray())
+ );
}
///