diff --git a/cli/Squidex.CLI/.editorconfig b/cli/Squidex.CLI/.editorconfig index 573b6046..d50e990b 100644 --- a/cli/Squidex.CLI/.editorconfig +++ b/cli/Squidex.CLI/.editorconfig @@ -30,9 +30,6 @@ dotnet_diagnostic.CA2016.severity = none # CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. dotnet_diagnostic.CS8618.severity = none -# IDE0290: Use primary constructor -dotnet_diagnostic.IDE0290.severity = none - # IDE0063: Use simple 'using' statement dotnet_diagnostic.IDE0063.severity = none diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/AI/AIContentGenerator.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/AI/AIContentGenerator.cs index 45ef1410..e0ae11b5 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/AI/AIContentGenerator.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/AI/AIContentGenerator.cs @@ -20,15 +20,8 @@ namespace Squidex.CLI.Commands.Implementation.AI; -public sealed class AIContentGenerator +public sealed class AIContentGenerator(IConfigurationStore configurationStore) { - private readonly IConfigurationStore configurationStore; - - public AIContentGenerator(IConfigurationStore configurationStore) - { - this.configurationStore = configurationStore; - } - public async Task GenerateAsync(string description, string apiKey, string? schemaName = null, CancellationToken ct = default) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFile.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFile.cs index 5669b23c..8aac5c2a 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFile.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFile.cs @@ -7,13 +7,11 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Default; -public sealed class DefaultFile : IFile +public sealed class DefaultFile(FileInfo fileInfo, string fullLocalName) : IFile { - private readonly FileInfo fileInfo; - public string FullName => fileInfo.FullName; - public string FullLocalName { get; } + public string FullLocalName { get; } = fullLocalName; public string Name => fileInfo.Name; @@ -29,13 +27,6 @@ public bool Exists public bool Readonly { get; init; } - public DefaultFile(FileInfo fileInfo, string fullLocalName) - { - this.fileInfo = fileInfo; - - FullLocalName = fullLocalName; - } - public Stream OpenRead() { return fileInfo.OpenRead(); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFileSystem.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFileSystem.cs index 9cc72aac..cf51530a 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFileSystem.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Default/DefaultFileSystem.cs @@ -7,19 +7,12 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Default; -public sealed class DefaultFileSystem : IFileSystem +public sealed class DefaultFileSystem(DirectoryInfo directory) : IFileSystem { - private readonly DirectoryInfo directory; - public string FullName => directory.FullName; public bool Readonly { get; init; } - public DefaultFileSystem(DirectoryInfo directory) - { - this.directory = directory; - } - public Task OpenAsync() { return Task.CompletedTask; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFile.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFile.cs index ffa9f147..7adfae4c 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFile.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFile.cs @@ -9,15 +9,13 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Emedded; -public sealed class EmbeddedFile : IFile +public sealed class EmbeddedFile(Assembly assembly, string name, string fullName, string fullLocalName) : IFile { - private readonly Assembly assembly; + public string FullName { get; } = fullName; - public string FullName { get; } + public string FullLocalName { get; } = fullLocalName; - public string FullLocalName { get; } - - public string Name { get; } + public string Name { get; } = name; public long Size { @@ -29,26 +27,11 @@ public bool Exists get => CanOpen(); } - public EmbeddedFile(Assembly assembly, string name, string fullName, string fullLocalName) - { - this.assembly = assembly; - - Name = name; - - FullName = fullName; - FullLocalName = fullLocalName; - } - public Stream OpenRead() { var stream = assembly.GetManifestResourceStream(FullName); - if (stream == null) - { - throw new FileNotFoundException(null, FullName); - } - - return stream; + return stream ?? throw new FileNotFoundException(null, FullName); } public Stream OpenWrite() diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFileSystem.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFileSystem.cs index 27667e9a..005276da 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFileSystem.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Emedded/EmbeddedFileSystem.cs @@ -9,23 +9,12 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Emedded; -public sealed class EmbeddedFileSystem : IFileSystem +public sealed class EmbeddedFileSystem(Assembly assembly, string assemblyPath) : IFileSystem { - private readonly Assembly assembly; - private readonly string assemblyPath; - - public string FullName { get; } + public string FullName { get; } = $"{assembly.FullName}/{assemblyPath}"; public bool CanWrite => false; - public EmbeddedFileSystem(Assembly assembly, string assemblyPath) - { - this.assembly = assembly; - this.assemblyPath = assemblyPath; - - FullName = $"{assembly.FullName}/{assemblyPath}"; - } - public Task OpenAsync() { return Task.CompletedTask; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/FilePath.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/FilePath.cs index 443f03c9..6a7a8a52 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/FilePath.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/FilePath.cs @@ -7,16 +7,11 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem; -public sealed class FilePath +public sealed class FilePath(params string[] elements) { public static readonly FilePath Root = new FilePath(string.Empty); - public string[] Elements { get; } - - public FilePath(params string[] elements) - { - Elements = elements; - } + public string[] Elements { get; } = elements; public static FilePath Create(string path) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFile.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFile.cs index c3c3767d..795a883e 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFile.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFile.cs @@ -9,17 +9,15 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Zip; -public sealed class ZipFile : IFile +public sealed class ZipFile(ZipArchive archive, string archivePath, string name, string filePath) : IFile { - private readonly ZipArchive archive; - private readonly string archivePath; - private ZipArchiveEntry? entry; + private ZipArchiveEntry? entry = archive.GetEntry(archivePath); - public string FullName { get; } + public string FullName { get; } = $"{filePath}//{archivePath}"; public string FullLocalName => archivePath; - public string Name { get; } + public string Name { get; } = name; public long Size { @@ -31,18 +29,6 @@ public bool Exists get => entry != null; } - public ZipFile(ZipArchive archive, string archivePath, string name, string filePath) - { - entry = archive.GetEntry(archivePath); - - this.archive = archive; - this.archivePath = archivePath; - - Name = name; - - FullName = $"{filePath}//{archivePath}"; - } - public void Delete() { entry?.Delete(); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFileSystem.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFileSystem.cs index a0d8755b..475a189b 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFileSystem.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/FileSystem/Zip/ZipFileSystem.cs @@ -9,22 +9,14 @@ namespace Squidex.CLI.Commands.Implementation.FileSystem.Zip; -public sealed class ZipFileSystem : IFileSystem +public sealed class ZipFileSystem(FileInfo fileInfo) : IFileSystem { - private readonly ZipArchive zipArchive; - private readonly FileInfo fileInfo; + private readonly ZipArchive zipArchive = new ZipArchive(fileInfo.Open(FileMode.OpenOrCreate), ZipArchiveMode.Update); public string FullName => fileInfo.FullName; public bool CanAccessInParallel => false; - public ZipFileSystem(FileInfo fileInfo) - { - zipArchive = new ZipArchive(fileInfo.Open(FileMode.OpenOrCreate), ZipArchiveMode.Update); - - this.fileInfo = fileInfo; - } - public Task OpenAsync() { return Task.CompletedTask; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Csv2SquidexConverter.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Csv2SquidexConverter.cs index 25e43d53..de31c9da 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Csv2SquidexConverter.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Csv2SquidexConverter.cs @@ -12,14 +12,9 @@ namespace Squidex.CLI.Commands.Implementation.ImExport; -public sealed class Csv2SquidexConverter +public sealed class Csv2SquidexConverter(string? fields) { - private readonly JsonMapping mapping; - - public Csv2SquidexConverter(string? fields) - { - mapping = JsonMapping.ForCsv2Json(fields); - } + private readonly JsonMapping mapping = JsonMapping.ForCsv2Json(fields); public IEnumerable ReadAll(CsvReader csvReader) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Squidex2CsvConverter.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Squidex2CsvConverter.cs index 04b96271..8cf538fc 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Squidex2CsvConverter.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/Squidex2CsvConverter.cs @@ -11,20 +11,15 @@ namespace Squidex.CLI.Commands.Implementation.ImExport; -public sealed class Squidex2CsvConverter +public sealed class Squidex2CsvConverter(string? fields) { - private readonly JsonMapping mapping; + private readonly JsonMapping mapping = JsonMapping.ForJson2Csv(fields); public IEnumerable FieldNames { get { return mapping.Select(x => x.Name); } } - public Squidex2CsvConverter(string? fields) - { - mapping = JsonMapping.ForJson2Csv(fields); - } - public IEnumerable GetValues(DynamicContent entity) { foreach (var (_, path, _) in mapping) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs index d8b16dc5..2ae88ce7 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs @@ -11,20 +11,14 @@ namespace Squidex.CLI.Commands.Implementation.Sync.App; -public sealed class AppSynchronizer : ISynchronizer +public sealed class AppSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "__json/app"; - private readonly ILogger log; public string Name => "App"; public string Description => "Synchronize all app settings: clients, contributors, roles, languages and asset scripts. But not: workflows."; - public AppSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { return Task.CompletedTask; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/AssetFolders/AssetFoldersSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/AssetFolders/AssetFoldersSynchronizer.cs index 5a70edb5..60f7233d 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/AssetFolders/AssetFoldersSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/AssetFolders/AssetFoldersSynchronizer.cs @@ -10,10 +10,9 @@ namespace Squidex.CLI.Commands.Implementation.Sync.AssetFolders; -public sealed class AssetFoldersSynchronizer : ISynchronizer +public sealed class AssetFoldersSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/assetFolders"; - private readonly ILogger log; public int Order => -2000; @@ -21,11 +20,6 @@ public sealed class AssetFoldersSynchronizer : ISynchronizer public string Description => "Synchronizes all asset folders, even if they do not contain assets."; - public AssetFoldersSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs index 3d282d3e..0ad9ea3d 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs @@ -10,10 +10,9 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Assets; -public sealed class AssetsSynchronizer : ISynchronizer +public sealed class AssetsSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/assets"; - private readonly ILogger log; public int Order => -1000; @@ -21,11 +20,6 @@ public sealed class AssetsSynchronizer : ISynchronizer public string Description => "Synchronizes all assets and creates asset folders if they do not exist yet."; - public AssetsSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs index 99f889cb..ca117dfa 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs @@ -11,20 +11,14 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Contents; -public sealed class ContentsSynchronizer : ISynchronizer +public sealed class ContentsSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/contents"; - private readonly ILogger log; public string Name => "Contents"; public string Description => "Synchronizes all content items across all schemas."; - public ContentsSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/InheritanceAttribute.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/InheritanceAttribute.cs index 0f1c66c7..244230f9 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/InheritanceAttribute.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/InheritanceAttribute.cs @@ -8,12 +8,7 @@ namespace Squidex.CLI.Commands.Implementation.Sync; [AttributeUsage(AttributeTargets.All)] -public sealed class InheritanceAttribute : Attribute +public sealed class InheritanceAttribute(string discriminator) : Attribute { - public string Discriminator { get; } - - public InheritanceAttribute(string discriminator) - { - Discriminator = discriminator; - } + public string Discriminator { get; } = discriminator; } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/MarkdownWriter.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/MarkdownWriter.cs index 7d248cf7..634351f3 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/MarkdownWriter.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/MarkdownWriter.cs @@ -9,15 +9,8 @@ namespace Squidex.CLI.Commands.Implementation.Sync; -public sealed class MarkdownWriter +public sealed class MarkdownWriter(TextWriter writer) { - private readonly TextWriter writer; - - public MarkdownWriter(TextWriter writer) - { - this.writer = writer; - } - public MarkdownWriter H1(string text) { writer.Write("# "); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs index a3065d7f..ffa8a6ab 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs @@ -11,20 +11,14 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Rules; -public sealed class RulesSynchronizer : ISynchronizer +public sealed class RulesSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/rule"; - private readonly ILogger log; public string Name => "Rules"; public string Description => "Synchronizes all rules, but not rule events."; - public RulesSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs index 2a39bcb9..12032d83 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs @@ -13,10 +13,9 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Schemas; -public sealed class SchemasSynchronizer : ISynchronizer +public sealed class SchemasSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/schema"; - private readonly ILogger log; public int Order => -1000; @@ -24,11 +23,6 @@ public sealed class SchemasSynchronizer : ISynchronizer public string Description => "Synchronizes all schemas, but not the content."; - public SchemasSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetSchemaFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Synchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Synchronizer.cs index d81c2d76..7a1a15c2 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Synchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Synchronizer.cs @@ -10,18 +10,8 @@ namespace Squidex.CLI.Commands.Implementation.Sync; -public sealed class Synchronizer +public sealed class Synchronizer(IEnumerable synchronizers, ILogger log) { - private readonly ILogger log; - private readonly IEnumerable synchronizers; - - public Synchronizer(IEnumerable synchronizers, ILogger log) - { - this.synchronizers = synchronizers; - - this.log = log; - } - public IEnumerable<(string Name, string Description)> GetTargets() { return GetSynchronizers().Select(x => (x.Name, x.Description)); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs index a6266180..34d0fa68 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs @@ -11,20 +11,14 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Workflows; -public sealed class WorkflowsSynchronizer : ISynchronizer +public sealed class WorkflowsSynchronizer(ILogger log) : ISynchronizer { private const string Ref = "../__json/workflow"; - private readonly ILogger log; public string Name => "Workflows"; public string Description => "Synchronizes all workflows from the app settings."; - public WorkflowsSynchronizer(ILogger log) - { - this.log = log; - } - public Task CleanupAsync(IFileSystem fs) { foreach (var file in GetFiles(fs)) diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/TestData/TestDataGenerator.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/TestData/TestDataGenerator.cs index e88ff950..c67ca77c 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/TestData/TestDataGenerator.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/TestData/TestDataGenerator.cs @@ -11,20 +11,11 @@ namespace Squidex.CLI.Commands.Implementation.TestData; -public sealed class TestDataGenerator +public sealed class TestDataGenerator(SchemaDto schema, AppLanguagesDto languages) { private readonly SlugHelper slugify = new SlugHelper(); - private readonly SchemaDto schema; - private readonly AppLanguagesDto languages; private readonly Random random = new Random(); - public TestDataGenerator(SchemaDto schema, AppLanguagesDto languages) - { - this.schema = schema; - - this.languages = languages; - } - public DynamicData GenerateTestData() { var data = new DynamicData(); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Utils/SimpleMapper.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Utils/SimpleMapper.cs index e16c1088..774ad125 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Utils/SimpleMapper.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Utils/SimpleMapper.cs @@ -14,15 +14,10 @@ namespace Squidex.CLI.Commands.Implementation.Utils; internal static class SimpleMapper { - private sealed class StringConversionPropertyMapper : PropertyMapper + private sealed class StringConversionPropertyMapper( + PropertyAccessor sourceAccessor, + PropertyAccessor targetAccessor) : PropertyMapper(sourceAccessor, targetAccessor) { - public StringConversionPropertyMapper( - PropertyAccessor sourceAccessor, - PropertyAccessor targetAccessor) - : base(sourceAccessor, targetAccessor) - { - } - public override void MapProperty(object source, object target, CultureInfo culture) { var value = GetValue(source); @@ -31,19 +26,11 @@ public override void MapProperty(object source, object target, CultureInfo cultu } } - private sealed class ConversionPropertyMapper : PropertyMapper + private sealed class ConversionPropertyMapper( + PropertyAccessor sourceAccessor, + PropertyAccessor targetAccessor, + Type targetType) : PropertyMapper(sourceAccessor, targetAccessor) { - private readonly Type targetType; - - public ConversionPropertyMapper( - PropertyAccessor sourceAccessor, - PropertyAccessor targetAccessor, - Type targetType) - : base(sourceAccessor, targetAccessor) - { - this.targetType = targetType; - } - public override void MapProperty(object source, object target, CultureInfo culture) { var value = GetValue(source); @@ -66,19 +53,11 @@ public override void MapProperty(object source, object target, CultureInfo cultu } } - private sealed class TypeConverterPropertyMapper : PropertyMapper + private sealed class TypeConverterPropertyMapper( + PropertyAccessor sourceAccessor, + PropertyAccessor targetAccessor, + TypeConverter converter) : PropertyMapper(sourceAccessor, targetAccessor) { - private readonly TypeConverter converter; - - public TypeConverterPropertyMapper( - PropertyAccessor sourceAccessor, - PropertyAccessor targetAccessor, - TypeConverter converter) - : base(sourceAccessor, targetAccessor) - { - this.converter = converter; - } - public override void MapProperty(object source, object target, CultureInfo culture) { var value = GetValue(source); @@ -101,17 +80,8 @@ public override void MapProperty(object source, object target, CultureInfo cultu } } - private class PropertyMapper + private class PropertyMapper(PropertyAccessor sourceAccessor, PropertyAccessor targetAccessor) { - private readonly PropertyAccessor sourceAccessor; - private readonly PropertyAccessor targetAccessor; - - public PropertyMapper(PropertyAccessor sourceAccessor, PropertyAccessor targetAccessor) - { - this.sourceAccessor = sourceAccessor; - this.targetAccessor = targetAccessor; - } - public virtual void MapProperty(object source, object target, CultureInfo culture) { var value = GetValue(source); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs index 18cdb862..57edf8a1 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs @@ -10,11 +10,10 @@ namespace Squidex.CLI.Configuration; -public sealed class ConfigurationService : IConfigurationService +public sealed class ConfigurationService(IConfigurationStore configurationStore) : IConfigurationService { private const string CloudUrl = "https://cloud.squidex.io"; - private readonly ConfigurationModel configuration; - private readonly IConfigurationStore configurationStore; + private readonly ConfigurationModel configuration = configurationStore.Get(".configuration").Value ?? new ConfigurationModel(); private sealed class ConfigurationModel { @@ -23,13 +22,6 @@ private sealed class ConfigurationModel public string? CurrentApp { get; set; } } - public ConfigurationService(IConfigurationStore configurationStore) - { - this.configurationStore = configurationStore; - - configuration = configurationStore.Get(".configuration").Value ?? new ConfigurationModel(); - } - private void Save() { try diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientProvider.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientProvider.cs index e495704e..63f496e8 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientProvider.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientProvider.cs @@ -10,13 +10,8 @@ namespace Squidex.CLI.Configuration; -public sealed class GetOnlyHttpClientProvider : StaticHttpClientProvider +public sealed class GetOnlyHttpClientProvider(SquidexOptions options) : StaticHttpClientProvider(options) { - public GetOnlyHttpClientProvider(SquidexOptions options) - : base(options) - { - } - protected override HttpMessageHandler CreateMessageHandler(SquidexOptions options) { var baseHandler = base.CreateMessageHandler(options); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs index 7962091c..3601a5e8 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs @@ -10,11 +10,11 @@ namespace Squidex.CLI.Configuration; -public sealed class Session : ISession +public sealed class Session(DirectoryInfo workingDirectory, ISquidexClient client) : ISession { - public DirectoryInfo WorkingDirectory { get; } + public DirectoryInfo WorkingDirectory { get; } = workingDirectory; - public ISquidexClient Client { get; } + public ISquidexClient Client { get; } = client; public string App => Client.Options.AppName; @@ -23,11 +23,4 @@ public sealed class Session : ISession public string ClientSecret => Client.Options.ClientSecret; public string Url => Client.Options.Url; - - public Session(DirectoryInfo workingDirectory, ISquidexClient client) - { - WorkingDirectory = workingDirectory; - - Client = client; - } } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs index 010f18d3..b8388866 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs @@ -167,7 +167,10 @@ public sealed class OutArguments : AppArguments public SyncOptions ToOptions() { - return SimpleMapper.Map(this, new SyncOptions()); + return SimpleMapper.Map(this, new SyncOptions + { + MaxAgeDate = GetMaxAgeDate() + }); } public sealed class Validator : AbstractValidator diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs index e74a46c3..62792101 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs @@ -18,22 +18,14 @@ namespace Squidex.CLI.Commands.Implementation.OpenLibrary; -public sealed class AuthorImporter +public sealed class AuthorImporter(ISession session, ILogger log) { - private readonly IContentsClient client; - private readonly ILogger log; + private readonly IContentsClient client = session.Client.Contents("author"); private sealed record CsvRecord(string Id, string Json); private sealed record AuthorRecord(string Id, AuthorData Author); - public AuthorImporter(ISession session, ILogger log) - { - client = session.Client.Contents("author"); - - this.log = log; - } - public async Task ImportAsync(Stream stream) { var deserializeBlock = new TransformBlock(x => diff --git a/csharp/.editorconfig b/csharp/.editorconfig index 573b6046..d50e990b 100644 --- a/csharp/.editorconfig +++ b/csharp/.editorconfig @@ -30,9 +30,6 @@ dotnet_diagnostic.CA2016.severity = none # CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. dotnet_diagnostic.CS8618.severity = none -# IDE0290: Use primary constructor -dotnet_diagnostic.IDE0290.severity = none - # IDE0063: Use simple 'using' statement dotnet_diagnostic.IDE0063.severity = none diff --git a/csharp/Squidex.ClientLibrary/CodeGeneration/CustomValueGenerator.cs b/csharp/Squidex.ClientLibrary/CodeGeneration/CustomValueGenerator.cs index d5797e51..6fad0442 100644 --- a/csharp/Squidex.ClientLibrary/CodeGeneration/CustomValueGenerator.cs +++ b/csharp/Squidex.ClientLibrary/CodeGeneration/CustomValueGenerator.cs @@ -11,13 +11,8 @@ namespace CodeGeneration; -public sealed class CustomValueGenerator : CSharpValueGenerator +public sealed class CustomValueGenerator(CSharpGeneratorSettings settings) : CSharpValueGenerator(settings) { - public CustomValueGenerator(CSharpGeneratorSettings settings) - : base(settings) - { - } - public override string? GetDefaultValue(JsonSchema schema, bool allowsNull, string targetType, string? typeNameHint, bool useSchemaDefault, TypeResolverBase typeResolver) { if (!string.IsNullOrWhiteSpace(schema.ActualDiscriminator)) diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs index ac053f56..74e319be 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs @@ -9,15 +9,8 @@ namespace Squidex.ClientLibrary.ServiceExtensions; -internal sealed class HttpClientProvider : IHttpClientProvider +internal sealed class HttpClientProvider(Func factory) : IHttpClientProvider { - private readonly Func factory; - - public HttpClientProvider(Func factory) - { - this.factory = factory; - } - /// public HttpClient Get() { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs index 1c94fd49..b1b1ba63 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs @@ -10,15 +10,9 @@ namespace Squidex.ClientLibrary.ServiceExtensions; -internal sealed class SquidexClientProvider : ISquidexClientProvider +internal sealed class SquidexClientProvider(IOptionsMonitor optionsMonitor) : ISquidexClientProvider { private readonly ConcurrentDictionary clients = new ConcurrentDictionary(); - private readonly IOptionsMonitor optionsMonitor; - - public SquidexClientProvider(IOptionsMonitor optionsMonitor) - { - this.optionsMonitor = optionsMonitor; - } public ISquidexClient Get() { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexLoggingTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexLoggingTests.cs index a0000d40..91b39aa7 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexLoggingTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexLoggingTests.cs @@ -73,16 +73,8 @@ public async Task Should_log_with_manual_client() Assert.Contains(loggingHandler.Log, x => x.Url.Contains("identity-server/connect/token", StringComparison.Ordinal)); } - private class ClientProvider : StaticHttpClientProvider + private class ClientProvider(SquidexOptions options, SampleLoggingHandler sampleLoggingHandler) : StaticHttpClientProvider(options) { - private readonly SampleLoggingHandler sampleLoggingHandler; - - public ClientProvider(SquidexOptions options, SampleLoggingHandler sampleLoggingHandler) - : base(options) - { - this.sampleLoggingHandler = sampleLoggingHandler; - } - protected override HttpMessageHandler CreateMessageHandler(SquidexOptions options) { sampleLoggingHandler.InnerHandler = base.CreateMessageHandler(options); diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs index 755b4ef3..226df5e4 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs @@ -18,19 +18,14 @@ namespace Squidex.ClientLibrary; /// The type that represents the data structure. /// /// -public sealed class ContentsSharedClient : SquidexClientBase, IContentsSharedClient where TEntity : Content where TData : class, new() +/// +/// Initializes a new instance of the class +/// with the name of the schema, the options from the and the HTTP client. +/// +/// The options from the . Cannot be null. +/// is null. +public sealed class ContentsSharedClient(SquidexOptions options) : SquidexClientBase(options), IContentsSharedClient where TEntity : Content where TData : class, new() { - /// - /// Initializes a new instance of the class - /// with the name of the schema, the options from the and the HTTP client. - /// - /// The options from the . Cannot be null. - /// is null. - public ContentsSharedClient(SquidexOptions options) - : base(options) - { - } - /// public async Task>> GraphQlAsync(IEnumerable requests, QueryContext? context = null, CancellationToken ct = default) diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs index 6020582e..08211bd3 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs @@ -12,8 +12,12 @@ namespace Squidex.ClientLibrary.EnrichedEvents; /// /// Default status strings. /// +/// +/// Initializes a new instance of the struct. +/// +/// Status name. [TypeConverter(typeof(StatusTypeConverter))] -public readonly struct Status : IEquatable, IComparable +public readonly struct Status(string name) : IEquatable, IComparable { /// /// Content is Archived (soft-delete). @@ -30,8 +34,6 @@ namespace Squidex.ClientLibrary.EnrichedEvents; /// public static readonly Status Published = new Status("Published"); - private readonly string name; - /// /// Name of the status. /// @@ -40,15 +42,6 @@ public string Name get { return name ?? "Unknown"; } } - /// - /// Initializes a new instance of the struct. - /// - /// Status name. - public Status(string name) - { - this.name = name; - } - /// public override bool Equals(object? obj) { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs index 1b889279..3a5c8370 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs @@ -14,19 +14,14 @@ namespace Squidex.ClientLibrary; /// /// /// -public sealed class ExtendableRulesClient : SquidexClientBase, IExtendableRulesClient +/// +/// Initializes a new instance of the class +/// with the name of the schema, the options from the and the HTTP client. +/// +/// The options from the . Cannot be null. +/// is null. +public sealed class ExtendableRulesClient(SquidexOptions options) : SquidexClientBase(options), IExtendableRulesClient { - /// - /// Initializes a new instance of the class - /// with the name of the schema, the options from the and the HTTP client. - /// - /// The options from the . Cannot be null. - /// is null. - public ExtendableRulesClient(SquidexOptions options) - : base(options) - { - } - /// public Task GetRulesAsync( CancellationToken ct = default) diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandler.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandler.cs index ab9e2f11..03bc7da4 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandler.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandler.cs @@ -14,116 +14,87 @@ namespace Squidex.ClientLibrary; /// /// Base class for all upload events. /// -public abstract class AssetUploadEvent +/// +/// Initializes a new instance of the class. +/// +/// The file id that can be used to resume an upload. +public abstract class AssetUploadEvent(string fileId) { /// /// The file id that can be used to resume an upload. /// - public string FileId { get; } - - /// - /// Initializes a new instance of the class. - /// - /// The file id that can be used to resume an upload. - protected AssetUploadEvent(string fileId) - { - FileId = fileId; - } + public string FileId { get; } = fileId; } /// /// Contains information about a success upload process. /// -public sealed class AssetUploadProgressEvent : AssetUploadEvent +/// +/// Initializes a new instance of the class. +/// +/// The file id that can be used to resume an upload. +/// The progress from 1 to 100. +/// The number of written bytes. +/// The number of total bytes (length or file or asset). +public sealed class AssetUploadProgressEvent(string fileId, int progress, long bytesWritten, long bytesTotal) : AssetUploadEvent(fileId) { /// /// The progress from 1 to 100. /// - public int Progress { get; } + public int Progress { get; } = progress; /// /// The number of written bytes. /// - public long BytesWritten { get; } + public long BytesWritten { get; } = bytesTotal; /// /// The number of total bytes (length or file or asset). /// - public long BytesTotal { get; } - - /// - /// Initializes a new instance of the class. - /// - /// The file id that can be used to resume an upload. - /// The progress from 1 to 100. - /// The number of written bytes. - /// The number of total bytes (length or file or asset). - public AssetUploadProgressEvent(string fileId, int progress, long bytesWritten, long bytesTotal) - : base(fileId) - { - Progress = progress; - BytesWritten = bytesTotal; - BytesTotal = bytesWritten; - } + public long BytesTotal { get; } = bytesWritten; } /// /// Contains information about a success creation of an upload. /// -public sealed class AssetUploadCreatedEvent : AssetUploadEvent +/// +/// Initializes a new instance of the class. +/// +/// The file id that can be used to resume an upload. +public sealed class AssetUploadCreatedEvent(string fileId) : AssetUploadEvent(fileId) { - /// - /// Initializes a new instance of the class. - /// - /// The file id that can be used to resume an upload. - public AssetUploadCreatedEvent(string fileId) - : base(fileId) - { - } } /// /// Contains information about a success upload process. /// -public sealed class AssetUploadCompletedEvent : AssetUploadEvent +/// +/// Initializes a new instance of the class with the asset. +/// +/// The file id that can be used to resume an upload. +/// The created or updated asset. +public sealed class AssetUploadCompletedEvent(string fileId, AssetDto asset) : AssetUploadEvent(fileId) { /// /// The created or updated asset. /// - public AssetDto Asset { get; } - - /// - /// Initializes a new instance of the class with the asset. - /// - /// The file id that can be used to resume an upload. - /// The created or updated asset. - public AssetUploadCompletedEvent(string fileId, AssetDto asset) - : base(fileId) - { - Asset = asset; - } + public AssetDto Asset { get; } = asset; } /// /// Contains information about a failed upload process. /// -public sealed class AssetUploadExceptionEvent : AssetUploadEvent +/// +/// Initializes a new instance of the class with the thrown exception. +/// +/// The file id that can be used to resume an upload. +/// The thrown exception. +public sealed class AssetUploadExceptionEvent(string fileId, SquidexException exception) : AssetUploadEvent(fileId) { /// /// The exception. /// - public SquidexException Exception { get; } - - /// - /// Initializes a new instance of the class with the thrown exception. - /// - /// The file id that can be used to resume an upload. - /// The thrown exception. - public AssetUploadExceptionEvent(string fileId, SquidexException exception) - : base(fileId) - { - Exception = exception; - } + public SquidexException Exception { get; } = exception; } /// diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandlerAdapter.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandlerAdapter.cs index 1c8acbd8..a89c164b 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandlerAdapter.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ProgressHandlerAdapter.cs @@ -9,17 +9,9 @@ namespace Squidex.ClientLibrary; -internal sealed class ProgressHandlerAdapter : IProgressHandler +internal sealed class ProgressHandlerAdapter(IAssetProgressHandler inner, AssetsClient client) : IProgressHandler { private static readonly Dictionary> NullHeaders = []; - private readonly IAssetProgressHandler inner; - private readonly AssetsClient client; - - public ProgressHandlerAdapter(IAssetProgressHandler inner, AssetsClient client) - { - this.inner = inner; - this.client = client; - } public Task OnProgressAsync(UploadProgressEvent @event, CancellationToken ct)