Skip to content

Commit

Permalink
FxCop -> Net Analyzers (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 committed Mar 13, 2021
1 parent 260b48e commit a8ed753
Show file tree
Hide file tree
Showing 70 changed files with 151 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Emby.Dlna/DlnaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DlnaManager : IDlnaManager
private readonly ILogger<DlnaManager> _logger;
private readonly IServerApplicationHost _appHost;
private static readonly Assembly _assembly = typeof(DlnaManager).Assembly;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

private readonly Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>> _profiles = new Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>>(StringComparer.Ordinal);

Expand Down
5 changes: 1 addition & 4 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Emby.Dlna;
Expand Down Expand Up @@ -51,7 +49,6 @@
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
using MediaBrowser.Common.Json;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates;
Expand Down Expand Up @@ -470,7 +467,7 @@ public IReadOnlyCollection<T> GetExports<T>(bool manageLifetime = true)
}

/// <inheritdoc />
public IReadOnlyCollection<T> GetExports<T>(CreationDelegate defaultFunc, bool manageLifetime = true)
public IReadOnlyCollection<T> GetExports<T>(CreationDelegateFactory defaultFunc, bool manageLifetime = true)
{
// Convert to list so this isn't executed for each iteration
var parts = GetExportTypes<T>()
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ChannelManager : IChannelManager
private readonly IProviderManager _providerManager;
private readonly IMemoryCache _memoryCache;
private readonly SemaphoreSlim _resourcePool = new SemaphoreSlim(1, 1);
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

/// <summary>
/// Initializes a new instance of the <see cref="ChannelManager"/> class.
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Data/SqliteItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public SqliteItemRepository(
_imageProcessor = imageProcessor;

_typeMapper = new TypeMapper();
_jsonOptions = JsonDefaults.GetOptions();
_jsonOptions = JsonDefaults.Options;

DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public WebSocketConnection(
RemoteEndPoint = remoteEndPoint;
QueryString = query;

_jsonOptions = JsonDefaults.GetOptions();
_jsonOptions = JsonDefaults.Options;
LastActivityDate = DateTime.Now;
}

Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/LiveStreamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LiveStreamHelper
private readonly IMediaEncoder _mediaEncoder;
private readonly ILogger _logger;
private readonly IApplicationPaths _appPaths;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

public LiveStreamHelper(IMediaEncoder mediaEncoder, ILogger logger, IApplicationPaths appPaths)
{
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class MediaSourceManager : IMediaSourceManager, IDisposable

private readonly ConcurrentDictionary<string, ILiveStream> _openStreams = new ConcurrentDictionary<string, ILiveStream>(StringComparer.OrdinalIgnoreCase);
private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1);
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

private IMediaSourceProvider[] _providers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class EncodedRecorder : IRecorder
private readonly IServerApplicationPaths _appPaths;
private readonly TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>();
private readonly IServerConfigurationManager _serverConfigurationManager;
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
private bool _hasExited;
private Stream _logFileStream;
private string _targetPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ItemDataProvider<T>
{
private readonly string _dataPath;
private readonly object _fileDataLock = new object();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
private T[] _items;

public ItemDataProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SchedulesDirect : IListingsProvider
private readonly ICryptoProvider _cryptoProvider;

private readonly ConcurrentDictionary<string, NameValuePair> _tokens = new ConcurrentDictionary<string, NameValuePair>();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
private DateTime _lastErrorResponse;

public SchedulesDirect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public HdHomerunHost(
_networkManager = networkManager;
_streamHelper = streamHelper;

_jsonOptions = JsonDefaults.GetOptions();
_jsonOptions = JsonDefaults.Options;
}

public string Name => "HD Homerun";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LocalizationManager : ILocalizationManager

private List<CultureDto> _cultures;

private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

/// <summary>
/// Initializes a new instance of the <see cref="LocalizationManager" /> class.
Expand Down
4 changes: 2 additions & 2 deletions Emby.Server.Implementations/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public PluginManager(
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_pluginsPath = pluginsPath;
_appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion));
_jsonOptions = new JsonSerializerOptions(JsonDefaults.GetOptions())
_jsonOptions = new JsonSerializerOptions(JsonDefaults.Options)
{
WriteIndented = true
};
Expand Down Expand Up @@ -678,7 +678,7 @@ private IEnumerable<LocalPlugin> DiscoverPlugins()
var entry = versions[x];
if (!string.Equals(lastName, entry.Name, StringComparison.OrdinalIgnoreCase))
{
entry.DllFiles.AddRange(Directory.EnumerateFiles(entry.Path, "*.dll", SearchOption.AllDirectories));
entry.DllFiles = Directory.GetFiles(entry.Path, "*.dll", SearchOption.AllDirectories);
if (entry.IsEnabledAndSupported)
{
lastName = entry.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class ScheduledTaskWorker : IScheduledTaskWorker
/// <summary>
/// The options for the json Serializer.
/// </summary>
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;

/// <summary>
/// Initializes a new instance of the <see cref="ScheduledTaskWorker" /> class.
Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/Updates/InstallationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public InstallationManager(
_httpClientFactory = httpClientFactory;
_config = config;
_zipClient = zipClient;
_jsonSerializerOptions = JsonDefaults.GetOptions();
_jsonSerializerOptions = JsonDefaults.Options;
_pluginManager = pluginManager;
}

Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Api/Controllers/ConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ConfigurationController : BaseJellyfinApiController
private readonly IServerConfigurationManager _configurationManager;
private readonly IMediaEncoder _mediaEncoder;

private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.GetOptions();
private readonly JsonSerializerOptions _serializerOptions = JsonDefaults.Options;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationController"/> class.
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Api/Controllers/PluginsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public PluginsController(
{
_installationManager = installationManager;
_pluginManager = pluginManager;
_serializerOptions = JsonDefaults.GetOptions();
_serializerOptions = JsonDefaults.Options;
_config = config;
}

Expand Down
60 changes: 7 additions & 53 deletions Jellyfin.Data/DayOfWeekHelper.cs
Original file line number Diff line number Diff line change
@@ -1,67 +1,21 @@
#pragma warning disable CS1591

using System;
using System.Collections.Generic;
using Jellyfin.Data.Enums;

namespace Jellyfin.Data
{
public static class DayOfWeekHelper
{
public static List<DayOfWeek> GetDaysOfWeek(DynamicDayOfWeek day)
public static DayOfWeek[] GetDaysOfWeek(DynamicDayOfWeek day)
{
var days = new List<DayOfWeek>(7);

if (day == DynamicDayOfWeek.Sunday
|| day == DynamicDayOfWeek.Weekend
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Sunday);
}

if (day == DynamicDayOfWeek.Monday
|| day == DynamicDayOfWeek.Weekday
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Monday);
}

if (day == DynamicDayOfWeek.Tuesday
|| day == DynamicDayOfWeek.Weekday
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Tuesday);
}

if (day == DynamicDayOfWeek.Wednesday
|| day == DynamicDayOfWeek.Weekday
|| day == DynamicDayOfWeek.Everyday)
return day switch
{
days.Add(DayOfWeek.Wednesday);
}

if (day == DynamicDayOfWeek.Thursday
|| day == DynamicDayOfWeek.Weekday
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Thursday);
}

if (day == DynamicDayOfWeek.Friday
|| day == DynamicDayOfWeek.Weekday
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Friday);
}

if (day == DynamicDayOfWeek.Saturday
|| day == DynamicDayOfWeek.Weekend
|| day == DynamicDayOfWeek.Everyday)
{
days.Add(DayOfWeek.Saturday);
}

return days;
DynamicDayOfWeek.Everyday => new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday },
DynamicDayOfWeek.Weekday => new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday },
DynamicDayOfWeek.Weekend => new[] { DayOfWeek.Saturday, DayOfWeek.Sunday },
_ => new[] { (DayOfWeek)day }
};
}
}
}
1 change: 1 addition & 0 deletions Jellyfin.Data/Entities/Libraries/Collection.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
#pragma warning disable CA2227

using System.Collections.Generic;
Expand Down
2 changes: 2 additions & 0 deletions Jellyfin.Data/Entities/Libraries/MediaFileStream.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
Expand Down
2 changes: 2 additions & 0 deletions Jellyfin.Data/Entities/Permission.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Jellyfin.Data.Enums;
Expand Down
6 changes: 2 additions & 4 deletions Jellyfin.Data/Jellyfin.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -24,10 +26,6 @@
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
11 changes: 7 additions & 4 deletions Jellyfin.Drawing.Skia/Jellyfin.Drawing.Skia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,15 +32,16 @@
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
</ItemGroup>

<ItemGroup>
<!-- Needed for https://github.com/dotnet/roslyn-analyzers/issues/4382 which is in the SDK yet -->
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3" PrivateAssets="All" />
</ItemGroup>

<!-- Code analysers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="SerilogAnalyzer" Version="0.15.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

</Project>
13 changes: 4 additions & 9 deletions Jellyfin.Drawing.Skia/SkiaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ private static SKEncodedOrigin GetSKEncodedOrigin(ImageOrientation? orientation)

if (requiresTransparencyHack || forceCleanBitmap)
{
using var codec = SKCodec.Create(NormalizePath(path));
if (codec == null)
using SKCodec codec = SKCodec.Create(NormalizePath(path), out SKCodecResult res);
if (res != SKCodecResult.Success)
{
origin = GetSKEncodedOrigin(orientation);
return null;
Expand Down Expand Up @@ -345,11 +345,6 @@ private static SKEncodedOrigin GetSKEncodedOrigin(ImageOrientation? orientation)

private SKBitmap OrientImage(SKBitmap bitmap, SKEncodedOrigin origin)
{
if (origin == SKEncodedOrigin.Default)
{
return bitmap;
}

var needsFlip = origin == SKEncodedOrigin.LeftBottom
|| origin == SKEncodedOrigin.LeftTop
|| origin == SKEncodedOrigin.RightBottom
Expand Down Expand Up @@ -447,7 +442,7 @@ internal static SKImage ResizeImage(SKBitmap source, SKImageInfo targetInfo, boo
}

/// <inheritdoc/>
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, ImageOrientation? orientation, int quality, ImageProcessingOptions options, ImageFormat outputFormat)
{
if (inputPath.Length == 0)
{
Expand All @@ -459,7 +454,7 @@ public string EncodeImage(string inputPath, DateTime dateModified, string output
throw new ArgumentException("String can't be empty.", nameof(outputPath));
}

var skiaOutputFormat = GetImageFormat(selectedOutputFormat);
var skiaOutputFormat = GetImageFormat(outputFormat);

var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor);
var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer);
Expand Down
6 changes: 2 additions & 4 deletions Jellyfin.Networking/Jellyfin.Networking.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,10 +20,6 @@
<PackageReference Include="SmartAnalyzers.MultithreadingAnalyzer" Version="1.1.31" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
Expand Down
Loading

0 comments on commit a8ed753

Please sign in to comment.