From 05836c8cd31ceaa3b84c2fa7dd04dfdbc9d7cc3c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 7 Jan 2022 11:48:59 +0100 Subject: [PATCH] Fix warning SA1414 and CA1849 --- Emby.Dlna/ContentDirectory/ControlHandler.cs | 6 +-- Emby.Dlna/PlayTo/Device.cs | 6 +-- Emby.Dlna/Service/BaseControlHandler.cs | 47 +++++++++---------- .../TunerHosts/HdHomerun/HdHomerunManager.cs | 4 +- .../LiveTv/TunerHosts/SharedHttpStream.cs | 14 ++---- Jellyfin.Api/Helpers/RequestHelpers.cs | 2 +- jellyfin.ruleset | 4 ++ 7 files changed, 37 insertions(+), 46 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 /// /// A . /// The . - private static QueryResult ToResult(QueryResult<(BaseItem, ItemCounts)> result) + private static QueryResult 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 @@ -1213,7 +1213,7 @@ namespace Emby.Dlna.ContentDirectory /// /// The . /// True if pre-sorted. - 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 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); - } + if (reader.IsEmptyElement) + { + await reader.ReadAsync().ConfigureAwait(false); + continue; + } - break; - } - - default: - { - await reader.SkipAsync().ConfigureAwait(false); - break; - } + 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 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 @@ + + @@ -73,6 +75,8 @@ + +