refactor: use correct container types through code base

From Sonarcloud code smell list
pull/47/head
Robert Dailey 3 years ago
parent ebb924da12
commit ee3cfec50a

@ -0,0 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Common.Extensions
{
public static class CollectionExtensions
{
// From: https://stackoverflow.com/a/34362585/157971
public static IReadOnlyCollection<T> AsReadOnly<T>(this ICollection<T> source)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
return source as IReadOnlyCollection<T> ?? new ReadOnlyCollectionAdapter<T>(source);
}
// From: https://stackoverflow.com/a/34362585/157971
private sealed class ReadOnlyCollectionAdapter<T> : IReadOnlyCollection<T>
{
private readonly ICollection<T> _source;
public ReadOnlyCollectionAdapter(ICollection<T> source) => _source = source;
public int Count => _source.Count;
public IEnumerator<T> GetEnumerator() => _source.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> source)
{
foreach (var item in source)
{
destination.Add(item);
}
}
}
}

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NSubstitute;
@ -46,7 +47,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat
var testCfObj = new CustomFormatCache
{
Version = versionToTest,
TrashIdMappings = new List<TrashIdMapping> {new("", "", 5)}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "", 5)}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -61,7 +62,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat
var testCfObj = new CustomFormatCache
{
Version = CustomFormatCache.LatestVersion,
TrashIdMappings = new List<TrashIdMapping> {new("", "", 5)}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "", 5)}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -116,7 +117,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat
// Load initial CfCache just to test that it gets replaced
var testCfObj = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping> {new("", "") {CustomFormatId = 5}}
TrashIdMappings = new Collection<TrashIdMapping> {new("", "") {CustomFormatId = 5}}
};
ctx.ServiceCache.Load<CustomFormatCache>().Returns(testCfObj);
ctx.Persister.Load();
@ -133,7 +134,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat
ctx.Persister.Update(customFormatData);
ctx.Persister.CfCache.Should().BeEquivalentTo(new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping> {customFormatData[0].CacheEntry!}
TrashIdMappings = new Collection<TrashIdMapping> {customFormatData[0].CacheEntry!}
});
customFormatData.Should().ContainSingle()

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using FluentAssertions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -51,7 +52,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
var testCache = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping>
TrashIdMappings = new Collection<TrashIdMapping>
{
new("id1", "name1")
}
@ -97,7 +98,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
var testCache = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping>
TrashIdMappings = new Collection<TrashIdMapping>
{
new("id1000", "name1")
}
@ -183,7 +184,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
var testCache = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping> {new("id1000", "name1")}
TrashIdMappings = new Collection<TrashIdMapping> {new("id1000", "name1")}
};
var processor = new CustomFormatStep();
@ -205,7 +206,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
{
var cache = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping> {new("id1", "3D", 9)}
TrashIdMappings = new Collection<TrashIdMapping> {new("id1", "3D", 9)}
};
var guideCfs = new List<string>
@ -237,7 +238,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
var testCache = new CustomFormatCache
{
TrashIdMappings = new List<TrashIdMapping> {new("id1", "name1")}
TrashIdMappings = new Collection<TrashIdMapping> {new("id1", "name1")}
};
var processor = new CustomFormatStep();

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
@ -61,7 +62,8 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
processor.ProfileScores.Should()
.ContainKey("profile1").WhoseValue.Should()
.BeEquivalentTo(CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats[0], 50)));
.BeEquivalentTo(
CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats.First(), 50)));
processor.CustomFormatsWithoutScore.Should().BeEmpty();
}
@ -89,7 +91,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
processor.Process(testConfigData);
var expectedScoreEntries =
CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats[0], 100));
CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats.First(), 100));
processor.ProfileScores.Should().BeEquivalentTo(
new Dictionary<string, QualityProfileCustomFormatScoreMapping>
@ -124,7 +126,7 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
processor.ProfileScores.Should()
.ContainKey("profile1").WhoseValue.Should()
.BeEquivalentTo(CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats[0], 0)));
.BeEquivalentTo(CfTestUtils.NewMapping(new FormatMappingEntry(testConfigData[0].CustomFormats.First(), 0)));
processor.CustomFormatsWithoutScore.Should().BeEmpty();
}

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Autofac;
using FluentAssertions;
@ -28,13 +29,13 @@ namespace TrashLib.Tests.Radarr
private static readonly TestCaseData[] NameOrIdsTestData =
{
new(new List<string> {"name"}, new List<string>()),
new(new List<string>(), new List<string> {"trash_id"})
new(new Collection<string> {"name"}, new Collection<string>()),
new(new Collection<string>(), new Collection<string> {"trash_id"})
};
[TestCaseSource(nameof(NameOrIdsTestData))]
public void Custom_format_is_valid_with_one_of_either_names_or_trash_id(List<string> namesList,
List<string> trashIdsList)
public void Custom_format_is_valid_with_one_of_either_names_or_trash_id(Collection<string> namesList,
Collection<string> trashIdsList)
{
var config = new RadarrConfiguration
{

@ -1,12 +1,19 @@
using System;
using System.Runtime.Serialization;
namespace TrashLib.ExceptionTypes
{
[Serializable]
public class VersionException : Exception
{
public VersionException(string msg)
: base(msg)
{
}
protected VersionException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

@ -9,16 +9,16 @@ namespace TrashLib.Radarr.Config
public class RadarrConfiguration : ServiceConfiguration
{
public QualityDefinitionConfig? QualityDefinition { get; init; }
public List<CustomFormatConfig> CustomFormats { get; init; } = new();
public ICollection<CustomFormatConfig> CustomFormats { get; init; } = new List<CustomFormatConfig>();
public bool DeleteOldCustomFormats { get; init; }
}
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class CustomFormatConfig
{
public List<string> Names { get; init; } = new();
public List<string> TrashIds { get; init; } = new();
public List<QualityProfileConfig> QualityProfiles { get; init; } = new();
public ICollection<string> Names { get; init; } = new List<string>();
public ICollection<string> TrashIds { get; init; } = new List<string>();
public ICollection<QualityProfileConfig> QualityProfiles { get; init; } = new List<QualityProfileConfig>();
}
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Common.Extensions;
using Serilog;
using TrashLib.Cache;
using TrashLib.Radarr.CustomFormat.Models;

@ -33,7 +33,7 @@ namespace TrashLib.Radarr.CustomFormat
{
_cache.Load();
await _guideProcessor.BuildGuideDataAsync(config.CustomFormats, _cache.CfCache);
await _guideProcessor.BuildGuideDataAsync(config.CustomFormats.AsReadOnly(), _cache.CfCache);
if (!ValidateGuideDataAndCheckShouldProceed(config))
{

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using TrashLib.Cache;
namespace TrashLib.Radarr.CustomFormat.Models.Cache
@ -9,7 +9,7 @@ namespace TrashLib.Radarr.CustomFormat.Models.Cache
public const int LatestVersion = 1;
public int Version { get; init; } = LatestVersion;
public List<TrashIdMapping> TrashIdMappings { get; init; } = new();
public Collection<TrashIdMapping> TrashIdMappings { get; init; } = new();
}
public class TrashIdMapping

@ -5,7 +5,10 @@ namespace TrashLib.Radarr.CustomFormat.Models
{
public class ProcessedConfigData
{
public List<ProcessedCustomFormatData> CustomFormats { get; init; } = new();
public List<QualityProfileConfig> QualityProfiles { get; init; } = new();
public ICollection<ProcessedCustomFormatData> CustomFormats { get; init; }
= new List<ProcessedCustomFormatData>();
public ICollection<QualityProfileConfig> QualityProfiles { get; init; }
= new List<QualityProfileConfig>();
}
}

@ -12,6 +12,6 @@ namespace TrashLib.Radarr.CustomFormat.Models
}
public bool ResetUnmatchedScores { get; }
public List<FormatMappingEntry> Mapping { get; init; } = new();
public ICollection<FormatMappingEntry> Mapping { get; init; } = new List<FormatMappingEntry>();
}
}

@ -53,13 +53,13 @@ namespace TrashLib.Radarr.CustomFormat.Processors
public IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache
=> _steps.CustomFormat.DeletedCustomFormatsInCache;
public List<(string, string)> CustomFormatsWithOutdatedNames
public IReadOnlyCollection<(string, string)> CustomFormatsWithOutdatedNames
=> _steps.CustomFormat.CustomFormatsWithOutdatedNames;
public Dictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats
public IDictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats
=> _steps.CustomFormat.DuplicatedCustomFormats;
public async Task BuildGuideDataAsync(IReadOnlyList<CustomFormatConfig> config, CustomFormatCache? cache)
public async Task BuildGuideDataAsync(IReadOnlyCollection<CustomFormatConfig> config, CustomFormatCache? cache)
{
if (_guideCustomFormatJson == null)
{

@ -9,8 +9,11 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
internal class ConfigStep : IConfigStep
{
public List<string> CustomFormatsNotInGuide { get; } = new();
public List<ProcessedConfigData> ConfigData { get; } = new();
private readonly List<ProcessedConfigData> _configData = new();
private readonly List<string> _customFormatsNotInGuide = new();
public IReadOnlyCollection<string> CustomFormatsNotInGuide => _customFormatsNotInGuide;
public IReadOnlyCollection<ProcessedConfigData> ConfigData => _configData;
public void Process(IReadOnlyCollection<ProcessedCustomFormatData> processedCfs,
IEnumerable<CustomFormatConfig> config)
@ -24,7 +27,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
var match = FindCustomFormatByName(processedCfs, name);
if (match == null)
{
CustomFormatsNotInGuide.Add(name);
_customFormatsNotInGuide.Add(name);
}
else
{
@ -37,7 +40,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
var match = processedCfs.FirstOrDefault(cf => cf.TrashId.EqualsIgnoreCase(trashId));
if (match == null)
{
CustomFormatsNotInGuide.Add(trashId);
_customFormatsNotInGuide.Add(trashId);
}
else
{
@ -45,7 +48,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
}
}
ConfigData.Add(new ProcessedConfigData
_configData.Add(new ProcessedConfigData
{
QualityProfiles = singleConfig.QualityProfiles,
CustomFormats = validCfs
@ -58,10 +61,8 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
private static ProcessedCustomFormatData? FindCustomFormatByName(
IReadOnlyCollection<ProcessedCustomFormatData> processedCfs, string name)
{
return processedCfs.FirstOrDefault(
cf => cf.CacheEntry?.CustomFormatName.EqualsIgnoreCase(name) ?? false) ??
processedCfs.FirstOrDefault(
cf => cf.Name.EqualsIgnoreCase(name));
return processedCfs.FirstOrDefault(cf => cf.CacheEntry?.CustomFormatName.EqualsIgnoreCase(name) ?? false)
?? processedCfs.FirstOrDefault(cf => cf.Name.EqualsIgnoreCase(name));
}
}
}

@ -12,12 +12,15 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
internal class CustomFormatStep : ICustomFormatStep
{
public List<(string, string)> CustomFormatsWithOutdatedNames { get; } = new();
public List<ProcessedCustomFormatData> ProcessedCustomFormats { get; } = new();
public List<TrashIdMapping> DeletedCustomFormatsInCache { get; } = new();
private readonly List<(string, string)> _customFormatsWithOutdatedNames = new();
private readonly List<ProcessedCustomFormatData> _processedCustomFormats = new();
private readonly List<TrashIdMapping> _deletedCustomFormatsInCache = new();
private readonly Dictionary<string, List<ProcessedCustomFormatData>> _duplicatedCustomFormats = new();
public Dictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; private set; } =
new();
public IReadOnlyCollection<(string, string)> CustomFormatsWithOutdatedNames => _customFormatsWithOutdatedNames;
public IReadOnlyCollection<ProcessedCustomFormatData> ProcessedCustomFormats => _processedCustomFormats;
public IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache => _deletedCustomFormatsInCache;
public IDictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats => _duplicatedCustomFormats;
public void Process(IEnumerable<string> customFormatGuideData,
IReadOnlyCollection<CustomFormatConfig> config, CustomFormatCache? cache)
@ -27,7 +30,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
.ToList();
// For each ID listed under the `trash_ids` YML property, match it to an existing CF
ProcessedCustomFormats.AddRange(config
_processedCustomFormats.AddRange(config
.SelectMany(c => c.TrashIds)
.Distinct(StringComparer.CurrentCultureIgnoreCase)
.Join(processedCfs,
@ -60,7 +63,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
cf.CacheEntry.CustomFormatName = cf.Name;
}
ProcessedCustomFormats.Add(cf);
_processedCustomFormats.Add(cf);
continue;
}
@ -69,8 +72,8 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
if (configName != null)
{
// Config name is out of sync with the guide and should be updated
CustomFormatsWithOutdatedNames.Add((configName, cf.Name));
ProcessedCustomFormats.Add(cf);
_customFormatsWithOutdatedNames.Add((configName, cf.Name));
_processedCustomFormats.Add(cf);
}
// If we get here, we can't find a match in the config using cache or guide name, so the user must have
@ -86,12 +89,13 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
private void ProcessDuplicates()
{
DuplicatedCustomFormats = ProcessedCustomFormats
_duplicatedCustomFormats.Clear();
_duplicatedCustomFormats.AddRange(ProcessedCustomFormats
.GroupBy(cf => cf.Name)
.Where(grp => grp.Count() > 1)
.ToDictionary(grp => grp.Key, grp => grp.ToList());
.ToDictionary(grp => grp.Key, grp => grp.ToList()));
ProcessedCustomFormats.RemoveAll(cf => DuplicatedCustomFormats.ContainsKey(cf.Name));
_processedCustomFormats.RemoveAll(cf => DuplicatedCustomFormats.ContainsKey(cf.Name));
}
private static ProcessedCustomFormatData ProcessCustomFormatData(string guideData, CustomFormatCache? cache)
@ -129,7 +133,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
=> cf.CacheEntry != null && cf.CacheEntry.TrashId == c.TrashId;
// Delete if CF is in cache and not in the guide or config
DeletedCustomFormatsInCache.AddRange(cache.TrashIdMappings
_deletedCustomFormatsInCache.AddRange(cache.TrashIdMappings
.Where(c => !ProcessedCustomFormats.Any(cf => MatchCfInCache(cf, c))));
}
}

@ -6,8 +6,8 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface IConfigStep
{
List<string> CustomFormatsNotInGuide { get; }
List<ProcessedConfigData> ConfigData { get; }
IReadOnlyCollection<string> CustomFormatsNotInGuide { get; }
IReadOnlyCollection<ProcessedConfigData> ConfigData { get; }
void Process(IReadOnlyCollection<ProcessedCustomFormatData> processedCfs,
IEnumerable<CustomFormatConfig> config);

@ -7,10 +7,10 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface ICustomFormatStep
{
List<ProcessedCustomFormatData> ProcessedCustomFormats { get; }
List<TrashIdMapping> DeletedCustomFormatsInCache { get; }
List<(string, string)> CustomFormatsWithOutdatedNames { get; }
Dictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; }
IReadOnlyCollection<ProcessedCustomFormatData> ProcessedCustomFormats { get; }
IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache { get; }
IReadOnlyCollection<(string, string)> CustomFormatsWithOutdatedNames { get; }
IDictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; }
void Process(IEnumerable<string> customFormatGuideData,
IReadOnlyCollection<CustomFormatConfig> config, CustomFormatCache? cache);

@ -5,8 +5,8 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
public interface IQualityProfileStep
{
Dictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; }
List<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; }
IDictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; }
IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; }
void Process(IEnumerable<ProcessedConfigData> configData);
}
}

@ -5,8 +5,11 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
internal class QualityProfileStep : IQualityProfileStep
{
public Dictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; } = new();
public List<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; } = new();
private readonly Dictionary<string, QualityProfileCustomFormatScoreMapping> _profileScores = new();
private readonly List<(string name, string trashId, string profileName)> _customFormatsWithoutScore = new();
public IDictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores => _profileScores;
public IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore => _customFormatsWithoutScore;
public void Process(IEnumerable<ProcessedConfigData> configData)
{
@ -23,7 +26,7 @@ namespace TrashLib.Radarr.CustomFormat.Processors.GuideSteps
{
if (cf.Score == null)
{
CustomFormatsWithoutScore.Add((cf.Name, cf.TrashId, profile.Name));
_customFormatsWithoutScore.Add((cf.Name, cf.TrashId, profile.Name));
}
else
{

@ -14,10 +14,10 @@ namespace TrashLib.Radarr.CustomFormat.Processors
IDictionary<string, QualityProfileCustomFormatScoreMapping> ProfileScores { get; }
IReadOnlyCollection<(string name, string trashId, string profileName)> CustomFormatsWithoutScore { get; }
IReadOnlyCollection<TrashIdMapping> DeletedCustomFormatsInCache { get; }
List<(string, string)> CustomFormatsWithOutdatedNames { get; }
Dictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; }
IReadOnlyCollection<(string, string)> CustomFormatsWithOutdatedNames { get; }
IDictionary<string, List<ProcessedCustomFormatData>> DuplicatedCustomFormats { get; }
Task BuildGuideDataAsync(IReadOnlyList<CustomFormatConfig> config, CustomFormatCache? cache);
Task BuildGuideDataAsync(IReadOnlyCollection<CustomFormatConfig> config, CustomFormatCache? cache);
void Reset();
}
}

@ -12,6 +12,6 @@ namespace TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps
void Process(IEnumerable<ProcessedCustomFormatData> guideCfs,
IReadOnlyCollection<JObject> radarrCfs);
void RecordDeletions(IEnumerable<TrashIdMapping> deletedCfsInCache, List<JObject> radarrCfs);
void RecordDeletions(IEnumerable<TrashIdMapping> deletedCfsInCache, IEnumerable<JObject> radarrCfs);
}
}

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Common.Extensions;
using Newtonsoft.Json.Linq;
@ -9,10 +10,10 @@ namespace TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps
{
public class CustomFormatTransactionData
{
public List<ProcessedCustomFormatData> NewCustomFormats { get; } = new();
public List<ProcessedCustomFormatData> UpdatedCustomFormats { get; } = new();
public List<TrashIdMapping> DeletedCustomFormatIds { get; } = new();
public List<ProcessedCustomFormatData> UnchangedCustomFormats { get; } = new();
public Collection<ProcessedCustomFormatData> NewCustomFormats { get; } = new();
public Collection<ProcessedCustomFormatData> UpdatedCustomFormats { get; } = new();
public Collection<TrashIdMapping> DeletedCustomFormatIds { get; } = new();
public Collection<ProcessedCustomFormatData> UnchangedCustomFormats { get; } = new();
}
internal class JsonTransactionStep : IJsonTransactionStep
@ -59,12 +60,14 @@ namespace TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps
}
}
public void RecordDeletions(IEnumerable<TrashIdMapping> deletedCfsInCache, List<JObject> radarrCfs)
public void RecordDeletions(IEnumerable<TrashIdMapping> deletedCfsInCache, IEnumerable<JObject> radarrCfs)
{
var cfs = radarrCfs.ToList();
// The 'Where' excludes cached CFs that were deleted manually by the user in Radarr
// FindRadarrCf() specifies 'null' for name because we should never delete unless an ID is found
foreach (var del in deletedCfsInCache.Where(
del => FindRadarrCf(radarrCfs, del.CustomFormatId, null) != null))
del => FindRadarrCf(cfs, del.CustomFormatId, null) != null))
{
Transactions.DeletedCustomFormatIds.Add(del);
}

Loading…
Cancel
Save