Get items stored and retrieved from the db
This commit is contained in:
@@ -51,7 +51,7 @@ public partial class App : Application
|
|||||||
services.TryAddSingleton<IContainer<SecurityKey>, Container<SecurityKey>>();
|
services.TryAddSingleton<IContainer<SecurityKey>, Container<SecurityKey>>();
|
||||||
services.TryAddSingleton<IContainer<ContainerConnection>, Container<ContainerConnection>>();
|
services.TryAddSingleton<IContainer<ContainerConnection>, Container<ContainerConnection>>();
|
||||||
|
|
||||||
services.AddDbContextFactory<VaultDbContext>((provider, args) =>
|
services.AddDbContextFactory<ContainerDbContext>((provider, args) =>
|
||||||
{
|
{
|
||||||
if (provider.GetRequiredService<IContainer<ContainerConnection>>()
|
if (provider.GetRequiredService<IContainer<ContainerConnection>>()
|
||||||
is IContainer<ContainerConnection> connection)
|
is IContainer<ContainerConnection> connection)
|
||||||
@@ -87,6 +87,8 @@ public partial class App : Application
|
|||||||
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
|
|
||||||
|
services.AddHandler<ItemConfigurationHandler>();
|
||||||
});
|
});
|
||||||
})!);
|
})!);
|
||||||
|
|
||||||
@@ -94,7 +96,7 @@ public partial class App : Application
|
|||||||
services.AddHandler<CreateContainerHandler>();
|
services.AddHandler<CreateContainerHandler>();
|
||||||
|
|
||||||
services.AddSingleton<IContainerHostCollection, ContainerHostCollection>();
|
services.AddSingleton<IContainerHostCollection, ContainerHostCollection>();
|
||||||
services.AddInitializer<ContainerCollectionInitializer>();
|
services.AddInitializer<ContainerInitializer>();
|
||||||
|
|
||||||
services.AddTemplate<MainViewModel, MainView>("Main");
|
services.AddTemplate<MainViewModel, MainView>("Main");
|
||||||
services.AddHandler<MainViewModelHandler>();
|
services.AddHandler<MainViewModelHandler>();
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
<ComparisonCondition LeftOperand="{Binding Selected}" RightOperand="True" />
|
<ComparisonCondition LeftOperand="{Binding Selected}" RightOperand="True" />
|
||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Context="Main" Route="Container" />
|
|
||||||
<ChangePropertyAction
|
<ChangePropertyAction
|
||||||
PropertyName="SelectsOnInvoked"
|
PropertyName="SelectsOnInvoked"
|
||||||
TargetObject="{Binding #NavigationViewItem}"
|
TargetObject="{Binding #NavigationViewItem}"
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Bitvault.Data;
|
|
||||||
|
|
||||||
public record Category
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string? Name { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,23 @@
|
|||||||
using Bitvault.Data;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Bitvault.Data;
|
namespace Bitvault.Data;
|
||||||
|
|
||||||
public class VaultDbContext(DbContextOptions<VaultDbContext> options) :
|
public class ContainerDbContext(DbContextOptions<ContainerDbContext> options) :
|
||||||
DbContext(options)
|
DbContext(options)
|
||||||
{
|
{
|
||||||
public DbSet<Category> Categories { get; set; }
|
|
||||||
|
|
||||||
public DbSet<Document> Documents { get; set; }
|
public DbSet<Document> Documents { get; set; }
|
||||||
|
|
||||||
public DbSet<Content> Items { get; set; }
|
public DbSet<Item> Items { get; set; }
|
||||||
|
|
||||||
public DbSet<Tag> Tags { get; set; }
|
public DbSet<Tag> Tags { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.Entity<Content>()
|
modelBuilder.Entity<Item>()
|
||||||
.HasMany(x => x.Tags)
|
.HasMany(x => x.Tags)
|
||||||
.WithOne();
|
.WithOne();
|
||||||
|
|
||||||
modelBuilder.Entity<Content>()
|
modelBuilder.Entity<Item>()
|
||||||
.HasMany(x => x.Documents)
|
.HasMany(x => x.Documents)
|
||||||
.WithOne();
|
.WithOne();
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace Bitvault.Data;
|
namespace Bitvault.Data;
|
||||||
|
|
||||||
public record Content
|
public record Item
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@@ -12,11 +12,9 @@ public record Content
|
|||||||
|
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
public int State { get; set; }
|
public int State { get; set; } = 0;
|
||||||
|
|
||||||
public ICollection<Tag>? Tags { get; }
|
public ICollection<Tag>? Tags { get; }
|
||||||
|
|
||||||
public Category? Category { get; }
|
|
||||||
|
|
||||||
public ICollection<Document>? Documents { get; }
|
public ICollection<Document>? Documents { get; }
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
@@ -15,7 +14,4 @@ public partial class AddItemActionViewModel(IServiceProvider provider,
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string named = $"{named}";
|
private string named = $"{named}";
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public async Task Invoke() => await Publisher.Publish(new Test());
|
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public partial class AddItemViewModel :
|
public partial class AddItemViewModel :
|
||||||
ObservableCollectionViewModel<IItemViewModel>,
|
ObservableCollectionViewModel<IItemViewModel>,
|
||||||
INotificationHandler<Test>
|
INotificationHandler<Confirm<Item>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string named;
|
private string named;
|
||||||
@@ -27,7 +27,7 @@ public partial class AddItemViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public Task<bool> Confirm()
|
public async Task Handle(Confirm<Item> args, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ItemConfiguration configuration = new();
|
ItemConfiguration configuration = new();
|
||||||
foreach (IItemViewModel item in this)
|
foreach (IItemViewModel item in this)
|
||||||
@@ -35,11 +35,6 @@ public partial class AddItemViewModel :
|
|||||||
item.Invoke(configuration);
|
item.Invoke(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(true);
|
await Mediator.Handle<Create<ItemConfiguration>, bool>(Create.As(configuration), cancellationToken);
|
||||||
}
|
|
||||||
|
|
||||||
public Task Handle(Test args, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ using Toolkit.Foundation;
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public record Test;
|
|
||||||
|
|
||||||
public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
@@ -12,6 +10,7 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
|||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(new Test());
|
public async Task Invoke() => await Publisher.Publish(Confirm.As<Item>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public class ContainerFactory(IContainer<ContainerConnection> connection,
|
|||||||
connection.Set(new ContainerConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
connection.Set(new ContainerConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||||
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}"));
|
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}"));
|
||||||
|
|
||||||
IDbContextFactory<VaultDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<VaultDbContext>>();
|
IDbContextFactory<ContainerDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<ContainerDbContext>>();
|
||||||
using VaultDbContext context = await dbContextFactory.CreateDbContextAsync();
|
using ContainerDbContext context = await dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContainerCollectionInitializer(IEnumerable<IConfigurationDescriptor<ContainerConfiguration>> configurations,
|
public class ContainerInitializer(IEnumerable<IConfigurationDescriptor<ContainerConfiguration>> configurations,
|
||||||
IComponentFactory componentFactory,
|
IComponentFactory componentFactory,
|
||||||
IContainerHostCollection vaults) : IInitializer
|
IContainerHostCollection vaults) : IInitializer
|
||||||
{
|
{
|
||||||
@@ -1,48 +1,35 @@
|
|||||||
using Toolkit.Foundation;
|
using Bitvault.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContainerViewModelHandler(IServiceFactory factory,
|
public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||||
|
IServiceFactory factory,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args,
|
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (args.Options?.Filter is "All")
|
var items = await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 100; i++)
|
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||||
|
return await context.Set<Data.Item>().Select(x => new
|
||||||
{
|
{
|
||||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
x.Name,
|
||||||
{
|
x.State
|
||||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
}).Where(x => x.State != 3).ToListAsync();
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Options?.Filter is "Starred")
|
}, cancellationToken);
|
||||||
{
|
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
|
||||||
{
|
|
||||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Options?.Filter is "Archive")
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 1000; i++)
|
if (factory.Create<ItemNavigationViewModel>(item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||||
{
|
|
||||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
|
||||||
{
|
{
|
||||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
nameof(ContainerViewModel), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record Item;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using Bitvault.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public class ItemConfigurationHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||||
|
IHandler<Create<ItemConfiguration>, bool>
|
||||||
|
{
|
||||||
|
public async Task<bool> Handle(Create<ItemConfiguration> args,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (args.Value is ItemConfiguration configuration)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
await context.AddAsync(new Data.Item { Name = configuration.Name }, cancellationToken);
|
||||||
|
await context.SaveChangesAsync(cancellationToken);
|
||||||
|
}, cancellationToken);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
NamedComponent named,
|
NamedComponent named,
|
||||||
string name,
|
string name,
|
||||||
string description) :
|
string description) :
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
INotificationHandler<Test>
|
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string? description = description;
|
private string? description = description;
|
||||||
@@ -28,9 +27,4 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool selected;
|
private bool selected;
|
||||||
public IContentTemplate Template { get; set; } = template;
|
public IContentTemplate Template { get; set; } = template;
|
||||||
|
|
||||||
public Task Handle(Test args, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user