Allow subscription keys to be resolved by reflection
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggregateItemContentFromCategoryViewModelHandler(IItemConfigurationCollection configurations,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<IItemEntryViewModel, string>>
|
||||
@@ -15,12 +16,21 @@ public class AggregateItemContentFromCategoryViewModelHandler(IItemConfiguration
|
||||
{
|
||||
if (factory.Invoke() is ItemConfiguration configuration)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
foreach (ItemSectionConfiguration section in configuration.Sections)
|
||||
{
|
||||
foreach (ItemEntryConfiguration entryConfiguration in section.Entries)
|
||||
if (serviceFactory.Create<ItemSectionViewModel>($"{nameof(ItemSection)}{index}") is ItemSectionViewModel sectionViewModel)
|
||||
{
|
||||
var dod = await mediator.Handle<ItemEntryConfiguration, IItemEntryViewModel?>(entryConfiguration,
|
||||
entryConfiguration.GetType().Name);
|
||||
publisher.Publish(Create.As(sectionViewModel), nameof(ItemContentViewModel));
|
||||
foreach (ItemEntryConfiguration entryConfiguration in section.Entries)
|
||||
{
|
||||
if (await mediator.Handle<ItemEntryConfiguration, IItemEntryViewModel?>(entryConfiguration,
|
||||
entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(entryViewModel), $"{nameof(ItemSection)}{index}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,16 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
{
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
string? name = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
string?>(args, nameof(ItemHeader));
|
||||
|
||||
if (configuration is not null)
|
||||
if (name is not null)
|
||||
{
|
||||
publisher.Publish(Notify.As(configuration));
|
||||
|
||||
Guid id = Guid.NewGuid();
|
||||
|
||||
string? name = configuration.Name;
|
||||
string? category = configuration.Name;
|
||||
|
||||
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
|
||||
|
||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, category,
|
||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, ItemConfiguration)>((id, name, "",
|
||||
new ItemConfiguration())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(AggerateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(CreateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(InsertEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(MoveToEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
|
||||
@@ -44,13 +44,25 @@ public record ItemConfiguration
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static ItemConfiguration Login => new()
|
||||
{
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
new()
|
||||
{
|
||||
Entries = new List<ItemEntryConfiguration>
|
||||
{
|
||||
new TextEntryConfiguration
|
||||
{
|
||||
Label = "Username"
|
||||
},
|
||||
new PasswordEntryConfiguration
|
||||
{
|
||||
Label = "Password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,7 +70,16 @@ public record ItemConfiguration
|
||||
{
|
||||
Sections = new List<ItemSectionConfiguration>
|
||||
{
|
||||
|
||||
new()
|
||||
{
|
||||
Entries = new List<ItemEntryConfiguration>
|
||||
{
|
||||
new PasswordEntryConfiguration
|
||||
{
|
||||
Label = "Password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record ItemContent;
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(CreateEventArgs<ItemSectionViewModel>), nameof(ItemContentViewModel))]
|
||||
public partial class ItemContentViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory, IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -9,7 +10,7 @@ public partial class ItemContentViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
ItemState state = ItemState.Read) :
|
||||
ObservableCollection<IItemEntryViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
ObservableCollection<ItemSectionViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ public partial class ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IDisposer disposer,
|
||||
string? key = default,
|
||||
object? value = default) : Observable<string, object?>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ItemDropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
public Task<IItemEntryViewModel?> Handle(DropdownEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>() is ItemDropdownEntryViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>(args.Label, args.Value ?? new object()) is ItemDropdownEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record ItemHeader;
|
||||
@@ -3,9 +3,11 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemHeader))]
|
||||
public partial class ItemHeaderViewModel :
|
||||
Observable<string, string>,
|
||||
IHandler<ValidationEventArgs<Item>, bool>,
|
||||
IHandler<ConfirmEventArgs<Item>, ItemHeaderConfiguration>,
|
||||
IHandler<ConfirmEventArgs<Item>, string?>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>,
|
||||
@@ -38,9 +40,6 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public Task<ItemHeaderConfiguration> Handle(ConfirmEventArgs<Item> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value! });
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args) =>
|
||||
Task.FromResult(State = ItemState.Write);
|
||||
|
||||
@@ -69,4 +68,7 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<string?> Handle(ConfirmEventArgs<Item> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult(Value);
|
||||
}
|
||||
@@ -7,5 +7,7 @@ public partial class ItemMaskedTextEntryViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
IDisposer disposer,
|
||||
string? key = default,
|
||||
object? value = default) : Observable<string, object?>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ItemMaskedTextEntryViewModelHandler(IServiceFactory serviceFactory)
|
||||
public Task<IItemEntryViewModel?> Handle(MaskedTextEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>() is ItemMaskedTextEntryViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>(args.Label, args.Value ?? new object()) is ItemMaskedTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
@@ -7,5 +7,7 @@ public partial class ItemPasswordEntryViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
IDisposer disposer,
|
||||
string? key = default,
|
||||
object? value = default) : Observable<string, object?>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ItemPasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
public Task<IItemEntryViewModel?> Handle(PasswordEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemPasswordEntryViewModel>() is ItemPasswordEntryViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemPasswordEntryViewModel>(args.Label, args.Value ?? new object()) is ItemPasswordEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record ItemSection;
|
||||
@@ -0,0 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(typeof(CreateEventArgs<IItemEntryViewModel>), nameof(Section))]
|
||||
public partial class ItemSectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
string section) : ObservableCollection<IItemEntryViewModel>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string section = section;
|
||||
}
|
||||
@@ -7,5 +7,7 @@ public partial class ItemTextEntryViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
IDisposer disposer,
|
||||
string? key = default,
|
||||
string? value = default) : Observable<string, string>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||
IItemEntryViewModel;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ItemTextEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
public Task<IItemEntryViewModel?> Handle(TextEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemTextEntryViewModel>() is ItemTextEntryViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemTextEntryViewModel>(args.Label, args.Value ?? "") is ItemTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user