Add supported for key mediator handelrs
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggregateItemCategoryViewModelHandler(IEnumerable<IConfigurationDescriptor<ItemConfiguration>> descriptors,
|
||||
public class AggregateItemCategoryViewModelHandler(IItemConfigurationCollection configurations,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<ItemCategoryNavigationViewModel>>
|
||||
@@ -10,9 +10,9 @@ public class AggregateItemCategoryViewModelHandler(IEnumerable<IConfigurationDes
|
||||
public Task Handle(AggerateEventArgs<ItemCategoryNavigationViewModel> args)
|
||||
{
|
||||
bool selected = true;
|
||||
foreach (IConfigurationDescriptor<ItemConfiguration> descriptor in descriptors)
|
||||
foreach (KeyValuePair<string, Func<ItemConfiguration>> configuration in configurations)
|
||||
{
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(descriptor.Name, selected)
|
||||
if (serviceFactory.Create<ItemCategoryNavigationViewModel>(configuration.Key, selected)
|
||||
is ItemCategoryNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(Create.As(viewModel), nameof(ItemCategoryCollectionViewModel));
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggregateItemContentFromCategoryViewModelHandler(IItemConfigurationCollection configurations,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<IItemEntryViewModel, string>>
|
||||
{
|
||||
public async Task Handle(AggerateEventArgs<IItemEntryViewModel, string> args)
|
||||
{
|
||||
if (args.Value is string category)
|
||||
{
|
||||
if (configurations.TryGetValue(category, out Func<ItemConfiguration>? factory))
|
||||
{
|
||||
if (factory.Invoke() is ItemConfiguration configuration)
|
||||
{
|
||||
foreach (ItemSectionConfiguration section in configuration.Sections)
|
||||
{
|
||||
foreach (ItemEntryConfiguration entryConfiguration in section.Entries)
|
||||
{
|
||||
var dod = await mediator.Handle<ItemEntryConfiguration, IItemEntryViewModel?>(entryConfiguration,
|
||||
entryConfiguration.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggregateItemContentViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator,
|
||||
public class AggregateItemContentViewModelHandler(IMediator mediator,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<IItemEntryViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<IItemEntryViewModel> args)
|
||||
{
|
||||
var d = valueStore;
|
||||
//if (serviceFactory.Create<ItemHeaderViewModel>(false) is ItemHeaderViewModel viewModel)
|
||||
//wModel>(false) is ItemHeaderViewModel viewModel)
|
||||
//{
|
||||
// publisher.Publish(Create.As<IItemEntryViewModel>(viewModel), nameof(ItemViewModel));
|
||||
//}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,32 +8,31 @@ public class AggerateItemViewModelHandler(IMediator mediator,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher,
|
||||
LockerViewModelConfiguration dd) :
|
||||
INotificationHandler<AggregateEventArgs<ItemNavigationViewModel,
|
||||
INotificationHandler<AggerateEventArgs<ItemNavigationViewModel,
|
||||
LockerViewModelConfiguration>>
|
||||
{
|
||||
public async Task Handle(AggregateEventArgs<ItemNavigationViewModel,
|
||||
public async Task Handle(AggerateEventArgs<ItemNavigationViewModel,
|
||||
LockerViewModelConfiguration> args)
|
||||
{
|
||||
var ddddd = dd;
|
||||
if (args.Options is LockerViewModelConfiguration configuration)
|
||||
if (args.Value is LockerViewModelConfiguration configuration)
|
||||
{
|
||||
cache.Clear();
|
||||
bool selected = true;
|
||||
|
||||
if (await mediator.Handle<RequestEventArgs<QueryLockerConfiguration>,
|
||||
IReadOnlyCollection<(Guid Id, string Name, bool Favourite, bool Archived)>>(Request.As(new QueryLockerConfiguration
|
||||
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>>(Request.As(new QueryLockerConfiguration
|
||||
{
|
||||
Filter = configuration.Filter,
|
||||
Query = configuration.Query
|
||||
})) is IReadOnlyCollection<(Guid Id, string Name, bool Favourite, bool Archived)> results)
|
||||
})) is IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)> results)
|
||||
{
|
||||
foreach ((Guid Id, string Name, bool Favourite, bool Archived) in results)
|
||||
foreach ((Guid Id, string Name, string Category, bool Favourite, bool Archived) in results)
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IValueStore<Item<(Guid, string)>> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item<(Guid, string)>>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(Id, Name, "Description", selected, Favourite, Archived) is ItemNavigationViewModel viewModel)
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(Id, Name, "Description", Category, selected, Favourite, Archived) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
Item<(Guid, string)> item = new((Id, Name));
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IItemConfigurationCollection :
|
||||
IReadOnlyDictionary<string, Func<ItemConfiguration>>;
|
||||
@@ -1,6 +1,4 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IItemEntryViewModel :
|
||||
IDisposable
|
||||
{
|
||||
}
|
||||
IDisposable;
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(typeof(CreateEventArgs<ItemCategoryNavigationViewModel>), nameof(ItemCategoryCollectionViewModel))]
|
||||
[Notification(typeof(CreateEventArgs<ItemCategoryNavigationViewModel>), nameof(ItemCategoryCollectionViewModel))]
|
||||
public partial class ItemCategoryCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(typeof(AggerateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(AggerateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(CreateEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(InsertEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
[Notification(typeof(MoveToEventArgs<ItemNavigationViewModel>), nameof(ItemCollectionViewModel))]
|
||||
@@ -71,6 +71,6 @@ public partial class ItemCollectionViewModel :
|
||||
return base.OnActivated();
|
||||
}
|
||||
|
||||
protected override AggregateExpression CreateAggregateExpression() =>
|
||||
protected override AggregateExpression BuildAggregateExpression() =>
|
||||
new(Aggregate.As<ItemNavigationViewModel, LockerViewModelConfiguration>(configuration));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
public record ItemConfiguration
|
||||
{
|
||||
public IList<ItemSectionConfiguration>? Sections { get; set; }
|
||||
public IList<ItemSectionConfiguration> Sections { get; set; } = new List<ItemSectionConfiguration>();
|
||||
|
||||
public static ItemConfiguration Identity => new()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemConfigurationCollection(IDictionary<string, Func<ItemConfiguration>> dictionary) :
|
||||
ReadOnlyDictionary<string, Func<ItemConfiguration>>(dictionary),
|
||||
IItemConfigurationCollection;
|
||||
@@ -2,27 +2,29 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
//[Aggerate(nameof(ItemContentViewModel))]
|
||||
public partial class ItemContentViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
public partial class ItemContentViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory, IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
ItemState state = ItemState.Read) :
|
||||
ObservableCollection<IItemEntryViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>
|
||||
{
|
||||
public ItemContentViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory, IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
ItemState state = ItemState.Read) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
|
||||
public Task Handle(NotifyEventArgs<ItemCategory<string>> args)
|
||||
{
|
||||
if (args.Value is ItemCategory<string> category)
|
||||
{
|
||||
if (category.Value is string value)
|
||||
{
|
||||
Fetch(() => new AggregateExpression(new AggerateEventArgs<IItemEntryViewModel, string>(value)), true);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemDropdownEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
@@ -0,0 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemDropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
IHandler<DropdownEntryConfiguration, IItemEntryViewModel?>
|
||||
{
|
||||
public Task<IItemEntryViewModel?> Handle(DropdownEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemDropdownEntryViewModel>() is ItemDropdownEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,7 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>,
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>,
|
||||
IItemEntryViewModel
|
||||
INotificationHandler<NotifyEventArgs<ItemCategory<string>>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? category;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemMaskedTextEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
@@ -0,0 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemMaskedTextEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
IHandler<MaskedTextEntryConfiguration, IItemEntryViewModel?>
|
||||
{
|
||||
public Task<IItemEntryViewModel?> Handle(MaskedTextEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>() is ItemMaskedTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
IContentTemplate template,
|
||||
NamedComponent named,
|
||||
Guid id,
|
||||
string? name = "",
|
||||
string? description = "",
|
||||
string name = "",
|
||||
string description = "",
|
||||
string category = "",
|
||||
bool selected = false,
|
||||
bool favourite = false,
|
||||
bool archived = false) :
|
||||
@@ -30,6 +31,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private bool archived = archived;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? category = category;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? description = description;
|
||||
|
||||
@@ -48,8 +52,8 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private bool selected = selected;
|
||||
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
public bool Attached { get; set; }
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
|
||||
public Task Handle(ArchiveEventArgs<Item> args) =>
|
||||
Task.Run(Dispose);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemPasswordEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
@@ -0,0 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemPasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
IHandler<PasswordEntryConfiguration, IItemEntryViewModel?>
|
||||
{
|
||||
public Task<IItemEntryViewModel?> Handle(PasswordEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemPasswordEntryViewModel>() is ItemPasswordEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemTextEntryViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IItemEntryViewModel;
|
||||
@@ -0,0 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemTextEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||
IHandler<TextEntryConfiguration, IItemEntryViewModel?>
|
||||
{
|
||||
public Task<IItemEntryViewModel?> Handle(TextEntryConfiguration args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (serviceFactory.Create<ItemTextEntryViewModel>() is ItemTextEntryViewModel viewModel)
|
||||
{
|
||||
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||
}
|
||||
|
||||
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace Bitvault;
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.New))]
|
||||
[Notification(typeof(ConfirmEventArgs<Item>), nameof(ItemState.Write))]
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
ObservableCollection,
|
||||
INotificationHandler<UpdateEventArgs<Item>>,
|
||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||
INotificationHandler<CancelEventArgs<Item>>
|
||||
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
||||
[Notification(typeof(CreateEventArgs<IMainNavigationViewModel>), nameof(MainViewModel))]
|
||||
public partial class MainViewModel :
|
||||
ObservableCollection<IMainNavigationViewModel>
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class QueryLockerHandler(IDbContextFactory<LockerContext> dbContextFactory) :
|
||||
IHandler<RequestEventArgs<QueryLockerConfiguration>, IReadOnlyCollection<(Guid Id, string? Name, bool Favourite, bool Archived)>>
|
||||
IHandler<RequestEventArgs<QueryLockerConfiguration>, IReadOnlyCollection<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)>>
|
||||
{
|
||||
public async Task<IReadOnlyCollection<(Guid Id, string? Name, bool Favourite, bool Archived)>> Handle(RequestEventArgs<QueryLockerConfiguration> args,
|
||||
public async Task<IReadOnlyCollection<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)>> Handle(RequestEventArgs<QueryLockerConfiguration> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
List<(Guid Id, string? Name, bool Favourite, bool Archived)> items = [];
|
||||
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
|
||||
|
||||
if (args.Value is QueryLockerConfiguration queryConfiguration)
|
||||
{
|
||||
@@ -47,6 +47,7 @@ public class QueryLockerHandler(IDbContextFactory<LockerContext> dbContextFactor
|
||||
{
|
||||
x.Id,
|
||||
x.Name,
|
||||
x.Category,
|
||||
Favourite = x.State == 1,
|
||||
Archived = x.State == 2
|
||||
}).ToListAsync();
|
||||
@@ -54,7 +55,7 @@ public class QueryLockerHandler(IDbContextFactory<LockerContext> dbContextFactor
|
||||
|
||||
foreach (var result in results.OrderBy(x => x.Name, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
items.Add(new(result.Id, result.Name, result.Favourite, result.Archived));
|
||||
items.Add(new(result.Id, result.Name, result.Category, result.Favourite, result.Archived));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user