The Free Software Media System - Server Backend & API
Fix warning SA1414 and CA1849
Bond_00905836c8cd31c
diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.csindex 010f90c624..0cd1a0daf7 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.csindex 34fb8fddd6..7815e92937 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.PlayToreturn 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.csindex 780aad9c18..7bec2eb728 100644--- a/Emby.Dlna/Service/BaseControlHandler.cs+++ b/Emby.Dlna/Service/BaseControlHandler.cs@@ -47,7 +47,7 @@ namespace Emby.Dlna.Serviceprivate 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.ServiceLogger.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.ServicelocalName = 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.csindex f1a6ef3443..48d9e316de 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.csindex b1ce7b2b3c..ab4beb15b6 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 CS1591using System;@@ -51,7 +49,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHostsvar 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.csindex 1471f5a241..2cfd36d00e 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.rulesetindex 52bedabeec..dea1a748b6 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 oneor pass in 'CancellationToken.None' explicitly to indicate intentionally not propagating the token --><Rule Id="CA2016" Action="Error" />