diff options
| author | Bond_009 <bond.009@outlook.com> | 2022-01-07 11:48:59 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2022-01-10 10:57:32 +0100 |
| commit | 05836c8cd31ceaa3b84c2fa7dd04dfdbc9d7cc3c (patch) | |
| tree | 257bfef6ce7e223d8d4b5cd9c042088b1f081e93 | |
| parent | d24683f0abefe42daae366745422798079705243 (diff) | |
Fix warning SA1414 and CA1849
| -rw-r--r-- | Emby.Dlna/ContentDirectory/ControlHandler.cs | 6 | ||||
| -rw-r--r-- | Emby.Dlna/PlayTo/Device.cs | 6 | ||||
| -rw-r--r-- | Emby.Dlna/Service/BaseControlHandler.cs | 49 | ||||
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs | 4 | ||||
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs | 14 | ||||
| -rw-r--r-- | Jellyfin.Api/Helpers/RequestHelpers.cs | 2 | ||||
| -rw-r--r-- | jellyfin.ruleset | 4 |
7 files changed, 38 insertions, 47 deletions
diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs index 010f90c62..0cd1a0daf 100644 --- a/Emby.Dlna/ContentDirectory/ControlHandler.cs +++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs @@ -1192,13 +1192,13 @@ namespace Emby.Dlna.ContentDirectory /// </summary> /// <param name="result">A <see cref="QueryResult{BaseItem}"/>.</param> /// <returns>The <see cref="QueryResult{ServerItem}"/>.</returns> - private static QueryResult<ServerItem> ToResult(QueryResult<(BaseItem, ItemCounts)> result) + private static QueryResult<ServerItem> ToResult(QueryResult<(BaseItem Item, ItemCounts ItemCounts)> result) { var length = result.Items.Count; var serverItems = new ServerItem[length]; for (var i = 0; i < length; i++) { - serverItems[i] = new ServerItem(result.Items[i].Item1, null); + serverItems[i] = new ServerItem(result.Items[i].Item, null); } return new QueryResult<ServerItem> @@ -1213,7 +1213,7 @@ namespace Emby.Dlna.ContentDirectory /// </summary> /// <param name="sort">The <see cref="SortCriteria"/>.</param> /// <param name="isPreSorted">True if pre-sorted.</param> - private static (string, SortOrder)[] GetOrderBy(SortCriteria sort, bool isPreSorted) + private static (string SortName, SortOrder SortOrder)[] GetOrderBy(SortCriteria sort, bool isPreSorted) { return isPreSorted ? Array.Empty<(string, SortOrder)>() : new[] { (ItemSortBy.SortName, sort.SortOrder) }; } diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs index 34fb8fddd..7815e9293 100644 --- a/Emby.Dlna/PlayTo/Device.cs +++ b/Emby.Dlna/PlayTo/Device.cs @@ -535,9 +535,9 @@ namespace Emby.Dlna.PlayTo { var tuple = await GetPositionInfo(avCommands, cancellationToken).ConfigureAwait(false); - var currentObject = tuple.Item2; + var currentObject = tuple.Track; - if (tuple.Item1 && currentObject == null) + if (tuple.Success && currentObject == null) { currentObject = await GetMediaInfo(avCommands, cancellationToken).ConfigureAwait(false); } @@ -797,7 +797,7 @@ namespace Emby.Dlna.PlayTo return null; } - private async Task<(bool, UBaseObject)> GetPositionInfo(TransportCommands avCommands, CancellationToken cancellationToken) + private async Task<(bool Success, UBaseObject Track)> GetPositionInfo(TransportCommands avCommands, CancellationToken cancellationToken) { var command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "GetPositionInfo"); if (command == null) diff --git a/Emby.Dlna/Service/BaseControlHandler.cs b/Emby.Dlna/Service/BaseControlHandler.cs index 780aad9c1..7bec2eb72 100644 --- a/Emby.Dlna/Service/BaseControlHandler.cs +++ b/Emby.Dlna/Service/BaseControlHandler.cs @@ -47,7 +47,7 @@ namespace Emby.Dlna.Service private async Task<ControlResponse> ProcessControlRequestInternalAsync(ControlRequest request) { - ControlRequestInfo? requestInfo = null; + ControlRequestInfo requestInfo; using (var streamReader = new StreamReader(request.InputXml, Encoding.UTF8)) { @@ -66,6 +66,11 @@ namespace Emby.Dlna.Service Logger.LogDebug("Received control request {LocalName}, params: {@Headers}", requestInfo.LocalName, requestInfo.Headers); + return CreateControlResponse(requestInfo); + } + + private ControlResponse CreateControlResponse(ControlRequestInfo requestInfo) + { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, @@ -112,29 +117,19 @@ namespace Emby.Dlna.Service { if (reader.NodeType == XmlNodeType.Element) { - switch (reader.LocalName) + if (string.Equals(reader.LocalName, "Body", StringComparison.Ordinal)) { - case "Body": - { - if (!reader.IsEmptyElement) - { - using var subReader = reader.ReadSubtree(); - return await ParseBodyTagAsync(subReader).ConfigureAwait(false); - } - else - { - await reader.ReadAsync().ConfigureAwait(false); - } - - break; - } - - default: - { - await reader.SkipAsync().ConfigureAwait(false); - break; - } + if (reader.IsEmptyElement) + { + await reader.ReadAsync().ConfigureAwait(false); + continue; + } + + using var subReader = reader.ReadSubtree(); + return await ParseBodyTagAsync(subReader).ConfigureAwait(false); } + + await reader.SkipAsync().ConfigureAwait(false); } else { @@ -160,17 +155,17 @@ namespace Emby.Dlna.Service localName = reader.LocalName; namespaceURI = reader.NamespaceURI; - if (!reader.IsEmptyElement) + if (reader.IsEmptyElement) + { + await reader.ReadAsync().ConfigureAwait(false); + } + else { var result = new ControlRequestInfo(localName, namespaceURI); using var subReader = reader.ReadSubtree(); await ParseFirstBodyChildAsync(subReader, result.Headers).ConfigureAwait(false); return result; } - else - { - await reader.ReadAsync().ConfigureAwait(false); - } } else { diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs index f1a6ef344..48d9e316d 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs @@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun _remoteEndPoint = new IPEndPoint(remoteIp, HdHomeRunPort); _tcpClient = new TcpClient(); - _tcpClient.Connect(_remoteEndPoint); + await _tcpClient.ConnectAsync(_remoteEndPoint, cancellationToken).ConfigureAwait(false); if (!_lockkey.HasValue) { @@ -158,7 +158,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun } using var tcpClient = new TcpClient(); - tcpClient.Connect(_remoteEndPoint); + await tcpClient.ConnectAsync(_remoteEndPoint, cancellationToken).ConfigureAwait(false); using var stream = tcpClient.GetStream(); var commandList = commands.GetCommands(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index b1ce7b2b3..ab4beb15b 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -1,5 +1,3 @@ -#nullable disable - #pragma warning disable CS1591 using System; @@ -51,7 +49,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var url = mediaSource.Path; - Directory.CreateDirectory(Path.GetDirectoryName(TempFilePath)); + Directory.CreateDirectory(Path.GetDirectoryName(TempFilePath) ?? throw new InvalidOperationException("Path can't be a root directory.")); var typeName = GetType().Name; Logger.LogInformation("Opening {StreamType} Live stream from {Url}", typeName, url); @@ -94,14 +92,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts // OpenedMediaSource.SupportsDirectPlay = false; // OpenedMediaSource.SupportsDirectStream = true; // OpenedMediaSource.SupportsTranscoding = true; - await taskCompletionSource.Task.ConfigureAwait(false); - if (taskCompletionSource.Task.Exception != null) - { - // Error happened while opening the stream so raise the exception again to inform the caller - throw taskCompletionSource.Task.Exception; - } - - if (!taskCompletionSource.Task.Result) + var res = await taskCompletionSource.Task.ConfigureAwait(false); + if (!res) { Logger.LogWarning("Zero bytes copied from stream {StreamType} to {FilePath} but no exception raised", GetType().Name, TempFilePath); throw new EndOfStreamException(string.Format(CultureInfo.InvariantCulture, "Zero bytes copied from stream {0}", GetType().Name)); diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs index 1471f5a24..2cfd36d00 100644 --- a/Jellyfin.Api/Helpers/RequestHelpers.cs +++ b/Jellyfin.Api/Helpers/RequestHelpers.cs @@ -104,7 +104,7 @@ namespace Jellyfin.Api.Helpers } internal static QueryResult<BaseItemDto> CreateQueryResult( - QueryResult<(BaseItem, ItemCounts)> result, + QueryResult<(BaseItem Item, ItemCounts ItemCounts)> result, DtoOptions dtoOptions, IDtoService dtoService, bool includeItemTypes, diff --git a/jellyfin.ruleset b/jellyfin.ruleset index 52bedabee..dea1a748b 100644 --- a/jellyfin.ruleset +++ b/jellyfin.ruleset @@ -13,6 +13,8 @@ <Rule Id="SA1210" Action="Error" /> <!-- error on SA1316: Tuple element names should use correct casing --> <Rule Id="SA1316" Action="Error" /> + <!-- error on SA1414: Tuple types in signatures should have element names --> + <Rule Id="SA1414" Action="Error" /> <!-- error on SA1518: File is required to end with a single newline character --> <Rule Id="SA1518" Action="Error" /> <!-- error on SA1629: Documentation text should end with a period --> @@ -73,6 +75,8 @@ <Rule Id="CA1843" Action="Error" /> <!-- error on CA1845: Use span-based 'string.Concat' --> <Rule Id="CA1845" Action="Error" /> + <!-- error on CA1849: Call async methods when in an async method --> + <Rule Id="CA1849" Action="Error" /> <!-- error on CA2016: Forward the CancellationToken parameter to methods that take one or pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token --> <Rule Id="CA2016" Action="Error" /> |
