wip
This commit is contained in:
@@ -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<ItemConfiguration>("Item:Driving Licence", ItemConfiguration.DrivingLicence)
|
||||
.AddConfiguration<ItemConfiguration>("Item:Identity", ItemConfiguration.Identity)
|
||||
.AddConfiguration<ItemConfiguration>("Item:Login", ItemConfiguration.Login)
|
||||
.AddConfiguration<ItemConfiguration>("Item:Note", ItemConfiguration.Note)
|
||||
.AddConfiguration<ItemConfiguration>("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<MainWindowViewModel, MainWindow>("MainWindow");
|
||||
}
|
||||
|
||||
services.AddScoped<IProxyService<IEnumerable<ItemConfiguration>>>(provider =>
|
||||
new ProxyService<IEnumerable<ItemConfiguration>>(provider.GetRequiredService<IEnumerable<ItemConfiguration>>()));
|
||||
|
||||
services.AddHandler<LockerActivatedHandler>();
|
||||
|
||||
services.AddTransient<ILockerComponent>(provider => Component.Create<LockerComponent>(provider, args =>
|
||||
@@ -60,7 +57,7 @@ public partial class App : Application
|
||||
services.AddCache<Item<(Guid, string)>>();
|
||||
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IEnumerable<ItemConfiguration>>>());
|
||||
provider.GetServices<IConfigurationDescriptor<ItemConfiguration>>());
|
||||
|
||||
services.AddTransient<IKeyGenerator, KeyGenerator>();
|
||||
services.AddTransient<IEncryptor, AesEncryptor>();
|
||||
@@ -112,12 +109,12 @@ public partial class App : Application
|
||||
services.AddTemplate<ItemCategoryCollectionViewModel, ItemCategoryCollectionView>("LockerItemCategoryCollection");
|
||||
services.AddTemplate<ItemCategoryNavigationViewModel, ItemCategoryNavigationView>();
|
||||
|
||||
services.AddHandler<AggerateLockerCategoryViewModelHandler>();
|
||||
services.AddHandler<AggerateLockerItemCategoryViewModelHandler>();
|
||||
|
||||
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
|
||||
services.AddTemplate<ItemViewModel, ItemView>("Item");
|
||||
|
||||
services.AddHandler<AggerateItemViewModelHandler>();
|
||||
services.AddHandler<AggerateItemContentViewModelHandler>();
|
||||
|
||||
services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader");
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateItemViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
public class AggerateItemContentViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
@@ -1,26 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateLockerCategoryViewModelHandler(IProxyService<IEnumerable<ItemConfiguration>> proxyConfigurations,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args)
|
||||
{
|
||||
if (proxyConfigurations.Value is IEnumerable<ItemConfiguration> configurations)
|
||||
{
|
||||
foreach (ItemConfiguration configuration in configurations)
|
||||
{
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(configuration.Name)
|
||||
is ItemCategoryNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateLockerItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args)
|
||||
{
|
||||
foreach (IConfigurationDescriptor<ItemConfiguration> descriptor in descriptors)
|
||||
{
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name)
|
||||
is ItemCategoryNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,14 @@ public class AggerateMainViewModelHandler(IPublisher publisher,
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<IMainNavigationViewModel> args)
|
||||
{
|
||||
foreach (IComponentHost locker in lockers.OrderBy(x => x.GetConfiguration<LockerConfiguration>()
|
||||
is LockerConfiguration configuration ? configuration.Name : null))
|
||||
foreach (IComponentHost locker in lockers.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<LockerConfiguration>>()
|
||||
is IConfigurationDescriptor<LockerConfiguration> descriptor ? descriptor.Name : null))
|
||||
{
|
||||
if (locker.Services.GetRequiredService<LockerConfiguration>() is LockerConfiguration configuration)
|
||||
if (locker.Services.GetRequiredService<IConfigurationDescriptor<LockerConfiguration>>() is IConfigurationDescriptor<LockerConfiguration> descriptor)
|
||||
{
|
||||
if (locker.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
if (factory.Create<LockerNavigationViewModel>(configuration.Name) is LockerNavigationViewModel viewModel)
|
||||
if (factory.Create<LockerNavigationViewModel>(descriptor.Name) is LockerNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
|
||||
nameof(MainViewModel));
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Bitvault;
|
||||
public class ArchiveItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<ArchiveEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<ArchiveEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ArchiveEventArgs<Item<(Guid, string)>> args)
|
||||
public async Task Handle(ArchiveEventArgs<Item> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace Bitvault;
|
||||
public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item<(Guid, string)>> args)
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item<(Guid, string)>>,
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
|
||||
if (configuration is not null)
|
||||
@@ -27,16 +27,16 @@ public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
|
||||
valueStore.Set(newItem);
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid,
|
||||
ItemConfiguration)>((id, new ItemConfiguration { Name = name })));
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid, string,
|
||||
ItemConfiguration)>((id, name, new ItemConfiguration())));
|
||||
}
|
||||
else
|
||||
{
|
||||
Guid id = Guid.NewGuid();
|
||||
string? name = configuration.Name;
|
||||
|
||||
bool Success = await mediator.Handle<CreateEventArgs<(Guid,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, ItemConfiguration)>((id, new ItemConfiguration { Name = name })));
|
||||
bool Success = await mediator.Handle<CreateEventArgs<(Guid, string,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, ItemConfiguration)>((id, name, new ItemConfiguration())));
|
||||
|
||||
if (Success)
|
||||
{
|
||||
|
||||
@@ -6,17 +6,15 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory) :
|
||||
IHandler<CreateEventArgs<(Guid, ItemConfiguration)>, bool>
|
||||
IHandler<CreateEventArgs<(Guid, string, ItemConfiguration)>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(CreateEventArgs<(Guid, ItemConfiguration)> args,
|
||||
public async Task<bool> 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<ItemEntry>? result = null;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace Bitvault;
|
||||
|
||||
public class FavouriteItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<FavouriteEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<FavouriteEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(FavouriteEventArgs<Item<(Guid, string)>> args)
|
||||
public async Task Handle(FavouriteEventArgs<Item> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record ItemCategory<TValue>(TValue Value);
|
||||
|
||||
public record ItemCategory;
|
||||
@@ -2,6 +2,7 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(ItemCategoryCollectionViewModel))]
|
||||
public partial class ItemCategoryCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
|
||||
@@ -2,16 +2,10 @@
|
||||
|
||||
public record ItemConfiguration
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
|
||||
public IList<ItemSectionConfiguration>? Sections { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
public static ItemConfiguration Identity => new()
|
||||
{
|
||||
Name = "Identity",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -20,7 +14,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration BankAccount => new()
|
||||
{
|
||||
Name = "Bank Account",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -29,7 +22,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration Note => new()
|
||||
{
|
||||
Name = "Note",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -39,7 +31,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration Document => new()
|
||||
{
|
||||
Name = "Document",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -48,7 +39,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration DrivingLicence => new()
|
||||
{
|
||||
Name = "Driving Licence",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -58,7 +48,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration Login => new()
|
||||
{
|
||||
Name = "Login",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -67,7 +56,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration Password => new()
|
||||
{
|
||||
Name = "Password",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
@@ -76,7 +64,6 @@ public record ItemConfiguration
|
||||
|
||||
public static ItemConfiguration CreditCard => new()
|
||||
{
|
||||
Name = "Credit Card",
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
new()
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace Bitvault;
|
||||
[Aggerate(nameof(ItemContentViewModel))]
|
||||
public partial class ItemContentViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
|
||||
IItemEntryViewModel
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>
|
||||
{
|
||||
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<ItemCategory<string>> args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ public partial class ItemViewModel :
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool archived;
|
||||
|
||||
@@ -12,15 +12,16 @@ public class LockerActivatedHandler(ILockerHostCollection lockers,
|
||||
if (args.Value is IComponentHost locker)
|
||||
{
|
||||
List<IComponentHost> sortedLockers = [.. lockers, locker];
|
||||
sortedLockers = [.. sortedLockers.OrderBy(x => x.GetConfiguration<LockerConfiguration>() is LockerConfiguration configuration ? configuration.Name : null)];
|
||||
sortedLockers = [.. sortedLockers.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<LockerConfiguration>>() is
|
||||
IConfigurationDescriptor<LockerConfiguration> descriptor ? descriptor.Name : null)];
|
||||
|
||||
int index = sortedLockers.IndexOf(locker);
|
||||
|
||||
if (locker.Services.GetRequiredService<LockerConfiguration>() is LockerConfiguration configuration)
|
||||
if (locker.Services.GetRequiredService<ConfigurationDescriptor<LockerConfiguration>>() is ConfigurationDescriptor<LockerConfiguration> descriptor)
|
||||
{
|
||||
if (locker.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
|
||||
{
|
||||
if (serviceFactory.Create<LockerNavigationViewModel>(configuration.Name) is LockerNavigationViewModel viewModel)
|
||||
if (serviceFactory.Create<LockerNavigationViewModel>(descriptor.Name) is LockerNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
|
||||
nameof(MainViewModel));
|
||||
|
||||
@@ -5,7 +5,5 @@ namespace Bitvault;
|
||||
public record LockerConfiguration :
|
||||
ComponentConfiguration
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string? Key { get; set; }
|
||||
}
|
||||
@@ -7,8 +7,7 @@ public class LockerFactory(IComponentFactory componentFactory) :
|
||||
{
|
||||
public IComponentHost? Create(string name)
|
||||
{
|
||||
if (componentFactory.Create<ILockerComponent, LockerConfiguration>($"Locker:{name}",
|
||||
new LockerConfiguration { Name = name }) is IComponentHost host)
|
||||
if (componentFactory.Create<ILockerComponent, LockerConfiguration>($"Locker:{name}", new LockerConfiguration()) is IComponentHost host)
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class LockerStorageFactory(IValueStore<LockerConnection> 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<LockerContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<LockerContext>>();
|
||||
using LockerContext context = await dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class OpenLockerHandler(LockerConfiguration configuration,
|
||||
public class OpenLockerHandler(IConfigurationDescriptor<LockerConfiguration> descriptor,
|
||||
ISecurityKeyFactory securityKeyFactory,
|
||||
ILockerStorageFactory lockerStorageFactory) :
|
||||
IHandler<ActivateEventArgs<Locker>, bool>
|
||||
@@ -11,8 +11,9 @@ public class OpenLockerHandler(LockerConfiguration configuration,
|
||||
public async Task<bool> Handle(ActivateEventArgs<Locker> 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]);
|
||||
|
||||
@@ -6,9 +6,9 @@ namespace Bitvault;
|
||||
|
||||
public class UnarchiveItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IDbContextFactory<LockerContext> dbContextFactory) :
|
||||
INotificationHandler<UnarchiveEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(UnarchiveEventArgs<Item<(Guid, string)>> args)
|
||||
public async Task Handle(UnarchiveEventArgs<Item> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace Bitvault;
|
||||
public class UnfavouriteItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<UnfavouriteEventArgs<Item<(Guid, string)>>>
|
||||
INotificationHandler<UnfavouriteEventArgs<Item>>
|
||||
{
|
||||
public async Task Handle(UnfavouriteEventArgs<Item<(Guid, string)>> args)
|
||||
public async Task Handle(UnfavouriteEventArgs<Item> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -5,16 +5,15 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class UpdateItemHander(IDbContextFactory<LockerContext> dbContextFactory) :
|
||||
IHandler<UpdateEventArgs<(Guid, ItemConfiguration)>, bool>
|
||||
IHandler<UpdateEventArgs<(Guid, string, ItemConfiguration)>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(UpdateEventArgs<(Guid, ItemConfiguration)> args,
|
||||
public async Task<bool> 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user