Improved event naming
This commit is contained in:
@@ -89,7 +89,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
|
|
||||||
services.AddHandler<ItemConfigurationHandler>();
|
services.AddHandler<CreateItemHandler>();
|
||||||
});
|
});
|
||||||
})!);
|
})!);
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ using Toolkit.Foundation;
|
|||||||
namespace Bitvault.Avalonia;
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
public class AppHandler(IPublisher publisher) :
|
public class AppHandler(IPublisher publisher) :
|
||||||
INotificationHandler<Started>
|
INotificationHandler<StartedEventArgs>
|
||||||
{
|
{
|
||||||
public async Task Handle(Started args, CancellationToken cancellationToken = default)
|
public async Task Handle(StartedEventArgs args, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (Application.Current is Application application)
|
if (Application.Current is Application application)
|
||||||
{
|
{
|
||||||
if (application.ApplicationLifetime is IApplicationLifetime lifetime)
|
if (application.ApplicationLifetime is IApplicationLifetime lifetime)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new Navigate(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
|
await publisher.Publish(new NavigateEventArgs(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
|
||||||
lifetime is IClassicDesktopStyleApplicationLifetime ? typeof(IClassicDesktopStyleApplicationLifetime) :
|
lifetime is IClassicDesktopStyleApplicationLifetime ? typeof(IClassicDesktopStyleApplicationLifetime) :
|
||||||
typeof(ISingleViewApplicationLifetime)), cancellationToken);
|
typeof(ISingleViewApplicationLifetime)), cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -1,3 +1,10 @@
|
|||||||
namespace Bitvault;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
public record Closed;
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record Closed
|
||||||
|
{
|
||||||
|
public static ChangedEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||||
|
|
||||||
|
public static ChangedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record ClosedEventArgs<TValue>(TValue? Value = default);
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public record Container<TValue>(TValue? Value = default);
|
|
||||||
|
|
||||||
public record Container
|
public record Container
|
||||||
{
|
{
|
||||||
public Container(string name, string password)
|
public Container(string name, string password)
|
||||||
@@ -17,10 +15,10 @@ public record Container
|
|||||||
Password = password;
|
Password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Container()
|
||||||
|
{
|
||||||
|
|
||||||
public static Container<TValue> As<TValue>(TValue value) => new(value);
|
}
|
||||||
|
|
||||||
public static Container<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
|
||||||
|
|
||||||
|
|
||||||
[MaybeNull]
|
[MaybeNull]
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContainerActivatedHandler(IContainerHostCollection containers,
|
public class ContainerActivatedHandler(IContainerHostCollection containers,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<Activated<IComponentHost>>
|
INotificationHandler<ActivatedEventArgs<IComponentHost>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Activated<IComponentHost> args, CancellationToken cancellationToken = default)
|
public async Task Handle(ActivatedEventArgs<IComponentHost> args,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (args.Value is IComponentHost container)
|
if (args.Value is IComponentHost container)
|
||||||
{
|
{
|
||||||
@@ -18,15 +20,26 @@ public class ContainerActivatedHandler(IContainerHostCollection containers,
|
|||||||
|
|
||||||
if (container.Services.GetRequiredService<ContainerConfiguration>() is ContainerConfiguration configuration)
|
if (container.Services.GetRequiredService<ContainerConfiguration>() is ContainerConfiguration configuration)
|
||||||
{
|
{
|
||||||
if (container.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
if (container.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
|
||||||
{
|
{
|
||||||
if (factory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
if (serviceFactory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new Insert<IMainNavigationViewModel>(index, viewModel),
|
await publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
|
||||||
nameof(MainViewModel), cancellationToken);
|
nameof(MainViewModel), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ItemActivatedHandler(IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher) :
|
||||||
|
INotificationHandler<ActivatedEventArgs<ItemConfiguration>>
|
||||||
|
{
|
||||||
|
public async Task Handle(ActivatedEventArgs<ItemConfiguration> args,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<string, IDisposable>,
|
public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<string, IDisposable>,
|
||||||
INotificationHandler<Container<Filter<string>>>
|
INotificationHandler<ActivateEventArgs<Filter<string>>>
|
||||||
{
|
{
|
||||||
public ContainerHeaderViewModel(IServiceProvider provider,
|
public ContainerHeaderViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
@@ -20,7 +20,7 @@ public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<st
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public Task Handle(Container<Filter<string>> args,
|
public Task Handle(ActivateEventArgs<Filter<string>> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (args.Value is Filter<string> filter)
|
if (args.Value is Filter<string> filter)
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ namespace Bitvault;
|
|||||||
public partial class ContainerNavigationViewModel :
|
public partial class ContainerNavigationViewModel :
|
||||||
ObservableCollectionViewModel<IContainerNavigationViewModel>,
|
ObservableCollectionViewModel<IContainerNavigationViewModel>,
|
||||||
IMainNavigationViewModel,
|
IMainNavigationViewModel,
|
||||||
INotificationHandler<Container<Opened>>,
|
INotificationHandler<OpenedEventArgs<Container>>,
|
||||||
INotificationHandler<Container<Closed>>,
|
INotificationHandler<ClosedEventArgs<Container>>,
|
||||||
INotificationHandler<Container<Activated>>,
|
INotificationHandler<ActivatedEventArgs<Container>>,
|
||||||
INotificationHandler<Container<Deactivated>>
|
INotificationHandler<DeactivatedEventArgs<Container>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool activated;
|
private bool activated;
|
||||||
@@ -41,7 +41,7 @@ public partial class ContainerNavigationViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public Task Handle(Container<Opened> args,
|
public Task Handle(OpenedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
Add<AllNavigationViewModel>("All");
|
Add<AllNavigationViewModel>("All");
|
||||||
@@ -53,7 +53,7 @@ public partial class ContainerNavigationViewModel :
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(Container<Closed> args,
|
public Task Handle(ClosedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
Opened = true;
|
Opened = true;
|
||||||
@@ -62,11 +62,11 @@ public partial class ContainerNavigationViewModel :
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(Container<Deactivated> args,
|
public Task Handle(DeactivatedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
Task.FromResult(Activated = false);
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
public Task Handle(Container<Activated> args,
|
public Task Handle(ActivatedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
Task.FromResult(Activated = true);
|
Task.FromResult(Activated = true);
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
|||||||
IContentTemplate template,
|
IContentTemplate template,
|
||||||
NamedComponent named,
|
NamedComponent named,
|
||||||
string? filter = null) : ObservableCollectionViewModel<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
string? filter = null) : ObservableCollectionViewModel<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||||
INotificationHandler<Container<Filter<string>>>
|
INotificationHandler<RequestEventArgs<Filter<string>>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string? filter = filter;
|
private string? filter = filter;
|
||||||
@@ -24,19 +24,19 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; } = template;
|
public IContentTemplate Template { get; set; } = template;
|
||||||
|
|
||||||
public override async Task Activated()
|
public override async Task OnActivated()
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Container.As<Activated>());
|
await Publisher.Publish(Activated.As<Container>());
|
||||||
await base.Activated();
|
await base.OnActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Deactivated()
|
public override async Task OnDeactivated()
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Container.As<Deactivated>());
|
await Publisher.Publish(Deactivated.As<Container>());
|
||||||
await base.Deactivated();
|
await base.OnDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(Container<Filter<string>> args,
|
public async Task Handle(RequestEventArgs<Filter<string>> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (args.Value is Filter<string> filter)
|
if (args.Value is Filter<string> filter)
|
||||||
@@ -47,5 +47,5 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerate PrepareEnumeration(object? key) =>
|
protected override IEnumerate PrepareEnumeration(object? key) =>
|
||||||
Enumerate<ItemNavigationViewModel>.With(new ContainerViewModelConfiguration { Filter = Filter }) with { Key = key };
|
EnumerateEventArgs<ItemNavigationViewModel>.With(new ContainerViewModelConfiguration { Filter = Filter }) with { Key = key };
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
await publisher.Publish(new CreateEventArgs<ItemNavigationViewModel>(viewModel),
|
||||||
nameof(ContainerViewModel), cancellationToken);
|
nameof(ContainerViewModel), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public class CreateContainerHandler(IContainerFactory componentFactory,
|
public class CreateContainerHandler(IContainerFactory componentFactory,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
IHandler<Create<Container>, bool>
|
IHandler<CreateEventArgs<Container>, bool>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(Create<Container> args,
|
public async Task<bool> Handle(CreateEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (args.Value is Container container && container.Name is { Length: > 0 } name &&
|
if (args.Value is Container container && container.Name is { Length: > 0 } name &&
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ public partial class CreateContainerViewModel(IServiceProvider provider,
|
|||||||
private string password;
|
private string password;
|
||||||
|
|
||||||
public async Task<bool> Confirm() =>
|
public async Task<bool> Confirm() =>
|
||||||
await Mediator.Handle<Create<Container>, bool>(Create.As(new Container(Name, Password)));
|
await Mediator.Handle<CreateEventArgs<Container>, bool>(Create.As(new Container(Name, Password)));
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ using Toolkit.Foundation;
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ItemConfigurationHandler(IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory, IPublisher publisher) :
|
||||||
IHandler<Create<ItemConfiguration>, bool>
|
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(Create<ItemConfiguration> args,
|
public async Task<bool> Handle(CreateEventArgs<ItemConfiguration> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (args.Value is ItemConfiguration configuration)
|
if (args.Value is ItemConfiguration configuration)
|
||||||
@@ -19,8 +19,10 @@ public class ItemConfigurationHandler(IDbContextFactory<ContainerDbContext> dbCo
|
|||||||
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||||
await context.AddAsync(new Data.Item { Name = configuration.Name }, cancellationToken);
|
await context.AddAsync(new Data.Item { Name = configuration.Name }, cancellationToken);
|
||||||
await context.SaveChangesAsync(cancellationToken);
|
await context.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
|
|
||||||
|
await publisher.Publish(Activated.As(configuration));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -6,8 +6,8 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public partial class FilterContainerNavigationViewModel : ObservableViewModel,
|
public partial class FilterContainerNavigationViewModel : ObservableViewModel,
|
||||||
IContainerNavigationViewModel,
|
IContainerNavigationViewModel,
|
||||||
INotificationHandler<Container<Activated>>,
|
INotificationHandler<ActivatedEventArgs<Container>>,
|
||||||
INotificationHandler<Container<Deactivated>>
|
INotificationHandler<DeactivatedEventArgs<Container>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool activated;
|
private bool activated;
|
||||||
@@ -29,14 +29,14 @@ public partial class FilterContainerNavigationViewModel : ObservableViewModel,
|
|||||||
Filter = filter;
|
Filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(Container<Deactivated> args,
|
public Task Handle(DeactivatedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
Task.FromResult(Activated = false);
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
public Task Handle(Container<Activated> args,
|
public Task Handle(ActivatedEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken = default) =>
|
CancellationToken cancellationToken = default) =>
|
||||||
Task.FromResult(Activated = true);
|
Task.FromResult(Activated = true);
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Container.As(new Filter<string>(Filter)));
|
public async Task Invoke() => await Publisher.Publish(Request.As(new Filter<string>(Filter)));
|
||||||
}
|
}
|
||||||
+21
-1
@@ -1,3 +1,23 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public record Item;
|
public record Item<TValue>(TValue? Value = default);
|
||||||
|
|
||||||
|
public record Item
|
||||||
|
{
|
||||||
|
public Item(int id)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Item<TValue> As<TValue>(TValue value) => new(value);
|
||||||
|
|
||||||
|
public static Item<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||||
|
|
||||||
|
public int Id { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public partial class ItemViewModel :
|
public partial class ItemViewModel :
|
||||||
ObservableCollectionViewModel<IItemViewModel>,
|
ObservableCollectionViewModel<IItemViewModel>,
|
||||||
INotificationHandler<Confirm<Item>>
|
INotificationHandler<ConfirmEventArgs<Item>>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private int? id;
|
private int? id;
|
||||||
@@ -33,7 +33,7 @@ public partial class ItemViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public async Task Handle(Confirm<Item> args, CancellationToken cancellationToken = default)
|
public async Task Handle(ConfirmEventArgs<Item> args, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
ItemConfiguration configuration = new();
|
ItemConfiguration configuration = new();
|
||||||
foreach (IItemViewModel item in this)
|
foreach (IItemViewModel item in this)
|
||||||
@@ -41,6 +41,6 @@ public partial class ItemViewModel :
|
|||||||
item.Invoke(configuration);
|
item.Invoke(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Mediator.Handle<Create<ItemConfiguration>, bool>(Create.As(configuration), cancellationToken);
|
await Mediator.Handle<CreateEventArgs<ItemConfiguration>, bool>(Create.As(configuration), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ namespace Bitvault;
|
|||||||
|
|
||||||
public class MainViewModelHandler(IPublisher publisher,
|
public class MainViewModelHandler(IPublisher publisher,
|
||||||
IContainerHostCollection containers) :
|
IContainerHostCollection containers) :
|
||||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
INotificationHandler<EnumerateEventArgs<IMainNavigationViewModel>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
public async Task Handle(EnumerateEventArgs<IMainNavigationViewModel> args,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
foreach (IComponentHost container in containers.OrderBy(x => x.GetConfiguration<ContainerConfiguration>()
|
foreach (IComponentHost container in containers.OrderBy(x => x.GetConfiguration<ContainerConfiguration>()
|
||||||
@@ -19,7 +19,7 @@ public class MainViewModelHandler(IPublisher publisher,
|
|||||||
{
|
{
|
||||||
if (factory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
if (factory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new Create<IMainNavigationViewModel>(viewModel),
|
await publisher.Publish(new CreateEventArgs<IMainNavigationViewModel>(viewModel),
|
||||||
nameof(MainViewModel), cancellationToken);
|
nameof(MainViewModel), cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ namespace Bitvault;
|
|||||||
public class OpenContainerHandler(ContainerConfiguration configuration,
|
public class OpenContainerHandler(ContainerConfiguration configuration,
|
||||||
ISecurityKeyFactory keyVaultFactory,
|
ISecurityKeyFactory keyVaultFactory,
|
||||||
IContainerStorageFactory vaultStorage) :
|
IContainerStorageFactory vaultStorage) :
|
||||||
IHandler<Open<Container>, bool>
|
IHandler<ActivateEventArgs<Container>, bool>
|
||||||
{
|
{
|
||||||
public async Task<bool> Handle(Open<Container> args,
|
public async Task<bool> Handle(ActivateEventArgs<Container> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (args.Value is Container container && configuration.Name is { Length: > 0 } name && container.Password is { Length: > 0 } password)
|
if (args.Value is Container container && configuration.Name is { Length: > 0 } name && container.Password is { Length: > 0 } password)
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ public partial class OpenContainerViewModel(IServiceProvider provider,
|
|||||||
{
|
{
|
||||||
if (Password is { Length: > 0 })
|
if (Password is { Length: > 0 })
|
||||||
{
|
{
|
||||||
if (await Mediator.Handle<Open<Container>, bool>(Open.As(new Container(Password))))
|
if (await Mediator.Handle<ActivateEventArgs<Container>, bool>(Activate.As(new Container(Password))))
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Container.As<Opened>());
|
await Publisher.Publish(Opened.As<Container>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -1,3 +1,8 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public record Opened;
|
public record Opened
|
||||||
|
{
|
||||||
|
public static OpenedEventArgs<TValue> As<TValue>(TValue value) => new(value);
|
||||||
|
|
||||||
|
public static OpenedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record OpenedEventArgs<TValue>(TValue? Value = default);
|
||||||
Reference in New Issue
Block a user