Improve Publisher
This commit is contained in:
@@ -98,8 +98,12 @@ public partial class App : Application
|
|||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
|
|
||||||
|
|
||||||
services.AddHandler<CreateItemHandler>(ServiceLifetime.Singleton);
|
services.AddHandler<CreateItemHandler>(ServiceLifetime.Singleton);
|
||||||
services.AddHandler<ItemActivatedHandler>();
|
services.AddHandler<ItemActivatedHandler>();
|
||||||
|
|
||||||
|
services.AddScoped<IValueStore<Item>, ValueStore<Item>>();
|
||||||
|
services.AddHandler<ArchiveItemHandler>(ServiceLifetime.Scoped);
|
||||||
});
|
});
|
||||||
})!);
|
})!);
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,18 @@ namespace Bitvault.Avalonia;
|
|||||||
public class AppHandler(IPublisher publisher) :
|
public class AppHandler(IPublisher publisher) :
|
||||||
INotificationHandler<StartedEventArgs>
|
INotificationHandler<StartedEventArgs>
|
||||||
{
|
{
|
||||||
public async Task Handle(StartedEventArgs args, CancellationToken cancellationToken = default)
|
public Task Handle(StartedEventArgs args)
|
||||||
{
|
{
|
||||||
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 NavigateEventArgs(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
|
publisher.Publish(new NavigateEventArgs(lifetime is IClassicDesktopStyleApplicationLifetime ? "MainWindow" : "Main",
|
||||||
lifetime is IClassicDesktopStyleApplicationLifetime ? typeof(IClassicDesktopStyleApplicationLifetime) :
|
lifetime is IClassicDesktopStyleApplicationLifetime ? typeof(IClassicDesktopStyleApplicationLifetime) :
|
||||||
typeof(ISingleViewApplicationLifetime)), cancellationToken);
|
typeof(ISingleViewApplicationLifetime)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Command="{Binding InvokeCommand}"
|
Command="{Binding InvokeCommand}"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
|
HotKey="Delete"
|
||||||
ToolTip.Tip="Archive">
|
ToolTip.Tip="Archive">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ public partial class ArchiveItemActionViewModel(IServiceProvider provider,
|
|||||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Archive.As<Item>());
|
public void Invoke() => Publisher.Publish(Archive.As<Item>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
|||||||
{
|
{
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Confirm.As<Item>());
|
public void Invoke() => Publisher.Publish(Confirm.As<Item>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class ContainerActivatedHandler(IContainerHostCollection containers,
|
|||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<ActivatedEventArgs<IComponentHost>>
|
INotificationHandler<ActivatedEventArgs<IComponentHost>>
|
||||||
{
|
{
|
||||||
public async Task Handle(ActivatedEventArgs<IComponentHost> args,
|
public Task Handle(ActivatedEventArgs<IComponentHost> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
if (args.Value is IComponentHost container)
|
if (args.Value is IComponentHost container)
|
||||||
{
|
{
|
||||||
@@ -24,11 +23,13 @@ public class ContainerActivatedHandler(IContainerHostCollection containers,
|
|||||||
{
|
{
|
||||||
if (serviceFactory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
if (serviceFactory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
|
publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
|
||||||
nameof(MainViewModel), cancellationToken);
|
nameof(MainViewModel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,7 @@ public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<st
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public Task Handle(RequestEventArgs<Filter<string>> args,
|
public Task Handle(RequestEventArgs<Filter<string>> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
if (args.Value is Filter<string> filter)
|
if (args.Value is Filter<string> filter)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ public partial class ContainerNavigationViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public Task Handle(OpenedEventArgs<Container> args,
|
public Task Handle(OpenedEventArgs<Container> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
Add<AllNavigationViewModel>("All");
|
Add<AllNavigationViewModel>("All");
|
||||||
Add<StarredNavigationViewModel>("Starred");
|
Add<StarredNavigationViewModel>("Starred");
|
||||||
@@ -53,8 +52,7 @@ public partial class ContainerNavigationViewModel :
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(ClosedEventArgs<Container> args,
|
public Task Handle(ClosedEventArgs<Container> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
Opened = true;
|
Opened = true;
|
||||||
Clear();
|
Clear();
|
||||||
@@ -62,11 +60,9 @@ public partial class ContainerNavigationViewModel :
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(DeactivatedEventArgs<Container> args,
|
public Task Handle(DeactivatedEventArgs<Container> args) =>
|
||||||
CancellationToken cancellationToken = default) =>
|
|
||||||
Task.FromResult(Activated = false);
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
public Task Handle(ActivatedEventArgs<Container> args,
|
public Task Handle(ActivatedEventArgs<Container> args) =>
|
||||||
CancellationToken cancellationToken = default) =>
|
|
||||||
Task.FromResult(Activated = true);
|
Task.FromResult(Activated = true);
|
||||||
}
|
}
|
||||||
@@ -26,24 +26,25 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
|||||||
|
|
||||||
public override async Task OnActivated()
|
public override async Task OnActivated()
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Activated.As<Container>());
|
Publisher.Publish(Activated.As<Container>());
|
||||||
await base.OnActivated();
|
await base.OnActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnDeactivated()
|
public override async Task OnDeactivated()
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Deactivated.As<Container>());
|
Publisher.Publish(Deactivated.As<Container>());
|
||||||
await base.OnDeactivated();
|
await base.OnDeactivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Handle(RequestEventArgs<Filter<string>> args,
|
public Task Handle(RequestEventArgs<Filter<string>> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
if (args.Value is Filter<string> filter)
|
if (args.Value is Filter<string> filter)
|
||||||
{
|
{
|
||||||
Filter = filter.Value;
|
Filter = filter.Value;
|
||||||
await Enumerate();
|
Enumerate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerate PrepareEnumeration(object? key) =>
|
protected override IEnumerate PrepareEnumeration(object? key) =>
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args,
|
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
if (args.Options is ContainerViewModelConfiguration configuration)
|
if (args.Options is ContainerViewModelConfiguration configuration)
|
||||||
{
|
{
|
||||||
@@ -36,7 +35,7 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
predicate = predicate.And(x => x.State == 3);
|
predicate = predicate.And(x => x.State == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = await Task.Run(async () =>
|
var results = await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
using ContainerDbContext context = dbContextFactory.CreateDbContext();
|
||||||
return await context.Set<ItemEntry>().Where(predicate).Select(x => new
|
return await context.Set<ItemEntry>().Where(predicate).Select(x => new
|
||||||
@@ -44,19 +43,21 @@ public class ContainerViewModelHandler(IDbContextFactory<ContainerDbContext> dbC
|
|||||||
x.Id,
|
x.Id,
|
||||||
x.Name
|
x.Name
|
||||||
}).OrderBy(x => x.Name).ToListAsync();
|
}).OrderBy(x => x.Name).ToListAsync();
|
||||||
|
});
|
||||||
}, cancellationToken);
|
|
||||||
|
|
||||||
bool selected = true;
|
bool selected = true;
|
||||||
foreach (var item in items)
|
foreach (var result in results)
|
||||||
{
|
{
|
||||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||||
|
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1, selected) is ItemNavigationViewModel viewModel)
|
if (serviceFactory.Create<ItemNavigationViewModel>(result.Id, result.Name, "Description " + 1, selected) is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
cache.Add(new Item { Id = item.Id, Name = item.Name });
|
Item item = new() { Id = result.Id, Name = result.Name };
|
||||||
await publisher.Publish(Create.As(viewModel), nameof(ContainerViewModel), cancellationToken);
|
valueStore.Set(item);
|
||||||
|
|
||||||
|
publisher.Publish(Create.As(viewModel), nameof(ContainerViewModel));
|
||||||
}
|
}
|
||||||
|
|
||||||
selected = false;
|
selected = false;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class CreateContainerHandler(IContainerFactory componentFactory,
|
|||||||
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
||||||
host.Start();
|
host.Start();
|
||||||
|
|
||||||
await publisher.Publish(Activated.As(host), cancellationToken);
|
publisher.Publish(Activated.As(host), cancellationToken);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,41 @@
|
|||||||
using Bitvault.Data;
|
using Bitvault.Data;
|
||||||
using HarfBuzzSharp;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public class ArchiveItemHandler(IValueStore<Item> valueStore,
|
||||||
|
IDbContextFactory<ContainerDbContext> dbContextFactory) :
|
||||||
|
INotificationHandler<ArchiveEventArgs<Item>>
|
||||||
|
{
|
||||||
|
public async Task Handle(ArchiveEventArgs<Item> args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (valueStore.Value is Item item)
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
using ContainerDbContext context = await dbContextFactory.CreateDbContextAsync();
|
||||||
|
|
||||||
|
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
|
||||||
|
{
|
||||||
|
result.State = 3;
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFactory,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
IHandler<CreateEventArgs<ItemConfiguration>, bool>
|
||||||
@@ -30,7 +60,7 @@ public class CreateItemHandler(IDbContextFactory<ContainerDbContext> dbContextFa
|
|||||||
if (result is not null)
|
if (result is not null)
|
||||||
{
|
{
|
||||||
Item item = new() { Id = result.Entity.Id, Name = configuration.Name };
|
Item item = new() { Id = result.Entity.Id, Name = configuration.Name };
|
||||||
await publisher.Publish(Activated.As(item), cancellationToken);
|
publisher.Publish(Activated.As(item), cancellationToken);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ public partial class DeleteItemActionViewModel(IServiceProvider provider,
|
|||||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Delete.As<Item>());
|
public void Invoke() => Publisher.Publish(Delete.As<Item>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ public partial class EditItemActionViewModel(IServiceProvider provider,
|
|||||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Edit.As<Item>());
|
public void Invoke() => Publisher.Publish(Edit.As<Item>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,12 @@ public partial class FilterContainerNavigationViewModel : ObservableViewModel,
|
|||||||
Filter = filter;
|
Filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(DeactivatedEventArgs<Container> args,
|
public Task Handle(DeactivatedEventArgs<Container> args) =>
|
||||||
CancellationToken cancellationToken = default) =>
|
|
||||||
Task.FromResult(Activated = false);
|
Task.FromResult(Activated = false);
|
||||||
|
|
||||||
public Task Handle(ActivatedEventArgs<Container> args,
|
public Task Handle(ActivatedEventArgs<Container> args) =>
|
||||||
CancellationToken cancellationToken = default) =>
|
|
||||||
Task.FromResult(Activated = true);
|
Task.FromResult(Activated = true);
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
public async Task Invoke() => await Publisher.Publish(Request.As(new Filter<string>(Filter)), nameof(ContainerViewModel));
|
public void Invoke() => Publisher.Publish(Request.As(new Filter<string>(Filter)), nameof(ContainerViewModel));
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,5 @@ public record Item
|
|||||||
public int Id { get; init; }
|
public int Id { get; init; }
|
||||||
|
|
||||||
public string? Name { get; init; }
|
public string? Name { get; init; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
|||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<ActivatedEventArgs<Item>>
|
INotificationHandler<ActivatedEventArgs<Item>>
|
||||||
{
|
{
|
||||||
public async Task Handle(ActivatedEventArgs<Item> args,
|
public Task Handle(ActivatedEventArgs<Item> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
if (args.Value is Item item)
|
if (args.Value is Item item)
|
||||||
{
|
{
|
||||||
@@ -20,10 +19,12 @@ public class ItemActivatedHandler(IServiceProvider serviceProvider,
|
|||||||
cache.Add(item);
|
cache.Add(item);
|
||||||
int index = cache.IndexOf(item);
|
int index = cache.IndexOf(item);
|
||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1) is ItemNavigationViewModel viewModel)
|
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description " + 1, true) is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
await publisher.Publish(Insert.As(index, viewModel), nameof(ContainerViewModel), cancellationToken);
|
publisher.Publish(Insert.As(index, viewModel), nameof(ContainerViewModel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,8 +36,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; } = template;
|
public IContentTemplate Template { get; set; } = template;
|
||||||
|
|
||||||
public Task Handle(ArchiveEventArgs<Item> args,
|
public Task Handle(ArchiveEventArgs<Item> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
Dispose();
|
Dispose();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public partial class ItemViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|
||||||
public async Task Handle(ConfirmEventArgs<Item> args, CancellationToken cancellationToken = default)
|
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||||
{
|
{
|
||||||
ItemConfiguration configuration = new();
|
ItemConfiguration configuration = new();
|
||||||
foreach (IItemViewModel item in this)
|
foreach (IItemViewModel item in this)
|
||||||
@@ -46,6 +46,6 @@ public partial class ItemViewModel :
|
|||||||
item.Invoke(configuration);
|
item.Invoke(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Mediator.Handle<CreateEventArgs<ItemConfiguration>, bool>(Create.As(configuration), cancellationToken);
|
await Mediator.Handle<CreateEventArgs<ItemConfiguration>, bool>(Create.As(configuration));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ public class MainViewModelHandler(IPublisher publisher,
|
|||||||
IContainerHostCollection containers) :
|
IContainerHostCollection containers) :
|
||||||
INotificationHandler<EnumerateEventArgs<IMainNavigationViewModel>>
|
INotificationHandler<EnumerateEventArgs<IMainNavigationViewModel>>
|
||||||
{
|
{
|
||||||
public async Task Handle(EnumerateEventArgs<IMainNavigationViewModel> args,
|
public Task Handle(EnumerateEventArgs<IMainNavigationViewModel> args)
|
||||||
CancellationToken cancellationToken = default)
|
|
||||||
{
|
{
|
||||||
foreach (IComponentHost container in containers.OrderBy(x => x.GetConfiguration<ContainerConfiguration>()
|
foreach (IComponentHost container in containers.OrderBy(x => x.GetConfiguration<ContainerConfiguration>()
|
||||||
is ContainerConfiguration configuration ? configuration.Name : null))
|
is ContainerConfiguration configuration ? configuration.Name : null))
|
||||||
@@ -19,11 +18,13 @@ 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 CreateEventArgs<IMainNavigationViewModel>(viewModel),
|
publisher.Publish(new CreateEventArgs<IMainNavigationViewModel>(viewModel),
|
||||||
nameof(MainViewModel), cancellationToken);
|
nameof(MainViewModel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public partial class OpenContainerViewModel(IServiceProvider provider,
|
|||||||
{
|
{
|
||||||
if (await Mediator.Handle<ActivateEventArgs<Container>, bool>(Activate.As(new Container(Password))))
|
if (await Mediator.Handle<ActivateEventArgs<Container>, bool>(Activate.As(new Container(Password))))
|
||||||
{
|
{
|
||||||
await Publisher.Publish(Opened.As<Container>());
|
Publisher.Publish(Opened.As<Container>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user