tidy
This commit is contained in:
@@ -11,7 +11,7 @@ public class ClassicDesktopStyleApplicationHandler(INavigationContext navigation
|
||||
public Task Handle(Navigate<IClassicDesktopStyleApplicationLifetime> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is
|
||||
if (Application.Current?.ApplicationLifetime is
|
||||
IClassicDesktopStyleApplicationLifetime lifeTime)
|
||||
{
|
||||
if (args.Template is Window window)
|
||||
|
||||
@@ -4,7 +4,7 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class ContentControlHandler(INavigationContext navigationContext) :
|
||||
public class ContentControlHandler(INavigationContext navigationContext) :
|
||||
INavigateHandler<ContentControl>
|
||||
{
|
||||
public async Task Handle(Navigate<ContentControl> args,
|
||||
@@ -57,4 +57,4 @@ public class ContentControlHandler(INavigationContext navigationContext) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using Toolkit.UI.Controls.Avalonia;
|
||||
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
INavigateHandler<ContentDialog>
|
||||
{
|
||||
public async Task Handle(Navigate<ContentDialog> args,
|
||||
@@ -50,7 +50,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
async void HandleClosing(FluentAvalonia.UI.Controls.ContentDialog sender,
|
||||
FluentAvalonia.UI.Controls.ContentDialogClosingEventArgs args)
|
||||
{
|
||||
if (args.Result == FluentAvalonia.UI.Controls.ContentDialogResult.Primary ||
|
||||
if (args.Result == FluentAvalonia.UI.Controls.ContentDialogResult.Primary ||
|
||||
args.Result == FluentAvalonia.UI.Controls.ContentDialogResult.Secondary)
|
||||
{
|
||||
contentDialog.Closing -= HandleClosing;
|
||||
@@ -93,12 +93,12 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
}
|
||||
|
||||
if (content is IActivated activated)
|
||||
{
|
||||
{
|
||||
await activated.Activated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contentDialog.Opened += HandleOpened;
|
||||
contentDialog.Closing += HandleClosing;
|
||||
contentDialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ContentTemplate :
|
||||
|
||||
control.Loaded += HandleLoaded;
|
||||
control.Unloaded += HandleUnloaded;
|
||||
|
||||
|
||||
viewModelContentBinder?.Set(control);
|
||||
|
||||
return control;
|
||||
@@ -67,4 +67,4 @@ public class ContentTemplate :
|
||||
}
|
||||
|
||||
public bool Match(object? data) => true;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using Toolkit.UI.Controls.Avalonia;
|
||||
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class FrameHandler(INavigationContext navigationContext) :
|
||||
public class FrameHandler(INavigationContext navigationContext) :
|
||||
INavigateHandler<Frame>,
|
||||
INavigateBackHandler<Frame>
|
||||
{
|
||||
@@ -19,13 +19,13 @@ public class FrameHandler(INavigationContext navigationContext) :
|
||||
frame.NavigationPageFactory ??= new NavigationPageFactory();
|
||||
if (args.Template is Control control)
|
||||
{
|
||||
void NavigatingFrom(object? sender,
|
||||
void NavigatingFrom(object? sender,
|
||||
Control control)
|
||||
{
|
||||
async void HandleNavigatingFrom(object? _,
|
||||
async void HandleNavigatingFrom(object? _,
|
||||
NavigatingCancelEventArgs args)
|
||||
{
|
||||
Dictionary<string,object> results = [];
|
||||
Dictionary<string, object> results = [];
|
||||
|
||||
control.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
|
||||
NavigatedFrom(sender, control, () => results);
|
||||
@@ -71,13 +71,13 @@ public class FrameHandler(INavigationContext navigationContext) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
control.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
|
||||
}
|
||||
|
||||
void NavigatedFrom(object? sender,
|
||||
void NavigatedFrom(object? sender,
|
||||
Control control,
|
||||
Func<Dictionary<string, object>> resultCallBack)
|
||||
{
|
||||
@@ -109,9 +109,9 @@ public class FrameHandler(INavigationContext navigationContext) :
|
||||
contract.GetGenericArguments() is { Length: 1 } arguments)
|
||||
{
|
||||
if (contentType.GetMethods().FirstOrDefault(x =>
|
||||
x.Name == "NavigatedToAsync" &&
|
||||
x.Name == "NavigatedToAsync" &&
|
||||
x.GetCustomAttribute<NavigationContextAttribute>()
|
||||
is NavigationContextAttribute attribute && results.ContainsKey(attribute.Name))
|
||||
is NavigationContextAttribute attribute && results.ContainsKey(attribute.Name))
|
||||
is MethodInfo methodInfo)
|
||||
{
|
||||
if (methodInfo.GetCustomAttribute<NavigationContextAttribute>()
|
||||
@@ -153,10 +153,10 @@ public class FrameHandler(INavigationContext navigationContext) :
|
||||
control.AddHandler(Frame.NavigatedFromEvent, HandleNavigatedFrom);
|
||||
}
|
||||
|
||||
void NavigatedTo(object? sender,
|
||||
void NavigatedTo(object? sender,
|
||||
Control control)
|
||||
{
|
||||
async void HandleNavigatedTo(object? _,
|
||||
async void HandleNavigatedTo(object? _,
|
||||
NavigationEventArgs __)
|
||||
{
|
||||
control.RemoveHandler(Frame.NavigatedToEvent, HandleNavigatedTo);
|
||||
@@ -200,4 +200,4 @@ public class FrameHandler(INavigationContext navigationContext) :
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,4 @@ public class NavigationContext(INavigationContextCollection contexts) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,10 @@ using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Toolkit.Avalonia;
|
||||
|
||||
public class NavigationPageFactory :
|
||||
public class NavigationPageFactory :
|
||||
INavigationPageFactory
|
||||
{
|
||||
public Control? GetPage(Type srcType) => default;
|
||||
|
||||
public Control GetPageFromObject(object target) => (Control)target;
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,4 @@ public class SingleViewApplicationHandler(INavigationContext navigationContext)
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class AsyncLock(int initial = 1,
|
||||
int maximum = 1) :
|
||||
public class AsyncLock(int initial = 1,
|
||||
int maximum = 1) :
|
||||
IDisposable
|
||||
{
|
||||
private readonly SemaphoreSlim semaphore = new(initial, maximum);
|
||||
@@ -20,4 +20,4 @@ public class AsyncLock(int initial = 1,
|
||||
await semaphore.WaitAsync();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ public partial class CommandViewModel(IServiceProvider provider,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
public IRelayCommand InvokeCommand =>
|
||||
public IRelayCommand InvokeCommand =>
|
||||
new AsyncRelayCommand(InvokeAsync);
|
||||
|
||||
protected virtual Task InvokeAsync() =>
|
||||
protected virtual Task InvokeAsync() =>
|
||||
Task.CompletedTask;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ComponentBuilder :
|
||||
public class ComponentBuilder :
|
||||
IComponentBuilder
|
||||
{
|
||||
private readonly IHostBuilder hostBuilder;
|
||||
@@ -65,7 +65,7 @@ public class ComponentBuilder :
|
||||
}
|
||||
|
||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section,
|
||||
TConfiguration? configuration = null)
|
||||
TConfiguration? configuration = null)
|
||||
where TConfiguration :
|
||||
ComponentConfiguration, new()
|
||||
{
|
||||
@@ -88,7 +88,7 @@ public class ComponentBuilder :
|
||||
return this;
|
||||
}
|
||||
|
||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||
public IComponentBuilder AddConfiguration<TConfiguration>(string section)
|
||||
where TConfiguration : ComponentConfiguration, new()
|
||||
{
|
||||
AddConfiguration<TConfiguration>(section, null);
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
public record ComponentConfiguration
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,17 +8,16 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THe
|
||||
INotificationHandler<Changed<TConfiguration>>
|
||||
where TConfiguration : class
|
||||
{
|
||||
public ComponentConfigurationViewModel(IServiceProvider provider,
|
||||
public ComponentConfigurationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
THeader header,
|
||||
TDescription description,
|
||||
TAction action) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Task Handle(Changed<TConfiguration> args,
|
||||
@@ -58,6 +57,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAc
|
||||
Value = valueDelegate.Invoke(configuration);
|
||||
return base.Activated();
|
||||
}
|
||||
|
||||
public Task Handle(Changed<TConfiguration> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ public class ComponentHost(IServiceProvider services,
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||
@@ -38,4 +37,4 @@ public class ComponentHost(IServiceProvider services,
|
||||
await service.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,4 @@ public class ComponentHostCollection :
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
@@ -17,22 +16,22 @@ public class ComponentInitializer(IEnumerable<IComponent> components,
|
||||
IComponentBuilder builder = component.Create();
|
||||
builder.AddServices(services =>
|
||||
{
|
||||
services.AddTransient(_ =>
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IPublisher>>());
|
||||
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<INavigationContextCollection>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<INavigationContextProvider>());
|
||||
|
||||
services.AddScoped(_ =>
|
||||
services.AddScoped(_ =>
|
||||
provider.GetRequiredService<IComponentScopeCollection>());
|
||||
|
||||
services.AddTransient(_ =>
|
||||
services.AddTransient(_ =>
|
||||
provider.GetRequiredService<IComponentScopeProvider>());
|
||||
|
||||
services.AddRange(typedServices.Services);
|
||||
@@ -49,4 +48,4 @@ public class ComponentInitializer(IEnumerable<IComponent> components,
|
||||
await host.StartAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ComponentScope(string Name);
|
||||
public record ComponentScope(string Name);
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ComponentScopeCollection : List<ComponentScopeDescriptor>,
|
||||
IComponentScopeCollection;
|
||||
public class ComponentScopeCollection : List<ComponentScopeDescriptor>,
|
||||
IComponentScopeCollection;
|
||||
@@ -12,7 +12,6 @@ public class ConfigurationChangedHandler<TConfiguration, TValue>(ConfigurationVa
|
||||
{
|
||||
if (configurationValue.TryUpdate(configuration, out TValue value))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ public class ConfigurationDescriptor<TConfiguration>(string section,
|
||||
public TConfiguration Value => reader.Read();
|
||||
|
||||
public string Section => section;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ConfigurationFactory<TConfiguration>(Func<TConfiguration> factory) :
|
||||
IConfigurationFactory<TConfiguration>
|
||||
IConfigurationFactory<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
public object Create() => factory.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ConfigurationFile<TConfiguration>(IFileInfo fileInfo) :
|
||||
public class ConfigurationFile<TConfiguration>(IFileInfo fileInfo) :
|
||||
IConfigurationFile<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
public IFileInfo FileInfo => fileInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ConfigurationInitializer<TConfiguration>(IConfigurationReader<TConfiguration> reader,
|
||||
public class ConfigurationInitializer<TConfiguration>(IConfigurationReader<TConfiguration> reader,
|
||||
IConfigurationWriter<TConfiguration> writer,
|
||||
IConfigurationFactory<TConfiguration> factory,
|
||||
IPublisher publisher) :
|
||||
@@ -22,4 +22,4 @@ public class ConfigurationInitializer<TConfiguration>(IConfigurationReader<TConf
|
||||
|
||||
await publisher.PublishUI(new Changed<TConfiguration>(configuration));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,4 +43,4 @@ public class ConfigurationMonitor<TConfiguration>(IConfigurationFile<TConfigurat
|
||||
watcher?.Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,4 @@ public class ConfigurationReader<TConfiguration>(IConfigurationSource<TConfigura
|
||||
configuration = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class ConfigurationSource<TConfiguration>(IConfigurationFile<TConfigurati
|
||||
|
||||
if (currentNode is not null)
|
||||
{
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(currentNode[segments[lastIndex]],
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(currentNode[segments[lastIndex]],
|
||||
serializerOptions ?? defaultSerializerOptions());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ConfigurationValue<TConfiguration, TValue>(Func<TConfiguration, Action<TValue>> changed)
|
||||
where TValue :
|
||||
where TValue :
|
||||
class, new()
|
||||
{
|
||||
private TValue? currentValue;
|
||||
|
||||
public bool TryUpdate(TConfiguration configuration,
|
||||
public bool TryUpdate(TConfiguration configuration,
|
||||
out TValue value)
|
||||
{
|
||||
TValue newValue = new();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ContentTemplateDescriptor(object key,
|
||||
Type viewModelType,
|
||||
Type viewModelType,
|
||||
Type viewType,
|
||||
params object[]? parameters) :
|
||||
IContentTemplateDescriptor
|
||||
|
||||
@@ -13,4 +13,4 @@ public class ContentTemplateDescriptorProvider(IEnumerable<IContentTemplateDescr
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Create<TValue>(TValue Value);
|
||||
|
||||
@@ -8,6 +7,6 @@ public record Create
|
||||
public static Create<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
|
||||
public static Create<TValue> As<TValue>() where TValue : new() =>
|
||||
public static Create<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
@@ -144,13 +144,13 @@ public static class Test
|
||||
services.AddTransient(provider =>
|
||||
provider.GetRequiredKeyedService<IConfigurationDescriptor<TConfiguration>>(section).Value);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
public class DefaultBuilder :
|
||||
|
||||
public class DefaultBuilder :
|
||||
HostBuilder
|
||||
{
|
||||
public static IHostBuilder Create()
|
||||
@@ -166,7 +166,7 @@ public class DefaultBuilder :
|
||||
services.AddScoped<IServiceFactory>(provider =>
|
||||
new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)));
|
||||
|
||||
services.AddSingleton<IComponentHostCollection,
|
||||
services.AddSingleton<IComponentHostCollection,
|
||||
ComponentHostCollection>();
|
||||
|
||||
services.AddScoped<SubscriptionCollection>();
|
||||
@@ -211,4 +211,4 @@ public class DefaultBuilder :
|
||||
services.AddHostedService<AppService>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,15 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class DictionaryStringObjectJsonConverter :
|
||||
public class DictionaryStringObjectJsonConverter :
|
||||
JsonConverter<Dictionary<string, object?>>
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Dictionary<string, object>) ||
|
||||
typeToConvert == typeof(Dictionary<string, object?>);
|
||||
|
||||
public override Dictionary<string, object?> Read(ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
public override Dictionary<string, object?> Read(ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
Dictionary<string, object?> dictionary = [];
|
||||
@@ -42,7 +42,7 @@ public class DictionaryStringObjectJsonConverter :
|
||||
|
||||
public override void Write(Utf8JsonWriter writer,
|
||||
Dictionary<string, object?> value,
|
||||
JsonSerializerOptions options) =>
|
||||
JsonSerializerOptions options) =>
|
||||
JsonSerializer.Serialize(writer, (IDictionary<string, object?>)value, options);
|
||||
|
||||
private object? ExtractValue(ref Utf8JsonReader reader,
|
||||
@@ -56,20 +56,26 @@ public class DictionaryStringObjectJsonConverter :
|
||||
return date;
|
||||
}
|
||||
return reader.GetString();
|
||||
|
||||
case JsonTokenType.False:
|
||||
return false;
|
||||
|
||||
case JsonTokenType.True:
|
||||
return true;
|
||||
|
||||
case JsonTokenType.Null:
|
||||
return null;
|
||||
|
||||
case JsonTokenType.Number:
|
||||
if (reader.TryGetInt64(out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return reader.GetDecimal();
|
||||
|
||||
case JsonTokenType.StartObject:
|
||||
return Read(ref reader, null!, options);
|
||||
|
||||
case JsonTokenType.StartArray:
|
||||
List<object?> list = [];
|
||||
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
|
||||
@@ -77,6 +83,7 @@ public class DictionaryStringObjectJsonConverter :
|
||||
list.Add(ExtractValue(ref reader, options));
|
||||
}
|
||||
return list;
|
||||
|
||||
default:
|
||||
return default;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Reactive.Disposables;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reactive.Disposables;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class Disposer :
|
||||
public class Disposer :
|
||||
IDisposer
|
||||
{
|
||||
private readonly ConcurrentDictionary<object, CompositeDisposable> subjects = [];
|
||||
@@ -45,10 +45,10 @@ public class Disposer :
|
||||
}
|
||||
}
|
||||
|
||||
public TDisposable Replace<TDisposable>(object subject,
|
||||
IDisposable disposer,
|
||||
public TDisposable Replace<TDisposable>(object subject,
|
||||
IDisposable disposer,
|
||||
TDisposable replacement)
|
||||
where TDisposable :
|
||||
where TDisposable :
|
||||
IDisposable
|
||||
{
|
||||
CompositeDisposable disposables = subjects.GetOrAdd(subject, args => new CompositeDisposable());
|
||||
@@ -61,7 +61,7 @@ public class Disposer :
|
||||
return replacement;
|
||||
}
|
||||
|
||||
public void Remove(object subject,
|
||||
public void Remove(object subject,
|
||||
IDisposable disposer)
|
||||
{
|
||||
CompositeDisposable disposables = subjects.GetOrAdd(subject, args => new CompositeDisposable());
|
||||
@@ -78,4 +78,4 @@ public class Disposer :
|
||||
disposables?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ public class HandlerWrapper<TRequest, TResponse>(IHandler<TRequest, TResponse> h
|
||||
IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours)
|
||||
where TRequest : class
|
||||
{
|
||||
private readonly IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours =
|
||||
private readonly IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours =
|
||||
pipelineBehaviours.Reverse();
|
||||
|
||||
public async Task<TResponse> Handle(TRequest request,
|
||||
public async Task<TResponse> Handle(TRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
HandlerDelegate<TRequest, TResponse> currentHandler = handler.Handle;
|
||||
|
||||
@@ -14,10 +14,10 @@ public interface ICache<TKey, TValue> :
|
||||
IEnumerable<KeyValuePair<TKey, TValue>>
|
||||
where TKey :
|
||||
notnull
|
||||
where TValue :
|
||||
where TValue :
|
||||
notnull
|
||||
{
|
||||
void Add(TKey key,
|
||||
void Add(TKey key,
|
||||
TValue value);
|
||||
|
||||
void Clear();
|
||||
@@ -27,4 +27,4 @@ public interface ICache<TKey, TValue> :
|
||||
bool Remove(TKey key);
|
||||
|
||||
bool TryGetValue(TKey key, out TValue? value);
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
public interface IComponentConfigurationViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IComponentHost :
|
||||
public interface IComponentHost :
|
||||
IHost
|
||||
{
|
||||
ComponentConfiguration? Configuration { get; }
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IComponentScopeCollection :
|
||||
IList<ComponentScopeDescriptor>;
|
||||
|
||||
public interface IComponentScopeCollection :
|
||||
IList<ComponentScopeDescriptor>;
|
||||
@@ -3,5 +3,4 @@
|
||||
public interface IComponentScopeProvider
|
||||
{
|
||||
ComponentScopeDescriptor? Get(string key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IConfigurationChanged<TConfiguration> :
|
||||
public interface IConfigurationChanged<TConfiguration> :
|
||||
IInitializer;
|
||||
@@ -7,4 +7,4 @@ public interface IConfigurationDescriptor<out TConfiguration>
|
||||
TConfiguration Value { get; }
|
||||
|
||||
string Section { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IConfigurationFactory<TConfiguration>
|
||||
where TConfiguration :
|
||||
public interface IConfigurationFactory<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
object Create();
|
||||
|
||||
@@ -7,4 +7,4 @@ public interface IConfigurationFile<TConfiguration>
|
||||
class
|
||||
{
|
||||
IFileInfo FileInfo { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IConfigurationInitializer<TConfiguration>
|
||||
public interface IConfigurationInitializer<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IConfigurationMonitor<TConfiguration> :
|
||||
public interface IConfigurationMonitor<TConfiguration> :
|
||||
IHostedService
|
||||
where TConfiguration :
|
||||
class;
|
||||
@@ -7,4 +7,4 @@ public interface IConfigurationReader<TConfiguration>
|
||||
bool TryRead(out TConfiguration? configuration);
|
||||
|
||||
TConfiguration Read();
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,4 @@ public interface IConfigurationSource<TConfiguration>
|
||||
void Set(TConfiguration value);
|
||||
|
||||
void Set(object value);
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
public interface IContentTemplate
|
||||
{
|
||||
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IContentTemplateDescriptorProvider
|
||||
{
|
||||
IContentTemplateDescriptor? Get(object key);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ public interface IDeactivating
|
||||
Task Deactivating();
|
||||
}
|
||||
|
||||
public interface IDeactivating<TResult>
|
||||
public interface IDeactivating<TResult>
|
||||
{
|
||||
Task<TResult> Deactivating();
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IDispatcher
|
||||
{
|
||||
Task InvokeAsync(Action action);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
public interface IDisposer
|
||||
{
|
||||
void Add(object subject,
|
||||
void Add(object subject,
|
||||
params object[] objects);
|
||||
|
||||
TDisposable Replace<TDisposable>(object subject,
|
||||
IDisposable disposer,
|
||||
TDisposable replacement) where TDisposable : IDisposable;
|
||||
|
||||
void Remove(object subject,
|
||||
void Remove(object subject,
|
||||
IDisposable disposer);
|
||||
|
||||
void Dispose(object subject);
|
||||
|
||||
@@ -5,8 +5,7 @@ public interface IFactory<TParameter, TService>
|
||||
TService? Create(TParameter value);
|
||||
}
|
||||
|
||||
|
||||
public interface IFactory<TService>
|
||||
{
|
||||
TService? Create();
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,16 @@ namespace Toolkit.Foundation;
|
||||
|
||||
public static class IHostBuilderExtensions
|
||||
{
|
||||
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder,
|
||||
public static IHostBuilder UseContentRoot(this IHostBuilder hostBuilder,
|
||||
string contentRoot,
|
||||
bool createDirectory)
|
||||
{
|
||||
if (createDirectory)
|
||||
{
|
||||
{
|
||||
Directory.CreateDirectory(contentRoot);
|
||||
}
|
||||
|
||||
hostBuilder.UseContentRoot(contentRoot);
|
||||
return hostBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IMediator
|
||||
|
||||
namespace Toolkit.Foundation
|
||||
{
|
||||
Task<TResponse?> Handle<TRequest, TResponse>(TRequest request,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TRequest : notnull;
|
||||
|
||||
Task<object?> Handle(object request, CancellationToken
|
||||
cancellationToken = default);
|
||||
public interface IMediator
|
||||
{
|
||||
Task<object?> Handle(object message, CancellationToken cancellationToken = default);
|
||||
Task<TResponse?> Handle<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken = default) where TRequest : notnull;
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@ public interface INavigateHandler;
|
||||
|
||||
public interface INavigateHandler<TNavigation> :
|
||||
INotificationHandler<Navigate<TNavigation>>,
|
||||
INavigateHandler;
|
||||
INavigateHandler;
|
||||
@@ -3,5 +3,4 @@
|
||||
public interface INavigation
|
||||
{
|
||||
Type Type { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface INavigationContextCollection :
|
||||
IDictionary<object, object?>;
|
||||
IDictionary<object, object?>;
|
||||
@@ -4,6 +4,6 @@ public interface INavigationContextProvider
|
||||
{
|
||||
object? Get(object key);
|
||||
|
||||
bool TryGet(object key,
|
||||
bool TryGet(object key,
|
||||
out object? value);
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface INavigationProvider
|
||||
{
|
||||
INavigation? Get(Type type);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
public interface INavigationScope
|
||||
{
|
||||
Task NavigateAsync(string route, object? sender = null, object? context = null,
|
||||
Task NavigateAsync(string route, object? sender = null, object? context = null,
|
||||
EventHandler? navigated = null, object[]? parameters = null, CancellationToken cancellationToken = default);
|
||||
|
||||
Task NavigateBackAsync(object? context, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IObservableCollectionViewModel<TItem> :
|
||||
IObservableViewModel;
|
||||
public interface IObservableCollectionViewModel<TItem> :
|
||||
IObservableViewModel;
|
||||
@@ -8,5 +8,4 @@ public interface IPrimaryConfirmation
|
||||
public interface IConfirmation
|
||||
{
|
||||
Task<bool> Confirm();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IProxyService<TService>
|
||||
{
|
||||
TService Proxy { get; }
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public interface IPublisher
|
||||
object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull;
|
||||
|
||||
Task PublishUI<TMessage>(object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : new();
|
||||
@@ -42,4 +43,4 @@ public interface IPublisher
|
||||
where TMessage : new();
|
||||
|
||||
public Task Publish(object message, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IRequest<out TResponse> :
|
||||
IMessage;
|
||||
|
||||
public interface IRequest : IRequest<Unit>;
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.FileProviders.Physical;
|
||||
@@ -29,7 +28,7 @@ public static class IServiceCollectionExtensions
|
||||
}
|
||||
|
||||
public static IServiceCollection AddComponent<TComponent>(this IServiceCollection services)
|
||||
where TComponent : class,
|
||||
where TComponent : class,
|
||||
IComponent
|
||||
{
|
||||
services.AddTransient<IComponent, TComponent>();
|
||||
@@ -48,13 +47,13 @@ public static class IServiceCollectionExtensions
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
string section)
|
||||
where TConfiguration : class, new() =>
|
||||
services.AddConfiguration<TConfiguration>(section, "Settings.json", null);
|
||||
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services)
|
||||
where TConfiguration : class, new() =>
|
||||
where TConfiguration : class, new() =>
|
||||
services.AddConfiguration<TConfiguration>(typeof(TConfiguration).Name, "Settings.json", null);
|
||||
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
@@ -85,7 +84,7 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
object configuration)
|
||||
where TConfiguration : class, new() =>
|
||||
where TConfiguration : class, new() =>
|
||||
services.AddConfiguration(configuration.GetType().Name,
|
||||
"Settings.json", (TConfiguration?)configuration);
|
||||
|
||||
@@ -130,7 +129,7 @@ public static class IServiceCollectionExtensions
|
||||
services.TryAddKeyedTransient<IConfigurationWriter<TConfiguration>>(section, (provider, key) =>
|
||||
new ConfigurationWriter<TConfiguration>(provider.GetRequiredKeyedService<IConfigurationSource<TConfiguration>>(key)));
|
||||
|
||||
services.TryAddKeyedTransient<IConfigurationFactory<TConfiguration>>(section, (provider, key) =>
|
||||
services.TryAddKeyedTransient<IConfigurationFactory<TConfiguration>>(section, (provider, key) =>
|
||||
new ConfigurationFactory<TConfiguration>(() => defaultConfiguration ?? new TConfiguration()));
|
||||
|
||||
services.AddTransient<IInitializer, ConfigurationInitializer<TConfiguration>>(provider =>
|
||||
@@ -147,7 +146,7 @@ public static class IServiceCollectionExtensions
|
||||
services.TryAddKeyedTransient<IConfigurationDescriptor<TConfiguration>>(section, (provider, key) =>
|
||||
new ConfigurationDescriptor<TConfiguration>(section, provider.GetRequiredKeyedService<IConfigurationReader<TConfiguration>>(key)));
|
||||
|
||||
services.AddTransient(provider =>
|
||||
services.AddTransient(provider =>
|
||||
provider.GetRequiredKeyedService<IConfigurationDescriptor<TConfiguration>>(section));
|
||||
|
||||
services.AddTransient(provider =>
|
||||
@@ -258,7 +257,7 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
key ??= viewModelType.Name.Replace("ViewModel", "");
|
||||
|
||||
services.AddTransient(viewModelType, provider =>
|
||||
services.AddTransient(viewModelType, provider =>
|
||||
provider.GetRequiredService<IServiceFactory>().Create<TViewModel>(parameters)!);
|
||||
|
||||
services.AddTransient(viewType);
|
||||
@@ -268,7 +267,7 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
services.AddKeyedTransient(viewType, key);
|
||||
|
||||
services.AddTransient<IContentTemplateDescriptor>(provider =>
|
||||
services.AddTransient<IContentTemplateDescriptor>(provider =>
|
||||
new ContentTemplateDescriptor(key, viewModelType, viewType, parameters));
|
||||
|
||||
return services;
|
||||
|
||||
@@ -5,4 +5,4 @@ public interface IServiceFactory
|
||||
object Create(Type type, params object?[]? parameters);
|
||||
|
||||
TService Create<TService>(params object?[]? parameters);
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
public interface IServiceScopeFactory<TService>
|
||||
{
|
||||
TService? Create(params object?[] parameters);
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,4 @@ namespace Toolkit.Foundation;
|
||||
public interface IServiceScopeProvider<TService>
|
||||
{
|
||||
bool TryGet(TService service, out IServiceScope? serviceScope);
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,4 @@ public interface ISubscriptionManager
|
||||
void Remove(object subscriber);
|
||||
|
||||
void Add(object subscriber);
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,4 @@ public interface IWritableConfiguration<out TConfiguration>
|
||||
class
|
||||
{
|
||||
void Write(Action<TConfiguration> updateDelegate);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ public record Insert
|
||||
public static Insert<TValue> As<TValue>(int index, TValue value) =>
|
||||
new(index, value);
|
||||
|
||||
public static Insert<TValue> As<TValue>(int index) where TValue : new() =>
|
||||
public static Insert<TValue> As<TValue>(int index) where TValue : new() =>
|
||||
new(index, new TValue());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record KeyAccelerator(VirtualKey Key,
|
||||
VirtualKey[]? Modifiers = null) :
|
||||
IRequest;
|
||||
VirtualKey[]? Modifiers = null);
|
||||
@@ -12,7 +12,7 @@ public class Mediator(IServiceProvider provider) :
|
||||
Type handlerType = typeof(HandlerWrapper<,>).MakeGenericType(request.GetType(),
|
||||
typeof(TResponse));
|
||||
|
||||
if (provider.GetService(handlerType)
|
||||
if (provider.GetService(handlerType)
|
||||
is object handler)
|
||||
{
|
||||
if (handlerType.GetMethod("Handle") is MethodInfo handleMethod)
|
||||
@@ -27,14 +27,14 @@ public class Mediator(IServiceProvider provider) :
|
||||
public Task<object?> Handle(object message,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (message.GetType().GetInterface(typeof(IRequest<>).Name) is Type requestType &&
|
||||
if (message.GetType().GetInterface(message.GetType().Name) is Type requestType &&
|
||||
requestType.GetGenericArguments().Length == 1)
|
||||
{
|
||||
Type responseType = requestType.GetGenericArguments()[0];
|
||||
Type handlerType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(),
|
||||
Type handlerType = typeof(HandlerWrapper<,>).MakeGenericType(message.GetType(),
|
||||
responseType);
|
||||
|
||||
if (provider.GetService(handlerType)
|
||||
if (provider.GetService(handlerType)
|
||||
is object handler)
|
||||
{
|
||||
if (handlerType.GetMethod("Handle") is MethodInfo handleMethod)
|
||||
|
||||
@@ -12,7 +12,7 @@ public static class MethodInfoExtensions
|
||||
}
|
||||
|
||||
public static async Task InvokeAsync(this MethodInfo methodInfo,
|
||||
object? obj,
|
||||
object? obj,
|
||||
params object[] parameters)
|
||||
{
|
||||
await (dynamic?)methodInfo.Invoke(obj, parameters);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Navigate(string Route,
|
||||
object? Context = null,
|
||||
string? Scope = null,
|
||||
public record Navigate(string Route,
|
||||
object? Context = null,
|
||||
string? Scope = null,
|
||||
object? Sender = null,
|
||||
EventHandler? Navigated = null,
|
||||
object[]? Parameters = null);
|
||||
|
||||
public record Navigate<TNavigation>(object Context,
|
||||
object Template,
|
||||
public record Navigate<TNavigation>(object Context,
|
||||
object Template,
|
||||
object Content,
|
||||
object? Sender = null,
|
||||
object[]? Parameters = null);
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
public record NavigateBack(object? Context = null, string? Scope = null);
|
||||
|
||||
public record NavigateBack<TNavigation>(object? Context);
|
||||
public record NavigateBack<TNavigation>(object? Context);
|
||||
@@ -17,6 +17,4 @@ public class NavigateBackHandler(IComponentScopeProvider provider) :
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,10 +6,10 @@ public class NavigateHandler(ComponentScope scope,
|
||||
IComponentScopeProvider provider) :
|
||||
INotificationHandler<Navigate>
|
||||
{
|
||||
public async Task Handle(Navigate args,
|
||||
public async Task Handle(Navigate args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (provider.Get(args.Scope ?? scope.Name)
|
||||
if (provider.Get(args.Scope ?? scope.Name)
|
||||
is ComponentScopeDescriptor descriptor)
|
||||
{
|
||||
if (descriptor?.Services?.GetService<INavigationScope>() is INavigationScope navigationScope)
|
||||
@@ -19,4 +19,4 @@ public class NavigateHandler(ComponentScope scope,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record NavigatingFrom(object Content) :
|
||||
IRequest<IReadOnlyCollection<object>>;
|
||||
|
||||
public record NavigatingTo(object Content) :
|
||||
IRequest<IReadOnlyCollection<object>>;
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Navigation :
|
||||
public record Navigation :
|
||||
INavigation
|
||||
{
|
||||
public required Type Type { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,4 +9,4 @@ public class NavigationContextAttribute : Attribute
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class NavigationContextCollection : Dictionary<object, object?>,
|
||||
INavigationContextCollection;
|
||||
public class NavigationContextCollection : Dictionary<object, object?>,
|
||||
INavigationContextCollection;
|
||||
@@ -6,7 +6,7 @@ public class NavigationContextProvider(INavigationContextCollection contexts) :
|
||||
public object? Get(object key) =>
|
||||
contexts.TryGetValue(key, out object? target) ? target : default;
|
||||
|
||||
public bool TryGet(object name,
|
||||
public bool TryGet(object name,
|
||||
out object? value)
|
||||
{
|
||||
if (contexts.TryGetValue(name,
|
||||
@@ -21,4 +21,4 @@ public class NavigationContextProvider(INavigationContextCollection contexts) :
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,4 @@ public class NavigationProvider(IEnumerable<INavigation> navigations) :
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,16 @@ public class NavigationScope(IPublisher publisher,
|
||||
IServiceFactory factory,
|
||||
INavigationProvider navigationProvider,
|
||||
INavigationContextProvider navigationContextProvider,
|
||||
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
|
||||
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
|
||||
INavigationScope
|
||||
{
|
||||
public async Task NavigateAsync(string route, object? sender = null, object? context = null,
|
||||
public async Task NavigateAsync(string route, object? sender = null, object? context = null,
|
||||
EventHandler? navigated = null, object[]? parameters = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
string[] segments = route.Split('/');
|
||||
int segmentCount = segments.Length;
|
||||
int currentSegmentIndex = 0;
|
||||
|
||||
|
||||
foreach (object segment in segments)
|
||||
{
|
||||
currentSegmentIndex++;
|
||||
@@ -79,7 +79,7 @@ public class NavigationScope(IPublisher publisher,
|
||||
}
|
||||
}
|
||||
|
||||
public async Task NavigateBackAsync(object? context,
|
||||
public async Task NavigateBackAsync(object? context,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (context is not null)
|
||||
@@ -100,5 +100,4 @@ public class NavigationScope(IPublisher publisher,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
|
||||
public class NavigationTargetAttribute(string name) :
|
||||
public class NavigationTargetAttribute(string name) :
|
||||
Attribute
|
||||
{
|
||||
public string Name => name;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public delegate Task NotificationHandlerDelegate<TMessage>(TMessage message,
|
||||
CancellationToken cancellationToken);
|
||||
CancellationToken cancellationToken);
|
||||
@@ -18,7 +18,7 @@ public class NotificationHandlerWrapper<TMessage>(INotificationHandler<TMessage>
|
||||
await behaviour.Handle(args, previousHandler, token);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
await currentHandler(message, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public static class ObjectExtensions
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TAttribute? GetAttribute<TAttribute>(this object obj)
|
||||
public static TAttribute? GetAttribute<TAttribute>(this object obj)
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
Type type = obj.GetType();
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
ObservableObject,
|
||||
IObservableCollectionViewModel<TViewModel>,
|
||||
@@ -22,7 +23,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
INotificationHandler<Insert<TViewModel>>,
|
||||
INotificationHandler<Move<TViewModel>>,
|
||||
INotificationHandler<Replace<TViewModel>>
|
||||
where TViewModel :
|
||||
where TViewModel :
|
||||
notnull
|
||||
{
|
||||
private readonly ObservableCollection<TViewModel> collection = [];
|
||||
@@ -113,7 +114,6 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
this[index] = item!;
|
||||
@@ -172,7 +172,6 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Add(item!);
|
||||
@@ -280,7 +279,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Replace<TViewModel> args,
|
||||
public Task Handle(Replace<TViewModel> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Value is TViewModel item)
|
||||
@@ -366,7 +365,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
public void RemoveAt(int index) =>
|
||||
RemoveItem(index);
|
||||
|
||||
public bool Replace(int index,
|
||||
public bool Replace(int index,
|
||||
TViewModel item)
|
||||
{
|
||||
if (index <= Count - 1)
|
||||
@@ -409,12 +408,12 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
private static bool IsCompatibleObject(object? value) =>
|
||||
(value is TViewModel) || (value == null && default(TViewModel) == null);
|
||||
|
||||
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) =>
|
||||
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) =>
|
||||
CollectionChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
public class ObservableCollectionViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public partial class ObservableViewModel :
|
||||
public partial class ObservableViewModel :
|
||||
ObservableObject,
|
||||
IObservableViewModel,
|
||||
IInitializer,
|
||||
@@ -73,4 +73,4 @@ public partial class ObservableViewModel :
|
||||
IsInitialized = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,18 @@ namespace Toolkit.Foundation;
|
||||
|
||||
public class Publisher(ISubscriptionManager subscriptionManager,
|
||||
IServiceProvider provider,
|
||||
IDispatcher dispatcher) :
|
||||
IDispatcher dispatcher) :
|
||||
IPublisher
|
||||
{
|
||||
public Task Publish<TMessage>(object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : new() =>
|
||||
where TMessage : new() =>
|
||||
Publish(new TMessage(), async args => await args(),
|
||||
key, cancellationToken);
|
||||
|
||||
public Task Publish<TMessage>(TMessage message,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull =>
|
||||
where TMessage : notnull =>
|
||||
Publish(message, async args => await args(),
|
||||
null, cancellationToken);
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Publisher(ISubscriptionManager subscriptionManager,
|
||||
object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull =>
|
||||
Publish(message, async args => await args(),
|
||||
Publish(message, async args => await args(),
|
||||
key, cancellationToken);
|
||||
|
||||
public async Task Publish(object message,
|
||||
@@ -65,31 +65,32 @@ public class Publisher(ISubscriptionManager subscriptionManager,
|
||||
async args => await args(),
|
||||
null, cancellationToken);
|
||||
|
||||
public Task Publish<TMessage>(CancellationToken cancellationToken = default)
|
||||
where TMessage : new() =>
|
||||
public Task Publish<TMessage>(CancellationToken cancellationToken = default)
|
||||
where TMessage : new() =>
|
||||
Publish(new TMessage(), async args => await args(),
|
||||
null, cancellationToken);
|
||||
|
||||
public Task PublishUI<TMessage>(object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : new() =>
|
||||
Publish(new TMessage(), args => dispatcher.InvokeAsync(async () => await args()),
|
||||
where TMessage : new() =>
|
||||
Publish(new TMessage(), args => dispatcher.InvokeAsync(async () => await args()),
|
||||
key, cancellationToken);
|
||||
|
||||
public Task PublishUI<TMessage>(TMessage message,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull =>
|
||||
where TMessage : notnull =>
|
||||
Publish(message, args => dispatcher.InvokeAsync(async () => await args()),
|
||||
null, cancellationToken);
|
||||
|
||||
public Task PublishUI<TMessage>(TMessage message,
|
||||
object key,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TMessage : notnull =>
|
||||
where TMessage : notnull =>
|
||||
Publish(message, args => dispatcher.InvokeAsync(async () => await args()),
|
||||
key, cancellationToken);
|
||||
|
||||
public Task PublishUI<TMessage>(CancellationToken cancellationToken = default)
|
||||
where TMessage : new() =>
|
||||
where TMessage : new() =>
|
||||
Publish(new TMessage(), args => dispatcher.InvokeAsync(async () => await args()),
|
||||
null, cancellationToken);
|
||||
|
||||
@@ -97,4 +98,4 @@ public class Publisher(ISubscriptionManager subscriptionManager,
|
||||
CancellationToken cancellationToken = default) => Publish(message, args =>
|
||||
dispatcher.InvokeAsync(async () => await args()),
|
||||
null, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Remove<TValue>(TValue Value);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Replace<TValue>(int Index, TValue Value);
|
||||
|
||||
|
||||
@@ -6,6 +6,6 @@ public class ServiceFactory(Func<Type, object?[]?, object> factory) :
|
||||
public TService Create<TService>(params object?[]? parameters) =>
|
||||
(TService)factory(typeof(TService), parameters);
|
||||
|
||||
public object Create(Type type, params object?[]? parameters) =>
|
||||
public object Create(Type type, params object?[]? parameters) =>
|
||||
factory(type, parameters);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFactory,
|
||||
public class ServiceScopeFactory<TService>(IServiceScopeFactory serviceScopeFactory,
|
||||
ICache<TService, IServiceScope> cache) :
|
||||
IServiceScopeFactory<TService>
|
||||
where TService : notnull
|
||||
|
||||
@@ -6,7 +6,7 @@ public class ServiceScopeProvider<TService>(ICache<TService, IServiceScope> cach
|
||||
IServiceScopeProvider<TService>
|
||||
where TService : notnull
|
||||
{
|
||||
public bool TryGet(TService service,
|
||||
public bool TryGet(TService service,
|
||||
out IServiceScope? serviceScope)
|
||||
{
|
||||
if (cache.TryGetValue(service, out IServiceScope? value))
|
||||
@@ -18,4 +18,4 @@ public class ServiceScopeProvider<TService>(ICache<TService, IServiceScope> cach
|
||||
serviceScope = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,4 @@
|
||||
public class NavigationRouteAttribute(string route) : Attribute
|
||||
{
|
||||
public string Route => route;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user