diff --git a/Bitvault.Avalonia/App.axaml.cs b/Bitvault.Avalonia/App.axaml.cs index 671408c..36e8649 100644 --- a/Bitvault.Avalonia/App.axaml.cs +++ b/Bitvault.Avalonia/App.axaml.cs @@ -30,11 +30,11 @@ public partial class App : Application .AddConfiguration("Item:Bank Account", ItemConfiguration.BankAccount) .AddConfiguration("Item:Credit Card", ItemConfiguration.CreditCard) .AddConfiguration("Item:Document", ItemConfiguration.Document) - .AddConfiguration("Item:Driving Licence", ItemConfiguration.DrivingLicence) - .AddConfiguration("Item:Identity", ItemConfiguration.Identity) - .AddConfiguration("Item:Login", ItemConfiguration.Login) - .AddConfiguration("Item:Note", ItemConfiguration.Note) - .AddConfiguration("Item:Password", ItemConfiguration.Password) + .AddConfiguration("Item:Driving Licence", ItemConfiguration.DrivingLicence) + .AddConfiguration("Item:Identity", ItemConfiguration.Identity) + .AddConfiguration("Item:Login", ItemConfiguration.Login) + .AddConfiguration("Item:Note", ItemConfiguration.Note) + .AddConfiguration("Item:Password", ItemConfiguration.Password) .ConfigureServices((context, services) => { services.AddAvalonia(); @@ -45,9 +45,6 @@ public partial class App : Application services.AddTemplate("MainWindow"); } - services.AddScoped>>(provider => - new ProxyService>(provider.GetRequiredService>())); - services.AddHandler(); services.AddTransient(provider => Component.Create(provider, args => @@ -60,7 +57,7 @@ public partial class App : Application services.AddCache>(); services.AddTransient(_ => - provider.GetRequiredService>>()); + provider.GetServices>()); services.AddTransient(); services.AddTransient(); @@ -112,12 +109,12 @@ public partial class App : Application services.AddTemplate("LockerItemCategoryCollection"); services.AddTemplate(); - services.AddHandler(); + services.AddHandler(); services.AddTemplate(); services.AddTemplate("Item"); - services.AddHandler(); + services.AddHandler(); services.AddTemplate("ItemCommandHeader"); diff --git a/Bitvault/AggerateItemViewModelHandler.cs b/Bitvault/AggerateItemContentViewModelHandler.cs similarity index 85% rename from Bitvault/AggerateItemViewModelHandler.cs rename to Bitvault/AggerateItemContentViewModelHandler.cs index 58d5687..caec2e0 100644 --- a/Bitvault/AggerateItemViewModelHandler.cs +++ b/Bitvault/AggerateItemContentViewModelHandler.cs @@ -2,7 +2,7 @@ namespace Bitvault; -public class AggerateItemViewModelHandler(IValueStore> valueStore, +public class AggerateItemContentViewModelHandler(IValueStore> valueStore, IMediator mediator, IServiceFactory serviceFactory, IPublisher publisher) : diff --git a/Bitvault/AggerateLockerCategoryViewModelHandler.cs b/Bitvault/AggerateLockerCategoryViewModelHandler.cs deleted file mode 100644 index a4a551b..0000000 --- a/Bitvault/AggerateLockerCategoryViewModelHandler.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Toolkit.Foundation; - -namespace Bitvault; - -public class AggerateLockerCategoryViewModelHandler(IProxyService> proxyConfigurations, - IServiceFactory serviceFactory, - IPublisher publisher) : - INotificationHandler> -{ - public Task Handle(AggerateEventArgs args) - { - if (proxyConfigurations.Value is IEnumerable configurations) - { - foreach (ItemConfiguration configuration in configurations) - { - if (serviceFactory.Create(configuration.Name) - is ItemCategoryNavigationViewModel viewModel) - { - publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel)); - } - } - } - - return Task.CompletedTask; - } -} diff --git a/Bitvault/AggerateLockerItemCategoryViewModelHandler.cs b/Bitvault/AggerateLockerItemCategoryViewModelHandler.cs new file mode 100644 index 0000000..6ca4a5f --- /dev/null +++ b/Bitvault/AggerateLockerItemCategoryViewModelHandler.cs @@ -0,0 +1,23 @@ +using Toolkit.Foundation; + +namespace Bitvault; + +public class AggerateLockerItemCategoryViewModelHandler(IEnumerable> descriptors, + IServiceFactory serviceFactory, + IPublisher publisher) : + INotificationHandler> +{ + public Task Handle(AggerateEventArgs args) + { + foreach (IConfigurationDescriptor descriptor in descriptors) + { + if (serviceFactory.Create(descriptor.Name) + is ItemCategoryNavigationViewModel viewModel) + { + publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel)); + } + } + + return Task.CompletedTask; + } +} diff --git a/Bitvault/AggerateMainViewModelHandler.cs b/Bitvault/AggerateMainViewModelHandler.cs index d909baf..b0cee6c 100644 --- a/Bitvault/AggerateMainViewModelHandler.cs +++ b/Bitvault/AggerateMainViewModelHandler.cs @@ -9,14 +9,14 @@ public class AggerateMainViewModelHandler(IPublisher publisher, { public Task Handle(AggerateEventArgs args) { - foreach (IComponentHost locker in lockers.OrderBy(x => x.GetConfiguration() - is LockerConfiguration configuration ? configuration.Name : null)) + foreach (IComponentHost locker in lockers.OrderBy(x => x.Services.GetRequiredService>() + is IConfigurationDescriptor descriptor ? descriptor.Name : null)) { - if (locker.Services.GetRequiredService() is LockerConfiguration configuration) + if (locker.Services.GetRequiredService>() is IConfigurationDescriptor descriptor) { if (locker.Services.GetRequiredService() is IServiceFactory factory) { - if (factory.Create(configuration.Name) is LockerNavigationViewModel viewModel) + if (factory.Create(descriptor.Name) is LockerNavigationViewModel viewModel) { publisher.Publish(Create.As(viewModel), nameof(MainViewModel)); diff --git a/Bitvault/ArchiveItemHandler.cs b/Bitvault/ArchiveItemHandler.cs index 363e315..c2fbf57 100644 --- a/Bitvault/ArchiveItemHandler.cs +++ b/Bitvault/ArchiveItemHandler.cs @@ -5,9 +5,9 @@ namespace Bitvault; public class ArchiveItemHandler(IValueStore> valueStore, ICache> cache, IMediator mediator) : - INotificationHandler>> + INotificationHandler> { - public async Task Handle(ArchiveEventArgs> args) + public async Task Handle(ArchiveEventArgs args) { try { diff --git a/Bitvault/ConfirmItemHandler.cs b/Bitvault/ConfirmItemHandler.cs index fc537d2..769fddc 100644 --- a/Bitvault/ConfirmItemHandler.cs +++ b/Bitvault/ConfirmItemHandler.cs @@ -5,11 +5,11 @@ namespace Bitvault; public class ConfirmItemHandler(IValueStore> valueStore, IMediator mediator, IPublisher publisher) : - INotificationHandler>> + INotificationHandler> { - public async Task Handle(ConfirmEventArgs> args) + public async Task Handle(ConfirmEventArgs args) { - ItemHeaderConfiguration? configuration = await mediator.Handle>, + ItemHeaderConfiguration? configuration = await mediator.Handle, ItemHeaderConfiguration>(args); if (configuration is not null) @@ -27,16 +27,16 @@ public class ConfirmItemHandler(IValueStore> valueStore, valueStore.Set(newItem); - await mediator.Handle, bool>(new UpdateEventArgs<(Guid, - ItemConfiguration)>((id, new ItemConfiguration { Name = name }))); + await mediator.Handle, bool>(new UpdateEventArgs<(Guid, string, + ItemConfiguration)>((id, name, new ItemConfiguration()))); } else { Guid id = Guid.NewGuid(); string? name = configuration.Name; - bool Success = await mediator.Handle, bool>(new CreateEventArgs<(Guid, ItemConfiguration)>((id, new ItemConfiguration { Name = name }))); + bool Success = await mediator.Handle, bool>(new CreateEventArgs<(Guid, string, ItemConfiguration)>((id, name, new ItemConfiguration()))); if (Success) { diff --git a/Bitvault/CreateItemHandler.cs b/Bitvault/CreateItemHandler.cs index effbaa7..ff139ab 100644 --- a/Bitvault/CreateItemHandler.cs +++ b/Bitvault/CreateItemHandler.cs @@ -6,17 +6,15 @@ using Toolkit.Foundation; namespace Bitvault; public class CreateItemHandler(IDbContextFactory dbContextFactory) : - IHandler, bool> + IHandler, bool> { - public async Task Handle(CreateEventArgs<(Guid, ItemConfiguration)> args, + public async Task Handle(CreateEventArgs<(Guid, string, ItemConfiguration)> args, CancellationToken cancellationToken) { - if (args.Value is (Guid id, ItemConfiguration configuration)) + if (args.Value is (Guid id, string name, ItemConfiguration configuration)) { try { - string? name = configuration.Name; - using LockerContext context = dbContextFactory.CreateDbContext(); EntityEntry? result = null; diff --git a/Bitvault/FavouriteItemHandler.cs b/Bitvault/FavouriteItemHandler.cs index 7bcd6ba..09cefbf 100644 --- a/Bitvault/FavouriteItemHandler.cs +++ b/Bitvault/FavouriteItemHandler.cs @@ -4,9 +4,9 @@ namespace Bitvault; public class FavouriteItemHandler(IValueStore> valueStore, IMediator mediator) : - INotificationHandler>> + INotificationHandler> { - public async Task Handle(FavouriteEventArgs> args) + public async Task Handle(FavouriteEventArgs args) { try { diff --git a/Bitvault/ItemCategory.cs b/Bitvault/ItemCategory.cs new file mode 100644 index 0000000..de56c6b --- /dev/null +++ b/Bitvault/ItemCategory.cs @@ -0,0 +1,5 @@ +namespace Bitvault; + +public record ItemCategory(TValue Value); + +public record ItemCategory; \ No newline at end of file diff --git a/Bitvault/ItemCategoryCollectionViewModel.cs b/Bitvault/ItemCategoryCollectionViewModel.cs index 60b8289..de0dc7d 100644 --- a/Bitvault/ItemCategoryCollectionViewModel.cs +++ b/Bitvault/ItemCategoryCollectionViewModel.cs @@ -2,6 +2,7 @@ using Toolkit.Foundation; namespace Bitvault; + [Aggerate(nameof(ItemCategoryCollectionViewModel))] public partial class ItemCategoryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, diff --git a/Bitvault/ItemConfiguration.cs b/Bitvault/ItemConfiguration.cs index dd4cb2e..e1699fb 100644 --- a/Bitvault/ItemConfiguration.cs +++ b/Bitvault/ItemConfiguration.cs @@ -2,16 +2,10 @@ public record ItemConfiguration { - public string Name { get; set; } = ""; - public IList? Sections { get; set; } - - - public static ItemConfiguration Identity => new() { - Name = "Identity", Sections = new List { @@ -20,7 +14,6 @@ public record ItemConfiguration public static ItemConfiguration BankAccount => new() { - Name = "Bank Account", Sections = new List { @@ -29,7 +22,6 @@ public record ItemConfiguration public static ItemConfiguration Note => new() { - Name = "Note", Sections = new List { @@ -39,7 +31,6 @@ public record ItemConfiguration public static ItemConfiguration Document => new() { - Name = "Document", Sections = new List { @@ -48,7 +39,6 @@ public record ItemConfiguration public static ItemConfiguration DrivingLicence => new() { - Name = "Driving Licence", Sections = new List { @@ -58,7 +48,6 @@ public record ItemConfiguration public static ItemConfiguration Login => new() { - Name = "Login", Sections = new List { @@ -67,7 +56,6 @@ public record ItemConfiguration public static ItemConfiguration Password => new() { - Name = "Password", Sections = new List { @@ -76,7 +64,6 @@ public record ItemConfiguration public static ItemConfiguration CreditCard => new() { - Name = "Credit Card", Sections = new List { new() diff --git a/Bitvault/ItemContentViewModel.cs b/Bitvault/ItemContentViewModel.cs index 716c01e..a31656c 100644 --- a/Bitvault/ItemContentViewModel.cs +++ b/Bitvault/ItemContentViewModel.cs @@ -5,8 +5,8 @@ namespace Bitvault; [Aggerate(nameof(ItemContentViewModel))] public partial class ItemContentViewModel : ObservableCollection, - - IItemEntryViewModel + IItemEntryViewModel, + INotificationHandler>> { public ItemContentViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, @@ -20,4 +20,9 @@ public partial class ItemContentViewModel : } public IContentTemplate Template { get; set; } + + public Task Handle(NotifyEventArgs> args) + { + throw new NotImplementedException(); + } } diff --git a/Bitvault/ItemViewModel.cs b/Bitvault/ItemViewModel.cs index 93fec30..aaf5064 100644 --- a/Bitvault/ItemViewModel.cs +++ b/Bitvault/ItemViewModel.cs @@ -8,6 +8,7 @@ public partial class ItemViewModel : INotificationHandler>, INotificationHandler>, INotificationHandler> + { [ObservableProperty] private bool archived; diff --git a/Bitvault/LockerActivatedHandler.cs b/Bitvault/LockerActivatedHandler.cs index 02b71bf..b3cab94 100644 --- a/Bitvault/LockerActivatedHandler.cs +++ b/Bitvault/LockerActivatedHandler.cs @@ -12,15 +12,16 @@ public class LockerActivatedHandler(ILockerHostCollection lockers, if (args.Value is IComponentHost locker) { List sortedLockers = [.. lockers, locker]; - sortedLockers = [.. sortedLockers.OrderBy(x => x.GetConfiguration() is LockerConfiguration configuration ? configuration.Name : null)]; + sortedLockers = [.. sortedLockers.OrderBy(x => x.Services.GetRequiredService>() is + IConfigurationDescriptor descriptor ? descriptor.Name : null)]; int index = sortedLockers.IndexOf(locker); - if (locker.Services.GetRequiredService() is LockerConfiguration configuration) + if (locker.Services.GetRequiredService>() is ConfigurationDescriptor descriptor) { if (locker.Services.GetRequiredService() is IServiceFactory serviceFactory) { - if (serviceFactory.Create(configuration.Name) is LockerNavigationViewModel viewModel) + if (serviceFactory.Create(descriptor.Name) is LockerNavigationViewModel viewModel) { publisher.Publish(new InsertEventArgs(index, viewModel), nameof(MainViewModel)); diff --git a/Bitvault/LockerConfiguration.cs b/Bitvault/LockerConfiguration.cs index 6f5a83f..098fd88 100644 --- a/Bitvault/LockerConfiguration.cs +++ b/Bitvault/LockerConfiguration.cs @@ -5,7 +5,5 @@ namespace Bitvault; public record LockerConfiguration : ComponentConfiguration { - public string? Name { get; set; } - public string? Key { get; set; } } \ No newline at end of file diff --git a/Bitvault/LockerFactory.cs b/Bitvault/LockerFactory.cs index 24de798..4cdd1e1 100644 --- a/Bitvault/LockerFactory.cs +++ b/Bitvault/LockerFactory.cs @@ -7,8 +7,7 @@ public class LockerFactory(IComponentFactory componentFactory) : { public IComponentHost? Create(string name) { - if (componentFactory.Create($"Locker:{name}", - new LockerConfiguration { Name = name }) is IComponentHost host) + if (componentFactory.Create($"Locker:{name}", new LockerConfiguration()) is IComponentHost host) { return host; } diff --git a/Bitvault/LockerStorageFactory.cs b/Bitvault/LockerStorageFactory.cs index d1d7729..ba6868b 100644 --- a/Bitvault/LockerStorageFactory.cs +++ b/Bitvault/LockerStorageFactory.cs @@ -15,7 +15,7 @@ public class LockerStorageFactory(IValueStore connection, SecurityKey key) { connection.Set(new LockerConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" + - $".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}")); + $".vault;Mode=ReadWriteCreate;Pooling=true;Password={Convert.ToBase64String(key.DecryptedKey)}")); IDbContextFactory dbContextFactory = provider.GetRequiredService>(); using LockerContext context = await dbContextFactory.CreateDbContextAsync(); diff --git a/Bitvault/OpenLockerHandler.cs b/Bitvault/OpenLockerHandler.cs index b175c40..92bb135 100644 --- a/Bitvault/OpenLockerHandler.cs +++ b/Bitvault/OpenLockerHandler.cs @@ -3,7 +3,7 @@ using Toolkit.Foundation; namespace Bitvault; -public class OpenLockerHandler(LockerConfiguration configuration, +public class OpenLockerHandler(IConfigurationDescriptor descriptor, ISecurityKeyFactory securityKeyFactory, ILockerStorageFactory lockerStorageFactory) : IHandler, bool> @@ -11,8 +11,9 @@ public class OpenLockerHandler(LockerConfiguration configuration, public async Task Handle(ActivateEventArgs args, CancellationToken cancellationToken) { - if (args.Value is Locker locker && configuration.Name is { Length: > 0 } name && locker.Password is { Length: > 0 } password) + if (args.Value is Locker locker && descriptor.Name is { Length: > 0 } name && locker.Password is { Length: > 0 } password) { + LockerConfiguration configuration = descriptor.Value; if (configuration.Key?.Split(':') is { Length: >= 2 } keyPart) { byte[]? salt = Convert.FromBase64String(keyPart[0]); diff --git a/Bitvault/UnarchiveItemHandler.cs b/Bitvault/UnarchiveItemHandler.cs index d808cec..b156956 100644 --- a/Bitvault/UnarchiveItemHandler.cs +++ b/Bitvault/UnarchiveItemHandler.cs @@ -6,9 +6,9 @@ namespace Bitvault; public class UnarchiveItemHandler(IValueStore> valueStore, IDbContextFactory dbContextFactory) : - INotificationHandler>> + INotificationHandler> { - public async Task Handle(UnarchiveEventArgs> args) + public async Task Handle(UnarchiveEventArgs args) { try { diff --git a/Bitvault/UnfavouriteItemHandler.cs b/Bitvault/UnfavouriteItemHandler.cs index e8d3de6..420d6e5 100644 --- a/Bitvault/UnfavouriteItemHandler.cs +++ b/Bitvault/UnfavouriteItemHandler.cs @@ -3,9 +3,9 @@ namespace Bitvault; public class UnfavouriteItemHandler(IValueStore> valueStore, IMediator mediator) : - INotificationHandler>> + INotificationHandler> { - public async Task Handle(UnfavouriteEventArgs> args) + public async Task Handle(UnfavouriteEventArgs args) { try { diff --git a/Bitvault/UpdateItemHander.cs b/Bitvault/UpdateItemHander.cs index ccdb1c2..6dc36f8 100644 --- a/Bitvault/UpdateItemHander.cs +++ b/Bitvault/UpdateItemHander.cs @@ -5,16 +5,15 @@ using Toolkit.Foundation; namespace Bitvault; public class UpdateItemHander(IDbContextFactory dbContextFactory) : - IHandler, bool> + IHandler, bool> { - public async Task Handle(UpdateEventArgs<(Guid, ItemConfiguration)> args, + public async Task Handle(UpdateEventArgs<(Guid, string, ItemConfiguration)> args, CancellationToken cancellationToken) { - if (args.Value is (Guid id, ItemConfiguration configuration)) + if (args.Value is (Guid id, string name, ItemConfiguration configuration)) { try { - string? name = configuration.Name; using LockerContext context = dbContextFactory.CreateDbContext(); ItemEntry? result = null;