Mass rename
This commit is contained in:
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class AddVaultContentActionViewModel(IServiceProvider provider,
|
||||
public partial class AddItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
+4
-4
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class AddVaultContentCommandHeaderViewModel : ObservableCollectionViewModel
|
||||
public partial class AddItemCommandHeaderViewModel : ObservableCollectionViewModel
|
||||
{
|
||||
public AddVaultContentCommandHeaderViewModel(IServiceProvider provider,
|
||||
public AddItemCommandHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -12,8 +12,8 @@ public partial class AddVaultContentCommandHeaderViewModel : ObservableCollectio
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Add<ConfirmVaultContentActionViewModel>();
|
||||
Add<DismissVaultContentActionViewModel>();
|
||||
Add<ConfirmItemActionViewModel>();
|
||||
Add<DismissItemActionViewModel>();
|
||||
|
||||
Template = template;
|
||||
}
|
||||
@@ -3,13 +3,13 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class AddVaultContentViewModel :
|
||||
ObservableCollectionViewModel<IVaultContentEntryViewModel>
|
||||
public partial class AddItemViewModel :
|
||||
ObservableCollectionViewModel<IItemViewModel>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string named;
|
||||
|
||||
public AddVaultContentViewModel(IServiceProvider provider,
|
||||
public AddItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -21,15 +21,15 @@ public partial class AddVaultContentViewModel :
|
||||
Template = template;
|
||||
Named = $"{named}";
|
||||
|
||||
Add<VaultContentHeaderViewModel>();
|
||||
Add<ItemHeaderViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
public Task<bool> Confirm()
|
||||
{
|
||||
VaultContentConfiguration configuration = new();
|
||||
foreach (IVaultContentEntryViewModel item in this)
|
||||
ItemConfiguration configuration = new();
|
||||
foreach (IItemViewModel item in this)
|
||||
{
|
||||
item.Invoke(configuration);
|
||||
}
|
||||
@@ -8,4 +8,4 @@ public partial class AllNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string filter) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||
string filter) : FilterContainerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, filter);
|
||||
|
||||
@@ -8,4 +8,4 @@ public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
string name) : FilterContainerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
@@ -8,4 +8,4 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
string name) : FilterContainerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class DeleteVaultContentActionViewModel(IServiceProvider provider,
|
||||
public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultStorageConnection(string connection)
|
||||
public class ContaienrConnection(string connection)
|
||||
{
|
||||
private readonly string connection = connection;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public record Vault<TValue>(TValue? Value = default);
|
||||
public record SecureStorage<TValue>(TValue? Value = default);
|
||||
|
||||
public record Vault
|
||||
{
|
||||
@@ -18,9 +18,9 @@ public record Vault
|
||||
}
|
||||
|
||||
|
||||
public static Vault<TValue> As<TValue>(TValue value) => new(value);
|
||||
public static SecureStorage<TValue> As<TValue>(TValue value) => new(value);
|
||||
|
||||
public static Vault<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
public static SecureStorage<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
|
||||
|
||||
[MaybeNull]
|
||||
@@ -0,0 +1,21 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ContainerCollectionInitializer(IEnumerable<IConfigurationDescriptor<ContainerConfiguration>> configurations,
|
||||
IComponentFactory componentFactory,
|
||||
IContainerHostCollection vaults) : IInitializer
|
||||
{
|
||||
public async Task Initialize()
|
||||
{
|
||||
foreach (IConfigurationDescriptor<ContainerConfiguration> configuration in configurations)
|
||||
{
|
||||
if (componentFactory.Create<IContainerComponent, ContainerConfiguration>(configuration.Section, configuration.Value) is IComponentHost host)
|
||||
{
|
||||
vaults.Add(host);
|
||||
await host.StartAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ContainerComponent(IComponentBuilder builder) : Component(builder),
|
||||
IContainerComponent
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ContainerComponentFactory(IComponentFactory componentFactory) :
|
||||
IContainerComponentFactory
|
||||
{
|
||||
public IComponentHost? Create(string name)
|
||||
{
|
||||
if (componentFactory.Create<IContainerComponent, ContainerConfiguration>($"Vault:{name}",
|
||||
new ContainerConfiguration { Name = name }) is IComponentHost host)
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultConfiguration : ComponentConfiguration
|
||||
public record ContainerConfiguration : ComponentConfiguration
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
@@ -6,15 +6,15 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultStorage(IContainer<VaultStorageConnection> connection,
|
||||
public class ContainerFactory(IContainer<ContaienrConnection> connection,
|
||||
IHostEnvironment environment,
|
||||
IServiceProvider provider) :
|
||||
IVaultStorage
|
||||
IContainer
|
||||
{
|
||||
public async Task<bool> Create(string name,
|
||||
VaultKey key)
|
||||
SecurityKey key)
|
||||
{
|
||||
connection.Set(new VaultStorageConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||
connection.Set(new ContaienrConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}"));
|
||||
|
||||
IDbContextFactory<VaultDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<VaultDbContext>>();
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class VaultHeaderViewModel : ObservableCollectionViewModel<string, IDisposable>,
|
||||
INotificationHandler<Vault<Filter<string>>>
|
||||
public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<string, IDisposable>,
|
||||
INotificationHandler<SecureStorage<Filter<string>>>
|
||||
{
|
||||
public VaultHeaderViewModel(IServiceProvider provider,
|
||||
public ContainerHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -15,12 +15,12 @@ public partial class VaultHeaderViewModel : ObservableCollectionViewModel<string
|
||||
{
|
||||
Template = template;
|
||||
|
||||
Add<AddVaultContentActionViewModel>();
|
||||
Add<AddItemActionViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
public Task Handle(Vault<Filter<string>> args,
|
||||
public Task Handle(SecureStorage<Filter<string>> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (args.Value is Filter<string> filter)
|
||||
@@ -3,8 +3,8 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultHostCollection :
|
||||
IVaultHostCollection
|
||||
public class ContainerHostCollection :
|
||||
IContainerHostCollection
|
||||
|
||||
{
|
||||
private readonly List<IComponentHost> hosts = [];
|
||||
@@ -3,13 +3,13 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class VaultNavigationViewModel :
|
||||
ObservableCollectionViewModel<IVaultNavigationViewModel>,
|
||||
public partial class ContainerNavigationViewModel :
|
||||
ObservableCollectionViewModel<IContainerNavigationViewModel>,
|
||||
IMainNavigationViewModel,
|
||||
INotificationHandler<Vault<Opened>>,
|
||||
INotificationHandler<Vault<Closed>>,
|
||||
INotificationHandler<Vault<Activated>>,
|
||||
INotificationHandler<Vault<Deactivated>>
|
||||
INotificationHandler<SecureStorage<Opened>>,
|
||||
INotificationHandler<SecureStorage<Closed>>,
|
||||
INotificationHandler<SecureStorage<Activated>>,
|
||||
INotificationHandler<SecureStorage<Deactivated>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
@@ -26,7 +26,7 @@ public partial class VaultNavigationViewModel :
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
public VaultNavigationViewModel(IServiceProvider provider,
|
||||
public ContainerNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -41,7 +41,7 @@ public partial class VaultNavigationViewModel :
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
public Task Handle(Vault<Opened> args,
|
||||
public Task Handle(SecureStorage<Opened> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
Add<AllNavigationViewModel>("All");
|
||||
@@ -53,7 +53,7 @@ public partial class VaultNavigationViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Vault<Closed> args,
|
||||
public Task Handle(SecureStorage<Closed> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
Opened = true;
|
||||
@@ -62,11 +62,11 @@ public partial class VaultNavigationViewModel :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Vault<Deactivated> args,
|
||||
public Task Handle(SecureStorage<Deactivated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = false);
|
||||
|
||||
public Task Handle(Vault<Activated> args,
|
||||
public Task Handle(SecureStorage<Activated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = true);
|
||||
}
|
||||
@@ -4,8 +4,8 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
|
||||
[Enumerate(nameof(VaultViewModel))]
|
||||
public partial class VaultViewModel(IServiceProvider provider,
|
||||
[Enumerate(nameof(ContainerViewModel))]
|
||||
public partial class ContainerViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -13,8 +13,8 @@ public partial class VaultViewModel(IServiceProvider provider,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
NamedComponent named,
|
||||
string? filter = null) : ObservableCollectionViewModel<VaultContentNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<Vault<Filter<string>>>
|
||||
string? filter = null) : ObservableCollectionViewModel<ItemNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<SecureStorage<Filter<string>>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? filter = filter;
|
||||
@@ -36,7 +36,7 @@ public partial class VaultViewModel(IServiceProvider provider,
|
||||
await base.Deactivated();
|
||||
}
|
||||
|
||||
public async Task Handle(Vault<Filter<string>> args,
|
||||
public async Task Handle(SecureStorage<Filter<string>> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (args.Value is Filter<string> filter)
|
||||
@@ -47,5 +47,5 @@ public partial class VaultViewModel(IServiceProvider provider,
|
||||
}
|
||||
|
||||
protected override IEnumerate PrepareEnumeration(object? key) =>
|
||||
Enumerate<VaultContentNavigationViewModel>.With(new VaultViewModelOptions { Filter = Filter }) with { Key = key };
|
||||
Enumerate<ItemNavigationViewModel>.With(new ContainerViewModelConfiguration { Filter = Filter }) with { Key = key };
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultViewModelOptions
|
||||
public record ContainerViewModelConfiguration
|
||||
{
|
||||
public string? Filter { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ContainerViewModelHandler(IServiceFactory factory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||
{
|
||||
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (args.Options?.Filter is "All")
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
||||
nameof(ContainerViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Options?.Filter is "Starred")
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
||||
nameof(ContainerViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Options?.Filter is "Archive")
|
||||
{
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
if (factory.Create<ItemNavigationViewModel>("Name " + i, "Description " + 1) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<ItemNavigationViewModel>(viewModel),
|
||||
nameof(ContainerViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreateVaultHandler(IVaultComponentFactory componentFactory) :
|
||||
public class CreateContainerHandler(IContainerComponentFactory componentFactory) :
|
||||
IHandler<Create<Vault>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(Create<Vault> args,
|
||||
@@ -16,18 +16,18 @@ public class CreateVaultHandler(IVaultComponentFactory componentFactory) :
|
||||
{
|
||||
if (componentFactory.Create(name) is IComponentHost host)
|
||||
{
|
||||
IVaultKeyFactory keyVaultFactory = host.Services.GetRequiredService<IVaultKeyFactory>();
|
||||
IContainer<VaultKey> vaultKeyContainer = host.Services.GetRequiredService<IContainer<VaultKey>>();
|
||||
IVaultStorage vaultStorage = host.Services.GetRequiredService<IVaultStorage>();
|
||||
ISecurityKeyFactory keyVaultFactory = host.Services.GetRequiredService<ISecurityKeyFactory>();
|
||||
IContainer<SecurityKey> vaultKeyContainer = host.Services.GetRequiredService<IContainer<SecurityKey>>();
|
||||
IContainer vaultStorage = host.Services.GetRequiredService<IContainer>();
|
||||
|
||||
if (keyVaultFactory.Create(Encoding.UTF8.GetBytes(password)) is VaultKey key)
|
||||
if (keyVaultFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key)
|
||||
{
|
||||
vaultKeyContainer.Set(key);
|
||||
|
||||
if (await vaultStorage.Create(name, key))
|
||||
{
|
||||
IWritableConfiguration<VaultConfiguration> configuration =
|
||||
host.Services.GetRequiredService<IWritableConfiguration<VaultConfiguration>>();
|
||||
IWritableConfiguration<ContainerConfiguration> configuration =
|
||||
host.Services.GetRequiredService<IWritableConfiguration<ContainerConfiguration>>();
|
||||
|
||||
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
|
||||
host.Start();
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class CreateVaultNavigationViewModel(IServiceProvider provider,
|
||||
public partial class CreateContainerNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class CreateVaultViewModel(IServiceProvider provider,
|
||||
public partial class CreateContainerViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IPublisher publisher,
|
||||
IMediator mediator,
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ConfirmVaultContentActionViewModel(IServiceProvider provider,
|
||||
public partial class DeleteItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class DismissVaultContentActionViewModel(IServiceProvider provider,
|
||||
public partial class DismissItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class EditVaultContentActionViewModel(IServiceProvider provider,
|
||||
public partial class EditItemActionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
+7
-7
@@ -4,10 +4,10 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class FilterVaultNavigationViewModel : ObservableViewModel,
|
||||
IVaultNavigationViewModel,
|
||||
INotificationHandler<Vault<Activated>>,
|
||||
INotificationHandler<Vault<Deactivated>>
|
||||
public partial class FilterContainerNavigationViewModel : ObservableViewModel,
|
||||
IContainerNavigationViewModel,
|
||||
INotificationHandler<SecureStorage<Activated>>,
|
||||
INotificationHandler<SecureStorage<Deactivated>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
@@ -18,7 +18,7 @@ public partial class FilterVaultNavigationViewModel : ObservableViewModel,
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
public FilterVaultNavigationViewModel(IServiceProvider provider,
|
||||
public FilterContainerNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -29,11 +29,11 @@ public partial class FilterVaultNavigationViewModel : ObservableViewModel,
|
||||
Filter = filter;
|
||||
}
|
||||
|
||||
public Task Handle(Vault<Deactivated> args,
|
||||
public Task Handle(SecureStorage<Deactivated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = false);
|
||||
|
||||
public Task Handle(Vault<Activated> args,
|
||||
public Task Handle(SecureStorage<Activated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = true);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IContainer
|
||||
{
|
||||
Task<bool> Create(string name, SecurityKey key);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IContainerComponent : IComponent;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault
|
||||
{
|
||||
public interface IVaultComponentFactory
|
||||
public interface IContainerComponentFactory
|
||||
{
|
||||
IComponentHost? Create(string name);
|
||||
}
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultHost : IComponentHost;
|
||||
public interface IContainerHost : IComponentHost;
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultHostCollection :
|
||||
public interface IContainerHostCollection :
|
||||
IEnumerable<IComponentHost>
|
||||
{
|
||||
void Add(IComponentHost host);
|
||||
@@ -0,0 +1,5 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IContainerNavigationViewModel : ISelectable;
|
||||
@@ -0,0 +1,6 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IItemViewModel :
|
||||
IValueInvoker<ItemConfiguration>;
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultKeyFactory
|
||||
public interface ISecurityKeyFactory
|
||||
{
|
||||
VaultKey? Create(byte[] phrase,
|
||||
SecurityKey? Create(byte[] phrase,
|
||||
byte[]? encryptedKey = null,
|
||||
byte[]? salt = null);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultComponent : IComponent;
|
||||
|
||||
public class VaultComponent(IComponentBuilder builder) : Component(builder),
|
||||
IVaultComponent
|
||||
{
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Bitvault
|
||||
{
|
||||
public interface IVaultConnectionPersistence
|
||||
{
|
||||
void Dispose();
|
||||
string? Get(string key);
|
||||
void Set(string key, string connection);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultContentEntryViewModel :
|
||||
IValueInvoker<VaultContentConfiguration>;
|
||||
@@ -1,5 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultNavigationViewModel : ISelectable;
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultStorage
|
||||
{
|
||||
Task<bool> Create(string name, VaultKey key);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultContentConfiguration
|
||||
public record ItemConfiguration
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class VaultContentHeaderViewModel(IServiceProvider provider,
|
||||
public partial class ItemHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) : ObservableViewModel<string, string>(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultContentEntryViewModel
|
||||
IItemViewModel
|
||||
{
|
||||
public void Invoke(VaultContentConfiguration args) =>
|
||||
public void Invoke(ItemConfiguration args) =>
|
||||
args.Name = Value;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class VaultContentNavigationViewModel(IServiceProvider provider,
|
||||
public partial class ItemNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultContentViewModel(IServiceProvider provider,
|
||||
public class ItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewModelHandler(IPublisher publisher,
|
||||
IVaultHostCollection vaults) :
|
||||
IContainerHostCollection vaults) :
|
||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
||||
@@ -12,11 +12,11 @@ public class MainViewModelHandler(IPublisher publisher,
|
||||
{
|
||||
foreach (IComponentHost vault in vaults)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<VaultConfiguration>() is VaultConfiguration configuration)
|
||||
if (vault.Services.GetRequiredService<ContainerConfiguration>() is ContainerConfiguration configuration)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
if (factory.Create<VaultNavigationViewModel>(configuration.Name) is VaultNavigationViewModel viewModel)
|
||||
if (factory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<IMainNavigationViewModel>(viewModel),
|
||||
nameof(MainViewModel), cancellationToken);
|
||||
|
||||
@@ -16,7 +16,7 @@ public partial class ManageViewModel :
|
||||
{
|
||||
Template = template;
|
||||
|
||||
Add<CreateVaultNavigationViewModel>();
|
||||
Add<CreateContainerNavigationViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
@@ -3,9 +3,9 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class OpenVaultHandler(VaultConfiguration configuration,
|
||||
IVaultKeyFactory keyVaultFactory,
|
||||
IVaultStorage vaultStorage) :
|
||||
public class OpenContainerHandler(ContainerConfiguration configuration,
|
||||
ISecurityKeyFactory keyVaultFactory,
|
||||
IContainer vaultStorage) :
|
||||
IHandler<Open<Vault>, bool>
|
||||
{
|
||||
public async Task<bool> Handle(Open<Vault> args,
|
||||
@@ -18,7 +18,7 @@ public class OpenVaultHandler(VaultConfiguration configuration,
|
||||
byte[]? salt = Convert.FromBase64String(keyPart[0]);
|
||||
byte[]? encryptedKey = Convert.FromBase64String(keyPart[1]);
|
||||
|
||||
if ( keyVaultFactory.Create(Encoding.UTF8.GetBytes(password), encryptedKey, salt) is VaultKey key)
|
||||
if ( keyVaultFactory.Create(Encoding.UTF8.GetBytes(password), encryptedKey, salt) is SecurityKey key)
|
||||
{
|
||||
if (await vaultStorage.Create(name, key))
|
||||
{
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class OpenVaultViewModel(IServiceProvider provider,
|
||||
public partial class OpenContainerViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class VaultSearchHeaderViewModel(IServiceProvider provider,
|
||||
public partial class SearchHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultKey(byte[] Salt, byte[] EncryptedKey, byte[] DecryptedKey) :
|
||||
public record SecurityKey(byte[] Salt, byte[] EncryptedKey, byte[] DecryptedKey) :
|
||||
IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultKeyFactory(IKeyGenerator generator,
|
||||
public class SecurityKeyFactory(IKeyGenerator generator,
|
||||
IKeyDeriver deriver,
|
||||
IEncryptor encryptor,
|
||||
IDecryptor decryptor) :
|
||||
IVaultKeyFactory
|
||||
ISecurityKeyFactory
|
||||
{
|
||||
public VaultKey? Create(byte[] phrase,
|
||||
public SecurityKey? Create(byte[] phrase,
|
||||
byte[]? encryptedKey = null,
|
||||
byte[]? salt = null)
|
||||
{
|
||||
@@ -28,7 +28,7 @@ public class VaultKeyFactory(IKeyGenerator generator,
|
||||
return default;
|
||||
}
|
||||
|
||||
return new VaultKey(salt, encryptedKey, decryptedKey);
|
||||
return new SecurityKey(salt, encryptedKey, decryptedKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ public partial class StarredNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
string name) : FilterContainerNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
@@ -1,21 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultCollectionInitializer(IEnumerable<IConfigurationDescriptor<VaultConfiguration>> configurations,
|
||||
IComponentFactory componentFactory,
|
||||
IVaultHostCollection vaults) : IInitializer
|
||||
{
|
||||
public async Task Initialize()
|
||||
{
|
||||
foreach (IConfigurationDescriptor<VaultConfiguration> configuration in configurations)
|
||||
{
|
||||
if (componentFactory.Create<IVaultComponent, VaultConfiguration>(configuration.Section, configuration.Value) is IComponentHost host)
|
||||
{
|
||||
vaults.Add(host);
|
||||
await host.StartAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultComponentFactory(IComponentFactory componentFactory) :
|
||||
IVaultComponentFactory
|
||||
{
|
||||
public IComponentHost? Create(string name)
|
||||
{
|
||||
if (componentFactory.Create<IVaultComponent, VaultConfiguration>($"Vault:{name}",
|
||||
new VaultConfiguration { Name = name }) is IComponentHost host)
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer);
|
||||
@@ -1,48 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultViewModelHandler(IServiceFactory factory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<Enumerate<VaultContentNavigationViewModel, VaultViewModelOptions>>
|
||||
{
|
||||
public async Task Handle(Enumerate<VaultContentNavigationViewModel, VaultViewModelOptions> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (args.Options?.Filter is "All")
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (factory.Create<VaultContentNavigationViewModel>("Name " + i, "Description " + 1) is VaultContentNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<VaultContentNavigationViewModel>(viewModel),
|
||||
nameof(VaultViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Options?.Filter is "Starred")
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (factory.Create<VaultContentNavigationViewModel>("Name " + i, "Description " + 1) is VaultContentNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<VaultContentNavigationViewModel>(viewModel),
|
||||
nameof(VaultViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Options?.Filter is "Archive")
|
||||
{
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
if (factory.Create<VaultContentNavigationViewModel>("Name " + i, "Description " + 1) is VaultContentNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<VaultContentNavigationViewModel>(viewModel),
|
||||
nameof(VaultViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user