Fix some warnings

pull/6852/head
Bond_009 3 years ago
parent 9c74103fbe
commit 474b035d99

@ -7,7 +7,7 @@ using SQLitePCL.pretty;
namespace Emby.Server.Implementations.Data namespace Emby.Server.Implementations.Data
{ {
public class ManagedConnection : IDisposable public sealed class ManagedConnection : IDisposable
{ {
private readonly SemaphoreSlim _writeLock; private readonly SemaphoreSlim _writeLock;

@ -1,5 +1,3 @@
#nullable disable
#pragma warning disable CS1591 #pragma warning disable CS1591
using System; using System;
@ -14,7 +12,7 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO namespace Emby.Server.Implementations.IO
{ {
public class FileRefresher : IDisposable public sealed class FileRefresher : IDisposable
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
@ -22,7 +20,7 @@ namespace Emby.Server.Implementations.IO
private readonly List<string> _affectedPaths = new List<string>(); private readonly List<string> _affectedPaths = new List<string>();
private readonly object _timerLock = new object(); private readonly object _timerLock = new object();
private Timer _timer; private Timer? _timer;
private bool _disposed; private bool _disposed;
public FileRefresher(string path, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger logger) public FileRefresher(string path, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ILogger logger)
@ -36,7 +34,7 @@ namespace Emby.Server.Implementations.IO
AddPath(path); AddPath(path);
} }
public event EventHandler<EventArgs> Completed; public event EventHandler<EventArgs>? Completed;
public string Path { get; private set; } public string Path { get; private set; }
@ -111,7 +109,7 @@ namespace Emby.Server.Implementations.IO
RestartTimer(); RestartTimer();
} }
private void OnTimerCallback(object state) private void OnTimerCallback(object? state)
{ {
List<string> paths; List<string> paths;
@ -127,7 +125,7 @@ namespace Emby.Server.Implementations.IO
try try
{ {
ProcessPathChanges(paths.ToList()); ProcessPathChanges(paths);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -137,12 +135,12 @@ namespace Emby.Server.Implementations.IO
private void ProcessPathChanges(List<string> paths) private void ProcessPathChanges(List<string> paths)
{ {
var itemsToRefresh = paths IEnumerable<BaseItem> itemsToRefresh = paths
.Distinct(StringComparer.OrdinalIgnoreCase) .Distinct(StringComparer.OrdinalIgnoreCase)
.Select(GetAffectedBaseItem) .Select(GetAffectedBaseItem)
.Where(item => item != null) .Where(item => item != null)
.GroupBy(x => x.Id) .GroupBy(x => x!.Id) // Removed null values in the previous .Where()
.Select(x => x.First()); .Select(x => x.First())!;
foreach (var item in itemsToRefresh) foreach (var item in itemsToRefresh)
{ {
@ -176,15 +174,15 @@ namespace Emby.Server.Implementations.IO
/// </summary> /// </summary>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>BaseItem.</returns> /// <returns>BaseItem.</returns>
private BaseItem GetAffectedBaseItem(string path) private BaseItem? GetAffectedBaseItem(string path)
{ {
BaseItem item = null; BaseItem? item = null;
while (item == null && !string.IsNullOrEmpty(path)) while (item == null && !string.IsNullOrEmpty(path))
{ {
item = _libraryManager.FindByPath(path, null); item = _libraryManager.FindByPath(path, null);
path = System.IO.Path.GetDirectoryName(path); path = System.IO.Path.GetDirectoryName(path) ?? string.Empty;
} }
if (item != null) if (item != null)

@ -449,12 +449,12 @@ namespace Emby.Server.Implementations.IO
} }
var newRefresher = new FileRefresher(path, _configurationManager, _libraryManager, _logger); var newRefresher = new FileRefresher(path, _configurationManager, _libraryManager, _logger);
newRefresher.Completed += NewRefresher_Completed; newRefresher.Completed += OnNewRefresherCompleted;
_activeRefreshers.Add(newRefresher); _activeRefreshers.Add(newRefresher);
} }
} }
private void NewRefresher_Completed(object sender, EventArgs e) private void OnNewRefresherCompleted(object sender, EventArgs e)
{ {
var refresher = (FileRefresher)sender; var refresher = (FileRefresher)sender;
DisposeRefresher(refresher); DisposeRefresher(refresher);
@ -481,6 +481,7 @@ namespace Emby.Server.Implementations.IO
{ {
lock (_activeRefreshers) lock (_activeRefreshers)
{ {
refresher.Completed -= OnNewRefresherCompleted;
refresher.Dispose(); refresher.Dispose();
_activeRefreshers.Remove(refresher); _activeRefreshers.Remove(refresher);
} }
@ -492,6 +493,7 @@ namespace Emby.Server.Implementations.IO
{ {
foreach (var refresher in _activeRefreshers.ToList()) foreach (var refresher in _activeRefreshers.ToList())
{ {
refresher.Completed -= OnNewRefresherCompleted;
refresher.Dispose(); refresher.Dispose();
} }

@ -187,7 +187,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
CultureInfo.InvariantCulture, CultureInfo.InvariantCulture,
"-i \"{0}\" {2} -map_metadata -1 -threads {6} {3}{4}{5} -y \"{1}\"", "-i \"{0}\" {2} -map_metadata -1 -threads {6} {3}{4}{5} -y \"{1}\"",
inputTempFile, inputTempFile,
targetFile.Replace("\"", "\\\""), // Escape quotes in filename targetFile.Replace("\"", "\\\"", StringComparison.Ordinal), // Escape quotes in filename
videoArgs, videoArgs,
GetAudioArgs(mediaSource), GetAudioArgs(mediaSource),
subtitleArgs, subtitleArgs,

@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
public async Task<bool> CheckTunerAvailability(IPAddress remoteIp, int tuner, CancellationToken cancellationToken) public async Task<bool> CheckTunerAvailability(IPAddress remoteIp, int tuner, CancellationToken cancellationToken)
{ {
using var client = new TcpClient(); using var client = new TcpClient();
client.Connect(remoteIp, HdHomeRunPort); await client.ConnectAsync(remoteIp, HdHomeRunPort).ConfigureAwait(false);
using var stream = client.GetStream(); using var stream = client.GetStream();
return await CheckTunerAvailability(stream, tuner, cancellationToken).ConfigureAwait(false); return await CheckTunerAvailability(stream, tuner, cancellationToken).ConfigureAwait(false);

@ -283,7 +283,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
// #EXTINF:0,84.0 - VOX Schweiz // #EXTINF:0,84.0 - VOX Schweiz
if (!string.IsNullOrWhiteSpace(nameInExtInf)) if (!string.IsNullOrWhiteSpace(nameInExtInf))
{ {
var numberIndex = nameInExtInf.IndexOf(' '); var numberIndex = nameInExtInf.IndexOf(' ', StringComparison.Ordinal);
if (numberIndex > 0) if (numberIndex > 0)
{ {
var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' }); var numberPart = nameInExtInf.Substring(0, numberIndex).Trim(new[] { ' ', '.' });

@ -527,7 +527,7 @@ namespace Emby.Server.Implementations.Playlists
var relativeUri = folderUri.MakeRelativeUri(fileAbsoluteUri); var relativeUri = folderUri.MakeRelativeUri(fileAbsoluteUri);
string relativePath = Uri.UnescapeDataString(relativeUri.ToString()); string relativePath = Uri.UnescapeDataString(relativeUri.ToString());
if (fileAbsoluteUri.Scheme.Equals("file", StringComparison.CurrentCultureIgnoreCase)) if (fileAbsoluteUri.Scheme.Equals("file", StringComparison.OrdinalIgnoreCase))
{ {
relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
} }

@ -26,7 +26,7 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y) public int Compare(BaseItem? x, BaseItem? y)
{ {
return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase); return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
} }
/// <summary> /// <summary>

@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
public int Compare(BaseItem? x, BaseItem? y) public int Compare(BaseItem? x, BaseItem? y)
{ {
return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase); return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
} }
/// <summary> /// <summary>
@ -35,9 +35,7 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private static string? GetValue(BaseItem? x) private static string? GetValue(BaseItem? x)
{ {
var audio = x as Audio; return x is Audio audio ? audio.Album : string.Empty;
return audio == null ? string.Empty : audio.Album;
} }
} }
} }

@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.Sorting
/// <inheritdoc /> /// <inheritdoc />
public int Compare(BaseItem? x, BaseItem? y) public int Compare(BaseItem? x, BaseItem? y)
{ {
return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase); return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
} }
/// <summary> /// <summary>

@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.Sorting
throw new ArgumentNullException(nameof(y)); throw new ArgumentNullException(nameof(y));
} }
return string.Compare(x.Name, y.Name, StringComparison.CurrentCultureIgnoreCase); return string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase);
} }
} }
} }

@ -25,7 +25,7 @@ namespace Emby.Server.Implementations.Sorting
/// <returns>System.Int32.</returns> /// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y) public int Compare(BaseItem x, BaseItem y)
{ {
return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase); return string.Compare(GetValue(x), GetValue(y), StringComparison.OrdinalIgnoreCase);
} }
private static string GetValue(BaseItem item) private static string GetValue(BaseItem item)

@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Sorting
throw new ArgumentNullException(nameof(y)); throw new ArgumentNullException(nameof(y));
} }
return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase); return string.Compare(x.SortName, y.SortName, StringComparison.OrdinalIgnoreCase);
} }
} }
} }

@ -82,7 +82,7 @@ namespace Rssdp.Infrastructure
throw new ArgumentNullException(nameof(versionData)); throw new ArgumentNullException(nameof(versionData));
} }
var versionSeparatorIndex = versionData.IndexOf('/'); var versionSeparatorIndex = versionData.IndexOf('/', StringComparison.Ordinal);
if (versionSeparatorIndex <= 0 || versionSeparatorIndex == versionData.Length) if (versionSeparatorIndex <= 0 || versionSeparatorIndex == versionData.Length)
{ {
throw new ArgumentException("request header line is invalid. Http Version not supplied or incorrect format.", nameof(versionData)); throw new ArgumentException("request header line is invalid. Http Version not supplied or incorrect format.", nameof(versionData));
@ -101,7 +101,7 @@ namespace Rssdp.Infrastructure
{ {
// Header format is // Header format is
// name: value // name: value
var headerKeySeparatorIndex = line.IndexOf(":", StringComparison.OrdinalIgnoreCase); var headerKeySeparatorIndex = line.IndexOf(':', StringComparison.Ordinal);
var headerName = line.Substring(0, headerKeySeparatorIndex).Trim(); var headerName = line.Substring(0, headerKeySeparatorIndex).Trim();
var headerValue = line.Substring(headerKeySeparatorIndex + 1).Trim(); var headerValue = line.Substring(headerKeySeparatorIndex + 1).Trim();
@ -172,7 +172,7 @@ namespace Rssdp.Infrastructure
else else
{ {
var segments = headerValue.Split(SeparatorCharacters); var segments = headerValue.Split(SeparatorCharacters);
if (headerValue.Contains('"')) if (headerValue.Contains('"', StringComparison.Ordinal))
{ {
for (int segmentIndex = 0; segmentIndex < segments.Length; segmentIndex++) for (int segmentIndex = 0; segmentIndex < segments.Length; segmentIndex++)
{ {

@ -38,8 +38,14 @@
</Rules> </Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.Design"> <Rules AnalyzerId="Microsoft.CodeAnalysis.NetAnalyzers" RuleNamespace="Microsoft.Design">
<!-- error on CA1063: Implement IDisposable correctly -->
<Rule Id="CA1063" Action="Error" />
<!-- error on CA1305: Specify IFormatProvider --> <!-- error on CA1305: Specify IFormatProvider -->
<Rule Id="CA1305" Action="Error" /> <Rule Id="CA1305" Action="Error" />
<!-- error on CA1307: Specify StringComparison for clarity -->
<Rule Id="CA1307" Action="Error" />
<!-- error on CA1309: Use ordinal StringComparison -->
<Rule Id="CA1309" Action="Error" />
<!-- error on CA1725: Parameter names should match base declaration --> <!-- error on CA1725: Parameter names should match base declaration -->
<Rule Id="CA1725" Action="Error" /> <Rule Id="CA1725" Action="Error" />
<!-- error on CA1725: Call async methods when in an async method --> <!-- error on CA1725: Call async methods when in an async method -->

Loading…
Cancel
Save