aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ApplicationHost.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2019-03-27 16:34:26 +0100
committerGitHub <noreply@github.com>2019-03-27 16:34:26 +0100
commitd0fbd260d5cc386119d96f53cdc1d164b80d02df (patch)
tree55d465b25aae29128b77d1867f0bfd9a1fc3708f /Emby.Server.Implementations/ApplicationHost.cs
parent7f42dcc60fd3aaf30f2408f6bddeb2b8bf921cdf (diff)
parent524357bfa845e1c01ef280b1d0fc3896b7b9dbaa (diff)
Merge branch 'master' into httpclient
Diffstat (limited to 'Emby.Server.Implementations/ApplicationHost.cs')
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs295
1 files changed, 147 insertions, 148 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 2f396f814..0b4c161fd 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -37,7 +37,6 @@ using Emby.Server.Implementations.LiveTv;
using Emby.Server.Implementations.Localization;
using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.Playlists;
-using Emby.Server.Implementations.Reflection;
using Emby.Server.Implementations.ScheduledTasks;
using Emby.Server.Implementations.Security;
using Emby.Server.Implementations.Serialization;
@@ -45,7 +44,6 @@ using Emby.Server.Implementations.Session;
using Emby.Server.Implementations.SocketSharp;
using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates;
-using Emby.Server.Implementations.Xml;
using MediaBrowser.Api;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
@@ -93,13 +91,11 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Net;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
-using MediaBrowser.Model.Xml;
using MediaBrowser.Providers.Chapters;
using MediaBrowser.Providers.Manager;
using MediaBrowser.Providers.Subtitles;
@@ -115,6 +111,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using ServiceStack;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations
{
@@ -143,12 +140,8 @@ namespace Emby.Server.Implementations
return false;
}
- if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows)
- {
- return true;
- }
-
- if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX)
+ if (OperatingSystem.Id == OperatingSystemId.Windows
+ || OperatingSystem.Id == OperatingSystemId.Darwin)
{
return true;
}
@@ -168,7 +161,7 @@ namespace Emby.Server.Implementations
public event EventHandler<GenericEventArgs<PackageVersionInfo>> ApplicationUpdated;
/// <summary>
- /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart.
+ /// Gets a value indicating whether this instance has changes that require the entire application to restart.
/// </summary>
/// <value><c>true</c> if this instance has pending application restart; otherwise, <c>false</c>.</value>
public bool HasPendingRestart { get; private set; }
@@ -182,7 +175,7 @@ namespace Emby.Server.Implementations
protected ILogger Logger { get; set; }
/// <summary>
- /// Gets or sets the plugins.
+ /// Gets the plugins.
/// </summary>
/// <value>The plugins.</value>
public IPlugin[] Plugins { get; protected set; }
@@ -194,13 +187,13 @@ namespace Emby.Server.Implementations
public ILoggerFactory LoggerFactory { get; protected set; }
/// <summary>
- /// Gets the application paths.
+ /// Gets or sets the application paths.
/// </summary>
/// <value>The application paths.</value>
protected ServerApplicationPaths ApplicationPaths { get; set; }
/// <summary>
- /// Gets all concrete types.
+ /// Gets or sets all concrete types.
/// </summary>
/// <value>All concrete types.</value>
public Type[] AllConcreteTypes { get; protected set; }
@@ -208,7 +201,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// The disposable parts
/// </summary>
- protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
+ private readonly List<IDisposable> _disposableParts = new List<IDisposable>();
/// <summary>
/// Gets the configuration manager.
@@ -218,16 +211,15 @@ namespace Emby.Server.Implementations
public IFileSystem FileSystemManager { get; set; }
- protected IEnvironmentInfo EnvironmentInfo { get; set; }
-
public PackageVersionClass SystemUpdateLevel
{
get
{
#if BETA
return PackageVersionClass.Beta;
-#endif
+#else
return PackageVersionClass.Release;
+#endif
}
}
@@ -239,15 +231,6 @@ namespace Emby.Server.Implementations
/// <value>The server configuration manager.</value>
public IServerConfigurationManager ServerConfigurationManager => (IServerConfigurationManager)ConfigurationManager;
- /// <summary>
- /// Gets the configuration manager.
- /// </summary>
- /// <returns>IConfigurationManager.</returns>
- protected IConfigurationManager GetConfigurationManager()
- {
- return new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager);
- }
-
protected virtual IResourceFileManager CreateResourceFileManager()
{
return new ResourceFileManager(HttpResultFactory, LoggerFactory, FileSystemManager);
@@ -258,27 +241,33 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The user manager.</value>
public IUserManager UserManager { get; set; }
+
/// <summary>
/// Gets or sets the library manager.
/// </summary>
/// <value>The library manager.</value>
internal ILibraryManager LibraryManager { get; set; }
+
/// <summary>
/// Gets or sets the directory watchers.
/// </summary>
/// <value>The directory watchers.</value>
private ILibraryMonitor LibraryMonitor { get; set; }
+
/// <summary>
/// Gets or sets the provider manager.
/// </summary>
/// <value>The provider manager.</value>
private IProviderManager ProviderManager { get; set; }
+
/// <summary>
/// Gets or sets the HTTP server.
/// </summary>
/// <value>The HTTP server.</value>
private IHttpServer HttpServer { get; set; }
+
private IDtoService DtoService { get; set; }
+
public IImageProcessor ImageProcessor { get; set; }
/// <summary>
@@ -286,6 +275,7 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The media encoder.</value>
private IMediaEncoder MediaEncoder { get; set; }
+
private ISubtitleEncoder SubtitleEncoder { get; set; }
private ISessionManager SessionManager { get; set; }
@@ -295,6 +285,7 @@ namespace Emby.Server.Implementations
public LocalizationManager LocalizationManager { get; set; }
private IEncodingManager EncodingManager { get; set; }
+
private IChannelManager ChannelManager { get; set; }
/// <summary>
@@ -302,20 +293,29 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The user data repository.</value>
private IUserDataManager UserDataManager { get; set; }
+
private IUserRepository UserRepository { get; set; }
+
internal SqliteItemRepository ItemRepository { get; set; }
private INotificationManager NotificationManager { get; set; }
+
private ISubtitleManager SubtitleManager { get; set; }
+
private IChapterManager ChapterManager { get; set; }
+
private IDeviceManager DeviceManager { get; set; }
internal IUserViewManager UserViewManager { get; set; }
private IAuthenticationRepository AuthenticationRepository { get; set; }
+
private ITVSeriesManager TVSeriesManager { get; set; }
+
private ICollectionManager CollectionManager { get; set; }
+
private IMediaSourceManager MediaSourceManager { get; set; }
+
private IPlaylistManager PlaylistManager { get; set; }
private readonly IConfiguration _configuration;
@@ -331,52 +331,55 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The zip client.</value>
protected IZipClient ZipClient { get; private set; }
+
protected IHttpResultFactory HttpResultFactory { get; private set; }
+
protected IAuthService AuthService { get; private set; }
- public IStartupOptions StartupOptions { get; private set; }
+ public IStartupOptions StartupOptions { get; }
internal IImageEncoder ImageEncoder { get; private set; }
protected IProcessFactory ProcessFactory { get; private set; }
- protected ICryptoProvider CryptographyProvider = new CryptographyProvider();
+
protected readonly IXmlSerializer XmlSerializer;
protected ISocketFactory SocketFactory { get; private set; }
+
protected ITaskManager TaskManager { get; private set; }
+
public IHttpClient HttpClient { get; private set; }
+
protected INetworkManager NetworkManager { get; set; }
+
public IJsonSerializer JsonSerializer { get; private set; }
+
protected IIsoManager IsoManager { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
/// </summary>
- public ApplicationHost(ServerApplicationPaths applicationPaths,
+ public ApplicationHost(
+ ServerApplicationPaths applicationPaths,
ILoggerFactory loggerFactory,
IStartupOptions options,
IFileSystem fileSystem,
- IEnvironmentInfo environmentInfo,
IImageEncoder imageEncoder,
INetworkManager networkManager,
IConfiguration configuration)
{
_configuration = configuration;
- // hack alert, until common can target .net core
- BaseExtensions.CryptographyProvider = CryptographyProvider;
-
XmlSerializer = new MyXmlSerializer(fileSystem, loggerFactory);
NetworkManager = networkManager;
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
- EnvironmentInfo = environmentInfo;
ApplicationPaths = applicationPaths;
LoggerFactory = loggerFactory;
FileSystemManager = fileSystem;
- ConfigurationManager = GetConfigurationManager();
+ ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager);
Logger = LoggerFactory.CreateLogger("App");
@@ -415,7 +418,7 @@ namespace Emby.Server.Implementations
_validAddressResults.Clear();
}
- public string ApplicationVersion => typeof(ApplicationHost).Assembly.GetName().Version.ToString(3);
+ public string ApplicationVersion { get; } = typeof(ApplicationHost).Assembly.GetName().Version.ToString(3);
/// <summary>
/// Gets the current application user agent
@@ -423,14 +426,23 @@ namespace Emby.Server.Implementations
/// <value>The application user agent.</value>
public string ApplicationUserAgent => Name.Replace(' ','-') + "/" + ApplicationVersion;
+ /// <summary>
+ /// Gets the email address for use within a comment section of a user agent field.
+ /// Presently used to provide contact information to MusicBrainz service.
+ /// </summary>
+ public string ApplicationUserAgentAddress { get; } = "team@jellyfin.org";
+
private string _productName;
+
/// <summary>
/// Gets the current application name
/// </summary>
/// <value>The application name.</value>
- public string ApplicationProductName => _productName ?? (_productName = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductName);
+ public string ApplicationProductName
+ => _productName ?? (_productName = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductName);
private DeviceId _deviceId;
+
public string SystemId
{
get
@@ -461,15 +473,15 @@ namespace Emby.Server.Implementations
/// <summary>
/// Creates an instance of type and resolves all constructor dependencies
/// </summary>
- /// <param name="type">The type.</param>
- /// <returns>System.Object.</returns>
+ /// /// <typeparam name="T">The type</typeparam>
+ /// <returns>T</returns>
public T CreateInstance<T>()
=> ActivatorUtilities.CreateInstance<T>(_serviceProvider);
/// <summary>
/// Creates the instance safe.
/// </summary>
- /// <param name="typeInfo">The type information.</param>
+ /// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
protected object CreateInstanceSafe(Type type)
{
@@ -488,14 +500,14 @@ namespace Emby.Server.Implementations
/// <summary>
/// Resolves this instance.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <returns>``0.</returns>
public T Resolve<T>() => _serviceProvider.GetService<T>();
/// <summary>
/// Gets the export types.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <returns>IEnumerable{Type}.</returns>
public IEnumerable<Type> GetExportTypes<T>()
{
@@ -507,22 +519,22 @@ namespace Emby.Server.Implementations
/// <summary>
/// Gets the exports.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <param name="manageLifetime">if set to <c>true</c> [manage lifetime].</param>
/// <returns>IEnumerable{``0}.</returns>
public IEnumerable<T> GetExports<T>(bool manageLifetime = true)
{
var parts = GetExportTypes<T>()
- .Select(x => CreateInstanceSafe(x))
+ .Select(CreateInstanceSafe)
.Where(i => i != null)
.Cast<T>()
.ToList(); // Convert to list so this isn't executed for each iteration
if (manageLifetime)
{
- lock (DisposableParts)
+ lock (_disposableParts)
{
- DisposableParts.AddRange(parts.OfType<IDisposable>());
+ _disposableParts.AddRange(parts.OfType<IDisposable>());
}
}
@@ -532,7 +544,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// Runs the startup tasks.
/// </summary>
- public async Task RunStartupTasks()
+ public async Task RunStartupTasksAsync()
{
Logger.LogInformation("Running startup tasks");
@@ -542,29 +554,20 @@ namespace Emby.Server.Implementations
MediaEncoder.SetFFmpegPath();
- //if (string.IsNullOrWhiteSpace(MediaEncoder.EncoderPath))
- //{
- // if (ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
- // {
- // ServerConfigurationManager.Configuration.IsStartupWizardCompleted = false;
- // ServerConfigurationManager.SaveConfiguration();
- // }
- //}
-
Logger.LogInformation("ServerId: {0}", SystemId);
- var entryPoints = GetExports<IServerEntryPoint>();
+ var entryPoints = GetExports<IServerEntryPoint>().ToList();
var stopWatch = new Stopwatch();
stopWatch.Start();
- await Task.WhenAll(StartEntryPoints(entryPoints, true));
+ await Task.WhenAll(StartEntryPoints(entryPoints, true)).ConfigureAwait(false);
Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed);
Logger.LogInformation("Core startup complete");
HttpServer.GlobalResponse = null;
stopWatch.Restart();
- await Task.WhenAll(StartEntryPoints(entryPoints, false));
+ await Task.WhenAll(StartEntryPoints(entryPoints, false)).ConfigureAwait(false);
Logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed);
stopWatch.Stop();
}
@@ -584,7 +587,7 @@ namespace Emby.Server.Implementations
}
}
- public async Task Init(IServiceCollection serviceCollection)
+ public async Task InitAsync(IServiceCollection serviceCollection)
{
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
@@ -614,14 +617,14 @@ namespace Emby.Server.Implementations
SetHttpLimit();
- await RegisterResources(serviceCollection);
+ await RegisterResources(serviceCollection).ConfigureAwait(false);
FindParts();
string contentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
if (string.IsNullOrEmpty(contentRoot))
{
- contentRoot = Path.Combine(ServerConfigurationManager.ApplicationPaths.ApplicationResourcesPath, "jellyfin-web", "src");
+ contentRoot = ServerConfigurationManager.ApplicationPaths.WebPath;
}
var host = new WebHostBuilder()
@@ -629,7 +632,7 @@ namespace Emby.Server.Implementations
{
options.ListenAnyIP(HttpPort);
- if (EnableHttps)
+ if (EnableHttps && Certificate != null)
{
options.ListenAnyIP(HttpsPort, listenOptions => { listenOptions.UseHttps(Certificate); });
}
@@ -651,7 +654,7 @@ namespace Emby.Server.Implementations
})
.Build();
- await host.StartAsync();
+ await host.StartAsync().ConfigureAwait(false);
}
private async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func<Task> next)
@@ -700,14 +703,14 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton<IApplicationPaths>(ApplicationPaths);
+ serviceCollection.AddSingleton<IConfiguration>(_configuration);
+
serviceCollection.AddSingleton(JsonSerializer);
serviceCollection.AddSingleton(LoggerFactory);
serviceCollection.AddLogging();
serviceCollection.AddSingleton(Logger);
- serviceCollection.AddSingleton(EnvironmentInfo);
-
serviceCollection.AddSingleton(FileSystemManager);
serviceCollection.AddSingleton<TvDbClientManager>();
@@ -730,13 +733,12 @@ namespace Emby.Server.Implementations
ApplicationHost.StreamHelper = new StreamHelper();
serviceCollection.AddSingleton(StreamHelper);
- serviceCollection.AddSingleton(CryptographyProvider);
+ serviceCollection.AddSingleton(typeof(ICryptoProvider), typeof(CryptographyProvider));
SocketFactory = new SocketFactory();
serviceCollection.AddSingleton(SocketFactory);
- InstallationManager = new InstallationManager(LoggerFactory, this, ApplicationPaths, HttpClient, JsonSerializer, ServerConfigurationManager, FileSystemManager, CryptographyProvider, ZipClient, PackageRuntime);
- serviceCollection.AddSingleton(InstallationManager);
+ serviceCollection.AddSingleton(typeof(IInstallationManager), typeof(InstallationManager));
ZipClient = new ZipClient();
serviceCollection.AddSingleton(ZipClient);
@@ -749,17 +751,12 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(ServerConfigurationManager);
- var assemblyInfo = new AssemblyInfo();
- serviceCollection.AddSingleton<IAssemblyInfo>(assemblyInfo);
-
- LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer, LoggerFactory);
- await LocalizationManager.LoadAll();
+ LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, LoggerFactory);
+ await LocalizationManager.LoadAll().ConfigureAwait(false);
serviceCollection.AddSingleton<ILocalizationManager>(LocalizationManager);
serviceCollection.AddSingleton<IBlurayExaminer>(new BdInfoExaminer(FileSystemManager));
- serviceCollection.AddSingleton<IXmlReaderSettingsFactory>(new XmlReaderSettingsFactory());
-
UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager);
serviceCollection.AddSingleton(UserDataManager);
@@ -770,7 +767,7 @@ namespace Emby.Server.Implementations
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
- ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, assemblyInfo);
+ ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, LocalizationManager);
serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
AuthenticationRepository = GetAuthenticationRepository();
@@ -786,7 +783,7 @@ namespace Emby.Server.Implementations
var musicManager = new MusicManager(LibraryManager);
serviceCollection.AddSingleton<IMusicManager>(new MusicManager(LibraryManager));
- LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager, EnvironmentInfo);
+ LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager);
serviceCollection.AddSingleton(LibraryMonitor);
serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));
@@ -794,16 +791,19 @@ namespace Emby.Server.Implementations
CertificateInfo = GetCertificateInfo(true);
Certificate = GetCertificate(CertificateInfo);
- HttpServer = new HttpListenerHost(this,
+ HttpServer = new HttpListenerHost(
+ this,
LoggerFactory,
ServerConfigurationManager,
_configuration,
NetworkManager,
JsonSerializer,
XmlSerializer,
- CreateHttpListener());
+ CreateHttpListener())
+ {
+ GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading")
+ };
- HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
serviceCollection.AddSingleton(HttpServer);
ImageProcessor = GetImageProcessor();
@@ -862,13 +862,13 @@ namespace Emby.Server.Implementations
LoggerFactory,
JsonSerializer,
StartupOptions.FFmpegPath,
- StartupOptions.FFprobePath,
ServerConfigurationManager,
FileSystemManager,
() => SubtitleEncoder,
() => MediaSourceManager,
ProcessFactory,
- 5000);
+ 5000,
+ LocalizationManager);
serviceCollection.AddSingleton(MediaEncoder);
EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager);
@@ -905,9 +905,7 @@ namespace Emby.Server.Implementations
_serviceProvider = serviceCollection.BuildServiceProvider();
}
- public virtual string PackageRuntime => "netcore";
-
- public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, EnvironmentInfo.EnvironmentInfo environmentInfo)
+ public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths)
{
// Distinct these to prevent users from reporting problems that aren't actually problems
var commandLineArgs = Environment
@@ -915,12 +913,14 @@ namespace Emby.Server.Implementations
.Distinct();
logger.LogInformation("Arguments: {Args}", commandLineArgs);
- logger.LogInformation("Operating system: {OS} {OSVersion}", environmentInfo.OperatingSystemName, environmentInfo.OperatingSystemVersion);
- logger.LogInformation("Architecture: {Architecture}", environmentInfo.SystemArchitecture);
+ // FIXME: @bond this logs the kernel version, not the OS version
+ logger.LogInformation("Operating system: {OS} {OSVersion}", OperatingSystem.Name, Environment.OSVersion.Version);
+ logger.LogInformation("Architecture: {Architecture}", RuntimeInformation.OSArchitecture);
logger.LogInformation("64-Bit Process: {Is64Bit}", Environment.Is64BitProcess);
logger.LogInformation("User Interactive: {IsUserInteractive}", Environment.UserInteractive);
logger.LogInformation("Processor count: {ProcessorCount}", Environment.ProcessorCount);
logger.LogInformation("Program data path: {ProgramDataPath}", appPaths.ProgramDataPath);
+ logger.LogInformation("Web resources path: {WebPath}", appPaths.WebPath);
logger.LogInformation("Application directory: {ApplicationPath}", appPaths.ProgramSystemPath);
}
@@ -957,7 +957,7 @@ namespace Emby.Server.Implementations
var password = string.IsNullOrWhiteSpace(info.Password) ? null : info.Password;
var localCert = new X509Certificate2(certificateLocation, password);
- //localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
+ // localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
if (!localCert.HasPrivateKey)
{
Logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation);
@@ -1044,6 +1044,8 @@ namespace Emby.Server.Implementations
/// </summary>
protected void FindParts()
{
+ InstallationManager = _serviceProvider.GetService<IInstallationManager>();
+
if (!ServerConfigurationManager.Configuration.IsPortAuthorized)
{
ServerConfigurationManager.Configuration.IsPortAuthorized = true;
@@ -1058,13 +1060,15 @@ namespace Emby.Server.Implementations
HttpServer.Init(GetExports<IService>(false), GetExports<IWebSocketListener>(), GetUrlPrefixes());
- LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
+ LibraryManager.AddParts(
+ GetExports<IResolverIgnoreRule>(),
GetExports<IItemResolver>(),
GetExports<IIntroProvider>(),
GetExports<IBaseItemComparer>(),
GetExports<ILibraryPostScanTask>());
- ProviderManager.AddParts(GetExports<IImageProvider>(),
+ ProviderManager.AddParts(
+ GetExports<IImageProvider>(),
GetExports<IMetadataService>(),
GetExports<IMetadataProvider>(),
GetExports<IMetadataSaver>(),
@@ -1145,6 +1149,7 @@ namespace Emby.Server.Implementations
}
private CertificateInfo CertificateInfo { get; set; }
+
protected X509Certificate2 Certificate { get; private set; }
private IEnumerable<string> GetUrlPrefixes()
@@ -1155,7 +1160,7 @@ namespace Emby.Server.Implementations
{
var prefixes = new List<string>
{
- "http://"+i+":" + HttpPort + "/"
+ "http://" + i + ":" + HttpPort + "/"
};
if (CertificateInfo != null)
@@ -1184,30 +1189,12 @@ namespace Emby.Server.Implementations
// Generate self-signed cert
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + (certHost + "2").GetMD5().ToString("N") + ".pfx");
- var password = "embycert";
-
- //if (generateCertificate)
- //{
- // if (!File.Exists(certPath))
- // {
- // FileSystemManager.CreateDirectory(FileSystemManager.GetDirectoryName(certPath));
-
- // try
- // {
- // CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, password, Logger);
- // }
- // catch (Exception ex)
- // {
- // Logger.LogError(ex, "Error creating ssl cert");
- // return null;
- // }
- // }
- //}
+ const string Password = "embycert";
return new CertificateInfo
{
Path = certPath,
- Password = password
+ Password = Password
};
}
@@ -1242,9 +1229,9 @@ namespace Emby.Server.Implementations
requiresRestart = true;
}
- var currentCertPath = CertificateInfo == null ? null : CertificateInfo.Path;
+ var currentCertPath = CertificateInfo?.Path;
var newCertInfo = GetCertificateInfo(false);
- var newCertPath = newCertInfo == null ? null : newCertInfo.Path;
+ var newCertPath = newCertInfo?.Path;
if (!string.Equals(currentCertPath, newCertPath, StringComparison.OrdinalIgnoreCase))
{
@@ -1377,6 +1364,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// Gets the system status.
/// </summary>
+ /// <param name="cancellationToken">The cancellation token</param>
/// <returns>SystemInfo.</returns>
public async Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken)
{
@@ -1393,6 +1381,7 @@ namespace Emby.Server.Implementations
CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
Id = SystemId,
ProgramDataPath = ApplicationPaths.ProgramDataPath,
+ WebPath = ApplicationPaths.WebPath,
LogPath = ApplicationPaths.LogDirectoryPath,
ItemsByNamePath = ApplicationPaths.InternalMetadataPath,
InternalMetadataPath = ApplicationPaths.InternalMetadataPath,
@@ -1400,8 +1389,8 @@ namespace Emby.Server.Implementations
HttpServerPortNumber = HttpPort,
SupportsHttps = SupportsHttps,
HttpsPortNumber = HttpsPort,
- OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(),
- OperatingSystemDisplayName = EnvironmentInfo.OperatingSystemName,
+ OperatingSystem = OperatingSystem.Id.ToString(),
+ OperatingSystemDisplayName = OperatingSystem.Name,
CanSelfRestart = CanSelfRestart,
CanLaunchWebBrowser = CanLaunchWebBrowser,
WanAddress = wanAddress,
@@ -1411,7 +1400,7 @@ namespace Emby.Server.Implementations
LocalAddress = localAddress,
SupportsLibraryMonitor = true,
EncoderLocation = MediaEncoder.EncoderLocation,
- SystemArchitecture = EnvironmentInfo.SystemArchitecture,
+ SystemArchitecture = RuntimeInformation.OSArchitecture,
SystemUpdateLevel = SystemUpdateLevel,
PackageName = StartupOptions.PackageName
};
@@ -1435,7 +1424,7 @@ namespace Emby.Server.Implementations
{
Version = ApplicationVersion,
Id = SystemId,
- OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(),
+ OperatingSystem = OperatingSystem.Id.ToString(),
WanAddress = wanAddress,
ServerName = FriendlyName,
LocalAddress = localAddress
@@ -1470,18 +1459,18 @@ namespace Emby.Server.Implementations
public async Task<string> GetWanApiUrl(CancellationToken cancellationToken)
{
- const string url = "http://ipv4.icanhazip.com";
+ const string Url = "http://ipv4.icanhazip.com";
try
{
using (var response = await HttpClient.Get(new HttpRequestOptions
{
- Url = url,
+ Url = Url,
LogErrorResponseBody = false,
LogErrors = false,
LogRequest = false,
BufferContent = false,
CancellationToken = cancellationToken
- }))
+ }).ConfigureAwait(false))
{
string res = await response.ReadToEndAsync().ConfigureAwait(false);
return GetLocalApiUrl(res.Trim());
@@ -1570,10 +1559,12 @@ namespace Emby.Server.Implementations
{
return result;
}
+
return null;
}
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
+
private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address, CancellationToken cancellationToken)
{
if (address.Equals(IpAddressInfo.Loopback) ||
@@ -1590,25 +1581,26 @@ namespace Emby.Server.Implementations
return cachedResult;
}
- var logPing = false;
-
#if DEBUG
- logPing = true;
+ const bool LogPing = true;
+#else
+ const bool LogPing = false;
#endif
try
{
- using (var response = await HttpClient.SendAsync(new HttpRequestOptions
- {
- Url = apiUrl,
- LogErrorResponseBody = false,
- LogErrors = logPing,
- LogRequest = logPing,
- BufferContent = false,
+ using (var response = await HttpClient.SendAsync(
+ new HttpRequestOptions
+ {
+ Url = apiUrl,
+ LogErrorResponseBody = false,
+ LogErrors = logPing,
+ LogRequest = logPing,
+ BufferContent = false,
- CancellationToken = cancellationToken
+ CancellationToken = cancellationToken
- }, HttpMethod.Post).ConfigureAwait(false))
+ }, HttpMethod.Post).ConfigureAwait(false))
{
using (var reader = new StreamReader(response.Content))
{
@@ -1673,6 +1665,7 @@ namespace Emby.Server.Implementations
public event EventHandler HasUpdateAvailableChanged;
private bool _hasUpdateAvailable;
+
public bool HasUpdateAvailable
{
get => _hasUpdateAvailable;
@@ -1733,7 +1726,7 @@ namespace Emby.Server.Implementations
var process = ProcessFactory.Create(new ProcessOptions
{
FileName = url,
- //EnableRaisingEvents = true,
+ EnableRaisingEvents = true,
UseShellExecute = true,
ErrorDialog = false
});
@@ -1768,26 +1761,25 @@ namespace Emby.Server.Implementations
{
Logger.LogInformation("Application has been updated to version {0}", package.versionStr);
- ApplicationUpdated?.Invoke(this, new GenericEventArgs<PackageVersionInfo>
- {
- Argument = package
- });
+ ApplicationUpdated?.Invoke(
+ this,
+ new GenericEventArgs<PackageVersionInfo>()
+ {
+ Argument = package
+ });
NotifyPendingRestart();
}
- private bool _disposed;
+ private bool _disposed = false;
+
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
- if (!_disposed)
- {
- _disposed = true;
-
- Dispose(true);
- }
+ Dispose(true);
+ GC.SuppressFinalize(this);
}
/// <summary>
@@ -1796,14 +1788,19 @@ namespace Emby.Server.Implementations
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool dispose)
{
+ if (_disposed)
+ {
+ return;
+ }
+
if (dispose)
{
var type = GetType();
Logger.LogInformation("Disposing {Type}", type.Name);
- var parts = DisposableParts.Distinct().Where(i => i.GetType() != type).ToList();
- DisposableParts.Clear();
+ var parts = _disposableParts.Distinct().Where(i => i.GetType() != type).ToList();
+ _disposableParts.Clear();
foreach (var part in parts)
{
@@ -1819,6 +1816,8 @@ namespace Emby.Server.Implementations
}
}
}
+
+ _disposed = true;
}
}