Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
<!-- Enforce Minimum code analysis rules -->
<AnalysisMode>Minimum</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!-- Enable code style analysis at the latest level -->
<AnalysisLevelStyle>latest</AnalysisLevelStyle>
<!-- Enable documentation file generation to enable IDE0005 (unused usings) detection -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<!-- Suppress VSTHRD analyzers that are too strict for this project -->
<!-- These supressions should be addressed and removed. See https://github.com/jodavis/AdaptiveRemote/issues/41 -->
<NoWarn>$(NoWarn);VSTHRD011;VSTHRD002;VSTHRD003;VSTHRD103;VSTHRD105;VSTHRD110;VSTHRD200;MSTEST0045</NoWarn>
<!-- Suppress documentation warnings - we enable GenerateDocumentationFile only to get IDE0005 -->
<NoWarn>$(NoWarn);VSTHRD011;VSTHRD002;VSTHRD003;VSTHRD103;VSTHRD105;VSTHRD110;VSTHRD200;MSTEST0045;CS1591;CS1573;CS1584;CS1658</NoWarn>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class LoggingHostBuilderExtensions
internal static IHostBuilder OptionallyAddFileLogging(this IHostBuilder builder)
=> builder.ConfigureLogging((context, logging) =>
{
LoggingSettings settings = context.Configuration.GetSection(SettingsKeys.Logging).Get<LoggingSettings>()
LoggingSettings settings = context.Configuration.GetSection(SettingsKeys.Logging).Get<LoggingSettings>()
?? new LoggingSettings();
if (settings.FilePath is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace AdaptiveRemote.Configuration;

internal static class TestingHostBuilderExtensions
{
private const string ControlPortSettingKey = $"{SettingsKeys.Testing}:{nameof(TestingSettings.ControlPort)}";

/// <summary>
/// Optionally adds test control services for E2E testing.
/// The test control endpoint is only added when --test:ControlPort is provided.
Expand All @@ -15,8 +17,8 @@ internal static IHostBuilder OptionallyAddTestHookEndpoint(this IHostBuilder bui
=> builder.ConfigureServices((context, services) =>
{
// Only add the service if test:ControlPort is configured
int? controlPort = context.Configuration.GetValue<int?>($"{SettingsKeys.Testing}:{nameof(TestingSettings.ControlPort)}");
int? controlPort = context.Configuration.GetValue<int?>(ControlPortSettingKey);

if (controlPort.HasValue)
{
services.Configure<TestingSettings>(context.Configuration.GetSection(SettingsKeys.Testing));
Expand Down
2 changes: 1 addition & 1 deletion src/AdaptiveRemote.App/Models/RemoteLayoutElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public RemoteLayoutElement(string id, string? placement = null)
CSSID = id;
}

public override abstract string ToString();
public abstract override string ToString();
}
3 changes: 1 addition & 2 deletions src/AdaptiveRemote.App/Services/Broadlink/AesWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography;

namespace AdaptiveRemote.Services.Broadlink;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BroadlinkCommandService(
_connectionFactory = connectionFactory;
}

public async override Task InitializeAsync(ILifecycleActivity activity, CancellationToken cancellationToken)
public override async Task InitializeAsync(ILifecycleActivity activity, CancellationToken cancellationToken)
{
activity.Description = Phrases.Startup_ConnectingToBroadlink;

Expand Down
2 changes: 1 addition & 1 deletion src/AdaptiveRemote.App/Services/Broadlink/DeviceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

internal class DeviceLocator : IDeviceLocator
{
private IUdpService _udpService;
private readonly IUdpService _udpService;

public DeviceLocator(IUdpService udpService)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AdaptiveRemote.App/Services/Broadlink/IEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IEncryption
/// <returns>Decrypted result</returns>
Memory<byte> Decrypt(Memory<byte> memory);

public interface Factory
interface Factory
{
/// <summary>
/// Return an encryption model using the default Broadlink key
Expand Down
2 changes: 1 addition & 1 deletion src/AdaptiveRemote.App/Services/Broadlink/SocketWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AdaptiveRemote.Services.Broadlink;
[ExcludeFromCodeCoverage(Justification = "Simple wrapper around System.Net.Socket")]
internal class SocketWrapper : ISocket
{
private Socket _socket;
private readonly Socket _socket;

private SocketWrapper(Socket socket)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.CompilerServices;
using AdaptiveRemote.Logging;
using AdaptiveRemote.Logging;
using AdaptiveRemote.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace AdaptiveRemote.Services.Conversation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.IO;
using AdaptiveRemote.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand Down
4 changes: 1 addition & 3 deletions src/AdaptiveRemote.App/Services/IFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.IO;

namespace AdaptiveRemote.Services;
namespace AdaptiveRemote.Services;

/// <summary>
/// Abstraction for the file system
Expand Down
4 changes: 1 addition & 3 deletions src/AdaptiveRemote.App/Services/IFileSystemExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.IO;

namespace AdaptiveRemote.Services;
namespace AdaptiveRemote.Services;

internal static class IFileSystemExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace AdaptiveRemote.Services.Lifecycle;
internal class LifecycleViewController : ILifecycleViewController
{
private readonly List<Activity> _activities;
private readonly object _lock = new();

public LifecycleViewController(LifecycleView viewModel)
{
Expand Down Expand Up @@ -54,7 +55,6 @@ private static string DescriptionFor(LifecyclePhase phase)
_ => string.Empty,
};

private object _lock = new();
private void UpdateTaskName()
{
lock (_lock)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.IO;
using System.Text.RegularExpressions;
using AdaptiveRemote.Logging;
using Microsoft.Extensions.Logging;
Expand All @@ -15,19 +14,19 @@ internal class PersistSettings : IPersistSettings
private const string ValueKey = "value";
private const string ValuePattern = @"[^\\r\\n]*";

private static Regex KeyRegex = new($"^{NamePattern}$", RegexOptions.Singleline);
private static Regex ValueRegex = new($"^{ValuePattern}$", RegexOptions.Singleline);
private static Regex LineRegex = new($"^(?<{NameKey}>{NamePattern}){Separator}(?<{ValueKey}>{ValuePattern})$");
private static readonly Regex KeyRegex = new($"^{NamePattern}$", RegexOptions.Singleline);
private static readonly Regex ValueRegex = new($"^{ValuePattern}$", RegexOptions.Singleline);
private static readonly Regex LineRegex = new($"^(?<{NameKey}>{NamePattern}){Separator}(?<{ValueKey}>{ValuePattern})$");

private readonly IFileSystem _fileSystem;
private readonly string _filePath;
private readonly ILogger<PersistSettings> _logger;

private readonly Lazy<Task<ConcurrentDictionary<string, string>>> _lazyValues;
private readonly object _lockObject = new();

private bool _needsSave = false;
private bool _isSaving = false;
private object _lockObject = new();

public PersistSettings(IFileSystem fileSystem, IOptions<ProgrammaticSettings> settings, ILogger<PersistSettings> logger)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.IO;

namespace AdaptiveRemote.Services.SystemWrappers;
namespace AdaptiveRemote.Services.SystemWrappers;

internal class SystemIOWrapper : IFileSystem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using StreamJsonRpc;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
Expand All @@ -19,20 +18,16 @@ internal class TestEndpointService : BackgroundService, ITestEndpoint
{
private readonly TestingSettings _settings;
private readonly IApplicationScopeProvider _scopeProvider;
private readonly ILoggerFactory _loggerFactory;
private readonly ILogger<TestEndpointService> _logger;
private readonly ConcurrentDictionary<string, ILogger> _loggers = new();
private TcpListener? _listener;

public TestEndpointService(
IOptions<TestingSettings> settings,
IApplicationScopeProvider scopeProvider,
ILoggerFactory loggerFactory,
ILogger<TestEndpointService> logger)
{
_settings = settings.Value;
_scopeProvider = scopeProvider;
_loggerFactory = loggerFactory;
_logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Net;
using System.Net;
using AdaptiveRemote.Logging;
using I8Beef.TiVo;
using I8Beef.TiVo.Commands;
Expand Down
5 changes: 1 addition & 4 deletions src/AdaptiveRemote/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System.Windows;
using AdaptiveRemote.Services.Lifecycle;
using AdaptiveRemote.Services.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Web.WebView2.Core;

namespace AdaptiveRemote;

Expand All @@ -15,7 +12,7 @@ protected override void OnStartup(StartupEventArgs e)
{
WpfAcceleratedServices accelerator = CreateAcceleratedServices(e.Args);
accelerator.ViewModel.ShutdownCommand = new ActionCommand(Shutdown);

accelerator.MainWindow.Show();

IHostBuilder hostBuilder = Host.CreateDefaultBuilder(e.Args)
Expand Down
1 change: 0 additions & 1 deletion src/AdaptiveRemote/AppHostConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AdaptiveRemote.Services.Conversation;
using AdaptiveRemote.Services.Lifecycle;
using AdaptiveRemote.Services.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand Down
4 changes: 2 additions & 2 deletions src/AdaptiveRemote/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel;
using System.Windows;
using System.Windows;

namespace AdaptiveRemote;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AdaptiveRemote.Services.Testing;
using Microsoft.AspNetCore.Components.WebView.Wpf;
using Microsoft.Extensions.Configuration;

namespace AdaptiveRemote.Services.Lifecycle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public BlazorWindowServicesSetter(MainWindow mainWindow, IServiceProvider servic

public async Task StartAsync(CancellationToken cancellationToken)
=> await _browser.Dispatcher.InvokeAsync(() => _browser.Services = _services);

public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using AdaptiveRemote.Services.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace AdaptiveRemote.Services.Lifecycle;

public class WpfAcceleratedServices : AcceleratedServices
{
private IBrowserDebuggerAccess? _browserDebugger = null;
private readonly IBrowserDebuggerAccess? _browserDebugger;

public WpfAcceleratedServices(string[] args)
: base(args)
Expand All @@ -28,7 +27,7 @@ public WpfAcceleratedServices(string[] args)

public MainWindow MainWindow { get; }

protected override void AddPrecreatedServices(IServiceCollection services)
protected override void AddPrecreatedServices(IServiceCollection services)
{
base.AddPrecreatedServices(services);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CommandServiceBaseTests
private ILifecycleActivity InitializeActivity => MockInitializeActivity.Object;
private ILifecycleActivity CleanupActivity => MockCleanupActivity.Object;

private LayoutGroup RemoteDefinition = new LayoutGroup("ROOT",
private readonly LayoutGroup RemoteDefinition = new LayoutGroup("ROOT",
[
new MockCommand("Mock1") { IsEnabled = true, IsActive = true },
new OtherCommand("Other1") { IsEnabled = true, IsActive = true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void ApplicationLifecycle_StartAsync_ErrorDuringConstructor_SetsFatalErro
.Verifiable(Times.Once);

Expect_SetFatalErrorOn(MockLifecycleViewController, expectedError1);

// Act
Task startTask = sut.StartAsync(default);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using AdaptiveRemote.Logging;
using AdaptiveRemote.Models;
using AdaptiveRemote.TestUtilities;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;

namespace AdaptiveRemote.Services.Lifecycle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public void ScopedBackgroundProcess_InitializeAsync_OnErrorDuringInitialize_Retu
// Arrange
Exception expectedException = new DataMisalignedException();

// No error logged here because lifecycle should report it
TestBackgroundProcess sut = CreateSut()
.Expect_LogMessages(
Expect_Starting
// No error logged here because lifecycle should report it
);

sut.ExecuteCompletionSource.SetException(expectedException);
Expand Down
2 changes: 1 addition & 1 deletion test/AdaptiveRemote.App.Tests/TestUtilities/MockLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ internal class MockLogger<LoggerType1, LoggerType2> : MockLogger<LoggerType1>, I
internal class MockLogger<LoggerType> : ILogger<LoggerType>
{
private readonly List<string> _messages = new();
private readonly object _lock = new();
private Exception? _assertException = null;
private object _lock = new();

public IEnumerable<string> Messages => _messages;
public TestContext? OutputWriter { get; set; }
Expand Down
8 changes: 3 additions & 5 deletions test/AdaptiveRemote.App.Tests/TestUtilities/TaskAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ public AndConstraint<TaskAssertions<TResult>> HaveResult(TResult expectedResult,
.TaskShouldBeCompleted()
.Given(task => ((Task<TResult>)task).Result)
.ForCondition(CheckEquivalency)
//.ForCondition(result => (result is null) == (expectedResult is null))
//.FailWith("found {context}.Result=<null>")
//.Then
//.ForCondition(result => result!.Equals(expectedResult))
.FailWith("found {context}.Result={0}", result => result);
.FailWith(
"found {context}.Result={0}",
result => result);
});

return Continuation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task InvokeCommandAsync(string commandName, CancellationToken cance
// Find the Exit command by walking the remote tree
Command command = FindCommandByName(_remoteDefinitionService.RemoteRoot, commandName)
?? throw new InvalidOperationException($"{commandName} command not found in remote definition service");

if (command.ExecuteAsync is null)
{
throw new InvalidOperationException($"{commandName} command does not have an ExecuteAsync delegate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BlazorWebViewUITestService : PlaywrightUITestService
private static readonly TimeSpan InitializePlaywrightTimeout = TimeSpan.FromSeconds(30);

public BlazorWebViewUITestService(IBrowserDebuggerAccess browserDebugger, ILogger<BlazorWebViewUITestService> logger)
: base (new BrowserFromPortProvider(browserDebugger, logger))
: base(new BrowserFromPortProvider(browserDebugger, logger))
{
}

Expand Down Expand Up @@ -85,7 +85,9 @@ public void Dispose()
{
_ = _browser.Value.CloseAsync().ConfigureAwait(false);
}
catch { }
catch
{
}
}

if (_playwright.IsValueCreated)
Expand Down
Loading
Loading