From a709cbdc64de36a1ce989636a19344af61d9026d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 27 Jan 2019 12:03:43 +0100 Subject: Fix more analyzer warnings --- .../Services/RequestHelper.cs | 2 +- .../Services/ServiceExec.cs | 2 +- .../Services/ServiceMethod.cs | 2 +- .../Services/ServicePath.cs | 10 ++++---- .../Services/SwaggerService.cs | 28 +++++++--------------- 5 files changed, 16 insertions(+), 28 deletions(-) (limited to 'Emby.Server.Implementations/Services') diff --git a/Emby.Server.Implementations/Services/RequestHelper.cs b/Emby.Server.Implementations/Services/RequestHelper.cs index 24e9cbfa4..2563cac99 100644 --- a/Emby.Server.Implementations/Services/RequestHelper.cs +++ b/Emby.Server.Implementations/Services/RequestHelper.cs @@ -45,7 +45,7 @@ namespace Emby.Server.Implementations.Services { return contentType == null ? null - : contentType.Split(';')[0].ToLower().Trim(); + : contentType.Split(';')[0].ToLowerInvariant().Trim(); } } diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs index 45c918fa1..aa67a3601 100644 --- a/Emby.Server.Implementations/Services/ServiceExec.cs +++ b/Emby.Server.Implementations/Services/ServiceExec.cs @@ -98,7 +98,7 @@ namespace Emby.Server.Implementations.Services return Task.FromResult(response); } - var expectedMethodName = actionName.Substring(0, 1) + actionName.Substring(1).ToLower(); + var expectedMethodName = actionName.Substring(0, 1) + actionName.Substring(1).ToLowerInvariant(); throw new NotImplementedException(string.Format("Could not find method named {1}({0}) or Any({0}) on Service {2}", requestDto.GetType().GetMethodName(), expectedMethodName, serviceType.GetMethodName())); } diff --git a/Emby.Server.Implementations/Services/ServiceMethod.cs b/Emby.Server.Implementations/Services/ServiceMethod.cs index 7add72815..5018bf4a2 100644 --- a/Emby.Server.Implementations/Services/ServiceMethod.cs +++ b/Emby.Server.Implementations/Services/ServiceMethod.cs @@ -11,7 +11,7 @@ namespace Emby.Server.Implementations.Services public static string Key(Type serviceType, string method, string requestDtoName) { - return serviceType.FullName + " " + method.ToUpper() + " " + requestDtoName; + return serviceType.FullName + " " + method.ToUpperInvariant() + " " + requestDtoName; } } } diff --git a/Emby.Server.Implementations/Services/ServicePath.cs b/Emby.Server.Implementations/Services/ServicePath.cs index 7e1993b71..f575baca3 100644 --- a/Emby.Server.Implementations/Services/ServicePath.cs +++ b/Emby.Server.Implementations/Services/ServicePath.cs @@ -60,7 +60,7 @@ namespace Emby.Server.Implementations.Services public static string[] GetPathPartsForMatching(string pathInfo) { - return pathInfo.ToLower().Split(new[] { PathSeperatorChar }, StringSplitOptions.RemoveEmptyEntries); + return pathInfo.ToLowerInvariant().Split(new[] { PathSeperatorChar }, StringSplitOptions.RemoveEmptyEntries); } public static List GetFirstMatchHashKeys(string[] pathPartsForMatching) @@ -104,7 +104,7 @@ namespace Emby.Server.Implementations.Services this.Description = description; this.restPath = path; - this.Verbs = string.IsNullOrWhiteSpace(verbs) ? ServiceExecExtensions.AllVerbs : verbs.ToUpper().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); + this.Verbs = string.IsNullOrWhiteSpace(verbs) ? ServiceExecExtensions.AllVerbs : verbs.ToUpperInvariant().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); var componentsList = new List(); @@ -154,7 +154,7 @@ namespace Emby.Server.Implementations.Services } else { - this.literalsToMatch[i] = component.ToLower(); + this.literalsToMatch[i] = component.ToLowerInvariant(); if (firstLiteralMatch == null) { @@ -189,7 +189,7 @@ namespace Emby.Server.Implementations.Services foreach (var propertyInfo in GetSerializableProperties(RequestType)) { var propertyName = propertyInfo.Name; - propertyNamesMap.Add(propertyName.ToLower(), propertyName); + propertyNamesMap.Add(propertyName.ToLowerInvariant(), propertyName); } } @@ -483,7 +483,7 @@ namespace Emby.Server.Implementations.Services continue; } - if (!this.propertyNamesMap.TryGetValue(variableName.ToLower(), out var propertyNameOnRequest)) + if (!this.propertyNamesMap.TryGetValue(variableName.ToLowerInvariant(), out var propertyNameOnRequest)) { if (string.Equals("ignore", variableName, StringComparison.OrdinalIgnoreCase)) { diff --git a/Emby.Server.Implementations/Services/SwaggerService.cs b/Emby.Server.Implementations/Services/SwaggerService.cs index 9bceeabec..3e6970eef 100644 --- a/Emby.Server.Implementations/Services/SwaggerService.cs +++ b/Emby.Server.Implementations/Services/SwaggerService.cs @@ -216,40 +216,28 @@ namespace Emby.Server.Implementations.Services { var responses = new Dictionary { + { "200", new SwaggerResponse { description = "OK" } } }; - responses["200"] = new SwaggerResponse + var apiKeySecurity = new Dictionary { - description = "OK" + { "api_key", Array.Empty() } }; - var security = new List>(); - - var apiKeySecurity = new Dictionary(); - apiKeySecurity["api_key"] = Array.Empty(); - - security.Add(apiKeySecurity); - - result[verb.ToLower()] = new SwaggerMethod + result[verb.ToLowerInvariant()] = new SwaggerMethod { summary = info.Summary, description = info.Description, - produces = new[] - { - "application/json" - }, - consumes = new[] - { - "application/json" - }, + produces = new[] { "application/json" }, + consumes = new[] { "application/json" }, operationId = info.RequestType.Name, tags = Array.Empty(), - parameters = new SwaggerParam[] { }, + parameters = Array.Empty(), responses = responses, - security = security.ToArray() + security = new [] { apiKeySecurity } }; } -- cgit v1.2.3 From 70c85925af31ee341f87fced39a67ab7fb4eed77 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 6 Feb 2019 21:31:41 +0100 Subject: Move some arrays to generics --- Emby.Drawing/ImageProcessor.cs | 18 +++++++++--------- Emby.Drawing/NullImageEncoder.cs | 15 ++++++--------- Emby.Server.Implementations/IO/LibraryMonitor.cs | 8 ++++---- .../Library/Resolvers/PhotoResolver.cs | 7 ++++--- Emby.Server.Implementations/Services/ResponseHelper.cs | 2 +- Emby.Server.Implementations/Services/ServiceExec.cs | 2 -- Jellyfin.Drawing.Skia/SkiaEncoder.cs | 13 ++++++++----- MediaBrowser.Controller/Drawing/IImageEncoder.cs | 5 +++-- MediaBrowser.Controller/Drawing/IImageProcessor.cs | 6 +++--- 9 files changed, 38 insertions(+), 38 deletions(-) (limited to 'Emby.Server.Implementations/Services') diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 097b4c40b..1e4646227 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -83,8 +83,8 @@ namespace Emby.Drawing } } - public string[] SupportedInputFormats => - new string[] + public IReadOnlyCollection SupportedInputFormats => + new HashSet(StringComparer.OrdinalIgnoreCase) { "tiff", "tif", @@ -137,14 +137,14 @@ namespace Emby.Drawing } } - public ImageFormat[] GetSupportedImageOutputFormats() - { - return _imageEncoder.SupportedOutputFormats; - } + public IReadOnlyCollection GetSupportedImageOutputFormats() + => _imageEncoder.SupportedOutputFormats; + + private static readonly HashSet TransparentImageTypes + = new HashSet(StringComparer.OrdinalIgnoreCase) { ".png", ".webp", ".gif" }; - private static readonly string[] TransparentImageTypes = new string[] { ".png", ".webp", ".gif" }; public bool SupportsTransparency(string path) - => TransparentImageTypes.Contains(Path.GetExtension(path).ToLowerInvariant()); + => TransparentImageTypes.Contains(Path.GetExtension(path)); public async Task<(string path, string mimeType, DateTime dateModified)> ProcessImage(ImageProcessingOptions options) { @@ -472,7 +472,7 @@ namespace Emby.Drawing return (originalImagePath, dateModified); } - if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat, StringComparer.OrdinalIgnoreCase)) + if (!_imageEncoder.SupportedInputFormats.Contains(inputFormat)) { try { diff --git a/Emby.Drawing/NullImageEncoder.cs b/Emby.Drawing/NullImageEncoder.cs index 14f0424ac..fc4a5af9f 100644 --- a/Emby.Drawing/NullImageEncoder.cs +++ b/Emby.Drawing/NullImageEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using MediaBrowser.Controller.Drawing; using MediaBrowser.Model.Drawing; @@ -6,15 +7,11 @@ namespace Emby.Drawing { public class NullImageEncoder : IImageEncoder { - public string[] SupportedInputFormats => - new[] - { - "png", - "jpeg", - "jpg" - }; - - public ImageFormat[] SupportedOutputFormats => new[] { ImageFormat.Jpg, ImageFormat.Png }; + public IReadOnlyCollection SupportedInputFormats + => new HashSet(StringComparer.OrdinalIgnoreCase) { "png", "jpeg", "jpg" }; + + public IReadOnlyCollection SupportedOutputFormats + => new HashSet() { ImageFormat.Jpg, ImageFormat.Png }; public void CropWhiteSpace(string inputPath, string outputPath) { diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 11c684b12..607a4d333 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.IO /// /// Any file name ending in any of these will be ignored by the watchers /// - private readonly string[] _alwaysIgnoreFiles = new string[] + private readonly HashSet _alwaysIgnoreFiles = new HashSet(StringComparer.OrdinalIgnoreCase) { "small.jpg", "albumart.jpg", @@ -53,7 +53,7 @@ namespace Emby.Server.Implementations.IO ".actors" }; - private readonly string[] _alwaysIgnoreExtensions = new string[] + private readonly HashSet _alwaysIgnoreExtensions = new HashSet(StringComparer.OrdinalIgnoreCase) { // thumbs.db ".db", @@ -456,8 +456,8 @@ namespace Emby.Server.Implementations.IO var filename = Path.GetFileName(path); var monitorPath = !string.IsNullOrEmpty(filename) && - !_alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase) && - !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase) && + !_alwaysIgnoreFiles.Contains(filename) && + !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path)) && _alwaysIgnoreSubstrings.All(i => path.IndexOf(i, StringComparison.OrdinalIgnoreCase) == -1); // Ignore certain files diff --git a/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs index 9de766767..a3298c580 100644 --- a/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/PhotoResolver.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using MediaBrowser.Controller.Drawing; @@ -85,7 +86,7 @@ namespace Emby.Server.Implementations.Library.Resolvers return false; } - private static readonly string[] IgnoreFiles = + private static readonly HashSet IgnoreFiles = new HashSet(StringComparer.OrdinalIgnoreCase) { "folder", "thumb", @@ -102,7 +103,7 @@ namespace Emby.Server.Implementations.Library.Resolvers { var filename = Path.GetFileNameWithoutExtension(path) ?? string.Empty; - if (IgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase)) + if (IgnoreFiles.Contains(filename)) { return false; } @@ -112,7 +113,7 @@ namespace Emby.Server.Implementations.Library.Resolvers return false; } - return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.'), StringComparer.OrdinalIgnoreCase); + return imageProcessor.SupportedInputFormats.Contains((Path.GetExtension(path) ?? string.Empty).TrimStart('.')); } } diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs index 16de1a083..dc9975347 100644 --- a/Emby.Server.Implementations/Services/ResponseHelper.cs +++ b/Emby.Server.Implementations/Services/ResponseHelper.cs @@ -70,7 +70,7 @@ namespace Emby.Server.Implementations.Services response.ContentType = defaultContentType; } - if (new HashSet { "application/json", }.Contains(response.ContentType)) + if (response.ContentType == "application/json") { response.ContentType += "; charset=utf-8"; } diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs index aa67a3601..79f5c59e6 100644 --- a/Emby.Server.Implementations/Services/ServiceExec.cs +++ b/Emby.Server.Implementations/Services/ServiceExec.cs @@ -23,8 +23,6 @@ namespace Emby.Server.Implementations.Services "POLL", "SUBSCRIBE", "UNSUBSCRIBE" }; - public static HashSet AllVerbsSet = new HashSet(AllVerbs); - public static List GetActions(this Type serviceType) { var list = new List(); diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs index f1b886ec6..dc714ed18 100644 --- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs +++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -35,8 +36,8 @@ namespace Jellyfin.Drawing.Skia LogVersion(); } - public string[] SupportedInputFormats => - new[] + public IReadOnlyCollection SupportedInputFormats => + new HashSet(StringComparer.OrdinalIgnoreCase) { "jpeg", "jpg", @@ -62,7 +63,8 @@ namespace Jellyfin.Drawing.Skia "arw" }; - public ImageFormat[] SupportedOutputFormats => new[] { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; + public IReadOnlyCollection SupportedOutputFormats + => new HashSet() { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; private void LogVersion() { @@ -253,7 +255,8 @@ namespace Jellyfin.Drawing.Skia } } - private static string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" }; + private static readonly HashSet TransparentImageTypes + = new HashSet(StringComparer.OrdinalIgnoreCase) { ".png", ".gif", ".webp" }; internal static SKBitmap Decode(string path, bool forceCleanBitmap, IFileSystem fileSystem, ImageOrientation? orientation, out SKEncodedOrigin origin) { @@ -262,7 +265,7 @@ namespace Jellyfin.Drawing.Skia throw new FileNotFoundException("File not found", path); } - var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty); + var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path)); if (requiresTransparencyHack || forceCleanBitmap) { diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 5b8c9da6f..4eaecd0a0 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using MediaBrowser.Model.Drawing; namespace MediaBrowser.Controller.Drawing @@ -9,12 +10,12 @@ namespace MediaBrowser.Controller.Drawing /// Gets the supported input formats. /// /// The supported input formats. - string[] SupportedInputFormats { get; } + IReadOnlyCollection SupportedInputFormats { get; } /// /// Gets the supported output formats. /// /// The supported output formats. - ImageFormat[] SupportedOutputFormats { get; } + IReadOnlyCollection SupportedOutputFormats { get; } /// /// Encodes the image. diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 783182730..b713d50b1 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Drawing /// Gets the supported input formats. /// /// The supported input formats. - string[] SupportedInputFormats { get; } + IReadOnlyCollection SupportedInputFormats { get; } /// /// Gets the image enhancers. @@ -96,8 +96,8 @@ namespace MediaBrowser.Controller.Drawing /// /// Gets the supported image output formats. /// - /// ImageOutputFormat[]. - ImageFormat[] GetSupportedImageOutputFormats(); + /// IReadOnlyCollection{ImageOutput}. + IReadOnlyCollection GetSupportedImageOutputFormats(); /// /// Creates the image collage. -- cgit v1.2.3