Skip to content

Commit

Permalink
Use primary constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 18, 2024
1 parent 29a5a9a commit 8048c18
Show file tree
Hide file tree
Showing 38 changed files with 119 additions and 421 deletions.
3 changes: 0 additions & 3 deletions cli/Squidex.CLI/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeneratedContent> GenerateAsync(string description, string apiKey, string? schemaName = null,
CancellationToken ct = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DynamicData> ReadAll(CsvReader csvReader)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> FieldNames
{
get { return mapping.Select(x => x.Name); }
}

public Squidex2CsvConverter(string? fields)
{
mapping = JsonMapping.ForJson2Csv(fields);
}

public IEnumerable<object?> GetValues(DynamicContent entity)
{
foreach (var (_, path, _) in mapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@

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;

public string Name => "AssetFolders";

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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@

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;

public string Name => "Assets";

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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit 8048c18

Please sign in to comment.