More warning fixes

This commit is contained in:
Bond-009
2019-03-13 22:32:52 +01:00
parent 1d443d2ff5
commit bf43dc00bb
12 changed files with 532 additions and 487 deletions

View File

@@ -34,7 +34,6 @@ using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Library;
using Emby.Server.Implementations.LiveTv;
using Emby.Server.Implementations.Localization;
using Emby.Server.Implementations.Middleware;
using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.Playlists;
using Emby.Server.Implementations.ScheduledTasks;
@@ -161,7 +160,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; }
@@ -175,7 +174,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; }
@@ -187,13 +186,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; }
@@ -201,7 +200,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// The disposable parts
/// </summary>
protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
protected readonly List<IDisposable> _disposableParts = new List<IDisposable>();
/// <summary>
/// Gets the configuration manager.
@@ -240,27 +239,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>
@@ -268,6 +273,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; }
@@ -277,6 +283,7 @@ namespace Emby.Server.Implementations
public LocalizationManager LocalizationManager { get; set; }
private IEncodingManager EncodingManager { get; set; }
private IChannelManager ChannelManager { get; set; }
/// <summary>
@@ -284,20 +291,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;
@@ -313,28 +329,37 @@ 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,
@@ -395,7 +420,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
@@ -404,13 +429,16 @@ namespace Emby.Server.Implementations
public string ApplicationUserAgent => Name.Replace(' ','-') + "/" + ApplicationVersion;
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
@@ -441,15 +469,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)
{
@@ -468,14 +496,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>()
{
@@ -487,22 +515,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>());
}
}
@@ -522,29 +550,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();
}
@@ -594,7 +613,7 @@ namespace Emby.Server.Implementations
SetHttpLimit();
await RegisterResources(serviceCollection);
await RegisterResources(serviceCollection).ConfigureAwait(false);
FindParts();
@@ -631,7 +650,7 @@ namespace Emby.Server.Implementations
})
.Build();
await host.StartAsync();
await host.StartAsync().ConfigureAwait(false);
}
private async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func<Task> next)
@@ -729,8 +748,8 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(ServerConfigurationManager);
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));
@@ -769,16 +788,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();
@@ -933,7 +955,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);
@@ -1034,13 +1056,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>(),
@@ -1121,6 +1145,7 @@ namespace Emby.Server.Implementations
}
private CertificateInfo CertificateInfo { get; set; }
protected X509Certificate2 Certificate { get; private set; }
private IEnumerable<string> GetUrlPrefixes()
@@ -1131,7 +1156,7 @@ namespace Emby.Server.Implementations
{
var prefixes = new List<string>
{
"http://"+i+":" + HttpPort + "/"
"http://" + i + ":" + HttpPort + "/"
};
if (CertificateInfo != null)
@@ -1160,30 +1185,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
};
}
@@ -1218,9 +1225,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))
{
@@ -1353,6 +1360,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)
{
@@ -1447,19 +1455,19 @@ 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,
TimeoutMs = 10000,
BufferContent = false,
CancellationToken = cancellationToken
}))
}).ConfigureAwait(false))
{
return GetLocalApiUrl(response.ReadToEnd().Trim());
}
@@ -1547,10 +1555,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) ||
@@ -1567,26 +1577,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,
TimeoutMs = 5000,
BufferContent = false,
using (var response = await HttpClient.SendAsync(
new HttpRequestOptions
{
Url = apiUrl,
LogErrorResponseBody = false,
LogErrors = LogPing,
LogRequest = LogPing,
TimeoutMs = 5000,
BufferContent = false,
CancellationToken = cancellationToken
}, "POST").ConfigureAwait(false))
CancellationToken = cancellationToken
}, "POST").ConfigureAwait(false))
{
using (var reader = new StreamReader(response.Content))
{
@@ -1651,6 +1661,7 @@ namespace Emby.Server.Implementations
public event EventHandler HasUpdateAvailableChanged;
private bool _hasUpdateAvailable;
public bool HasUpdateAvailable
{
get => _hasUpdateAvailable;
@@ -1711,7 +1722,7 @@ namespace Emby.Server.Implementations
var process = ProcessFactory.Create(new ProcessOptions
{
FileName = url,
//EnableRaisingEvents = true,
EnableRaisingEvents = true,
UseShellExecute = true,
ErrorDialog = false
});
@@ -1746,26 +1757,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>
@@ -1774,14 +1784,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)
{
@@ -1797,6 +1812,8 @@ namespace Emby.Server.Implementations
}
}
}
_disposed = true;
}
}