Implements directory browser dialog, part 1: file system treeview

This commit is contained in:
BinaryAlley committed 2024-09-15 13:07:53 +03:00
1 parent 4a53348013
commit 4e4ecbbfca
318 files changed
+6012 -1184

No files matched your search

@@ -1,23 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Collections.Generic;
#endregion
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="BookDto"/> entity.
/// Configures the entity mapping for the <see cref="BookModel"/> entity.
/// </summary>
public class BookConfiguration : IEntityTypeConfiguration<BookDto>
public class BookConfiguration : IEntityTypeConfiguration<BookModel>
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Configures the <see cref="BookDto"/> entity.
/// Configures the <see cref="BookModel"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<BookDto> builder)
public void Configure(EntityTypeBuilder<BookModel> builder)
{
builder.ToTable("Books");
builder.HasKey(book => book.Id);
@@ -46,8 +47,8 @@ public class BookConfiguration : IEntityTypeConfiguration<BookDto>
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookTags",
j => j.HasOne<TagDto>().WithMany().HasForeignKey("TagId"),
j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
j => j.HasOne<TagModel>().WithMany().HasForeignKey("TagId"),
j => j.HasOne<BookModel>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "TagId");
@@ -58,8 +59,8 @@ public class BookConfiguration : IEntityTypeConfiguration<BookDto>
.WithMany()
.UsingEntity<Dictionary<string, object>>(
"BookGenres",
j => j.HasOne<GenreDto>().WithMany().HasForeignKey("GenreId"),
j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
j => j.HasOne<GenreModel>().WithMany().HasForeignKey("GenreId"),
j => j.HasOne<BookModel>().WithMany().HasForeignKey("BookId"),
j =>
{
j.HasKey("BookId", "GenreId");
@@ -83,12 +84,12 @@ public class BookConfiguration : IEntityTypeConfiguration<BookDto>
builder.Property(book => book.Created).HasColumnOrder(30);
builder.Property(book => book.Updated).HasColumnOrder(31);
//builder.HasMany<ContributorIdDto>()
//builder.HasMany<ContributorIdModel>()
//.WithMany()
//.UsingEntity<Dictionary<string, object>>(
// "BookContributors",
// j => j.HasOne<ContributorIdDto>().WithMany().HasForeignKey("ContributorId"),
// j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
// j => j.HasOne<ContributorIdModel>().WithMany().HasForeignKey("ContributorId"),
// j => j.HasOne<BookModel>().WithMany().HasForeignKey("BookId"),
// j =>
// {
// j.HasKey("BookId", "ContributorId");
@@ -150,9 +151,9 @@ public class BookConfiguration : IEntityTypeConfiguration<BookDto>
#endregion
}
//public class ContributorConfiguration : IEntityTypeConfiguration<ContributorIdDto>
//public class ContributorConfiguration : IEntityTypeConfiguration<ContributorIdModel>
//{
// public void Configure(EntityTypeBuilder<ContributorIdDto> builder)
// public void Configure(EntityTypeBuilder<ContributorIdModel> builder)
// {
// builder.ToTable("Contributors");
// builder.HasKey(c => c.Id);
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
@@ -7,16 +7,16 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="GenreDto"/> entity.
/// Configures the entity mapping for the <see cref="GenreModel"/> entity.
/// </summary>
public class GenreConfiguration : IEntityTypeConfiguration<GenreDto>
public class GenreConfiguration : IEntityTypeConfiguration<GenreModel>
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Configures the <see cref="GenreDto"/> entity.
/// Configures the <see cref="GenreModel"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<GenreDto> builder)
public void Configure(EntityTypeBuilder<GenreModel> builder)
{
builder.ToTable("Genres");
builder.HasKey(genre => genre.Name);
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
#endregion
@@ -7,16 +7,16 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Lumina.DataAccess.Common.Configuration;
/// <summary>
/// Configures the entity mapping for the <see cref="TagDto"/> entity.
/// Configures the entity mapping for the <see cref="TagModel"/> entity.
/// </summary>
public class TagConfiguration : IEntityTypeConfiguration<TagDto>
public class TagConfiguration : IEntityTypeConfiguration<TagModel>
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Configures the <see cref="TagDto"/> entity.
/// Configures the <see cref="TagModel"/> entity.
/// </summary>
/// <param name="builder">The builder to be used to configure the entity.</param>
public void Configure(EntityTypeBuilder<TagDto> builder)
public void Configure(EntityTypeBuilder<TagModel> builder)
{
builder.ToTable("Tags");
builder.HasKey(tag => tag.Name);
@@ -1,11 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.DataAccess.Core.UoW;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.DataAccess.Core.UoW;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
#endregion
namespace Lumina.DataAccess.Common.DependencyInjection;
@@ -50,7 +50,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("BookTags", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
@@ -197,7 +197,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Books", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreModel", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
@@ -208,7 +208,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Genres", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagModel", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
@@ -221,13 +221,13 @@ namespace Lumina.DataAccess.Common.Migrations
modelBuilder.Entity("BookGenres", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
b.HasOne("Lumina.Application.Common.Models.Common.GenreModel", null)
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
@@ -236,22 +236,22 @@ namespace Lumina.DataAccess.Common.Migrations
modelBuilder.Entity("BookTags", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
b.HasOne("Lumina.Application.Common.Models.Common.TagModel", null)
.WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b =>
{
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingModel", "Ratings", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -284,7 +284,7 @@ namespace Lumina.DataAccess.Common.Migrations
.HasForeignKey("BookId");
});
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnModel", "ISBNs", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -47,7 +47,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("BookTags", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b =>
{
b.Property<Guid>("Id")
.HasColumnType("TEXT")
@@ -194,7 +194,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Books", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreModel", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
@@ -205,7 +205,7 @@ namespace Lumina.DataAccess.Common.Migrations
b.ToTable("Genres", (string)null);
});
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagModel", b =>
{
b.Property<string>("Name")
.HasMaxLength(50)
@@ -218,13 +218,13 @@ namespace Lumina.DataAccess.Common.Migrations
modelBuilder.Entity("BookGenres", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
b.HasOne("Lumina.Application.Common.Models.Common.GenreModel", null)
.WithMany()
.HasForeignKey("GenreId")
.OnDelete(DeleteBehavior.Cascade)
@@ -233,22 +233,22 @@ namespace Lumina.DataAccess.Common.Migrations
modelBuilder.Entity("BookTags", b =>
{
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null)
.WithMany()
.HasForeignKey("BookId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
b.HasOne("Lumina.Application.Common.Models.Common.TagModel", null)
.WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b =>
{
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingModel", "Ratings", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -281,7 +281,7 @@ namespace Lumina.DataAccess.Common.Migrations
.HasForeignKey("BookId");
});
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnModel", "ISBNs", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
@@ -1,11 +1,15 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Errors;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Books;
@@ -36,25 +40,25 @@ internal sealed class BookRepository : IBookRepository
/// </summary>
/// <param name="book">The book to add.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(BookDto book, CancellationToken cancellationToken)
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
public async Task<ErrorOr<Created>> InsertAsync(BookModel book, CancellationToken cancellationToken)
{
var jobExists = await _luminaDbContext.Books.AnyAsync(_book => _book.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
if (jobExists)
return Errors.WrittenContent.BookAlreadyExists;
// fetch existing tags and genres
var existingTags = await _luminaDbContext.Set<TagDto>()
var existingTags = await _luminaDbContext.Set<TagModel>()
.Where(t => book.Tags.Select(bt => bt.Name).Contains(t.Name))
.ToListAsync(cancellationToken);
.ToListAsync(cancellationToken).ConfigureAwait(false);
var existingGenres = await _luminaDbContext.Set<GenreDto>()
var existingGenres = await _luminaDbContext.Set<GenreModel>()
.Where(g => book.Genres.Select(bg => bg.Name).Contains(g.Name))
.ToListAsync(cancellationToken);
.ToListAsync(cancellationToken).ConfigureAwait(false);
// replace tags and genres in the book with existing ones
book.Tags = new HashSet<TagDto>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreDto>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
book.Tags = new HashSet<TagModel>(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag));
book.Genres = new HashSet<GenreModel>(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre));
_luminaDbContext.Books.Add(book);
return Result.Created;
@@ -64,8 +68,8 @@ internal sealed class BookRepository : IBookRepository
/// Gets all books.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <see cref="BookDto"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookDto>>> GetAllAsync(CancellationToken cancellationToken)
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookModel"/>, or an error.</returns>
public async Task<ErrorOr<IEnumerable<BookModel>>> GetAllAsync(CancellationToken cancellationToken)
{
return await _luminaDbContext.Books
.Include(book => book.Tags)
@@ -1,7 +1,7 @@
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
/// <summary>
/// Repositories abstract factory.
/// Interface for the repositories factory.
/// </summary>
public interface IRepositoryFactory
{
@@ -1,5 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
@@ -14,6 +17,9 @@ public class RepositoryDictionary
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the number of added repositories.
/// </summary>
public int Count { get { return _container.Count; } }
#endregion
@@ -1,11 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Microsoft.Extensions.DependencyInjection;
using System;
#endregion
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
/// <summary>
/// Concrete implementation for the repositories abstract factory.
/// Concrete implementation for the repositories factory.
/// </summary>
public class RepositoryFactory : IRepositoryFactory
{
@@ -15,7 +16,7 @@ public class RepositoryFactory : IRepositoryFactory
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// Initializes a new instance of the <see cref="RepositoryFactory"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
public RepositoryFactory(IServiceProvider serviceProvider)
@@ -1,8 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Events;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.DataAccess.Core.UoW;
@@ -15,12 +18,12 @@ namespace Lumina.DataAccess.Core.UoW;
public class LuminaDbContext : DbContext
{
#region ==================================================================== PROPERTIES =================================================================================
public virtual DbSet<BookDto> Books { get; set; } = null!;
public virtual DbSet<BookModel> Books { get; set; } = null!;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// Initializes a new instance of the <see cref="LuminaDbContext"/> class.
/// </summary>
/// <param name="options">The options for configuring the database context.</param>
public LuminaDbContext(DbContextOptions<LuminaDbContext> options) : base(options)
+11 -3
View File
@@ -2,7 +2,12 @@
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.DataAccess.Core.UoW;
@@ -18,14 +23,17 @@ public class UnitOfWork : IUnitOfWork
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets or sets the collection of available repositories.
/// </summary>
internal RepositoryDictionary Repositories { get; private set; } = new RepositoryDictionary();
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Overload C-tor.
/// Initializes a new instance of the <see cref="UnitOfWork"/> class.
/// </summary>
/// <param name="repositoryFactory">The abstract factory used to generate repositories.</param>
/// <param name="repositoryFactory">The factory used to generate repositories.</param>
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
public UnitOfWork(IRepositoryFactory repositoryFactory, LuminaDbContext luminaDbContext)
{
@@ -95,7 +103,7 @@ public class UnitOfWork : IUnitOfWork
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public async Task SaveChangesAsync(CancellationToken cancellationToken)
{
await _luminaDbContext.SaveChangesAsync(cancellationToken);
await _luminaDbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
/// <summary>
@@ -2,9 +2,9 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\..\bin\</BaseOutputPath>
<BaseOutputPath>$(SolutionDir)..\bin\server\</BaseOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>