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

Some files were not shown because too many files have changed in this diff Show More