lots of tidying up

This commit is contained in:
TheXamlGuy
2024-01-25 20:33:55 +00:00
parent 5e26e97f6b
commit a322893166
20 changed files with 115 additions and 123 deletions
+1 -1
View File
@@ -27,8 +27,8 @@ public class PrimaryWidget :
.AddCache<Guid, IWidgetComponentViewModel>()
.AddTransient<IProvider<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentProvider>()
.AddTransient<IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentFactory>()
.AddTransient<IEnumerator<IWidgetComponentViewModel>, WidgetComponentEnumerationHandler>()
.AddWidgetTemplate<PrimaryWidgetViewModel>()
.AddHandler<WidgetComponentViewModelEnumerator>()
.AddHandler<PrimaryWidgetConfigurationHandler>();
});
}
@@ -6,9 +6,8 @@ namespace Hyperbar.Windows.Primary;
public class PrimaryWidgetViewModel(ITemplateFactory templateFactory,
IServiceFactory serviceFactory,
IMediator mediator,
IDisposer disposer,
IEnumerator<IWidgetComponentViewModel> enumerator) :
ObservableCollectionViewModel<IWidgetComponentViewModel>(serviceFactory, mediator, disposer, enumerator),
IDisposer disposer) :
ObservableCollectionViewModel<IWidgetComponentViewModel>(serviceFactory, mediator, disposer),
IWidgetViewModel,
ITemplatedViewModel
{
@@ -2,12 +2,13 @@
namespace Hyperbar.Windows.Primary;
public class WidgetComponentEnumerationHandler(PrimaryWidgetConfiguration configuration,
public class WidgetComponentViewModelEnumerator(PrimaryWidgetConfiguration configuration,
IMediator mediator,
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory,
ICache<(Guid ParentId, Guid Id), PrimaryCommandConfiguration> cache) :
IEnumerator<IWidgetComponentViewModel>
INotificationHandler<Enumerate<IWidgetComponentViewModel>>
{
public IEnumerable<IWidgetComponentViewModel?> Get()
public async Task Handle(Enumerate<IWidgetComponentViewModel> notification, CancellationToken cancellationToken)
{
Stack<(Guid, List<PrimaryCommandConfiguration>)> stack = new();
stack.Push((Guid.Empty, configuration.Commands));
@@ -27,7 +28,11 @@ public class WidgetComponentEnumerationHandler(PrimaryWidgetConfiguration config
foreach (PrimaryCommandConfiguration item in configuration.Commands.OrderBy(x => x.Order))
{
yield return factory.Create(item);
if (factory.Create(item) is IWidgetComponentViewModel viewModel)
{
await mediator.PublishAsync(new Created<IWidgetComponentViewModel>(viewModel), nameof(PrimaryWidgetViewModel),
cancellationToken);
}
}
}
}