Worlds fastest rename

This commit is contained in:
TheXamlGuy
2024-06-09 13:47:58 +01:00
parent 727bf877e9
commit 1f777e19cd
71 changed files with 282 additions and 282 deletions
+1 -1
View File
@@ -8,4 +8,4 @@ public partial class AllNavigationViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
string filter) : FilterLockerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
string filter) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
+1 -1
View File
@@ -8,4 +8,4 @@ public partial class ArchiveNavigationViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
string name) : FilterLockerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
+1 -1
View File
@@ -8,4 +8,4 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
string name) : FilterLockerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
+2 -2
View File
@@ -7,7 +7,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory) :
public class CreateItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<CreateEventArgs<(Guid, string, string, ItemConfiguration)>, bool>
{
public async Task<bool> Handle(CreateEventArgs<(Guid, string, string, ItemConfiguration)> args,
@@ -32,7 +32,7 @@ public class CreateItemHandler(IDbContextFactory<LockerContext> dbContextFactory
Type = 0,
});
using LockerContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
EntityEntry<ItemEntry>? result = await context.AddAsync(itemEntry, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
@@ -5,16 +5,16 @@ using Toolkit.Foundation;
namespace Bitvault;
public class CreateLockerHandler(ILockerFactory componentFactory,
public class CreateWalletHandler(IWalletFactory componentFactory,
IPublisher publisher) :
IHandler<CreateEventArgs<Locker<(string, string)>>, bool>
IHandler<CreateEventArgs<Wallet<(string, string)>>, bool>
{
public async Task<bool> Handle(CreateEventArgs<Locker<(string, string)>> args,
public async Task<bool> Handle(CreateEventArgs<Wallet<(string, string)>> args,
CancellationToken cancellationToken)
{
if (args.Value is Locker <(string, string)> locker)
if (args.Value is Wallet <(string, string)> Wallet)
{
if (locker.Value is (string name, string password) &&
if (Wallet.Value is (string name, string password) &&
name is { Length: > 0 } &&
password is { Length: > 0 })
{
@@ -22,16 +22,16 @@ public class CreateLockerHandler(ILockerFactory componentFactory,
{
ISecurityKeyFactory keyVaultFactory = host.Services.GetRequiredService<ISecurityKeyFactory>();
IDecoratorService<SecurityKey> secureKeyStore = host.Services.GetRequiredService<IDecoratorService<SecurityKey>>();
ILockerStorageFactory lockerStorageFactory = host.Services.GetRequiredService<ILockerStorageFactory>();
IWalletStorageFactory WalletStorageFactory = host.Services.GetRequiredService<IWalletStorageFactory>();
if (keyVaultFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key)
{
secureKeyStore.Set(key);
if (await lockerStorageFactory.Create(name, key))
if (await WalletStorageFactory.Create(name, key))
{
IWritableConfiguration<LockerConfiguration> configuration =
host.Services.GetRequiredService<IWritableConfiguration<LockerConfiguration>>();
IWritableConfiguration<WalletConfiguration> configuration =
host.Services.GetRequiredService<IWritableConfiguration<WalletConfiguration>>();
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
host.Start();
@@ -2,7 +2,7 @@
namespace Bitvault;
public partial class CreateLockerNavigationViewModel(IServiceProvider provider,
public partial class CreateWalletNavigationViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class CreateLockerViewModel(IServiceProvider provider,
public partial class CreateWalletViewModel(IServiceProvider provider,
IServiceFactory factory,
IPublisher publisher,
IMediator mediator,
@@ -22,5 +22,5 @@ public partial class CreateLockerViewModel(IServiceProvider provider,
private string password;
public async Task<bool> Confirm() =>
await Mediator.Handle<CreateEventArgs<Locker<(string, string)>>, bool>(Create.As(new Locker<(string, string)>((Name, Password))));
await Mediator.Handle<CreateEventArgs<Wallet<(string, string)>>, bool>(Create.As(new Wallet<(string, string)>((Name, Password))));
}
@@ -4,10 +4,10 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class FilterLockerNavigationViewModel : Observable,
ILockerNavigationViewModel,
INotificationHandler<ActivatedEventArgs<Locker>>,
INotificationHandler<DeactivatedEventArgs<Locker>>
public partial class FilterWalletNavigationViewModel : Observable,
IWalletNavigationViewModel,
INotificationHandler<ActivatedEventArgs<Wallet>>,
INotificationHandler<DeactivatedEventArgs<Wallet>>
{
[ObservableProperty]
private bool activated;
@@ -18,7 +18,7 @@ public partial class FilterLockerNavigationViewModel : Observable,
[ObservableProperty]
private bool selected;
public FilterLockerNavigationViewModel(IServiceProvider provider,
public FilterWalletNavigationViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -29,10 +29,10 @@ public partial class FilterLockerNavigationViewModel : Observable,
Filter = filter;
}
public Task Handle(DeactivatedEventArgs<Locker> args) =>
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
Task.FromResult(Activated = false);
public Task Handle(ActivatedEventArgs<Locker> args) =>
public Task Handle(ActivatedEventArgs<Wallet> args) =>
Task.FromResult(Activated = true);
[RelayCommand]
@@ -2,4 +2,4 @@
namespace Bitvault;
public interface ILockerComponent : IComponent;
public interface IWalletComponent : IComponent;
@@ -2,7 +2,7 @@
namespace Bitvault
{
public interface ILockerFactory
public interface IWalletFactory
{
IComponentHost? Create(string name);
}
@@ -2,4 +2,4 @@
namespace Bitvault;
public interface ILockerHost : IComponentHost;
public interface IWalletHost : IComponentHost;
@@ -2,7 +2,7 @@
namespace Bitvault;
public interface ILockerHostCollection :
public interface IWalletHostCollection :
IEnumerable<IComponentHost>
{
void Add(IComponentHost host);
@@ -2,6 +2,6 @@
namespace Bitvault;
public interface ILockerNavigationViewModel :
public interface IWalletNavigationViewModel :
ISelectable,
IDisposable;
@@ -1,6 +1,6 @@
namespace Bitvault;
public interface ILockerStorageFactory
public interface IWalletStorageFactory
{
Task<bool> Create(string name, SecurityKey key);
}
+1 -1
View File
@@ -18,7 +18,7 @@ public partial class ItemCategoryCollectionViewModel(IServiceProvider provider,
public override Task OnActivated()
{
Publisher.Publish(Notify.As(Factory.Create<LockerCommandHeaderCollection>(new List<IDisposable>
Publisher.Publish(Notify.As(Factory.Create<WalletCommandHeaderCollection>(new List<IDisposable>
{
Factory.Create<BackActionViewModel>(),
})));
+5 -5
View File
@@ -16,7 +16,7 @@ public partial class ItemCollectionViewModel :
[ObservableProperty]
public string? named;
private LockerViewModelConfiguration configuration;
private WalletViewModelConfiguration configuration;
public ItemCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
@@ -26,7 +26,7 @@ public partial class ItemCollectionViewModel :
IDisposer disposer,
IContentTemplate template,
NamedComponent named,
LockerViewModelConfiguration configuration,
WalletViewModelConfiguration configuration,
string? filter = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
{
Template = template;
@@ -61,15 +61,15 @@ public partial class ItemCollectionViewModel :
public override Task OnActivated()
{
Publisher.Publish(Notify.As(Factory.Create<LockerCommandHeaderCollection>(new List<IDisposable>
Publisher.Publish(Notify.As(Factory.Create<WalletCommandHeaderCollection>(new List<IDisposable>
{
Factory.Create<CreateItemActionViewModel>(),
Factory.Create<SearchLockerActionViewModel>(),
Factory.Create<SearchWalletActionViewModel>(),
})));
return base.OnActivated();
}
protected override SynchronizeExpression BuildAggregateExpression() =>
new(Synchronize.As<ItemNavigationViewModel, LockerViewModelConfiguration>(configuration));
new(Synchronize.As<ItemNavigationViewModel, WalletViewModelConfiguration>(configuration));
}
-5
View File
@@ -1,5 +0,0 @@
namespace Bitvault;
public record Locker<TValue>(TValue Value);
public record Locker;
-35
View File
@@ -1,35 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Toolkit.Foundation;
namespace Bitvault;
public class LockerActivatedHandler(ILockerHostCollection lockers,
IPublisher publisher) :
INotificationHandler<ActivatedEventArgs<IComponentHost>>
{
public Task Handle(ActivatedEventArgs<IComponentHost> args)
{
if (args.Value is IComponentHost locker)
{
List<IComponentHost> sortedLockers = [.. lockers, locker];
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<ConfigurationDescriptor<LockerConfiguration>>() is ConfigurationDescriptor<LockerConfiguration> descriptor)
{
if (locker.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
{
if (serviceFactory.Create<LockerNavigationViewModel>(descriptor.Name) is LockerNavigationViewModel viewModel)
{
publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
nameof(MainViewModel));
}
}
}
}
return Task.CompletedTask;
}
}
-6
View File
@@ -1,6 +0,0 @@
using Toolkit.Foundation;
namespace Bitvault;
public class LockerComponent(IComponentBuilder builder) : Component(builder),
ILockerComponent;
-17
View File
@@ -1,17 +0,0 @@
using Toolkit.Foundation;
namespace Bitvault;
public class LockerFactory(IComponentFactory componentFactory) :
ILockerFactory
{
public IComponentHost? Create(string name)
{
if (componentFactory.Create<ILockerComponent, LockerConfiguration>($"Locker:{name}", new LockerConfiguration()) is IComponentHost host)
{
return host;
}
return default;
}
}
-22
View File
@@ -1,22 +0,0 @@
using Toolkit.Foundation;
namespace Bitvault;
public class LockerInitializer(IEnumerable<IConfigurationDescriptor<LockerConfiguration>> configurations,
IComponentFactory componentFactory,
ILockerHostCollection lockers) : IInitializer
{
public async Task Initialize()
{
foreach (IConfigurationDescriptor<LockerConfiguration> configuration in configurations)
{
if (componentFactory.Create<ILockerComponent,
LockerConfiguration>(configuration.Section, configuration.Value)
is IComponentHost host)
{
lockers.Add(host);
await host.StartAsync();
}
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ public partial class ManageViewModel :
{
Template = template;
Add<CreateLockerNavigationViewModel>();
Add<CreateWalletNavigationViewModel>();
}
public IContentTemplate Template { get; set; }
@@ -3,19 +3,19 @@ using Toolkit.Foundation;
namespace Bitvault;
public class OpenLockerHandler(IConfigurationDescriptor<LockerConfiguration> descriptor,
public class OpenWalletHandler(IConfigurationDescriptor<WalletConfiguration> descriptor,
ISecurityKeyFactory securityKeyFactory,
ILockerStorageFactory lockerStorageFactory) :
IHandler<ActivateEventArgs<Locker<string>>, bool>
IWalletStorageFactory WalletStorageFactory) :
IHandler<ActivateEventArgs<Wallet<string>>, bool>
{
public async Task<bool> Handle(ActivateEventArgs<Locker<string>> args,
public async Task<bool> Handle(ActivateEventArgs<Wallet<string>> args,
CancellationToken cancellationToken)
{
if (args.Value is Locker<string> locker &&
if (args.Value is Wallet<string> Wallet &&
descriptor.Name is { Length: > 0 } name &&
locker.Value is { Length: > 0 } password)
Wallet.Value is { Length: > 0 } password)
{
LockerConfiguration configuration = descriptor.Value;
WalletConfiguration configuration = descriptor.Value;
if (configuration.Key?.Split(':') is { Length: >= 2 } keyPart)
{
byte[]? salt = Convert.FromBase64String(keyPart[0]);
@@ -23,7 +23,7 @@ public class OpenLockerHandler(IConfigurationDescriptor<LockerConfiguration> des
if (securityKeyFactory.Create(Encoding.UTF8.GetBytes(password), encryptedKey, salt) is SecurityKey key)
{
if (await lockerStorageFactory.Create(name, key))
if (await WalletStorageFactory.Create(name, key))
{
return true;
}
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class OpenLockerViewModel(IServiceProvider provider,
public partial class OpenWalletViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -24,9 +24,9 @@ public partial class OpenLockerViewModel(IServiceProvider provider,
{
if (Password is { Length: > 0 })
{
if (await Mediator.Handle<ActivateEventArgs<Locker<string>>, bool>(Activate.As(new Locker<string>(Password))))
if (await Mediator.Handle<ActivateEventArgs<Wallet<string>>, bool>(Activate.As(new Wallet<string>(Password))))
{
Publisher.Publish(Opened.As<Locker>());
Publisher.Publish(Opened.As<Wallet>());
}
}
}
@@ -5,16 +5,16 @@ using Toolkit.Foundation;
namespace Bitvault;
public class QueryLockerHandler(IDbContextFactory<LockerContext> dbContextFactory) :
IHandler<QueryEventArgs<Locker<(string, string)>>, IReadOnlyCollection<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)>>
public class QueryWalletHandler(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<QueryEventArgs<Wallet<(string, string)>>, IReadOnlyCollection<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)>>
{
public async Task<IReadOnlyCollection<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)>>
Handle(QueryEventArgs<Locker<(string, string)>> args,CancellationToken cancellationToken)
Handle(QueryEventArgs<Wallet<(string, string)>> args,CancellationToken cancellationToken)
{
List<(Guid Id, string? Name, string Category, bool Favourite, bool Archived)> items = [];
if (args.Value is Locker<(string, string)> locker)
if (args.Value is Wallet<(string, string)> Wallet)
{
(string filter, string text) = locker.Value;
(string filter, string text) = Wallet.Value;
ExpressionStarter<ItemEntry> predicate =
PredicateBuilder.New<ItemEntry>(true);
@@ -39,7 +39,7 @@ public class QueryLockerHandler(IDbContextFactory<LockerContext> dbContextFactor
predicate = predicate.And(x => EF.Functions.Like(x.Name, $"%{text}%"));
}
using LockerContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
var results = await context.Set<ItemEntry>()
.Where(predicate)
.Select(x => new
+2 -2
View File
@@ -5,7 +5,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public class RequestItemHandler(IDbContextFactory<LockerContext> dbContextFactory) :
public class RequestItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<RequestEventArgs<Item<Guid>>, (Guid, string, string?, string, ItemConfiguration?)>
{
public async Task<(Guid, string, string?, string, ItemConfiguration?)> Handle(RequestEventArgs<Item<Guid>> args,
@@ -15,7 +15,7 @@ public class RequestItemHandler(IDbContextFactory<LockerContext> dbContextFactor
{
Guid id = item.Value;
using LockerContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
var result = await context.Set<ItemEntry>()
.Where(x => x.Id == id)
.Select(x => new
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class SearchLockerActionViewModel(IServiceProvider provider,
public partial class SearchWalletActionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
+1 -1
View File
@@ -8,4 +8,4 @@ public partial class StarredNavigationViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
string name) : FilterLockerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
string name) : FilterWalletNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
+5 -5
View File
@@ -7,19 +7,19 @@ public class SynchronizeItemViewModelHandler(IMediator mediator,
IServiceProvider serviceProvider,
ICache<Item<(Guid, string)>> cache,
IPublisher publisher) :
INotificationHandler<SynchronizeEventArgs<ItemNavigationViewModel, LockerViewModelConfiguration>>
INotificationHandler<SynchronizeEventArgs<ItemNavigationViewModel, WalletViewModelConfiguration>>
{
public async Task Handle(SynchronizeEventArgs<ItemNavigationViewModel,
LockerViewModelConfiguration> args)
WalletViewModelConfiguration> args)
{
if (args.Value is LockerViewModelConfiguration configuration)
if (args.Value is WalletViewModelConfiguration configuration)
{
cache.Clear();
bool selected = true;
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>? results =
await mediator.Handle<QueryEventArgs<Locker<(string?, string?)>>,
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>>(Query.As(new Locker<(string?, string?)>((configuration.Filter, configuration.Query))));
await mediator.Handle<QueryEventArgs<Wallet<(string?, string?)>>,
IReadOnlyCollection<(Guid Id, string Name, string Category, bool Favourite, bool Archived)>>(Query.As(new Wallet<(string?, string?)>((configuration.Filter, configuration.Query))));
if (results is not null)
{
+8 -8
View File
@@ -4,22 +4,22 @@ using Toolkit.Foundation;
namespace Bitvault;
public class SynchronizeMainViewModelHandler(IPublisher publisher,
ILockerHostCollection lockers) :
IWalletHostCollection Wallets) :
INotificationHandler<SynchronizeEventArgs<IMainNavigationViewModel>>
{
public Task Handle(SynchronizeEventArgs<IMainNavigationViewModel> args)
{
bool selected = true;
foreach (IComponentHost locker in lockers.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<LockerConfiguration>>()
is IConfigurationDescriptor<LockerConfiguration> descriptor ? descriptor.Name : null))
foreach (IComponentHost Wallet in Wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
is IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null))
{
if (locker.Services.GetRequiredService<IConfigurationDescriptor<LockerConfiguration>>()
is IConfigurationDescriptor<LockerConfiguration> descriptor)
if (Wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
is IConfigurationDescriptor<WalletConfiguration> descriptor)
{
if (locker.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
if (Wallet.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
{
if (factory.Create<LockerNavigationViewModel>(descriptor.Name, selected)
is LockerNavigationViewModel viewModel)
if (factory.Create<WalletNavigationViewModel>(descriptor.Name, selected)
is WalletNavigationViewModel viewModel)
{
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
nameof(MainViewModel));
+2 -2
View File
@@ -6,7 +6,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decoratorService,
IDbContextFactory<LockerContext> dbContextFactory) :
IDbContextFactory<WalletContext> dbContextFactory) :
INotificationHandler<UnarchiveEventArgs<Item>>
{
public async Task Handle(UnarchiveEventArgs<Item> args)
@@ -17,7 +17,7 @@ public class UnarchiveItemHandler(IDecoratorService<Item<(Guid, string)>> decora
{
(Guid id, string name) = item.Value;
using LockerContext context = await dbContextFactory.CreateDbContextAsync();
using WalletContext context = await dbContextFactory.CreateDbContextAsync();
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
result.State = 0;
+2 -2
View File
@@ -6,7 +6,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public class UpdateItemHander(IDbContextFactory<LockerContext> dbContextFactory) :
public class UpdateItemHander(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<UpdateEventArgs<Item<(Guid, string, ItemConfiguration)>>, bool>
{
public async Task<bool> Handle(UpdateEventArgs<Item<(Guid, string, ItemConfiguration)>> args,
@@ -18,7 +18,7 @@ public class UpdateItemHander(IDbContextFactory<LockerContext> dbContextFactory)
try
{
using LockerContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
ItemEntry? result = result = await context.Set<ItemEntry>().FindAsync([id], cancellationToken);
if (result is not null)
+2 -2
View File
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public class UpdateItemStateHandler(IDbContextFactory<LockerContext> dbContextFactory) :
public class UpdateItemStateHandler(IDbContextFactory<WalletContext> dbContextFactory) :
IHandler<UpdateEventArgs<(Guid, int)>, bool>
{
public async Task<bool> Handle(UpdateEventArgs<(Guid, int)> args,
@@ -14,7 +14,7 @@ public class UpdateItemStateHandler(IDbContextFactory<LockerContext> dbContextFa
{
await Task.Run(async () =>
{
using LockerContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
using WalletContext context = await dbContextFactory.CreateDbContextAsync(cancellationToken);
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
{
result.State = state;
+5
View File
@@ -0,0 +1,5 @@
namespace Bitvault;
public record Wallet<TValue>(TValue Value);
public record Wallet;
+35
View File
@@ -0,0 +1,35 @@
using Microsoft.Extensions.DependencyInjection;
using Toolkit.Foundation;
namespace Bitvault;
public class WalletActivatedHandler(IWalletHostCollection Wallets,
IPublisher publisher) :
INotificationHandler<ActivatedEventArgs<IComponentHost>>
{
public Task Handle(ActivatedEventArgs<IComponentHost> args)
{
if (args.Value is IComponentHost Wallet)
{
List<IComponentHost> sortedWallets = [.. Wallets, Wallet];
sortedWallets = [.. sortedWallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)];
int index = sortedWallets.IndexOf(Wallet);
if (Wallet.Services.GetRequiredService<ConfigurationDescriptor<WalletConfiguration>>() is ConfigurationDescriptor<WalletConfiguration> descriptor)
{
if (Wallet.Services.GetRequiredService<IServiceFactory>() is IServiceFactory serviceFactory)
{
if (serviceFactory.Create<WalletNavigationViewModel>(descriptor.Name) is WalletNavigationViewModel viewModel)
{
publisher.Publish(new InsertEventArgs<IMainNavigationViewModel>(index, viewModel),
nameof(MainViewModel));
}
}
}
}
return Task.CompletedTask;
}
}
@@ -2,5 +2,5 @@
namespace Bitvault;
public class LockerCommandHeaderCollection(IList<IDisposable> list) :
public class WalletCommandHeaderCollection(IList<IDisposable> list) :
ReadOnlyCollection<IDisposable>(list);
+6
View File
@@ -0,0 +1,6 @@
using Toolkit.Foundation;
namespace Bitvault;
public class WalletComponent(IComponentBuilder builder) : Component(builder),
IWalletComponent;
@@ -2,7 +2,7 @@
namespace Bitvault;
public record LockerConfiguration :
public record WalletConfiguration :
ComponentConfiguration
{
public string? Key { get; set; }
@@ -1,6 +1,6 @@
namespace Bitvault;
public class LockerConnection(string connection)
public class WalletConnection(string connection)
{
private readonly string connection = connection;
+17
View File
@@ -0,0 +1,17 @@
using Toolkit.Foundation;
namespace Bitvault;
public class WalletFactory(IComponentFactory componentFactory) :
IWalletFactory
{
public IComponentHost? Create(string name)
{
if (componentFactory.Create<IWalletComponent, WalletConfiguration>($"Wallet:{name}", new WalletConfiguration()) is IComponentHost host)
{
return host;
}
return default;
}
}
@@ -2,7 +2,7 @@
namespace Bitvault;
public partial class LockerHeaderViewModel(IServiceProvider provider,
public partial class WalletHeaderViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -10,15 +10,15 @@ public partial class LockerHeaderViewModel(IServiceProvider provider,
IDisposer disposer,
IContentTemplate template) :
ObservableCollection(provider, factory, mediator, publisher, subscriber, disposer),
INotificationHandler<NotifyEventArgs<LockerCommandHeaderCollection>>
INotificationHandler<NotifyEventArgs<WalletCommandHeaderCollection>>
{
public IContentTemplate Template { get; set; } = template;
public Task Handle(NotifyEventArgs<LockerCommandHeaderCollection> args)
public Task Handle(NotifyEventArgs<WalletCommandHeaderCollection> args)
{
Clear();
if (args.Value is LockerCommandHeaderCollection commandCollection)
if (args.Value is WalletCommandHeaderCollection commandCollection)
{
foreach (IDisposable command in commandCollection)
{
@@ -3,8 +3,8 @@ using Toolkit.Foundation;
namespace Bitvault;
public class LockerHostCollection :
ILockerHostCollection
public class WalletHostCollection :
IWalletHostCollection
{
private readonly List<IComponentHost> hosts = [];
+22
View File
@@ -0,0 +1,22 @@
using Toolkit.Foundation;
namespace Bitvault;
public class WalletInitializer(IEnumerable<IConfigurationDescriptor<WalletConfiguration>> configurations,
IComponentFactory componentFactory,
IWalletHostCollection Wallets) : IInitializer
{
public async Task Initialize()
{
foreach (IConfigurationDescriptor<WalletConfiguration> configuration in configurations)
{
if (componentFactory.Create<IWalletComponent,
WalletConfiguration>(configuration.Section, configuration.Value)
is IComponentHost host)
{
Wallets.Add(host);
await host.StartAsync();
}
}
}
}
@@ -3,13 +3,13 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class LockerNavigationViewModel :
ObservableCollection<ILockerNavigationViewModel>,
public partial class WalletNavigationViewModel :
ObservableCollection<IWalletNavigationViewModel>,
IMainNavigationViewModel,
INotificationHandler<OpenedEventArgs<Locker>>,
INotificationHandler<ClosedEventArgs<Locker>>,
INotificationHandler<ActivatedEventArgs<Locker>>,
INotificationHandler<DeactivatedEventArgs<Locker>>,
INotificationHandler<OpenedEventArgs<Wallet>>,
INotificationHandler<ClosedEventArgs<Wallet>>,
INotificationHandler<ActivatedEventArgs<Wallet>>,
INotificationHandler<DeactivatedEventArgs<Wallet>>,
ISelectable
{
[ObservableProperty]
@@ -27,7 +27,7 @@ public partial class LockerNavigationViewModel :
[ObservableProperty]
private bool selected;
public LockerNavigationViewModel(IServiceProvider provider,
public WalletNavigationViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -44,7 +44,7 @@ public partial class LockerNavigationViewModel :
public IContentTemplate Template { get; set; }
public Task Handle(OpenedEventArgs<Locker> args)
public Task Handle(OpenedEventArgs<Wallet> args)
{
Add<AllNavigationViewModel>("All");
Add<StarredNavigationViewModel>("Starred");
@@ -55,7 +55,7 @@ public partial class LockerNavigationViewModel :
return Task.CompletedTask;
}
public Task Handle(ClosedEventArgs<Locker> args)
public Task Handle(ClosedEventArgs<Wallet> args)
{
Opened = true;
Clear();
@@ -63,9 +63,9 @@ public partial class LockerNavigationViewModel :
return Task.CompletedTask;
}
public Task Handle(DeactivatedEventArgs<Locker> args) =>
public Task Handle(DeactivatedEventArgs<Wallet> args) =>
Task.FromResult(Activated = false);
public Task Handle(ActivatedEventArgs<Locker> args) =>
public Task Handle(ActivatedEventArgs<Wallet> args) =>
Task.FromResult(Activated = true);
}
@@ -6,19 +6,19 @@ using Toolkit.Foundation;
namespace Bitvault;
public class LockerStorageFactory(IDecoratorService<LockerConnection> connection,
public class WalletStorageFactory(IDecoratorService<WalletConnection> connection,
IHostEnvironment environment,
IServiceProvider provider) :
ILockerStorageFactory
IWalletStorageFactory
{
public async Task<bool> Create(string name,
SecurityKey key)
{
connection.Set(new LockerConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
connection.Set(new WalletConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
$".vault;Mode=ReadWriteCreate;Pooling=true;Password={Convert.ToBase64String(key.DecryptedKey)}"));
IDbContextFactory<LockerContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<LockerContext>>();
using LockerContext context = await dbContextFactory.CreateDbContextAsync();
IDbContextFactory<WalletContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<WalletContext>>();
using WalletContext context = await dbContextFactory.CreateDbContextAsync();
try
{
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
namespace Bitvault;
public partial class LockerViewModel :
public partial class WalletViewModel :
Observable
{
[ObservableProperty]
@@ -11,7 +11,7 @@ public partial class LockerViewModel :
[ObservableProperty]
private string filter;
public LockerViewModel(IServiceProvider provider,
public WalletViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
@@ -26,13 +26,13 @@ public partial class LockerViewModel :
public override async Task OnActivated()
{
Publisher.Publish(Activated.As<Locker>());
Publisher.Publish(Activated.As<Wallet>());
await base.OnActivated();
}
public override async Task OnDeactivated()
{
Publisher.Publish(Deactivated.As<Locker>());
Publisher.Publish(Deactivated.As<Wallet>());
await base.OnDeactivated();
}
}
@@ -1,6 +1,6 @@
namespace Bitvault;
public record LockerViewModelConfiguration
public record WalletViewModelConfiguration
{
public string? Filter { get; set; } = "All";