switched to valuetuples for exhanging tokens
This commit is contained in:
@@ -54,10 +54,10 @@ public partial class App : Application
|
||||
{
|
||||
args.AddServices(services =>
|
||||
{
|
||||
services.AddTransient<IComparer<Item>>(provider => Comparer<Item>.Create((x, z) =>
|
||||
StringComparer.CurrentCultureIgnoreCase.Compare(x.Name, z.Name)));
|
||||
services.AddTransient<IComparer<Item<(Guid, string)>>>(provider => Comparer<Item<(Guid, string)>>.Create((x, z) =>
|
||||
StringComparer.CurrentCultureIgnoreCase.Compare(x.Value.Item2, z.Value.Item2)));
|
||||
|
||||
services.AddCache<Item>();
|
||||
services.AddCache<Item<(Guid, string)>>();
|
||||
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IEnumerable<ItemConfiguration>>>());
|
||||
@@ -133,7 +133,7 @@ public partial class App : Application
|
||||
services.AddTemplate<ItemContentViewModel, ItemContentView>();
|
||||
services.AddTemplate<AddItemNavigationViewModel, AddItemNavigationView>();
|
||||
|
||||
services.AddScoped<IValueStore<Item>, ValueStore<Item>>();
|
||||
services.AddScoped<IValueStore<Item<(Guid, string)>>, ValueStore<Item<(Guid, string)>>>();
|
||||
|
||||
services.AddHandler<ConfirmItemHandler>();
|
||||
services.AddHandler<ArchiveItemHandler>();
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
<Parameter Key="Transition" Value="FromRight" />
|
||||
<Parameter Key="NavigationStackEnabled" Value="{x:True}" />
|
||||
</NavigateAction>
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
Scope="self">
|
||||
<Parameter Key="Immutable" Value="{x:False}" />
|
||||
</NavigateAction>
|
||||
</EventTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</Button>
|
||||
|
||||
@@ -4,31 +4,14 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Bitvault"
|
||||
x:DataType="vm:ItemCategoryNavigationViewModel"
|
||||
Content="{Binding Name}"
|
||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||
<Interaction.Behaviors>
|
||||
<AttachedBehaviour>
|
||||
<ConditionAction>
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Selected}" RightOperand="True" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
Scope="self">
|
||||
<Parameter Key="Immutable" Value="{x:False}" />
|
||||
</NavigateAction>
|
||||
</ConditionAction>
|
||||
</AttachedBehaviour>
|
||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
Scope="self">
|
||||
<Parameter Key="Immutable" Value="{x:False}" />
|
||||
</NavigateAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<Grid Background="Transparent" ColumnDefinitions="Auto,*">
|
||||
<PersonPicture
|
||||
Grid.Column="0"
|
||||
Height="34"
|
||||
DisplayName="{Binding Name}" />
|
||||
<StackPanel Grid.Column="1" Margin="12,12,6,12">
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ListBoxItem>
|
||||
|
||||
@@ -61,4 +61,7 @@
|
||||
</ConditionAction>
|
||||
</AttachedEventTriggerBehaviour>
|
||||
</Interaction.Behaviors>
|
||||
<NavigationViewItem.IconSource>
|
||||
<PathIconSource Data="M512,757.76C525.653,757.76 537.6,752.64 547.84,742.4C558.08,732.16 563.2,720.213 563.2,706.56C563.2,692.907 558.08,680.96 547.84,670.72C537.6,660.48 525.653,655.36 512,655.36C498.347,655.36 486.4,660.48 476.16,670.72C465.92,680.96 460.8,692.907 460.8,706.56C460.8,720.213 465.92,732.16 476.16,742.4C486.4,752.64 498.347,757.76 512,757.76ZM307.2,399.36L358.4,399.36L358.4,348.16C358.4,305.835 373.419,269.653 403.456,239.616C433.493,209.579 469.675,194.56 512,194.56C554.325,194.56 590.507,209.579 620.544,239.616C650.581,269.653 665.6,305.835 665.6,348.16L665.6,399.36L716.8,399.36C759.125,399.36 795.307,414.379 825.344,444.416C855.381,474.453 870.4,510.635 870.4,552.96L870.4,860.16C870.4,902.485 855.381,938.667 825.344,968.704C795.307,998.741 759.125,1013.76 716.8,1013.76L307.2,1013.76C264.875,1013.76 228.693,998.741 198.656,968.704C168.619,938.667 153.6,902.485 153.6,860.16L153.6,552.96C153.6,510.635 168.619,474.453 198.656,444.416C228.693,414.379 264.875,399.36 307.2,399.36ZM512,245.76C483.328,245.76 459.093,255.659 439.296,275.456C419.499,295.253 409.6,319.488 409.6,348.16L409.6,399.36L614.4,399.36L614.4,348.16C614.4,319.488 604.501,295.253 584.704,275.456C564.907,255.659 540.672,245.76 512,245.76ZM819.2,552.96C819.2,524.288 809.301,500.053 789.504,480.256C769.707,460.459 745.472,450.56 716.8,450.56L307.2,450.56C278.528,450.56 254.293,460.459 234.496,480.256C214.699,500.053 204.8,524.288 204.8,552.96L204.8,860.16C204.8,888.832 214.699,913.067 234.496,932.864C254.293,952.661 278.528,962.56 307.2,962.56L716.8,962.56C745.472,962.56 769.707,952.661 789.504,932.864C809.301,913.067 819.2,888.832 819.2,860.16Z" />
|
||||
</NavigationViewItem.IconSource>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class AggerateItemViewModelHandler(IMediator mediator,
|
||||
public class AggerateItemViewModelHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<IItemEntryViewModel>>
|
||||
{
|
||||
public Task Handle(AggerateEventArgs<IItemEntryViewModel> args)
|
||||
{
|
||||
var d = valueStore;
|
||||
//if (serviceFactory.Create<ItemHeaderViewModel>(false) is ItemHeaderViewModel viewModel)
|
||||
//{
|
||||
// publisher.Publish(Create.As<IItemEntryViewModel>(viewModel), nameof(ItemViewModel));
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Bitvault;
|
||||
|
||||
public class AggerateLockerItemViewModelHandler(IMediator mediator,
|
||||
IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<AggerateEventArgs<ItemNavigationViewModel,
|
||||
LockerViewModelConfiguration>>
|
||||
@@ -29,11 +29,12 @@ public class AggerateLockerItemViewModelHandler(IMediator mediator,
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
||||
IValueStore<Item<(Guid, string)>> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item<(Guid, string)>>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(Id, Name, "Description", selected, Favourite, Archived) is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
Item item = new() { Id = Id, Name = Name };
|
||||
Item<(Guid, string)> item = new((Id, Name));
|
||||
|
||||
valueStore.Set(item);
|
||||
|
||||
cache.Add(item);
|
||||
|
||||
@@ -2,21 +2,23 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ArchiveItemHandler(IValueStore<Item> valueStore,
|
||||
ICache<Item> cache,
|
||||
public class ArchiveItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<ArchiveEventArgs<Item>>
|
||||
INotificationHandler<ArchiveEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(ArchiveEventArgs<Item> args)
|
||||
public async Task Handle(ArchiveEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valueStore.Value is Item item)
|
||||
if (valueStore.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
if (cache.Contains(item))
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>,
|
||||
bool>(new UpdateEventArgs<(Guid, int)>((item.Id, 2)));
|
||||
bool>(new UpdateEventArgs<(Guid, int)>((id, 2)));
|
||||
|
||||
cache.Remove(item);
|
||||
}
|
||||
|
||||
@@ -2,32 +2,33 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ConfirmItemHandler(IValueStore<Item> valueStore,
|
||||
public class ConfirmItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ConfirmEventArgs<Item>>
|
||||
INotificationHandler<ConfirmEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(ConfirmEventArgs<Item> args)
|
||||
public async Task Handle(ConfirmEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item>,
|
||||
ItemHeaderConfiguration? configuration = await mediator.Handle<ConfirmEventArgs<Item<(Guid, string)>>,
|
||||
ItemHeaderConfiguration>(args);
|
||||
|
||||
if (configuration is not null)
|
||||
{
|
||||
publisher.Publish(Notify.As(configuration));
|
||||
|
||||
if (valueStore?.Value is Item item)
|
||||
if (valueStore?.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
Guid id = item.Id;
|
||||
(Guid id, string _) = item.Value;
|
||||
|
||||
string? name = configuration.Name;
|
||||
|
||||
Item newItem = new() { Id = id, Name = name };
|
||||
Item<(Guid, string)> newItem = new((id, name));
|
||||
publisher.Publish(Modified.As(item, newItem));
|
||||
|
||||
valueStore.Set(newItem);
|
||||
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, ItemConfiguration)>, bool>(new UpdateEventArgs<(Guid,
|
||||
ItemConfiguration)>((item.Id, new ItemConfiguration { Name = name })));
|
||||
ItemConfiguration)>((id, new ItemConfiguration { Name = name })));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -39,7 +40,7 @@ public class ConfirmItemHandler(IValueStore<Item> valueStore,
|
||||
|
||||
if (Success)
|
||||
{
|
||||
publisher.Publish(Created.As(new Item { Id = id, Name = name }));
|
||||
publisher.Publish(Created.As(new Item<(Guid, string)>((id, name))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,21 @@ using Toolkit.Foundation;
|
||||
namespace Bitvault;
|
||||
|
||||
public class CreatedItemHandler(IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
ICache<Item<(Guid, string)>> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<CreatedEventArgs<Item>>
|
||||
INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public Task Handle(CreatedEventArgs<Item> args)
|
||||
public Task Handle(CreatedEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
if (args.Value is Item item)
|
||||
if (args.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
||||
IValueStore<Item<(Guid, string)>> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item<(Guid, string)>>>();
|
||||
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(item.Id, item.Name, "Description", true)
|
||||
if (serviceFactory.Create<ItemNavigationViewModel>(id, name, "Description", true)
|
||||
is ItemNavigationViewModel viewModel)
|
||||
{
|
||||
cache.Add(item);
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class FavouriteItemHandler(IValueStore<Item> valueStore,
|
||||
public class FavouriteItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<FavouriteEventArgs<Item>>
|
||||
INotificationHandler<FavouriteEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(FavouriteEventArgs<Item> args)
|
||||
public async Task Handle(FavouriteEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valueStore.Value is Item item)
|
||||
if (valueStore.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid,
|
||||
int)>((item.Id, 1)));
|
||||
(Guid id, string name) = item.Value;
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 1)));
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
+2
-5
@@ -1,8 +1,5 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record Item
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public record Item<TValue>(TValue Value);
|
||||
|
||||
public string? Name { get; init; } = "";
|
||||
}
|
||||
public record Item;
|
||||
@@ -9,7 +9,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
NamedComponent named,
|
||||
string name,
|
||||
bool selected = false) :
|
||||
Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
@@ -19,9 +18,6 @@ public partial class ItemCategoryNavigationViewModel(IServiceProvider provider,
|
||||
[ObservableProperty]
|
||||
private string name = name;
|
||||
|
||||
[ObservableProperty]
|
||||
private string named = $"{named}";
|
||||
|
||||
[ObservableProperty]
|
||||
private bool selected = selected;
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Aggerate(nameof(ItemContentViewModel))]
|
||||
public partial class ItemContentViewModel :
|
||||
ObservableCollection<IItemEntryViewModel>,
|
||||
|
||||
IItemEntryViewModel
|
||||
{
|
||||
public ItemContentViewModel(IServiceProvider provider,
|
||||
@@ -15,11 +17,6 @@ public partial class ItemContentViewModel :
|
||||
bool immutable = true) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
|
||||
if (!immutable)
|
||||
{
|
||||
Insert<AddItemNavigationViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
@@ -36,7 +36,7 @@ public partial class ItemHeaderViewModel : Observable<string, string>,
|
||||
}
|
||||
|
||||
public Task<ItemHeaderConfiguration> Handle(ConfirmEventArgs<Item> args,
|
||||
CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value });
|
||||
CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value! });
|
||||
|
||||
public Task Handle(UpdateEventArgs<Item> args) =>
|
||||
Task.FromResult(Immutable = false);
|
||||
|
||||
@@ -5,20 +5,20 @@ namespace Bitvault;
|
||||
|
||||
public class ModifiedItemHandler(IServiceProvider serviceProvider,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<ModifiedEventArgs<Item>>
|
||||
INotificationHandler<ModifiedEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public Task Handle(ModifiedEventArgs<Item> args)
|
||||
public Task Handle(ModifiedEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
Item oldItem = args.OldView;
|
||||
Item newItem = args.NewValue;
|
||||
Item<(Guid, string)> oldItem = args.OldView;
|
||||
Item<(Guid, string)> newItem = args.NewValue;
|
||||
|
||||
ICache<Item> cache = serviceProvider.GetRequiredService<ICache<Item>>();
|
||||
if (cache.TryGetValue(oldItem, out Item? cachedItem))
|
||||
ICache<Item<(Guid, string)>> cache = serviceProvider.GetRequiredService<ICache<Item<(Guid, string)>>>();
|
||||
if (cache.TryGetValue(oldItem, out Item<(Guid, string)>? cachedItem))
|
||||
{
|
||||
if (cachedItem is not null)
|
||||
{
|
||||
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||
IValueStore<Item> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item>>();
|
||||
IValueStore<Item<(Guid, string)>> valueStore = serviceScope.ServiceProvider.GetRequiredService<IValueStore<Item<(Guid, string)>>>();
|
||||
|
||||
int oldIndex = cache.IndexOf(cachedItem);
|
||||
cache.Remove(cachedItem);
|
||||
|
||||
@@ -4,21 +4,22 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class UnarchiveItemHandler(IValueStore<Item> valueStore,
|
||||
public class UnarchiveItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IDbContextFactory<LockerContext> dbContextFactory) :
|
||||
INotificationHandler<UnarchiveEventArgs<Item>>
|
||||
INotificationHandler<UnarchiveEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(UnarchiveEventArgs<Item> args)
|
||||
public async Task Handle(UnarchiveEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valueStore.Value is Item item)
|
||||
if (valueStore.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
(Guid id, string name) = item.Value;
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
using LockerContext context = await dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
if (await context.FindAsync<ItemEntry>(item.Id) is ItemEntry result)
|
||||
if (await context.FindAsync<ItemEntry>(id) is ItemEntry result)
|
||||
{
|
||||
result.State = 0;
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
public class UnfavouriteItemHandler(IValueStore<Item> valueStore,
|
||||
public class UnfavouriteItemHandler(IValueStore<Item<(Guid, string)>> valueStore,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<UnfavouriteEventArgs<Item>>
|
||||
INotificationHandler<UnfavouriteEventArgs<Item<(Guid, string)>>>
|
||||
{
|
||||
public async Task Handle(UnfavouriteEventArgs<Item> args)
|
||||
public async Task Handle(UnfavouriteEventArgs<Item<(Guid, string)>> args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (valueStore.Value is Item item)
|
||||
if (valueStore.Value is Item<(Guid, string)> item)
|
||||
{
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid,
|
||||
int)>((item.Id, 0)));
|
||||
(Guid id, string name) = item.Value;
|
||||
await mediator.Handle<UpdateEventArgs<(Guid, int)>, bool>(new UpdateEventArgs<(Guid, int)>((id, 0)));
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in New Issue
Block a user