This commit is contained in:
TheXamlGuy
2024-05-24 08:21:50 +01:00
parent 40a150fe80
commit c0c1a82846
103 changed files with 168 additions and 655 deletions
+1 -1
View File
@@ -5,4 +5,4 @@ public record Activate
public static ActivateEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static ActivateEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ActivateEventArgs<TValue>(TValue? Value = default);
public record ActivateEventArgs<TValue>(TValue? Value = default);
+1 -1
View File
@@ -5,4 +5,4 @@ public record Activated
public static ActivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static ActivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ActivatedEventArgs<TValue>(TValue? Value = default);
public record ActivatedEventArgs<TValue>(TValue? Value = default);
+2 -2
View File
@@ -8,7 +8,7 @@ public class AesDecryptor :
private const int IvSize = 16;
public bool TryDecrypt(byte[] cipher,
byte[] key,
byte[] key,
out byte[]? decryptedData)
{
decryptedData = null;
@@ -47,4 +47,4 @@ public class AesDecryptor :
return false;
}
}
}
}
+3 -3
View File
@@ -2,12 +2,12 @@
namespace Toolkit.Foundation;
public class AesEncryptor :
public class AesEncryptor :
IEncryptor
{
private const int IvSize = 16;
public bool TryEncrypt(byte[] data,
public bool TryEncrypt(byte[] data,
byte[] key,
out byte[]? encryptedData)
{
@@ -46,4 +46,4 @@ public class AesEncryptor :
return false;
}
}
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ public enum AggerateMode
{
Append,
Reset
}
}
+2
View File
@@ -66,6 +66,7 @@ public class Cache<TKey, TValue>(IComparer<TKey> comparer) :
notnull
{
private readonly List<KeyValuePair<TKey, TValue?>> items = [];
public TValue? this[TKey key]
{
get
@@ -108,6 +109,7 @@ public class Cache<TKey, TValue>(IComparer<TKey> comparer) :
items.Insert(index, new KeyValuePair<TKey, TValue?>(key, value));
}
public void Clear() => items.Clear();
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() =>
+1 -1
View File
@@ -7,4 +7,4 @@ public record Cancel
public static CancelEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record CancelEventArgs<TValue>(TValue Value);
public record CancelEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -5,4 +5,4 @@ public record Changed
public static ChangedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static ChangedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ChangedEventArgs<TValue>(TValue? Value = default);
public record ChangedEventArgs<TValue>(TValue? Value = default);
+2 -2
View File
@@ -13,7 +13,7 @@ public class Component :
}
public static TComponent? Create<TComponent>(IServiceProvider provider,
Action<IComponentBuilder> builderDelegate)
Action<IComponentBuilder> builderDelegate)
where TComponent : class, IComponent
{
if (provider.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
@@ -23,7 +23,7 @@ public class Component :
return factory.Create<TComponent>(builder);
}
return default ;
return default;
}
public virtual IComponentBuilder Create() => builder;
+3 -3
View File
@@ -4,11 +4,11 @@ namespace Toolkit.Foundation;
public class ComponentFactory(IServiceProvider provider,
IProxyServiceCollection<IComponentBuilder> proxy,
IComponentScopeCollection scopes) :
IComponentScopeCollection scopes) :
IComponentFactory
{
public IComponentHost? Create<TComponent, TConfiguration>(string name,
TConfiguration configuration,
TConfiguration configuration,
Action<IServiceCollection>? servicesDelegate = null)
where TComponent : IComponent
where TConfiguration : ComponentConfiguration, new()
@@ -56,4 +56,4 @@ public class ComponentFactory(IServiceProvider provider,
return default;
}
}
}
+1 -2
View File
@@ -10,14 +10,13 @@ public class ComponentHost(IServiceProvider services,
{
public IServiceProvider Services => services;
public void Dispose()
{
}
public TConfiguration? GetConfiguration<TConfiguration>() where TConfiguration : ComponentConfiguration
{
return Services.GetService<TConfiguration>();
return Services.GetService<TConfiguration>();
}
public async Task StartAsync(CancellationToken cancellationToken = default)
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ConfirmEventArgs<TValue>(TValue Value);
public record ConfirmEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record CreateEventArgs<TValue>(TValue Value);
public record CreateEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -7,4 +7,4 @@ public record Created
public static CreatedEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record CreatedEventArgs<TValue>(TValue Value);
public record CreatedEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -5,4 +5,4 @@ public record Deactivated
public static DeactivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static DeactivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record DeactivatedEventArgs<TValue>(TValue? Value = default);
public record DeactivatedEventArgs<TValue>(TValue? Value = default);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record DeleteEventArgs<TValue>(TValue Value);
public record DeleteEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -7,4 +7,4 @@ public record Edit
public static EditEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
namespace Toolkit.Foundation;
public class HandlerProvider(SubscriptionCollection subscriptions) :
public class HandlerProvider(SubscriptionCollection subscriptions) :
IHandlerProvider
{
public IEnumerable<object?> Get(Type type,
@@ -24,4 +24,4 @@ public class HandlerProvider(SubscriptionCollection subscriptions) :
}
}
}
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ public interface IActivated
public interface IActivated<TResult>
{
Task Activated(TResult result);
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
public interface IAggerate
{
object? Key { get; init; }
}
}
+1
View File
@@ -1,4 +1,5 @@
namespace Toolkit.Foundation;
public interface IDecryptor
{
bool TryDecrypt(byte[] cipher,
+1 -1
View File
@@ -3,4 +3,4 @@
public interface IDisposerRequired
{
IDisposer Disposer { get; }
}
}
+2 -3
View File
@@ -1,8 +1,7 @@
namespace Toolkit.Foundation;
namespace Toolkit.Foundation;
public interface IHandlerProvider
{
IEnumerable<object?> Get(Type type,
IEnumerable<object?> Get(Type type,
object? key = null);
}
+1 -1
View File
@@ -153,4 +153,4 @@ public static class IHostBuilderExtension
return builder;
}
}
}
+4 -3
View File
@@ -1,8 +1,9 @@
namespace Toolkit.Foundation;
public interface IKeyDeriver
{
byte[] DeriveKey(byte[] phrased,
byte[] salt,
int keySize = 32,
byte[] salt,
int keySize = 32,
int iterations = 10000);
}
}
+1
View File
@@ -1,4 +1,5 @@
namespace Toolkit.Foundation;
public interface IKeyGenerator
{
byte[] Generate(int size);
+4 -5
View File
@@ -1,13 +1,12 @@
namespace Toolkit.Foundation
namespace Toolkit.Foundation
{
public interface IMediator
{
Task<object?> Handle(object message,
Task<object?> Handle(object message,
CancellationToken cancellationToken = default);
Task<TResponse?> Handle<TMessage, TResponse>(TMessage message,
CancellationToken cancellationToken = default)
Task<TResponse?> Handle<TMessage, TResponse>(TMessage message,
CancellationToken cancellationToken = default)
where TMessage : notnull;
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
public interface IMediatorRequired
{
IMediator Mediator { get; }
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ public interface INavigationRegion
{
void Register(string name,
object target);
}
}
+2 -2
View File
@@ -2,10 +2,10 @@
public interface INavigationScope
{
void Navigate(string route,
void Navigate(string route,
object? sender = null,
object? region = null,
EventHandler? navigated = null,
EventHandler? navigated = null,
object[]? parameters = null);
void Back(object? region);
+1
View File
@@ -1,4 +1,5 @@
namespace Toolkit.Foundation;
public interface IPasswordHasher
{
string HashPassword(string password, int iterations = 10000);
+1 -1
View File
@@ -11,7 +11,7 @@ public interface IPublisher
void Publish<TMessage>(TMessage message,
object key)
where TMessage : notnull;
void Publish(object message,
Func<Func<Task>, Task> marshal,
object? key = null);
+1 -1
View File
@@ -3,4 +3,4 @@
public interface IPublisherRequired
{
IPublisher Publisher { get; }
}
}
@@ -3,4 +3,4 @@
public interface IServiceFactoryRequired
{
IServiceFactory Factory { get; }
}
}
@@ -3,4 +3,4 @@
public interface IServiceProviderRequired
{
IServiceProvider Provider { get; }
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
public interface ISubscriptionRequired
{
ISubscription Subscription { get; }
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
public interface IValueInvoker<TValue>
{
public void Invoke(TValue args);
}
}
+1 -1
View File
@@ -5,4 +5,4 @@ public interface IValueStore<T>
T? Value { get; }
void Set(T value);
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record InsertEventArgs<TValue>(int Index, TValue Value);
public record InsertEventArgs<TValue>(int Index, TValue Value);
+5 -5
View File
@@ -2,15 +2,15 @@
namespace Toolkit.Foundation;
public class KeyDeriver :
public class KeyDeriver :
IKeyDeriver
{
public byte[] DeriveKey(byte[] phrase,
byte[] salt,
int keySize = 32,
public byte[] DeriveKey(byte[] phrase,
byte[] salt,
int keySize = 32,
int iterations = 100000)
{
using Rfc2898DeriveBytes pbkdf2 = new(phrase, salt, iterations, HashAlgorithmName.SHA256);
return pbkdf2.GetBytes(keySize);
}
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
namespace Toolkit.Foundation;
public class KeyGenerator :
public class KeyGenerator :
IKeyGenerator
{
public byte[] Generate(int size)
@@ -12,4 +12,4 @@ public class KeyGenerator :
return key;
}
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ public class Mediator(IHandlerProvider handlerProvider,
{
if (handler?.GetType().GetMethod("Handle", [messageType, typeof(CancellationToken)]) is MethodInfo handleMethod)
{
return await (Task<TResponse?>)handleMethod.Invoke(handler,
return await (Task<TResponse?>)handleMethod.Invoke(handler,
new object[] { message, cancellationToken })!;
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ public record Modified
{
public static ModifiedEventArgs<TValue> As<TValue>(TValue oldValue, TValue newValue) =>
new(oldValue, newValue);
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ModifiedEventArgs<TValue>(TValue OldView, TValue NewValue);
public record ModifiedEventArgs<TValue>(TValue OldView, TValue NewValue);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record MoveEventArgs<TValue>(int Index, TValue Value);
public record MoveEventArgs<TValue>(int Index, TValue Value);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record MoveToEventArgs<TValue>(int OldIndex, int NewIndex);
public record MoveToEventArgs<TValue>(int OldIndex, int NewIndex);
+2 -2
View File
@@ -25,8 +25,8 @@ public class NavigateHandler(NamedComponent scope,
}
}
}
if (navigationScope is null)
if (navigationScope is null)
{
ComponentScopeDescriptor? descriptor = componentScopeProvider.Get(args.Scope ?? scope.Name);
navigationScope = descriptor?.Services?.GetRequiredService<INavigationScope>();
+3 -3
View File
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using System.Data.SqlTypes;
namespace Toolkit.Foundation;
@@ -11,8 +10,8 @@ public class NavigationScope(IPublisher publisher,
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
INavigationScope
{
public void Navigate(string route,
object? sender = null,
public void Navigate(string route,
object? sender = null,
object? region = null,
EventHandler? navigated = null,
object[]? parameters = null)
@@ -57,6 +56,7 @@ public class NavigationScope(IPublisher publisher,
case "self":
region = view;
break;
default:
if (navigationRegionProvider.TryGet(region, out object? value))
{
+1 -1
View File
@@ -4,4 +4,4 @@
public class NotificationAttribute(object key) : Attribute
{
public object Key => key;
}
}
+1 -1
View File
@@ -7,4 +7,4 @@ public class Notify
public static NotifyEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record NotifyEventArgs<TValue>(TValue Value);
public record NotifyEventArgs<TValue>(TValue Value);
+20 -8
View File
@@ -365,9 +365,29 @@ public partial class ObservableCollection<TItem> :
TItem item = this[oldIndex];
bool selected = false;
if (item is ISelectable selectable)
{
selected = selectable.Selected;
SelectedItem = default;
SelectedIndex = -1;
}
RemoveItem(oldIndex);
Insert(newIndex, item);
if (selected)
{
SelectedIndex = newIndex;
SelectedItem = item;
if (item is ISelectable selectable2)
{
selectable2.Selected = true;
}
}
return true;
}
@@ -493,14 +513,6 @@ public partial class ObservableCollection<TItem> :
added.Selected = true;
}
}
partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
{
if (oldValue is ISelectable selectable)
{
selectable.Selected = false;
}
}
}
public partial class ObservableCollection<TValue, TViewModel>(IServiceProvider provider,
+2 -2
View File
@@ -2,7 +2,7 @@
namespace Toolkit.Foundation;
public class PasswordHasher :
public class PasswordHasher :
IPasswordHasher
{
private const int SaltSize = 16;
@@ -16,4 +16,4 @@ public class PasswordHasher :
return $"{Convert.ToBase64String(salt)}:{Convert.ToBase64String(hash)}";
}
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ public class Publisher(IHandlerProvider handlerProvider,
Publish(message, async args => await args(), null);
public void Publish<TMessage>(TMessage message, object key)
where TMessage : notnull =>
where TMessage : notnull =>
Publish(message, async args => await args(), key);
public void Publish(object message,
@@ -59,7 +59,7 @@ public class Publisher(IHandlerProvider handlerProvider,
Publish(new TMessage(), async args => await args(), null);
public void PublishUI<TMessage>(object key)
where TMessage : new() =>
where TMessage : new() =>
Publish(new TMessage(), args => dispatcher.Invoke(async () => await args()), key);
public void PublishUI<TMessage>(TMessage message)
+1 -1
View File
@@ -4,4 +4,4 @@ public record RemoveAt
{
public static RemoveAtEventArgs<TValue> As<TValue>(int index) =>
new(index);
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record RemoveAtEventArgs<TValue>(int Index);
public record RemoveAtEventArgs<TValue>(int Index);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ReplaceEventArgs<TValue>(int Index, TValue Value);
public record ReplaceEventArgs<TValue>(int Index, TValue Value);
+1 -1
View File
@@ -7,4 +7,4 @@ public class Request
public static RequestEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record RequestEventArgs<TValue>(TValue Value);
public record RequestEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record SelectionEventArgs<TValue>(TValue? Value);
public record SelectionEventArgs<TValue>(TValue? Value);
-1
View File
@@ -49,7 +49,6 @@ public class Subscription(SubscriptionCollection subscriptions,
}
}
private void RemoveSubscriber(object subscriber,
string key)
{
+2 -2
View File
@@ -9,7 +9,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-preview.3.24172.9" />
<PackageReference Include="System.Reactive" Version="6.0.1-preview.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-preview.4.24266.19" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record ValidationEventArgs<TValue>(TValue Value);
public record ValidationEventArgs<TValue>(TValue Value);
+1 -1
View File
@@ -6,4 +6,4 @@ public class ValueStore<T> :
public T? Value { get; private set; }
public void Set(T value) => Value = value;
}
}