fixup! fixup! Add initial Blazor Server project

recyclarr
Robert Dailey 4 years ago
parent 9816fe0b50
commit 985e8b7923

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Common.Extensions;
using Recyclarr.Code.Settings.Persisters;
using TrashLib.Config;
using TrashLib.Radarr.Config;
namespace Recyclarr.Code
{
public class ConfigurationProvider : IConfigurationProvider
{
public IServiceConfiguration ActiveConfiguration { get; set; }
}
public interface IConfigurationProvider<T>
where T : IServiceConfiguration
{
public T Active { get; }
public IReadOnlyCollection<T> Configs { get; }
}
internal sealed class RadarrConfigurationProvider : IConfigurationProvider<RadarrConfiguration>, IDisposable
{
public void Dispose()
{
}
private RadarrConfiguration? _active;
public RadarrConfigurationProvider(IRadarrConfigPersister configPersister)
{
Configs = configPersister.Load().AsReadOnly();
}
public IReadOnlyCollection<RadarrConfiguration> Configs { get; }
public RadarrConfiguration Active
{
get => _active ?? throw new NullReferenceException("Active configuration has not been set");
set
{
_active = value;
ActiveChanged?.Invoke();
}
}
public event Action? ActiveChanged;
}
}

@ -5,7 +5,7 @@ namespace Recyclarr.Code.Settings.Persisters
{ {
public interface IRadarrConfigPersister public interface IRadarrConfigPersister
{ {
IList<RadarrConfiguration> Load(); ICollection<RadarrConfiguration> Load();
void Save(IEnumerable<RadarrConfiguration> settings); void Save(IEnumerable<RadarrConfiguration> settings);
} }
} }

@ -14,7 +14,7 @@ namespace Recyclarr.Code.Settings.Persisters
private const string Filename = "radarr.json"; private const string Filename = "radarr.json";
public IList<RadarrConfiguration> Load() public ICollection<RadarrConfiguration> Load()
{ {
return _persister.LoadSettings<List<RadarrConfiguration>>(Filename); return _persister.LoadSettings<List<RadarrConfiguration>>(Filename);
} }

@ -0,0 +1,66 @@
@using TrashLib.Radarr.Config
@using Blazored.LocalStorage
@using Recyclarr.Code.Settings.Persisters
@using TrashLib.Config
<MudSelect @bind-Value="@SelectedConfig" Label="@Label" Class="mt-3 mt-sm-0">
@foreach (var instance in _configs)
{
<MudSelectItem Value="@instance">@instance.BaseUrl</MudSelectItem>
}
</MudSelect>
@code {
private IList<RadarrConfiguration> _configs = new List<RadarrConfiguration>();
private readonly Queue<Func<Task>> _afterRenderActions = new();
private RadarrConfiguration? _selectedConfig;
[Inject]
public ILocalStorageService LocalStorage { get; set; } = default!;
[Inject]
public IRadarrConfigPersister SettingsPersister { get; set; } = default!;
[Parameter]
public string Label { get; set; } = "Select Server";
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
_configs = SettingsPersister.Load();
_afterRenderActions.Enqueue(async () =>
{
var savedSelection = await LocalStorage.GetItemAsync<string>("selectedInstance");
var instanceToSelect = _configs.FirstOrDefault(c => c.BaseUrl == savedSelection);
_selectedConfig = instanceToSelect ?? _configs.FirstOrDefault();
UpdateSelectedCustomFormats();
});
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
while (_afterRenderActions.TryDequeue(out var action))
{
await action.Invoke();
StateHasChanged();
}
await base.OnAfterRenderAsync(firstRender);
}
private RadarrConfiguration? SelectedConfig
{
get => _selectedConfig;
set
{
_selectedConfig = value;
UpdateSelectedCustomFormats();
_afterRenderActions.Enqueue(async ()
=> await LocalStorage.SetItemAsync("selectedInstance", _selectedConfig?.BaseUrl));
}
}
}

@ -12,12 +12,7 @@
Refresh Refresh
</MudButton> </MudButton>
</div> </div>
<MudSelect @bind-Value="@SelectedConfig" Label="Select Radarr Server" Class="mt-3 mt-sm-0"> <ServerSelector />
@foreach (var instance in _configs)
{
<MudSelectItem Value="@instance">@instance.BaseUrl</MudSelectItem>
}
</MudSelect>
</div> </div>
@if (_selectedConfig == null) @if (_selectedConfig == null)

@ -15,36 +15,18 @@ namespace Recyclarr.Pages.Radarr.CustomFormats
[UsedImplicitly] [UsedImplicitly]
public partial class CustomFormats : IDisposable public partial class CustomFormats : IDisposable
{ {
private readonly Queue<Func<Task>> _afterRenderActions = new();
private CustomFormatChooser? _cfChooser; private CustomFormatChooser? _cfChooser;
private IList<RadarrConfiguration> _configs = new List<RadarrConfiguration>();
private HashSet<SelectableCustomFormat> _currentSelection = new(); private HashSet<SelectableCustomFormat> _currentSelection = new();
private RadarrConfiguration? _selectedConfig;
private RadarrConfiguration? SelectedConfig
{
get => _selectedConfig;
set
{
_selectedConfig = value;
UpdateSelectedCustomFormats();
_afterRenderActions.Enqueue(async ()
=> await LocalStorage.SetItemAsync("selectedInstance", _selectedConfig?.BaseUrl));
}
}
[CascadingParameter] [CascadingParameter]
public CustomFormatAccessLayout? CfAccessor { get; set; } public CustomFormatAccessLayout? CfAccessor { get; set; }
[Inject] // [Inject]
public IDialogService DialogService { get; set; } = default!; // public IDialogService DialogService { get; set; } = default!;
[Inject] [Inject]
public IRadarrConfigPersister SettingsPersister { get; set; } = default!; public IRadarrConfigPersister SettingsPersister { get; set; } = default!;
[Inject]
public ILocalStorageService LocalStorage { get; set; } = default!;
private bool? SelectAllCheckbox { get; set; } = false; private bool? SelectAllCheckbox { get; set; } = false;
private List<string> ChosenCustomFormatIds => _currentSelection.Select(cf => cf.Item.TrashIds.First()).ToList(); private List<string> ChosenCustomFormatIds => _currentSelection.Select(cf => cf.Item.TrashIds.First()).ToList();
private bool IsRefreshDisabled => CfAccessor is not {IsLoaded: true}; private bool IsRefreshDisabled => CfAccessor is not {IsLoaded: true};
@ -67,13 +49,13 @@ namespace Recyclarr.Pages.Radarr.CustomFormats
_configs = SettingsPersister.Load(); _configs = SettingsPersister.Load();
_afterRenderActions.Enqueue(async () => // _afterRenderActions.Enqueue(async () =>
{ // {
var savedSelection = await LocalStorage.GetItemAsync<string>("selectedInstance"); // var savedSelection = await LocalStorage.GetItemAsync<string>("selectedInstance");
var instanceToSelect = _configs.FirstOrDefault(c => c.BaseUrl == savedSelection); // var instanceToSelect = _configs.FirstOrDefault(c => c.BaseUrl == savedSelection);
_selectedConfig = instanceToSelect ?? _configs.FirstOrDefault(); // _selectedConfig = instanceToSelect ?? _configs.FirstOrDefault();
UpdateSelectedCustomFormats(); // UpdateSelectedCustomFormats();
}); // });
if (CfAccessor != null) if (CfAccessor != null)
{ {
@ -81,17 +63,6 @@ namespace Recyclarr.Pages.Radarr.CustomFormats
} }
} }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
while (_afterRenderActions.TryDequeue(out var action))
{
await action.Invoke();
StateHasChanged();
}
await base.OnAfterRenderAsync(firstRender);
}
private void OnReloadCompleted() private void OnReloadCompleted()
{ {
_cfChooser?.RequestRefreshList(); _cfChooser?.RequestRefreshList();

@ -16,18 +16,20 @@ namespace TrashLib.Cache
internal class ServiceCache : IServiceCache internal class ServiceCache : IServiceCache
{ {
private static readonly Regex AllowedObjectNameCharacters = new(@"^[\w-]+$", RegexOptions.Compiled); private static readonly Regex AllowedObjectNameCharacters = new(@"^[\w-]+$", RegexOptions.Compiled);
private readonly IConfigurationProvider _configProvider;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IFNV1a _hash; private readonly IFNV1a _hash;
private readonly IServerInfo _serverInfo;
private readonly ICacheStoragePath _storagePath; private readonly ICacheStoragePath _storagePath;
public ServiceCache(IFileSystem fileSystem, ICacheStoragePath storagePath, public ServiceCache(
IConfigurationProvider configProvider, IFileSystem fileSystem,
ICacheStoragePath storagePath,
IServerInfo serverInfo,
ILogger log) ILogger log)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_storagePath = storagePath; _storagePath = storagePath;
_configProvider = configProvider; _serverInfo = serverInfo;
Log = log; Log = log;
_hash = FNV1aFactory.Instance.Create(FNVConfig.GetPredefinedConfig(32)); _hash = FNV1aFactory.Instance.Create(FNVConfig.GetPredefinedConfig(32));
} }
@ -83,7 +85,8 @@ namespace TrashLib.Cache
private string BuildServiceGuid() private string BuildServiceGuid()
{ {
return _hash.ComputeHash(Encoding.ASCII.GetBytes(_configProvider.ActiveConfiguration.BaseUrl)) return _hash
.ComputeHash(Encoding.ASCII.GetBytes(_serverInfo.BaseUrl))
.AsHexString(); .AsHexString();
} }

@ -19,7 +19,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors
internal class PersistenceProcessor : IPersistenceProcessor internal class PersistenceProcessor : IPersistenceProcessor
{ {
private readonly IConfigurationProvider _configProvider; private readonly IConfigurationProvider<RadarrConfiguration> _configProvider;
private readonly ICustomFormatService _customFormatService; private readonly ICustomFormatService _customFormatService;
private readonly IQualityProfileService _qualityProfileService; private readonly IQualityProfileService _qualityProfileService;
private readonly Func<IPersistenceProcessorSteps> _stepsFactory; private readonly Func<IPersistenceProcessorSteps> _stepsFactory;
@ -28,7 +28,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors
public PersistenceProcessor( public PersistenceProcessor(
ICustomFormatService customFormatService, ICustomFormatService customFormatService,
IQualityProfileService qualityProfileService, IQualityProfileService qualityProfileService,
IConfigurationProvider configProvider, IConfigurationProvider<RadarrConfiguration> configProvider,
Func<IPersistenceProcessorSteps> stepsFactory) Func<IPersistenceProcessorSteps> stepsFactory)
{ {
_customFormatService = customFormatService; _customFormatService = customFormatService;
@ -52,7 +52,8 @@ namespace TrashLib.Radarr.CustomFormat.Processors
_steps = _stepsFactory(); _steps = _stepsFactory();
} }
public async Task PersistCustomFormats(IReadOnlyCollection<ProcessedCustomFormatData> guideCfs, public async Task PersistCustomFormats(
IReadOnlyCollection<ProcessedCustomFormatData> guideCfs,
IEnumerable<TrashIdMapping> deletedCfsInCache, IEnumerable<TrashIdMapping> deletedCfsInCache,
IDictionary<string, QualityProfileCustomFormatScoreMapping> profileScores) IDictionary<string, QualityProfileCustomFormatScoreMapping> profileScores)
{ {
@ -64,7 +65,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors
_steps.JsonTransactionStep.Process(guideCfs, radarrCfs); _steps.JsonTransactionStep.Process(guideCfs, radarrCfs);
// Step 1.1: Optionally record deletions of custom formats in cache but not in the guide // Step 1.1: Optionally record deletions of custom formats in cache but not in the guide
var config = (RadarrConfiguration) _configProvider.ActiveConfiguration; var config = _configProvider.ActiveConfiguration;
if (config.DeleteOldCustomFormats) if (config.DeleteOldCustomFormats)
{ {
_steps.JsonTransactionStep.RecordDeletions(deletedCfsInCache, radarrCfs); _steps.JsonTransactionStep.RecordDeletions(deletedCfsInCache, radarrCfs);

Loading…
Cancel
Save