Update deps and add MultiThreading analyzer

This commit is contained in:
Bond_009 2019-09-23 23:10:51 +02:00
parent 89a21c96c0
commit 3f7836d9eb
12 changed files with 106 additions and 78 deletions

View File

@ -24,8 +24,9 @@
<!-- Code analysers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -35,7 +35,7 @@ namespace Emby.Server.Implementations.AppBase
/// <summary>
/// The _configuration sync lock.
/// </summary>
private object _configurationSyncLock = new object();
private readonly object _configurationSyncLock = new object();
/// <summary>
/// The _configuration.
@ -98,16 +98,31 @@ namespace Emby.Server.Implementations.AppBase
public IApplicationPaths CommonApplicationPaths { get; private set; }
/// <summary>
/// Gets the system configuration
/// Gets the system configuration.
/// </summary>
/// <value>The configuration.</value>
public BaseApplicationConfiguration CommonConfiguration
{
get
{
// Lazy load
LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => (BaseApplicationConfiguration)ConfigurationHelper.GetXmlConfiguration(ConfigurationType, CommonApplicationPaths.SystemConfigurationFilePath, XmlSerializer));
return _configuration;
if (_configurationLoaded)
{
return _configuration;
}
lock (_configurationSyncLock)
{
if (_configurationLoaded)
{
return _configuration;
}
_configuration = (BaseApplicationConfiguration)ConfigurationHelper.GetXmlConfiguration(ConfigurationType, CommonApplicationPaths.SystemConfigurationFilePath, XmlSerializer);
_configurationLoaded = true;
return _configuration;
}
}
protected set
{

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
@ -29,9 +29,9 @@
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.0.0" />
<PackageReference Include="ServiceStack.Text.Core" Version="5.6.0" />
<PackageReference Include="sharpcompress" Version="0.24.0" />
<PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.0.1" />
@ -47,16 +47,12 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<!-- We need at least C# 7.3 to compare tuples-->
<LangVersion>latest</LangVersion>
</PropertyGroup>
<!-- Code analysers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

View File

@ -27,6 +27,11 @@ namespace Emby.Server.Implementations.EntryPoints
private NatManager _natManager;
private readonly object _createdRulesLock = new object();
private List<string> _createdRules = new List<string>();
private readonly object _usnsHandledLock = new object();
private List<string> _usnsHandled = new List<string>();
public ExternalPortForwarding(ILoggerFactory loggerFactory, IServerApplicationHost appHost, IServerConfigurationManager config, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient)
{
_logger = loggerFactory.CreateLogger("PortMapper");
@ -127,12 +132,13 @@ namespace Emby.Server.Implementations.EntryPoints
return;
}
lock (_usnsHandled)
lock (_usnsHandledLock)
{
if (_usnsHandled.Contains(identifier))
{
return;
}
_usnsHandled.Add(identifier);
}
@ -186,11 +192,12 @@ namespace Emby.Server.Implementations.EntryPoints
private void ClearCreatedRules(object state)
{
lock (_createdRules)
lock (_createdRulesLock)
{
_createdRules.Clear();
}
lock (_usnsHandled)
lock (_usnsHandledLock)
{
_usnsHandled.Clear();
}
@ -216,8 +223,6 @@ namespace Emby.Server.Implementations.EntryPoints
}
}
private List<string> _createdRules = new List<string>();
private List<string> _usnsHandled = new List<string>();
private async void CreateRules(INatDevice device)
{
if (_disposed)
@ -231,7 +236,7 @@ namespace Emby.Server.Implementations.EntryPoints
var addressString = address.ToString();
lock (_createdRules)
lock (_createdRulesLock)
{
if (!_createdRules.Contains(addressString))
{

View File

@ -20,6 +20,9 @@ namespace Emby.Server.Implementations.Networking
private IPAddress[] _localIpAddresses;
private readonly object _localIpAddressSyncLock = new object();
private readonly object _subnetLookupLock = new object();
private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal);
public NetworkManager(ILogger<NetworkManager> logger)
{
_logger = logger;
@ -28,10 +31,10 @@ namespace Emby.Server.Implementations.Networking
NetworkChange.NetworkAvailabilityChanged += OnNetworkAvailabilityChanged;
}
public Func<string[]> LocalSubnetsFn { get; set; }
public event EventHandler NetworkChanged;
public Func<string[]> LocalSubnetsFn { get; set; }
private void OnNetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
{
_logger.LogDebug("NetworkAvailabilityChanged");
@ -179,10 +182,9 @@ namespace Emby.Server.Implementations.Networking
return false;
}
private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal);
private List<string> GetSubnets(string endpointFirstPart)
{
lock (_subnetLookup)
lock (_subnetLookupLock)
{
if (_subnetLookup.TryGetValue(endpointFirstPart, out var subnets))
{
@ -200,7 +202,11 @@ namespace Emby.Server.Implementations.Networking
int subnet_Test = 0;
foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.'))
{
if (part.Equals("0")) break;
if (part.Equals("0", StringComparison.Ordinal))
{
break;
}
subnet_Test++;
}

View File

@ -28,43 +28,10 @@ namespace Emby.Server.Implementations.Updates
/// </summary>
public class InstallationManager : IInstallationManager
{
public event EventHandler<InstallationEventArgs> PackageInstalling;
public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
/// <summary>
/// The current installations
/// </summary>
private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations { get; set; }
/// <summary>
/// The completed installations
/// </summary>
private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
/// <summary>
/// Occurs when [plugin uninstalled].
/// </summary>
public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated;
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
/// <summary>
/// The _logger
/// The _logger.
/// </summary>
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;
private readonly IJsonSerializer _jsonSerializer;
@ -79,6 +46,18 @@ namespace Emby.Server.Implementations.Updates
private readonly IZipClient _zipClient;
private readonly object _currentInstallationsLock = new object();
/// <summary>
/// The current installations.
/// </summary>
private List<(InstallationInfo info, CancellationTokenSource token)> _currentInstallations;
/// <summary>
/// The completed installations.
/// </summary>
private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
public InstallationManager(
ILogger<InstallationManager> logger,
IApplicationHost appHost,
@ -107,6 +86,31 @@ namespace Emby.Server.Implementations.Updates
_zipClient = zipClient;
}
public event EventHandler<InstallationEventArgs> PackageInstalling;
public event EventHandler<InstallationEventArgs> PackageInstallationCompleted;
public event EventHandler<InstallationFailedEventArgs> PackageInstallationFailed;
public event EventHandler<InstallationEventArgs> PackageInstallationCancelled;
/// <summary>
/// Occurs when [plugin uninstalled].
/// </summary>
public event EventHandler<GenericEventArgs<IPlugin>> PluginUninstalled;
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
public event EventHandler<GenericEventArgs<(IPlugin, PackageVersionInfo)>> PluginUpdated;
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
public event EventHandler<GenericEventArgs<PackageVersionInfo>> PluginInstalled;
public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
/// <summary>
/// Gets all available packages.
/// </summary>
@ -330,7 +334,7 @@ namespace Emby.Server.Implementations.Updates
var tuple = (installationInfo, innerCancellationTokenSource);
// Add it to the in-progress list
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
_currentInstallations.Add(tuple);
}
@ -349,7 +353,7 @@ namespace Emby.Server.Implementations.Updates
{
await InstallPackageInternal(package, linkedToken).ConfigureAwait(false);
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@ -360,7 +364,7 @@ namespace Emby.Server.Implementations.Updates
}
catch (OperationCanceledException)
{
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@ -375,7 +379,7 @@ namespace Emby.Server.Implementations.Updates
{
_logger.LogError(ex, "Package installation failed");
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
_currentInstallations.Remove(tuple);
}
@ -535,7 +539,7 @@ namespace Emby.Server.Implementations.Updates
/// <inheritdoc/>
public bool CancelInstallation(Guid id)
{
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
var install = _currentInstallations.Find(x => x.Item1.Id == id);
if (install == default((InstallationInfo, CancellationTokenSource)))
@ -563,7 +567,7 @@ namespace Emby.Server.Implementations.Updates
{
if (dispose)
{
lock (_currentInstallations)
lock (_currentInstallationsLock)
{
foreach (var tuple in _currentInstallations)
{

View File

@ -9,8 +9,6 @@
</PropertyGroup>
<PropertyGroup>
<!-- We need at least C# 7.1 for async main-->
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
@ -25,8 +23,9 @@
<!-- Code analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@ -35,8 +34,8 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />

View File

@ -12,7 +12,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.0" />
</ItemGroup>

View File

@ -18,7 +18,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
<PackageReference Include="UTF.Unknown" Version="2.1.0" />
</ItemGroup>

View File

@ -15,7 +15,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
<PackageReference Include="System.Text.Json" Version="4.6.0" />
</ItemGroup>

View File

@ -11,8 +11,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.0.0" />
<PackageReference Include="OptimizedPriorityQueue" Version="4.2.0" />
<PackageReference Include="PlaylistsNET" Version="1.0.4" />
<PackageReference Include="TvDbSharper" Version="2.0.0" />
@ -28,5 +28,5 @@
<!-- We need at least C# 7.1 -->
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>

View File

@ -10,6 +10,8 @@
<Rule Id="SA1101" Action="None" />
<!-- disable warning SA1108: Block statements should not contain embedded comments -->
<Rule Id="SA1108" Action="None" />
<!-- disable warning SA1128:: Put constructor initializers on their own line -->
<Rule Id="SA1128" Action="None" />
<!-- disable warning SA1130: Use lambda syntax -->
<Rule Id="SA1130" Action="None" />
<!-- disable warning SA1200: 'using' directive must appear within a namespace declaration -->