linting and warnings

This commit is contained in:
Andy Pack 2023-01-06 21:11:29 +00:00
parent 57b80c9902
commit faa1c55030
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7
8 changed files with 19 additions and 27 deletions

View File

@ -9,7 +9,6 @@ using Selector.Extensions;
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;
namespace Selector.CLI
{
@ -52,11 +51,11 @@ namespace Selector.CLI
private static void SetupExceptionHandling(ILogger logger, IHostEnvironment env)
{
AppDomain.CurrentDomain.UnhandledException += (obj, e) =>
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
if(e.ExceptionObject is Exception ex)
{
logger.LogError(ex as Exception, "Unhandled exception thrown");
logger.LogError(ex, "Unhandled exception thrown");
if (env.IsDevelopment())
{
@ -152,11 +151,11 @@ namespace Selector.CLI
.AddNLog(context.Configuration);
}
static IHostBuilder CreateHostBuilder(string[] args, Action<HostBuilderContext, IServiceCollection> BuildServices, Action<HostBuilderContext, ILoggingBuilder> BuildLogs)
static IHostBuilder CreateHostBuilder(string[] args, Action<HostBuilderContext, IServiceCollection> buildServices, Action<HostBuilderContext, ILoggingBuilder> buildLogs)
=> Host.CreateDefaultBuilder(args)
.UseWindowsService()
.UseSystemd()
.ConfigureServices((context, services) => BuildServices(context, services))
.ConfigureLogging((context, builder) => BuildLogs(context, builder));
.ConfigureServices((context, services) => buildServices(context, services))
.ConfigureLogging((context, builder) => buildLogs(context, builder));
}
}

View File

@ -33,7 +33,7 @@ namespace Selector.CLI
Console.WriteLine("Migrate database? (y/n) ");
var input = Console.ReadLine();
if (input.Trim().Equals("y", StringComparison.OrdinalIgnoreCase))
if (input?.Trim().Equals("y", StringComparison.OrdinalIgnoreCase) ?? false)
{
logger.LogInformation("Migrating database");
db.Database.Migrate();

View File

@ -2,7 +2,6 @@
using Microsoft.Extensions.Logging;
using Selector.CLI.Extensions;
using Selector.Model;
using Selector.Model.Extensions;
using System;
using System.CommandLine;
using System.CommandLine.Invocation;

View File

@ -49,9 +49,9 @@ namespace Selector.CLI.Consumer
{
Logger.LogWarning("Failed to update database, likely a duplicate Spotify URI");
}
catch (Exception e)
catch (Exception ex)
{
Logger.LogError(e, "Error occured during callback");
Logger.LogError(ex, "Error occured during callback");
}
}, CancelToken);
}
@ -104,7 +104,7 @@ namespace Selector.CLI.Consumer
}
else if (e.Current.Item is FullEpisode episode)
{
Logger.LogDebug("Ignoring podcast episdoe [{episode}]", episode.DisplayString());
Logger.LogDebug("Ignoring podcast episode [{episode}]", episode.DisplayString());
}
else if (e.Current.Item is null)
{
@ -118,7 +118,7 @@ namespace Selector.CLI.Consumer
public void Subscribe(IWatcher watch = null)
{
var watcher = watch ?? Watcher ?? throw new ArgumentNullException("No watcher provided");
var watcher = watch ?? Watcher ?? throw new ArgumentNullException(nameof(watch));
if (watcher is IPlayerWatcher watcherCast)
{
@ -132,7 +132,7 @@ namespace Selector.CLI.Consumer
public void Unsubscribe(IWatcher watch = null)
{
var watcher = watch ?? Watcher ?? throw new ArgumentNullException("No watcher provided");
var watcher = watch ?? Watcher ?? throw new ArgumentNullException(nameof(watch));
if (watcher is IPlayerWatcher watcherCast)
{

View File

@ -8,10 +8,6 @@ using Selector.Extensions;
using Selector.Model;
using Selector.Model.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Selector.CLI.Extensions
{

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -21,17 +20,17 @@ namespace Selector.CLI.Extensions
catch (APIUnauthorizedException e)
{
logger?.LogDebug("Unauthorised error: [{message}] (should be refreshed and retried?)", e.Message);
throw e;
throw;
}
catch (APITooManyRequestsException e)
{
logger?.LogDebug("Too many requests error: [{message}]", e.Message);
throw e;
throw;
}
catch (APIException e)
{
logger?.LogDebug("API error: [{message}]", e.Message);
throw e;
throw;
}
}
}

View File

@ -69,7 +69,7 @@ namespace Selector
var requests = tracksToPull.Select(a => new ScrobbleTrackMapping(
searchClient,
loggerFactory.CreateLogger<ScrobbleTrackMapping>() ?? NullLogger<ScrobbleTrackMapping>.Instance,
loggerFactory.CreateLogger<ScrobbleTrackMapping>(),
a.TrackName, a.ArtistName)
).ToArray();

View File

@ -1,5 +1,4 @@
using IF.Lastfm.Core.Objects;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@ -8,8 +7,8 @@ namespace Selector
{
public static class ListenMatcher
{
public static bool MatchTime(IListen nativeScrobble, LastTrack serviceScrobble)
=> serviceScrobble.TimePlayed.Equals(nativeScrobble);
// public static bool MatchTime(IListen nativeScrobble, LastTrack serviceScrobble)
// => serviceScrobble.TimePlayed.Equals(nativeScrobble);
public static bool MatchTime(IListen nativeScrobble, IListen serviceScrobble)
=> serviceScrobble.Timestamp.Equals(nativeScrobble.Timestamp);