Add foundation
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<AssemblyName>Toolkit.Controls.Avalonia</AssemblyName>
|
|
||||||
<RootNamespace>Toolkit.Controls.Avalonia</RootNamespace>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="FluentAvaloniaUI" Version="2.0.0-preview4" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Avalonia.Styling;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class ContentDialog : FluentAvalonia.UI.Controls.ContentDialog, IStyleable
|
|
||||||
{
|
|
||||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.ContentDialog);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Avalonia.Styling;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class Frame : FluentAvalonia.UI.Controls.Frame, IStyleable
|
|
||||||
{
|
|
||||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.Frame);
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Templates;
|
|
||||||
using Avalonia.LogicalTree;
|
|
||||||
using Avalonia.Metadata;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class ContentIcon : FluentAvalonia.UI.Controls.FAIconElement
|
|
||||||
{
|
|
||||||
public static readonly StyledProperty<IDataTemplate> IconTemplateProperty =
|
|
||||||
AvaloniaProperty.Register<ContentIcon, IDataTemplate>("IconTemplate");
|
|
||||||
|
|
||||||
public static readonly StyledProperty<object> ContentProperty =
|
|
||||||
AvaloniaProperty.Register<ContentIcon, object>("Content");
|
|
||||||
|
|
||||||
[Content]
|
|
||||||
public object Content
|
|
||||||
{
|
|
||||||
get => GetValue(ContentProperty);
|
|
||||||
set => SetValue(ContentProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContentControl? content;
|
|
||||||
|
|
||||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
|
||||||
{
|
|
||||||
if (VisualChildren.Count > 0)
|
|
||||||
{
|
|
||||||
((ILogical)VisualChildren[0]).NotifyAttachedToLogicalTree(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnAttachedToLogicalTree(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
|
||||||
{
|
|
||||||
if (VisualChildren.Count > 0)
|
|
||||||
{
|
|
||||||
((ILogical)VisualChildren[0]).NotifyDetachedFromLogicalTree(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnDetachedFromLogicalTree(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public IDataTemplate IconTemplate
|
|
||||||
{
|
|
||||||
get => GetValue(IconTemplateProperty);
|
|
||||||
set => SetValue(IconTemplateProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Size MeasureOverride(Size availableSize)
|
|
||||||
{
|
|
||||||
if (content == null)
|
|
||||||
{
|
|
||||||
CreateContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return base.MeasureOverride(availableSize);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateContent()
|
|
||||||
{
|
|
||||||
content = new ContentControl();
|
|
||||||
|
|
||||||
content.Bind(ContentControl.ContentProperty, this.GetBindingObservable(ContentProperty));
|
|
||||||
content.Bind(ContentControl.ContentTemplateProperty, this.GetBindingObservable(IconTemplateProperty));
|
|
||||||
|
|
||||||
LogicalChildren.Add(content);
|
|
||||||
VisualChildren.Add(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class FAIconElement : FluentAvalonia.UI.Controls.FAIconElement
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class FAPathIcon : FluentAvalonia.UI.Controls.FAPathIcon
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class FontIcon : FluentAvalonia.UI.Controls.FontIcon
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class SymbolIcon : FluentAvalonia.UI.Controls.SymbolIcon
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Avalonia.Styling;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class NavigationView : FluentAvalonia.UI.Controls.NavigationView, IStyleable
|
|
||||||
{
|
|
||||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationView);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Styling;
|
|
||||||
using Avalonia.VisualTree;
|
|
||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class NavigationViewItem : FluentAvalonia.UI.Controls.NavigationViewItem, IStyleable
|
|
||||||
{
|
|
||||||
private NavigationView? navigationView;
|
|
||||||
|
|
||||||
public event EventHandler<NavigationViewItemInvokedEventArgs>? Invoked;
|
|
||||||
|
|
||||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
|
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
|
|
||||||
{
|
|
||||||
navigationView = this.FindAncestorOfType<NavigationView>();
|
|
||||||
if (navigationView is not null)
|
|
||||||
{
|
|
||||||
navigationView.ItemInvoked += OnItemInvoked;
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnApplyTemplate(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnItemInvoked(object? sender, NavigationViewItemInvokedEventArgs args)
|
|
||||||
{
|
|
||||||
if (args.InvokedItemContainer == this)
|
|
||||||
{
|
|
||||||
Invoked?.Invoke(this, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
using Avalonia.Metadata;
|
|
||||||
|
|
||||||
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Toolkit.Controls.Avalonia")]
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Avalonia.Styling;
|
|
||||||
|
|
||||||
namespace Toolkit.Controls.Avalonia;
|
|
||||||
|
|
||||||
public class SettingsExpander : FluentAvalonia.UI.Controls.SettingsExpander, IStyleable
|
|
||||||
{
|
|
||||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.SettingsExpander);
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
|
||||||
<Styles.Resources>
|
|
||||||
<ResourceDictionary>
|
|
||||||
<ResourceDictionary.MergedDictionaries />
|
|
||||||
</ResourceDictionary>
|
|
||||||
</Styles.Resources>
|
|
||||||
</Styles>
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<AssemblyName>Toolkit.Framework.Avalonia</AssemblyName>
|
|
||||||
<RootNamespace>Toolkit.Framework.Avalonia</RootNamespace>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
|
|
||||||
<PackageReference Include="FluentAvaloniaUI" Version="2.0.0-preview4" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Controls\Avalonia\Avalonia.csproj" />
|
|
||||||
<ProjectReference Include="..\Foundation\Foundation.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ContentHandler : IRequestHandler<Content, object?>
|
|
||||||
{
|
|
||||||
private readonly INamedContentTemplateFactory namedContentTemplateFactory;
|
|
||||||
private readonly INamedContentFactory namedContentFactory;
|
|
||||||
private readonly IContentTemplateFactory contentTemplateFactory;
|
|
||||||
private readonly ITypedContentFactory typedContentFactory;
|
|
||||||
|
|
||||||
public ContentHandler(IContentTemplateFactory contentTemplateFactory,
|
|
||||||
INamedContentFactory namedContentFactory,
|
|
||||||
INamedContentTemplateFactory namedContentTemplateFactory,
|
|
||||||
ITypedContentFactory typedContentFactory)
|
|
||||||
{
|
|
||||||
this.contentTemplateFactory = contentTemplateFactory;
|
|
||||||
this.namedContentFactory = namedContentFactory;
|
|
||||||
this.namedContentTemplateFactory = namedContentTemplateFactory;
|
|
||||||
this.typedContentFactory = typedContentFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<object?> Handle(Content request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
object? content = null;
|
|
||||||
object? template = null;
|
|
||||||
|
|
||||||
if (request.Name is { Length: > 0 } name)
|
|
||||||
{
|
|
||||||
content = namedContentFactory.Create(name, request.Parameters);
|
|
||||||
template = namedContentTemplateFactory.Create(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.Type is Type type)
|
|
||||||
{
|
|
||||||
content = typedContentFactory.Create(type, request.Parameters);
|
|
||||||
template = contentTemplateFactory.Create(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template is Visual visual)
|
|
||||||
{
|
|
||||||
visual.DataContext = content;
|
|
||||||
return new ValueTask<object?>(visual);
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Templates;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ContentTemplateSelector : IDataTemplate, IContentTemplateSelector
|
|
||||||
{
|
|
||||||
private readonly Dictionary<object, IControl> dataTracking = new();
|
|
||||||
|
|
||||||
private readonly IContentTemplateFactory templateFactory;
|
|
||||||
|
|
||||||
public ContentTemplateSelector(IContentTemplateFactory templateFactory)
|
|
||||||
{
|
|
||||||
this.templateFactory = templateFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IControl? Build(object? content)
|
|
||||||
{
|
|
||||||
if (content is not null)
|
|
||||||
{
|
|
||||||
if (dataTracking.TryGetValue(content, out IControl? control))
|
|
||||||
{
|
|
||||||
return control;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
control = (IControl?)templateFactory.Create(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return control;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Match(object? data)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using Avalonia.Data.Converters;
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public static class EventArgsExtensions
|
|
||||||
{
|
|
||||||
public static dynamic? GetEventArguments(this EventArgs args, string? path, IValueConverter? converter, object? converterParameter)
|
|
||||||
{
|
|
||||||
return !string.IsNullOrWhiteSpace(path) ? GetEventArgsPropertyPathValue(args, path) : converter is not null ? converter.Convert(args, typeof(object), converterParameter, CultureInfo.CurrentCulture) : (dynamic)args;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static object GetEventArgsPropertyPathValue(object args, string path)
|
|
||||||
{
|
|
||||||
object? value = args;
|
|
||||||
if (path is { })
|
|
||||||
{
|
|
||||||
value = PropertyPathHelper.GetValue(args, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public static class IHostBuilderExtensions
|
|
||||||
{
|
|
||||||
public static IHostBuilder ConfigureContents(this IHostBuilder hostBuilder, Action<IContentTemplateBuilder> builderDelegate)
|
|
||||||
{
|
|
||||||
hostBuilder.ConfigureServices((hostBuilderContext, serviceCollection) =>
|
|
||||||
{
|
|
||||||
ContentTemplateBuilder? builder = new();
|
|
||||||
builderDelegate?.Invoke(builder);
|
|
||||||
|
|
||||||
serviceCollection.TryAddSingleton(builder.Descriptors);
|
|
||||||
serviceCollection.TryAddSingleton<IContentTemplateDescriptorProvider, ContentTemplateDescriptorProvider>();
|
|
||||||
serviceCollection.TryAddSingleton<IContentTemplateFactory, ContentTemplateFactory>();
|
|
||||||
serviceCollection.TryAddSingleton<INamedContentFactory, NamedContentFactory>();
|
|
||||||
serviceCollection.TryAddSingleton<ITypedContentFactory, TypedContentFactory>();
|
|
||||||
serviceCollection.TryAddSingleton<INamedContentTemplateFactory, NamedContentTemplateFactory>();
|
|
||||||
serviceCollection.TryAddSingleton<IContentTemplateSelector, ContentTemplateSelector>();
|
|
||||||
|
|
||||||
foreach (IContentTemplateDescriptor? descriptor in builder.Descriptors)
|
|
||||||
{
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(descriptor.TemplateType, descriptor.TemplateType, descriptor.Lifetime));
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(descriptor.ContentType, descriptor.ContentType, descriptor.Lifetime));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return hostBuilder;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public static class IServiceCollectionExtensions
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddAvalonia(this IServiceCollection serviceCollection)
|
|
||||||
{
|
|
||||||
serviceCollection.TryAddSingleton<INavigationRouteDescriptorCollection, NavigationRouteDescriptorCollection>();
|
|
||||||
|
|
||||||
serviceCollection.AddHandler<ContentHandler>();
|
|
||||||
serviceCollection.AddHandler<NavigationRouteHandler>();
|
|
||||||
serviceCollection.AddHandler<NavigateHandler>();
|
|
||||||
serviceCollection.AddHandler<FrameNavigationHandler>();
|
|
||||||
serviceCollection.AddHandler<ContentDialogNavigationHandler>();
|
|
||||||
serviceCollection.AddHandler<ContentControlNavigationHandler>();
|
|
||||||
|
|
||||||
return serviceCollection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using Avalonia.Data;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public static class MarkupExtensions
|
|
||||||
{
|
|
||||||
public static Binding? ToBinding(this object value)
|
|
||||||
{
|
|
||||||
if (value is Binding)
|
|
||||||
{
|
|
||||||
return value as Binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Binding { Mode = BindingMode.OneWay, Source = value };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Data;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public static class PropertyPathHelper
|
|
||||||
{
|
|
||||||
private static readonly Dummy dummy = new();
|
|
||||||
|
|
||||||
public static object GetValue(object args, string path)
|
|
||||||
{
|
|
||||||
Binding binding = new(path)
|
|
||||||
{
|
|
||||||
Mode = BindingMode.OneTime,
|
|
||||||
Source = args
|
|
||||||
};
|
|
||||||
|
|
||||||
dummy.Bind(Dummy.ValueProperty, binding);
|
|
||||||
return dummy.GetValue(Dummy.ValueProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Dummy : AvaloniaObject
|
|
||||||
{
|
|
||||||
public static readonly StyledProperty<object> ValueProperty =
|
|
||||||
AvaloniaProperty.Register<Dummy, object>("Value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,320 +0,0 @@
|
|||||||
using Avalonia.Markup.Xaml;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class CompositeExtension : TriggerExtension
|
|
||||||
{
|
|
||||||
[ConstructorArgument(nameof(Triggers))]
|
|
||||||
public TriggerCollection Triggers { get; } = new TriggerCollection();
|
|
||||||
|
|
||||||
public CompositeExtension(object args0)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0, object args1, object args2, object args3, object args4,
|
|
||||||
object args5, object args6, object args7, object args8, object args9, object args10)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0, object args1, object args2, object args3, object args4,
|
|
||||||
object args5, object args6, object args7, object args8, object args9, object args10, object args11)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
Triggers.Add(args11);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
Triggers.Add(args11);
|
|
||||||
Triggers.Add(args12);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
Triggers.Add(args11);
|
|
||||||
Triggers.Add(args12);
|
|
||||||
Triggers.Add(args13);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
Triggers.Add(args11);
|
|
||||||
Triggers.Add(args12);
|
|
||||||
Triggers.Add(args13);
|
|
||||||
Triggers.Add(args14);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompositeExtension(object args0,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14,
|
|
||||||
object args15)
|
|
||||||
{
|
|
||||||
Triggers.Add(args0);
|
|
||||||
Triggers.Add(args1);
|
|
||||||
Triggers.Add(args2);
|
|
||||||
Triggers.Add(args3);
|
|
||||||
Triggers.Add(args4);
|
|
||||||
Triggers.Add(args5);
|
|
||||||
Triggers.Add(args6);
|
|
||||||
Triggers.Add(args7);
|
|
||||||
Triggers.Add(args8);
|
|
||||||
Triggers.Add(args9);
|
|
||||||
Triggers.Add(args10);
|
|
||||||
Triggers.Add(args11);
|
|
||||||
Triggers.Add(args12);
|
|
||||||
Triggers.Add(args13);
|
|
||||||
Triggers.Add(args14);
|
|
||||||
Triggers.Add(args15);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnInvoked(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
foreach (Delegate? trigger in Triggers)
|
|
||||||
{
|
|
||||||
trigger.Method.Invoke(trigger.Target, new object[] { sender, args });
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnInvoked(sender, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,490 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Data;
|
|
||||||
using Avalonia.Interactivity;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ContentExtension : MarkupExtension
|
|
||||||
{
|
|
||||||
private static readonly AttachedProperty<IMediator> MediatorProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<ContentExtension, AvaloniaObject, IMediator>("Mediator");
|
|
||||||
|
|
||||||
private static readonly AttachedProperty<object> ParameterProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<ContentExtension, AvaloniaObject, object>("Parameter");
|
|
||||||
|
|
||||||
private static readonly AvaloniaProperty ToProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<ContentExtension, AvaloniaObject, object>("To");
|
|
||||||
|
|
||||||
private readonly Binding? mediatorBinding;
|
|
||||||
private readonly List<object?> parameters = new();
|
|
||||||
private readonly Binding? toBinding;
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentExtension(object mediator,
|
|
||||||
object to,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14,
|
|
||||||
object args15)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.toBinding = to is Binding toBinding ? toBinding : to.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
parameters.Add(args15 is MarkupExtension ? args15 : args15.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object? ProvideValue(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
if (serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget target)
|
|
||||||
{
|
|
||||||
AvaloniaObject? targetObject = null;
|
|
||||||
if (target.TargetObject is AvaloniaObject avaloniaObject)
|
|
||||||
{
|
|
||||||
targetObject = avaloniaObject;
|
|
||||||
}
|
|
||||||
else if (serviceProvider.GetService(typeof(IRootObjectProvider)) is IRootObjectProvider root)
|
|
||||||
{
|
|
||||||
targetObject = (AvaloniaObject)root.RootObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetObject is not null && toBinding is not null && mediatorBinding is not null)
|
|
||||||
{
|
|
||||||
if (target.TargetProperty is StyledProperty<object> targetProperty)
|
|
||||||
{
|
|
||||||
if (targetObject is Control control)
|
|
||||||
{
|
|
||||||
void SetContent()
|
|
||||||
{
|
|
||||||
targetObject.Bind(MediatorProperty, mediatorBinding);
|
|
||||||
if (targetObject.GetValue(MediatorProperty) is IMediator mediator)
|
|
||||||
{
|
|
||||||
targetObject.Bind(ToProperty, toBinding);
|
|
||||||
if (targetObject.GetValue(ToProperty) is { } to)
|
|
||||||
{
|
|
||||||
List<object>? parameters = new();
|
|
||||||
foreach (object? parameter in this.parameters)
|
|
||||||
{
|
|
||||||
if (parameter is not null)
|
|
||||||
{
|
|
||||||
switch (parameter)
|
|
||||||
{
|
|
||||||
case IParameter keyedParameter:
|
|
||||||
if (keyedParameter.GetValue(targetObject) is KeyValuePair<string, object> keyValuePair)
|
|
||||||
{
|
|
||||||
parameters.Add(keyValuePair);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (parameter.ToBinding() is Binding defaultDinding)
|
|
||||||
{
|
|
||||||
targetObject.Bind(ParameterProperty, defaultDinding);
|
|
||||||
parameters.Add((dynamic)targetObject.GetValue(ParameterProperty));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to is string name)
|
|
||||||
{
|
|
||||||
Trace.WriteLine(name);
|
|
||||||
|
|
||||||
ValueTask<object?> namedTask = mediator.Send(new Content(name, parameters.ToArray()));
|
|
||||||
if (namedTask is ValueTask<object?> { Result: object result })
|
|
||||||
{
|
|
||||||
control.SetValue(targetProperty, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to is Type type)
|
|
||||||
{
|
|
||||||
ValueTask<object?> typedTask = mediator.Send(new Content(type, parameters.ToArray()));
|
|
||||||
if (typedTask is ValueTask<object?> { Result: object result })
|
|
||||||
{
|
|
||||||
control.SetValue(targetProperty, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!control.IsLoaded)
|
|
||||||
{
|
|
||||||
void HandleLoaded(object? sender, RoutedEventArgs args)
|
|
||||||
{
|
|
||||||
control.Loaded -= HandleLoaded;
|
|
||||||
SetContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
control.Loaded += HandleLoaded;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetContent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using Avalonia.Data.Converters;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class EventParameterExtension : MarkupExtension, IEventParameter
|
|
||||||
{
|
|
||||||
private readonly IValueConverter? converter;
|
|
||||||
|
|
||||||
private readonly object? converterParameter;
|
|
||||||
|
|
||||||
private readonly string? key;
|
|
||||||
private readonly string? path;
|
|
||||||
|
|
||||||
public EventParameterExtension()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventParameterExtension(string key, string path)
|
|
||||||
{
|
|
||||||
this.key = key;
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventParameterExtension(string path)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventParameterExtension(IValueConverter? converter = null, object? converterParameter = null)
|
|
||||||
{
|
|
||||||
this.converter = converter;
|
|
||||||
this.converterParameter = converterParameter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<object> GetValues(EventArgs args)
|
|
||||||
{
|
|
||||||
List<object>? parameters = new();
|
|
||||||
|
|
||||||
dynamic? arguments = args.GetEventArguments(path, converter, converterParameter);
|
|
||||||
if (arguments is not null)
|
|
||||||
{
|
|
||||||
if (arguments is ICollection<object> collection)
|
|
||||||
{
|
|
||||||
foreach (object? argument in collection)
|
|
||||||
{
|
|
||||||
parameters.Add(key is not null ? new KeyValuePair<string, object>(key, (dynamic)argument) : argument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parameters.Add(key is not null ? new KeyValuePair<string, object>(key, arguments) : arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,423 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Data;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class InvokeExtension : TriggerExtension
|
|
||||||
{
|
|
||||||
private static readonly AvaloniaProperty TargetProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<InvokeExtension, Control, object>("Target");
|
|
||||||
|
|
||||||
private readonly object path;
|
|
||||||
private readonly List<object?> parameters = new();
|
|
||||||
|
|
||||||
public InvokeExtension(object path)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is not MarkupExtension ? args1.ToBinding() : args1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvokeExtension(object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14,
|
|
||||||
object args15)
|
|
||||||
{
|
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
parameters.Add(args15 is MarkupExtension ? args15 : args15.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnInvoked(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
if (sender is AvaloniaObject avaloniaObject)
|
|
||||||
{
|
|
||||||
CreaterHandler(avaloniaObject, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreaterHandler(AvaloniaObject sender, EventArgs args)
|
|
||||||
{
|
|
||||||
if (TryGetInvoke(sender, out (object? Target, MethodInfo? MethodInfo) invoker))
|
|
||||||
{
|
|
||||||
if (invoker.Target is object target)
|
|
||||||
{
|
|
||||||
if (invoker.MethodInfo is MethodInfo methodInfo)
|
|
||||||
{
|
|
||||||
ParameterInfo[] parameterInfo = methodInfo.GetParameters();
|
|
||||||
List<object> parameters = new();
|
|
||||||
|
|
||||||
foreach (object? parameter in this.parameters)
|
|
||||||
{
|
|
||||||
switch (parameter)
|
|
||||||
{
|
|
||||||
//case IParameter keyedParameter:
|
|
||||||
// BindingOperations.SetBinding(sender, ParameterProperty, parameter.ToBinding());
|
|
||||||
// parameters.Add(new KeyValuePair<string, object>(keyedParameter.Key, (dynamic)sender.GetValue(ParameterProperty)));
|
|
||||||
// break;
|
|
||||||
//case IEventParameter eventParameter:
|
|
||||||
// parameters.AddRange(eventParameter.GetParameters(args));
|
|
||||||
// break;
|
|
||||||
//default:
|
|
||||||
// BindingOperations.SetBinding(sender, ParameterProperty, parameter.ToBinding());
|
|
||||||
// parameters.Add((dynamic)sender.GetValue(ParameterProperty));
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
methodInfo.Invoke(target, parameters.Any() ? parameters.ToArray() : parameterInfo.Length > 0 ? new object?[] { null } : Array.Empty<object>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetInvoke(AvaloniaObject sender, [AllowNull] out (object?, MethodInfo?) invoker)
|
|
||||||
{
|
|
||||||
if (path is Binding binding)
|
|
||||||
{
|
|
||||||
sender.Bind(TargetProperty, binding);
|
|
||||||
if (sender.GetValue(TargetProperty) is Action action)
|
|
||||||
{
|
|
||||||
invoker = new(action.Target, action.Method);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path is string name)
|
|
||||||
{
|
|
||||||
if (sender.GetValue(StyledElement.DataContextProperty) is object dataContext)
|
|
||||||
{
|
|
||||||
if (dataContext.GetType().GetMethod(name, BindingFlags.Public | BindingFlags.Instance) is MethodInfo methodInfo)
|
|
||||||
{
|
|
||||||
invoker = new(dataContext, methodInfo);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
invoker = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,445 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Data;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
public class NavigateExtension : TriggerExtension
|
|
||||||
{
|
|
||||||
private static readonly AttachedProperty<IMediator> MediatorProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<NavigateExtension, Control, IMediator>("Mediator");
|
|
||||||
|
|
||||||
private static readonly AttachedProperty<object> ParameterProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<NavigateExtension, Control, object>("Parameter");
|
|
||||||
|
|
||||||
private static readonly AvaloniaProperty PathProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<NavigateExtension, Control, string>("Path");
|
|
||||||
|
|
||||||
private readonly Binding? mediatorBinding;
|
|
||||||
private readonly List<object?> parameters = new();
|
|
||||||
private readonly Binding? pathBinding;
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
public NavigateExtension(object mediator,
|
|
||||||
object path,
|
|
||||||
object args1,
|
|
||||||
object args2,
|
|
||||||
object args3,
|
|
||||||
object args4,
|
|
||||||
object args5,
|
|
||||||
object args6,
|
|
||||||
object args7,
|
|
||||||
object args8,
|
|
||||||
object args9,
|
|
||||||
object args10,
|
|
||||||
object args11,
|
|
||||||
object args12,
|
|
||||||
object args13,
|
|
||||||
object args14,
|
|
||||||
object args15)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator.ToBinding();
|
|
||||||
this.pathBinding = path is Binding pathBinding ? pathBinding : path.ToBinding();
|
|
||||||
|
|
||||||
parameters.Add(args1 is MarkupExtension ? args1 : args1.ToBinding());
|
|
||||||
parameters.Add(args2 is MarkupExtension ? args2 : args2.ToBinding());
|
|
||||||
parameters.Add(args3 is MarkupExtension ? args3 : args3.ToBinding());
|
|
||||||
parameters.Add(args4 is MarkupExtension ? args4 : args4.ToBinding());
|
|
||||||
parameters.Add(args5 is MarkupExtension ? args5 : args5.ToBinding());
|
|
||||||
parameters.Add(args6 is MarkupExtension ? args6 : args6.ToBinding());
|
|
||||||
parameters.Add(args7 is MarkupExtension ? args7 : args7.ToBinding());
|
|
||||||
parameters.Add(args8 is MarkupExtension ? args8 : args8.ToBinding());
|
|
||||||
parameters.Add(args9 is MarkupExtension ? args9 : args9.ToBinding());
|
|
||||||
parameters.Add(args10 is MarkupExtension ? args10 : args10.ToBinding());
|
|
||||||
parameters.Add(args11 is MarkupExtension ? args11 : args11.ToBinding());
|
|
||||||
parameters.Add(args12 is MarkupExtension ? args12 : args12.ToBinding());
|
|
||||||
parameters.Add(args13 is MarkupExtension ? args13 : args13.ToBinding());
|
|
||||||
parameters.Add(args14 is MarkupExtension ? args14 : args14.ToBinding());
|
|
||||||
parameters.Add(args15 is MarkupExtension ? args15 : args15.ToBinding());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnInvoked(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
if (TargetObject is not null && mediatorBinding is not null)
|
|
||||||
{
|
|
||||||
TargetObject.Bind(MediatorProperty, mediatorBinding);
|
|
||||||
if (TargetObject.GetValue(MediatorProperty) is IMediator mediator)
|
|
||||||
{
|
|
||||||
if (pathBinding is not null)
|
|
||||||
{
|
|
||||||
TargetObject.Bind(PathProperty, pathBinding);
|
|
||||||
if (TargetObject.GetValue(PathProperty) is string path)
|
|
||||||
{
|
|
||||||
List<object>? parameters = new();
|
|
||||||
foreach (object? parameter in this.parameters)
|
|
||||||
{
|
|
||||||
if (parameter is not null)
|
|
||||||
{
|
|
||||||
switch (parameter)
|
|
||||||
{
|
|
||||||
case IParameter keyedParameter:
|
|
||||||
if (keyedParameter.GetValue(TargetObject) is KeyValuePair<string, object> keyValuePair)
|
|
||||||
{
|
|
||||||
parameters.Add(keyValuePair);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IEventParameter eventParameter:
|
|
||||||
parameters.AddRange(eventParameter.GetValues(args));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (parameter.ToBinding() is Binding defaultDinding)
|
|
||||||
{
|
|
||||||
TargetObject.Bind(ParameterProperty, defaultDinding);
|
|
||||||
parameters.Add((dynamic)TargetObject.GetValue(ParameterProperty));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pathBinding?.StringFormat is string format)
|
|
||||||
{
|
|
||||||
path = string.Format(format, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
mediator.Send(new Navigate(path, parameters.ToArray()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnInvoked(sender, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Data;
|
|
||||||
using Avalonia.Interactivity;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class NavigationRouteExtension : MarkupExtension
|
|
||||||
{
|
|
||||||
private static readonly AttachedProperty<IMediator> MediatorProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<NavigationRouteExtension, Control, IMediator>("Mediator");
|
|
||||||
|
|
||||||
private readonly string name;
|
|
||||||
private readonly Binding? mediatorBinding;
|
|
||||||
|
|
||||||
public NavigationRouteExtension(object mediator, string name)
|
|
||||||
{
|
|
||||||
mediatorBinding = mediator is Binding toBinding ? toBinding : mediator.ToBinding();
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetBinding(AvaloniaObject sender, out object? binding)
|
|
||||||
{
|
|
||||||
binding = sender.GetValue(StyledElement.DataContextProperty);
|
|
||||||
return binding is not null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object? ProvideValue(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
if (serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget target)
|
|
||||||
{
|
|
||||||
if (target.TargetObject is TemplatedControl control)
|
|
||||||
{
|
|
||||||
if (!TryGetBinding(control, out object? binding))
|
|
||||||
{
|
|
||||||
void AddRoute(TemplatedControl control)
|
|
||||||
{
|
|
||||||
if (mediatorBinding is not null)
|
|
||||||
{
|
|
||||||
control.Bind(MediatorProperty, mediatorBinding);
|
|
||||||
if (control.GetValue(MediatorProperty) is IMediator mediator)
|
|
||||||
{
|
|
||||||
mediator.Send(new NavigationRoute(name, control));
|
|
||||||
control.ClearValue(MediatorProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleDataContextChanged(object? sender, EventArgs args)
|
|
||||||
{
|
|
||||||
control.Loaded -= HandleLoaded;
|
|
||||||
if (TryGetBinding(control, out binding))
|
|
||||||
{
|
|
||||||
AddRoute(control);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
control.DataContextChanged += HandleDataContextChanged;
|
|
||||||
void HandleLoaded(object? sender, RoutedEventArgs args)
|
|
||||||
{
|
|
||||||
control.Loaded -= HandleLoaded;
|
|
||||||
if (TryGetBinding(control, out binding))
|
|
||||||
{
|
|
||||||
AddRoute(control);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
control.Loaded += HandleLoaded;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (mediatorBinding is not null)
|
|
||||||
{
|
|
||||||
control.Bind(MediatorProperty, mediatorBinding);
|
|
||||||
if (control.GetValue(MediatorProperty) is IMediator mediator)
|
|
||||||
{
|
|
||||||
mediator.Send(new NavigationRoute(name, control));
|
|
||||||
control.ClearValue(MediatorProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Data;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ParameterBindingExtension : MarkupExtension, IParameter
|
|
||||||
{
|
|
||||||
private static readonly AttachedProperty<object> ValueProperty =
|
|
||||||
AvaloniaProperty.RegisterAttached<ParameterBindingExtension, Control, object>("Value");
|
|
||||||
|
|
||||||
private readonly Binding? valueBinding;
|
|
||||||
|
|
||||||
public ParameterBindingExtension(string key, object value)
|
|
||||||
{
|
|
||||||
Key = key;
|
|
||||||
valueBinding = value.ToBinding();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string? Key { get; }
|
|
||||||
|
|
||||||
public KeyValuePair<string, object>? GetValue(object target)
|
|
||||||
{
|
|
||||||
if (target is AvaloniaObject avaloniaObject)
|
|
||||||
{
|
|
||||||
if (valueBinding is not null)
|
|
||||||
{
|
|
||||||
avaloniaObject.Bind(ValueProperty, valueBinding);
|
|
||||||
return new KeyValuePair<string, object>(Key, (dynamic)avaloniaObject.GetValue(ValueProperty));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class TriggerCollection : Collection<Delegate>
|
|
||||||
{
|
|
||||||
public void Add(object item)
|
|
||||||
{
|
|
||||||
if (item is Delegate trigger)
|
|
||||||
{
|
|
||||||
base.Add(trigger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class TriggerExtension : MarkupExtension
|
|
||||||
{
|
|
||||||
public AvaloniaObject? TargetObject { get; protected set; }
|
|
||||||
|
|
||||||
protected object? TargetInvoke { get; private set; }
|
|
||||||
|
|
||||||
public void Invoke(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
OnInvoked(sender, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object? ProvideValue(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
if (serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget target)
|
|
||||||
{
|
|
||||||
if (target.TargetObject is AvaloniaObject avaloniaObject)
|
|
||||||
{
|
|
||||||
TargetObject = avaloniaObject;
|
|
||||||
}
|
|
||||||
else if (serviceProvider.GetService(typeof(IRootObjectProvider)) is IRootObjectProvider root)
|
|
||||||
{
|
|
||||||
TargetObject = (AvaloniaObject)root.RootObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TargetObject is not null)
|
|
||||||
{
|
|
||||||
string? targetName = target.TargetProperty as string;
|
|
||||||
TargetInvoke = target.TargetProperty;
|
|
||||||
OnAttached(serviceProvider);
|
|
||||||
|
|
||||||
EventInfo? eventInfo = target.TargetProperty as EventInfo ?? (targetName is not null ? TargetObject.GetType().GetEvent(targetName) : null);
|
|
||||||
MethodInfo? methodInfo = eventInfo is not null ? null : target.TargetProperty as MethodInfo ?? (targetName is not null ? TargetObject.GetType().GetMethod(targetName) : null);
|
|
||||||
|
|
||||||
MethodInfo invokeMethod = GetType().GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public)!;
|
|
||||||
if (invokeMethod is null)
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eventInfo is not null)
|
|
||||||
{
|
|
||||||
return Delegate.CreateDelegate(eventInfo.EventHandlerType!, this, invokeMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (methodInfo is not null)
|
|
||||||
{
|
|
||||||
if (methodInfo.GetParameters() is ParameterInfo[] methodParameters && methodParameters is { Length: 2 })
|
|
||||||
{
|
|
||||||
return Delegate.CreateDelegate(methodParameters[1].ParameterType, this, invokeMethod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnAttached(IServiceProvider serviceProvider)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnInvoked(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public record ContentControlNavigation : Navigation<ContentControl>
|
|
||||||
{
|
|
||||||
public ContentControlNavigation(ContentControl route,
|
|
||||||
object? content,
|
|
||||||
object? template,
|
|
||||||
IDictionary<string, object>? parameters) : base(route, content, template, parameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ContentControlNavigationHandler : IRequestHandler<ContentControlNavigation>
|
|
||||||
{
|
|
||||||
public ValueTask<Unit> Handle(ContentControlNavigation request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (request.Template is TemplatedControl control)
|
|
||||||
{
|
|
||||||
control.DataContext = request.Content;
|
|
||||||
request.Route.Content = control;
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public record ContentDialogNavigation : Navigation<ContentDialog>
|
|
||||||
{
|
|
||||||
public ContentDialogNavigation(ContentDialog route,
|
|
||||||
object? content,
|
|
||||||
object? template,
|
|
||||||
IDictionary<string, object>? parameters) : base(route, content, template, parameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class ContentDialogNavigationHandler : IRequestHandler<ContentDialogNavigation>
|
|
||||||
{
|
|
||||||
public ValueTask<Unit> Handle(ContentDialogNavigation request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (request.Template is ContentDialog contentDialog)
|
|
||||||
{
|
|
||||||
async void HandleButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
||||||
{
|
|
||||||
ContentDialogButtonClickDeferral defferal = args.GetDeferral();
|
|
||||||
if (sender.DataContext is INavigationConfirmation confirmation)
|
|
||||||
{
|
|
||||||
if (!await confirmation.CanConfirm())
|
|
||||||
{
|
|
||||||
args.Cancel = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!args.Cancel)
|
|
||||||
{
|
|
||||||
contentDialog.SecondaryButtonClick -= HandleButtonClick;
|
|
||||||
contentDialog.PrimaryButtonClick -= HandleButtonClick;
|
|
||||||
contentDialog.CloseButtonClick -= HandleButtonClick;
|
|
||||||
}
|
|
||||||
|
|
||||||
defferal.Complete();
|
|
||||||
}
|
|
||||||
|
|
||||||
contentDialog.SecondaryButtonClick += HandleButtonClick;
|
|
||||||
contentDialog.PrimaryButtonClick += HandleButtonClick;
|
|
||||||
contentDialog.CloseButtonClick += HandleButtonClick;
|
|
||||||
|
|
||||||
contentDialog.DataContext = request.Content;
|
|
||||||
|
|
||||||
contentDialog.ShowAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public record FrameNavigation : Navigation<Frame>
|
|
||||||
{
|
|
||||||
public FrameNavigation(Frame route,
|
|
||||||
object? content,
|
|
||||||
object? template,
|
|
||||||
IDictionary<string, object>?
|
|
||||||
parameters) : base(route, content, template, parameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using FluentAvalonia.UI.Navigation;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class FrameNavigationHandler : IRequestHandler<FrameNavigation>
|
|
||||||
{
|
|
||||||
public ValueTask<Unit> Handle(FrameNavigation request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
request.Route.NavigationPageFactory = new NavigationPageFactory();
|
|
||||||
|
|
||||||
TaskCompletionSource<bool> completionSource = new();
|
|
||||||
if (request.Template is TemplatedControl content)
|
|
||||||
{
|
|
||||||
void HandleNavigated(object sender, NavigationEventArgs args)
|
|
||||||
{
|
|
||||||
request.Route.Navigated -= HandleNavigated;
|
|
||||||
if (request.Route.Content is TemplatedControl control)
|
|
||||||
{
|
|
||||||
control.DataContext = request.Content;
|
|
||||||
completionSource.SetResult(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
request.Route.Navigated += HandleNavigated;
|
|
||||||
request.Route.NavigateFromObject(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class NavigateBackHandler : IRequestHandler<NavigateBack>
|
|
||||||
{
|
|
||||||
private readonly INavigationRouteDescriptorCollection descriptors;
|
|
||||||
|
|
||||||
public NavigateBackHandler(INavigationRouteDescriptorCollection descriptors)
|
|
||||||
{
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<Unit> Handle(NavigateBack request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => request.Route is string { } name && name == x.Name) is NavigationRouteDescriptor descriptor)
|
|
||||||
{
|
|
||||||
if (descriptor.Route is ContentControl { Content: TemplatedControl content })
|
|
||||||
{
|
|
||||||
if (content.DataContext is IDisposable disposable)
|
|
||||||
{
|
|
||||||
disposable.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor.Route is Frame frame)
|
|
||||||
{
|
|
||||||
frame.GoBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
using Toolkit.Controls.Avalonia;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class NavigateHandler : IRequestHandler<Navigate>
|
|
||||||
{
|
|
||||||
private readonly INavigationRouteDescriptorCollection descriptors;
|
|
||||||
private readonly IMediator mediator;
|
|
||||||
private readonly INamedContentTemplateFactory namedContentTemplateFactory;
|
|
||||||
private readonly INamedContentFactory namedContentFactory;
|
|
||||||
private readonly IContentTemplateFactory contentTemplateFactory;
|
|
||||||
private readonly ITypedContentFactory typedContentFactory;
|
|
||||||
|
|
||||||
public NavigateHandler(IMediator mediator,
|
|
||||||
IContentTemplateFactory contentTemplateFactory,
|
|
||||||
INamedContentFactory namedContentFactory,
|
|
||||||
INamedContentTemplateFactory namedContentTemplateFactory,
|
|
||||||
ITypedContentFactory typedContentFactory,
|
|
||||||
INavigationRouteDescriptorCollection descriptors)
|
|
||||||
{
|
|
||||||
this.mediator = mediator;
|
|
||||||
this.contentTemplateFactory = contentTemplateFactory;
|
|
||||||
this.namedContentFactory = namedContentFactory;
|
|
||||||
this.namedContentTemplateFactory = namedContentTemplateFactory;
|
|
||||||
this.typedContentFactory = typedContentFactory;
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<Unit> Handle(Navigate request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
foreach (NavigationSegment segment in NavigationSegment.FromPath(request.Path))
|
|
||||||
{
|
|
||||||
object? content = null;
|
|
||||||
object? template = null;
|
|
||||||
|
|
||||||
Dictionary<string, object> keyedParameters = new();
|
|
||||||
List<object> parameters = new();
|
|
||||||
|
|
||||||
foreach (object? parameter in request.Parameters)
|
|
||||||
{
|
|
||||||
if (parameter is not null)
|
|
||||||
{
|
|
||||||
if (parameter is KeyValuePair<string, object> keyed)
|
|
||||||
{
|
|
||||||
keyedParameters.Add(keyed.Key, keyed.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parameters.Add(parameter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (segment.Name is { Length: > 0 } name)
|
|
||||||
{
|
|
||||||
content = namedContentFactory.Create(name, parameters.ToArray());
|
|
||||||
template = namedContentTemplateFactory.Create(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (template is not null)
|
|
||||||
{
|
|
||||||
object? target = null;
|
|
||||||
if (descriptors.FirstOrDefault(x => segment.Target is string { } name && name == x.Name) is NavigationRouteDescriptor descriptor)
|
|
||||||
{
|
|
||||||
target = descriptor.Route;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
target = template;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target is Frame frame)
|
|
||||||
{
|
|
||||||
mediator.Send(new FrameNavigation(frame, content, template, keyedParameters));
|
|
||||||
}
|
|
||||||
else if (target is ContentDialog dialog)
|
|
||||||
{
|
|
||||||
mediator.Send(new ContentDialogNavigation(dialog, content, template, keyedParameters));
|
|
||||||
}
|
|
||||||
else if (target is ContentControl contentControl)
|
|
||||||
{
|
|
||||||
mediator.Send(new ContentControlNavigation(contentControl, content, template, keyedParameters));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => segment.Target is string { } name && name == x.Name) is NavigationRouteDescriptor descriptor)
|
|
||||||
{
|
|
||||||
if (descriptor.Route is ContentControl contentControl)
|
|
||||||
{
|
|
||||||
contentControl.Content = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public record Navigation<TRoute> : IRequest where TRoute : TemplatedControl
|
|
||||||
{
|
|
||||||
public TRoute Route { get; }
|
|
||||||
|
|
||||||
public Navigation(TRoute route,
|
|
||||||
object? content,
|
|
||||||
object? template,
|
|
||||||
IDictionary<string, object>? parameters)
|
|
||||||
{
|
|
||||||
Route = route;
|
|
||||||
Content = content;
|
|
||||||
Template = template;
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? Content { get; }
|
|
||||||
|
|
||||||
public object? Template { get; }
|
|
||||||
|
|
||||||
public IDictionary<string, object>? Parameters { get; }
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
using FluentAvalonia.UI.Controls;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
internal class NavigationPageFactory : INavigationPageFactory
|
|
||||||
{
|
|
||||||
public IControl? GetPage(Type srcType)
|
|
||||||
{
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IControl GetPageFromObject(object target)
|
|
||||||
{
|
|
||||||
return (IControl)target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using Avalonia.Controls.Primitives;
|
|
||||||
using Avalonia.Interactivity;
|
|
||||||
using Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Avalonia;
|
|
||||||
|
|
||||||
public class NavigationRouteHandler : IRequestHandler<NavigationRoute>
|
|
||||||
{
|
|
||||||
private readonly INavigationRouteDescriptorCollection descriptors;
|
|
||||||
|
|
||||||
public NavigationRouteHandler(INavigationRouteDescriptorCollection descriptors)
|
|
||||||
{
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<Unit> Handle(NavigationRoute request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (request.Route is TemplatedControl control)
|
|
||||||
{
|
|
||||||
void HandleUnloaded(object? sender, RoutedEventArgs args)
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => x.Route == sender) is INavigationRouteDescriptor descriptor)
|
|
||||||
{
|
|
||||||
descriptors.Remove(descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
control.Unloaded += HandleUnloaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptors.FirstOrDefault(x => x.Name == request.Name) is INavigationRouteDescriptor descriptor)
|
|
||||||
{
|
|
||||||
descriptors.Remove(descriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
descriptors.Add(new NavigationRouteDescriptor(request.Name, request.Route));
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
using Avalonia.Metadata;
|
|
||||||
|
|
||||||
[assembly: XmlnsDefinition("https://github.com/avaloniaui", "Toolkit.Framework.Avalonia")]
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public record ConfigurationChanged<TConfiguration>(TConfiguration Configuration) : INotification where TConfiguration : class;
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ConfigurationInitializer<TConfiguration> : IInitializable where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
private readonly TConfiguration configuration;
|
|
||||||
private readonly IMediator mediator;
|
|
||||||
|
|
||||||
public ConfigurationInitializer(TConfiguration configuration,
|
|
||||||
IMediator mediator)
|
|
||||||
{
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.mediator = mediator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
|
||||||
{
|
|
||||||
await mediator.Send(configuration);
|
|
||||||
await Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ConfigurationWriter<TConfiguration> : IConfigurationWriter<TConfiguration> where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
private readonly IConfiguration rootConfiguration;
|
|
||||||
private readonly string section;
|
|
||||||
|
|
||||||
public ConfigurationWriter(IConfiguration rootConfiguration, string section)
|
|
||||||
{
|
|
||||||
this.rootConfiguration = rootConfiguration;
|
|
||||||
this.section = section;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(TConfiguration configuration)
|
|
||||||
{
|
|
||||||
if (rootConfiguration is IConfigurationRoot root)
|
|
||||||
{
|
|
||||||
foreach (IConfigurationProvider? provider in root.Providers)
|
|
||||||
{
|
|
||||||
if (provider is IWritableConfigurationProvider writableConfigurationProvider)
|
|
||||||
{
|
|
||||||
writableConfigurationProvider.Write(section, configuration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IConfigurationWriter<TConfiguration> where TConfiguration : class
|
|
||||||
{
|
|
||||||
void Write(TConfiguration args);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IWritableConfigurationProvider
|
|
||||||
{
|
|
||||||
void Write<TValue>(string section, TValue value) where TValue : class, new();
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IWritableJsonConfigurationBuilder
|
|
||||||
{
|
|
||||||
Stream? DefaultFileStream { get; }
|
|
||||||
|
|
||||||
IWritableJsonConfigurationBuilder AddDefaultConfiguration<TConfiguration>(string Key) where TConfiguration : class;
|
|
||||||
|
|
||||||
IWritableJsonConfigurationBuilder AddDefaultFileStream(Stream stream);
|
|
||||||
|
|
||||||
void Build(string path);
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IWritableJsonConfigurationDescriptor
|
|
||||||
{
|
|
||||||
Type ConfigurationType { get; }
|
|
||||||
|
|
||||||
string Key { get; }
|
|
||||||
}
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
using Json.Patch;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class WritableJsonConfigurationBuilder : IWritableJsonConfigurationBuilder
|
|
||||||
{
|
|
||||||
private readonly List<IWritableJsonConfigurationDescriptor> descriptors = new();
|
|
||||||
|
|
||||||
public Stream? DefaultFileStream { get; private set; }
|
|
||||||
|
|
||||||
public IReadOnlyCollection<IWritableJsonConfigurationDescriptor> Descriptors => new ReadOnlyCollection<IWritableJsonConfigurationDescriptor>(descriptors);
|
|
||||||
|
|
||||||
public IWritableJsonConfigurationBuilder AddDefaultConfiguration<TConfiguration>(string Key) where TConfiguration : class
|
|
||||||
{
|
|
||||||
descriptors.Add(new WritableJsonConfigurationDescriptor(typeof(TConfiguration), Key));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IWritableJsonConfigurationBuilder AddDefaultFileStream(Stream stream)
|
|
||||||
{
|
|
||||||
DefaultFileStream = stream;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Build(string path)
|
|
||||||
{
|
|
||||||
JObject? sourceDocument = new();
|
|
||||||
if (TryLoadSource(out string? defaultContent))
|
|
||||||
{
|
|
||||||
sourceDocument = JObject.Parse(defaultContent!);
|
|
||||||
}
|
|
||||||
|
|
||||||
JObject? targetDocument = new();
|
|
||||||
if (TryLoadTarget(path, out string? targetContent))
|
|
||||||
{
|
|
||||||
targetDocument = JObject.Parse(targetContent!);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (IWritableJsonConfigurationDescriptor? descriptor in descriptors)
|
|
||||||
{
|
|
||||||
if (sourceDocument.SelectToken($"$.{descriptor.Key}") is JToken sourceSection)
|
|
||||||
{
|
|
||||||
if (targetDocument.SelectToken($"$.{descriptor.Key}") is JToken targetSection)
|
|
||||||
{
|
|
||||||
object? source = JsonSerializer.Deserialize(JsonConvert.SerializeObject(sourceSection), descriptor.ConfigurationType);
|
|
||||||
object? target = JsonSerializer.Deserialize(JsonConvert.SerializeObject(targetSection), descriptor.ConfigurationType);
|
|
||||||
|
|
||||||
JsonPatch? patch = source.CreatePatch(target);
|
|
||||||
|
|
||||||
object? sourcePatched = patch.Apply(source);
|
|
||||||
targetSection.Replace(JToken.Parse(JsonSerializer.Serialize(sourcePatched, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull })));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
object? source = JsonSerializer.Deserialize(JsonConvert.SerializeObject(sourceSection), descriptor.ConfigurationType);
|
|
||||||
targetDocument.Add(descriptor.Key, JToken.Parse(JsonSerializer.Serialize(source, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull })));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
object? configuration = Activator.CreateInstance(descriptor.ConfigurationType);
|
|
||||||
targetDocument.Add(descriptor.Key, JToken.Parse(JsonSerializer.Serialize(configuration, new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull })));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using FileStream? fileStream = new(path, FileMode.Create, FileAccess.Write);
|
|
||||||
using StreamWriter streamWriter = new(fileStream);
|
|
||||||
using JsonTextWriter writer = new(streamWriter) { Formatting = Formatting.Indented };
|
|
||||||
targetDocument.WriteTo(writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryLoadTarget(string path, [MaybeNull] out string? content)
|
|
||||||
{
|
|
||||||
if (File.Exists(path))
|
|
||||||
{
|
|
||||||
using FileStream? fileStream = new(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
||||||
using StreamReader? streamReader = new(fileStream);
|
|
||||||
content = streamReader.ReadToEnd();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
content = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryLoadSource([MaybeNull] out string? content)
|
|
||||||
{
|
|
||||||
if (DefaultFileStream is Stream fileStream)
|
|
||||||
{
|
|
||||||
using StreamReader? streamReader = new(fileStream);
|
|
||||||
content = streamReader.ReadToEnd();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
content = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public record WritableJsonConfigurationDescriptor(Type ConfigurationType, string Key) : IWritableJsonConfigurationDescriptor;
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
internal class WritableJsonConfigurationFile
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string, (JsonValueKind?, string?)> data = new(StringComparer.OrdinalIgnoreCase);
|
|
||||||
private readonly Stack<string> paths = new();
|
|
||||||
private JObject tokenCache = new();
|
|
||||||
private bool isParsing;
|
|
||||||
|
|
||||||
public IDictionary<string, string?> Parse(Stream input)
|
|
||||||
{
|
|
||||||
return ParseStream(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(string key, string value, Stream output)
|
|
||||||
{
|
|
||||||
if (isParsing)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key[^1] == ':')
|
|
||||||
{
|
|
||||||
key = key[0..^1];
|
|
||||||
}
|
|
||||||
|
|
||||||
string? tokenPath = $"$.{key.Replace(":", ".")}";
|
|
||||||
key = key.Replace("[", "").Replace("]", "");
|
|
||||||
|
|
||||||
if (tokenCache.SelectToken(tokenPath) is JToken token && data.ContainsKey(key))
|
|
||||||
{
|
|
||||||
(JsonValueKind? kind, string _) = data[key];
|
|
||||||
object? newValue = ConvertValue(kind, value);
|
|
||||||
|
|
||||||
data[key] = new(kind, value);
|
|
||||||
token.Replace(JToken.FromObject(newValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
using StreamWriter streamWriter = new(output);
|
|
||||||
using JsonTextWriter writer = new(streamWriter) { Formatting = Formatting.Indented };
|
|
||||||
tokenCache.WriteTo(writer);
|
|
||||||
|
|
||||||
output.SetLength(output.Position);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static object ConvertValue(JsonValueKind? kind, string value)
|
|
||||||
{
|
|
||||||
return kind is JsonValueKind.True or JsonValueKind.False ? bool.Parse(value) : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnterContext(string context)
|
|
||||||
{
|
|
||||||
paths.Push(paths.Count > 0 ? paths.Peek() + ConfigurationPath.KeyDelimiter + context : context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExitContext()
|
|
||||||
{
|
|
||||||
paths.Pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private IDictionary<string, string?> ParseStream(Stream input)
|
|
||||||
{
|
|
||||||
data.Clear();
|
|
||||||
|
|
||||||
JsonDocumentOptions jsonDocumentOptions = new()
|
|
||||||
{
|
|
||||||
CommentHandling = JsonCommentHandling.Skip,
|
|
||||||
AllowTrailingCommas = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
isParsing = true;
|
|
||||||
using (StreamReader? reader = new(input))
|
|
||||||
{
|
|
||||||
string? content = reader.ReadToEnd();
|
|
||||||
tokenCache = JObject.Parse(content);
|
|
||||||
|
|
||||||
using JsonDocument? doc = JsonDocument.Parse(content, jsonDocumentOptions);
|
|
||||||
VisitElement(doc.RootElement);
|
|
||||||
}
|
|
||||||
isParsing = false;
|
|
||||||
|
|
||||||
return data.ToDictionary(k => k.Key, v => v.Value.Item2?.ToString() ?? null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VisitElement(JsonElement element)
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
|
|
||||||
foreach (JsonProperty property in element.EnumerateObject())
|
|
||||||
{
|
|
||||||
isEmpty = false;
|
|
||||||
|
|
||||||
EnterContext(property.Name);
|
|
||||||
VisitValue(property.Value);
|
|
||||||
ExitContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEmpty && paths.Count > 0)
|
|
||||||
{
|
|
||||||
data[paths.Peek()] = (JsonValueKind.Null, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VisitValue(JsonElement value)
|
|
||||||
{
|
|
||||||
switch (value.ValueKind)
|
|
||||||
{
|
|
||||||
case JsonValueKind.Object:
|
|
||||||
VisitElement(value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JsonValueKind.Array:
|
|
||||||
int index = 0;
|
|
||||||
foreach (JsonElement arrayElement in value.EnumerateArray())
|
|
||||||
{
|
|
||||||
EnterContext(index.ToString());
|
|
||||||
VisitValue(arrayElement);
|
|
||||||
ExitContext();
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JsonValueKind.Number:
|
|
||||||
case JsonValueKind.String:
|
|
||||||
case JsonValueKind.True:
|
|
||||||
case JsonValueKind.False:
|
|
||||||
case JsonValueKind.Null:
|
|
||||||
string key = paths.Peek();
|
|
||||||
if (data.ContainsKey(key))
|
|
||||||
{
|
|
||||||
throw new FormatException();
|
|
||||||
}
|
|
||||||
data[key] = new(value.ValueKind, value.ToString());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case JsonValueKind.Undefined:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new FormatException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration.Json;
|
|
||||||
using Microsoft.Extensions.FileProviders;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class WritableJsonConfigurationProvider : JsonConfigurationProvider, IWritableConfigurationProvider
|
|
||||||
{
|
|
||||||
public WritableJsonConfigurationProvider(JsonConfigurationSource source) : base(source)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write<TValue>(string section, TValue value) where TValue : class, new()
|
|
||||||
{
|
|
||||||
IFileInfo? file = Source.FileProvider?.GetFileInfo(Source.Path ?? string.Empty);
|
|
||||||
static Stream OpenRead(IFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
return fileInfo.PhysicalPath is not null
|
|
||||||
? new FileStream(fileInfo.PhysicalPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
|
|
||||||
: fileInfo.CreateReadStream();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file is null)
|
|
||||||
{
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
using Stream stream = OpenRead(file);
|
|
||||||
using StreamReader? reader = new(stream);
|
|
||||||
|
|
||||||
string? content = reader.ReadToEnd();
|
|
||||||
JObject? document = JObject.Parse(content);
|
|
||||||
|
|
||||||
if (document.SelectToken($"$.{section}") is JToken sectionToken)
|
|
||||||
{
|
|
||||||
sectionToken.Replace(JToken.Parse(JsonConvert.SerializeObject(value)));
|
|
||||||
stream.SetLength(0);
|
|
||||||
|
|
||||||
using StreamWriter streamWriter = new(stream);
|
|
||||||
using JsonTextWriter writer = new(streamWriter) { Formatting = Formatting.Indented };
|
|
||||||
document.WriteTo(writer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Configuration.Json;
|
|
||||||
using Microsoft.Extensions.FileProviders;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class WritableJsonConfigurationSource : JsonConfigurationSource
|
|
||||||
{
|
|
||||||
public IWritableJsonConfigurationBuilder? Factory { get; set; }
|
|
||||||
|
|
||||||
public override IConfigurationProvider Build(IConfigurationBuilder builder)
|
|
||||||
{
|
|
||||||
EnsureDefaultsWithSteam(builder);
|
|
||||||
return new WritableJsonConfigurationProvider(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnsureDefaultsWithSteam(IConfigurationBuilder builder)
|
|
||||||
{
|
|
||||||
EnsureDefaults(builder);
|
|
||||||
|
|
||||||
if (FileProvider is PhysicalFileProvider physicalFileProvider)
|
|
||||||
{
|
|
||||||
string? outputFile = System.IO.Path.Combine(physicalFileProvider.Root, Path!);
|
|
||||||
Factory?.Build(outputFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public record Write<TConfiguration>(Action<TConfiguration> UpdateDelegate) : IRequest where TConfiguration : class;
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class WriteHandler<TConfiguration> : IRequestHandler<Write<TConfiguration>> where TConfiguration : class
|
|
||||||
{
|
|
||||||
private readonly IMediator mediator;
|
|
||||||
private readonly TConfiguration configuration;
|
|
||||||
private readonly IConfigurationWriter<TConfiguration> writer;
|
|
||||||
|
|
||||||
public WriteHandler(TConfiguration configuration,
|
|
||||||
IConfigurationWriter<TConfiguration> writer,
|
|
||||||
IMediator mediator)
|
|
||||||
{
|
|
||||||
this.mediator = mediator;
|
|
||||||
this.configuration = configuration;
|
|
||||||
this.writer = writer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask<Unit> Handle(Write<TConfiguration> request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
request.UpdateDelegate.Invoke(configuration);
|
|
||||||
writer.Write(configuration);
|
|
||||||
|
|
||||||
await mediator.Publish(new ConfigurationChanged<TConfiguration>(configuration), cancellationToken);
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public record Content : IRequest<object?>
|
|
||||||
{
|
|
||||||
public Content(string name, params object?[] parameters)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Content(Type type, params object?[] parameters)
|
|
||||||
{
|
|
||||||
Type = type;
|
|
||||||
Parameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type? Type { get; }
|
|
||||||
|
|
||||||
public string? Name { get; }
|
|
||||||
|
|
||||||
public object?[] Parameters { get; }
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ContentTemplateBuilder : IContentTemplateBuilder
|
|
||||||
{
|
|
||||||
private readonly List<IContentTemplateDescriptor> descriptors = new();
|
|
||||||
|
|
||||||
public IReadOnlyCollection<IContentTemplateDescriptor> Descriptors => new ReadOnlyCollection<IContentTemplateDescriptor>(descriptors);
|
|
||||||
|
|
||||||
public IContentTemplateBuilder Add<TViewModel, TView>(string name, ServiceLifetime lifetime = ServiceLifetime.Transient)
|
|
||||||
{
|
|
||||||
descriptors.Add(new ContentTemplateDescriptor(typeof(TViewModel), typeof(TView), name, lifetime));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IContentTemplateBuilder Add<TViewModel, TView>(ServiceLifetime lifetime = ServiceLifetime.Transient)
|
|
||||||
{
|
|
||||||
descriptors.Add(new ContentTemplateDescriptor(typeof(TViewModel), typeof(TView), null, lifetime));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ContentTemplateDescriptor : IContentTemplateDescriptor
|
|
||||||
{
|
|
||||||
public ContentTemplateDescriptor(Type dataType,
|
|
||||||
Type templateType,
|
|
||||||
string? name = null,
|
|
||||||
ServiceLifetime lifetime = ServiceLifetime.Transient)
|
|
||||||
{
|
|
||||||
TemplateType = templateType;
|
|
||||||
ContentType = dataType;
|
|
||||||
Name = name;
|
|
||||||
Lifetime = lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServiceLifetime Lifetime { get; }
|
|
||||||
|
|
||||||
public Type TemplateType { get; }
|
|
||||||
|
|
||||||
public Type ContentType { get; }
|
|
||||||
|
|
||||||
public string? Name { get; }
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ContentTemplateDescriptorProvider : IContentTemplateDescriptorProvider
|
|
||||||
{
|
|
||||||
private readonly IReadOnlyCollection<IContentTemplateDescriptor> descriptors;
|
|
||||||
|
|
||||||
public ContentTemplateDescriptorProvider(IReadOnlyCollection<IContentTemplateDescriptor> descriptors)
|
|
||||||
{
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IContentTemplateDescriptor? Get(string name)
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => x.Name == name) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IContentTemplateDescriptor? Get(Type type)
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => x.ContentType == type) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IContentTemplateDescriptor? Get<T>()
|
|
||||||
{
|
|
||||||
if (descriptors.FirstOrDefault(x => x.ContentType == typeof(T)) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class ContentTemplateFactory : IContentTemplateFactory
|
|
||||||
{
|
|
||||||
private readonly Dictionary<object, object> cache = new();
|
|
||||||
|
|
||||||
private readonly IContentTemplateDescriptorProvider provider;
|
|
||||||
private readonly IServiceFactory serviceFactory;
|
|
||||||
|
|
||||||
public ContentTemplateFactory(IContentTemplateDescriptorProvider provider,
|
|
||||||
IServiceFactory serviceFactory)
|
|
||||||
{
|
|
||||||
this.provider = provider;
|
|
||||||
this.serviceFactory = serviceFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual object? Create([MaybeNull] object? data)
|
|
||||||
{
|
|
||||||
if (data is null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cache.TryGetValue(data, out object? template))
|
|
||||||
{
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (provider.Get(data.GetType()) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
template = serviceFactory.Create(descriptor.TemplateType);
|
|
||||||
if (template is ICache cache)
|
|
||||||
{
|
|
||||||
this.cache[data] = cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IContentTemplateBuilder
|
|
||||||
{
|
|
||||||
IReadOnlyCollection<IContentTemplateDescriptor> Descriptors { get; }
|
|
||||||
|
|
||||||
IContentTemplateBuilder Add<TViewModel, TView>(string name, ServiceLifetime lifetime = ServiceLifetime.Transient);
|
|
||||||
|
|
||||||
IContentTemplateBuilder Add<TViewModel, TView>(ServiceLifetime lifetime = ServiceLifetime.Transient);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IContentTemplateDescriptor
|
|
||||||
{
|
|
||||||
Type ContentType { get; }
|
|
||||||
|
|
||||||
ServiceLifetime Lifetime { get; }
|
|
||||||
|
|
||||||
string? Name { get; }
|
|
||||||
|
|
||||||
Type TemplateType { get; }
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IContentTemplateDescriptorProvider
|
|
||||||
{
|
|
||||||
IContentTemplateDescriptor? Get(string name);
|
|
||||||
|
|
||||||
IContentTemplateDescriptor? Get(Type type);
|
|
||||||
|
|
||||||
IContentTemplateDescriptor? Get<T>();
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IContentTemplateFactory
|
|
||||||
{
|
|
||||||
object? Create([MaybeNull] object? content);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IContentTemplateSelector
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface INamedContentTemplateFactory
|
|
||||||
{
|
|
||||||
object? Create(string name);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface INamedContentFactory
|
|
||||||
{
|
|
||||||
object? Create(string name, params object?[] parameters);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface ITypedContentFactory
|
|
||||||
{
|
|
||||||
object? Create(Type type, params object?[] parameters);
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class NamedContentFactory : INamedContentFactory
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string, object> cache = new();
|
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<IContentTemplateDescriptor> descriptors;
|
|
||||||
private readonly IServiceFactory serviceFactory;
|
|
||||||
|
|
||||||
public NamedContentFactory(IReadOnlyCollection<IContentTemplateDescriptor> descriptors,
|
|
||||||
IServiceFactory serviceFactory)
|
|
||||||
{
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
this.serviceFactory = serviceFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual object? Create(string name, params object?[] parameters)
|
|
||||||
{
|
|
||||||
if (cache.TryGetValue(name, out object? data))
|
|
||||||
{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptors.FirstOrDefault(x => x.Name == name) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.ContentType, parameters) : serviceFactory.Create(descriptor.ContentType);
|
|
||||||
if (data is ICache cache)
|
|
||||||
{
|
|
||||||
this.cache[name] = cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class NamedContentTemplateFactory : INamedContentTemplateFactory
|
|
||||||
{
|
|
||||||
private readonly Dictionary<string, object> cache = new();
|
|
||||||
|
|
||||||
private readonly IContentTemplateDescriptorProvider provider;
|
|
||||||
private readonly IServiceFactory serviceFactory;
|
|
||||||
|
|
||||||
public NamedContentTemplateFactory(IContentTemplateDescriptorProvider provider,
|
|
||||||
IServiceFactory serviceFactory)
|
|
||||||
{
|
|
||||||
this.provider = provider;
|
|
||||||
this.serviceFactory = serviceFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual object? Create(string name)
|
|
||||||
{
|
|
||||||
if (cache.TryGetValue(name, out object? view))
|
|
||||||
{
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (provider.Get(name) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
view = serviceFactory.Create(descriptor.TemplateType);
|
|
||||||
if (view is ICache cache)
|
|
||||||
{
|
|
||||||
this.cache[name] = cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor.GetType().GenericTypeArguments is { Length: 2 })
|
|
||||||
{
|
|
||||||
(descriptor as dynamic).ViewInvoker?.Invoke(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class TypedContentFactory : ITypedContentFactory
|
|
||||||
{
|
|
||||||
private readonly Dictionary<Type, object> cache = new();
|
|
||||||
|
|
||||||
private readonly IReadOnlyCollection<IContentTemplateDescriptor> descriptors;
|
|
||||||
private readonly IServiceFactory serviceFactory;
|
|
||||||
|
|
||||||
public TypedContentFactory(IReadOnlyCollection<IContentTemplateDescriptor> descriptors,
|
|
||||||
IServiceFactory serviceFactory)
|
|
||||||
{
|
|
||||||
this.descriptors = descriptors;
|
|
||||||
this.serviceFactory = serviceFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? Create(Type type, params object?[] parameters)
|
|
||||||
{
|
|
||||||
if (cache.TryGetValue(type, out object? data))
|
|
||||||
{
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptors.FirstOrDefault(x => x.ContentType == type) is IContentTemplateDescriptor descriptor)
|
|
||||||
{
|
|
||||||
data = parameters is { Length: > 0 } ? serviceFactory.Create<object>(descriptor.ContentType, parameters) : serviceFactory.Create(descriptor.ContentType);
|
|
||||||
if (data is ICache cache)
|
|
||||||
{
|
|
||||||
this.cache[type] = cache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public static class AssemblyExtensions
|
|
||||||
{
|
|
||||||
public static Stream? ExtractResource(this Assembly assembly, string filename)
|
|
||||||
{
|
|
||||||
string? resourceName = $"{assembly.GetName()?.Name?.Replace("-", "_")}.{filename}";
|
|
||||||
return assembly.GetManifestResourceStream(resourceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public static class IServiceCollectionExtensions
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddConfiguration<TConfiguration>(this IServiceCollection serviceCollection, IConfiguration configuration) where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
serviceCollection.Configure<TConfiguration>(configuration);
|
|
||||||
serviceCollection.AddTransient(provider => provider.GetService<IOptionsMonitor<TConfiguration>>()!.CurrentValue);
|
|
||||||
serviceCollection.AddTransient<ConfigurationInitializer<TConfiguration>>();
|
|
||||||
|
|
||||||
return serviceCollection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddFoundation(this IServiceCollection serviceCollection)
|
|
||||||
{
|
|
||||||
serviceCollection
|
|
||||||
.AddSingleton<IMediator, Mediator>()
|
|
||||||
.AddHandler<InitializeHandler>()
|
|
||||||
.AddSingleton<IServiceFactory>(provider => new ServiceFactory(provider.GetService, (type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)))
|
|
||||||
.AddHandler<ServiceFactoryHandler>()
|
|
||||||
.AddSingleton<IInitialization, Initialization>(provider => new Initialization(() =>
|
|
||||||
{
|
|
||||||
return serviceCollection.Where(x => x.ServiceType.GetInterfaces()
|
|
||||||
.Contains(typeof(IInitializable)) || x.ServiceType == typeof(IInitializable))
|
|
||||||
.GroupBy(x => x.ServiceType)
|
|
||||||
.Select(x => x.First())
|
|
||||||
.SelectMany(x => provider.GetServices(x.ServiceType)
|
|
||||||
.Select(x => (IInitializable?)x)).ToList();
|
|
||||||
}));
|
|
||||||
|
|
||||||
return serviceCollection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddHandler<THandler>(this IServiceCollection serviceCollection, ServiceLifetime lifetime = ServiceLifetime.Transient) where THandler : notnull
|
|
||||||
{
|
|
||||||
if (typeof(THandler).GetInterface(typeof(INotificationHandler<>).Name) is { } notificationContract)
|
|
||||||
{
|
|
||||||
if (notificationContract.GetGenericArguments() is { Length: 1 } arguments)
|
|
||||||
{
|
|
||||||
Type notificationType = arguments[0];
|
|
||||||
|
|
||||||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(THandler), typeof(THandler), ServiceLifetime.Singleton));
|
|
||||||
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(typeof(INotificationHandler<>).MakeGenericType(notificationType), sp => sp.GetRequiredService<THandler>(), lifetime));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(THandler).GetInterface(typeof(IRequestHandler<,>).Name) is { } requestContract)
|
|
||||||
{
|
|
||||||
if (requestContract.GetGenericArguments() is { Length: 2 } arguments)
|
|
||||||
{
|
|
||||||
Type requestType = arguments[0];
|
|
||||||
Type responseType = arguments[1];
|
|
||||||
|
|
||||||
Type wrapperType = typeof(RequestClassHandlerWrapper<,>).MakeGenericType(requestType, responseType);
|
|
||||||
|
|
||||||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(THandler), typeof(THandler), lifetime));
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(wrapperType,
|
|
||||||
sp =>
|
|
||||||
{
|
|
||||||
return sp.GetService<IServiceFactory>()?.Create(wrapperType, sp.GetRequiredService<THandler>(), sp.GetServices(typeof(IPipelineBehavior<,>).MakeGenericType(requestType, responseType)))!;
|
|
||||||
},
|
|
||||||
lifetime
|
|
||||||
));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(THandler).GetInterface(typeof(ICommandHandler<,>).Name) is { } commandContract)
|
|
||||||
{
|
|
||||||
if (commandContract.GetGenericArguments() is { Length: 2 } arguments)
|
|
||||||
{
|
|
||||||
Type requestType = arguments[0];
|
|
||||||
Type responseType = arguments[1];
|
|
||||||
|
|
||||||
Type wrapperType = typeof(CommandClassHandlerWrapper<,>).MakeGenericType(requestType, responseType);
|
|
||||||
|
|
||||||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(THandler), typeof(THandler), lifetime));
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(wrapperType,
|
|
||||||
sp =>
|
|
||||||
{
|
|
||||||
return sp.GetService<IServiceFactory>()?.Create(wrapperType, sp.GetRequiredService<THandler>(), sp.GetServices(typeof(IPipelineBehavior<,>).MakeGenericType(requestType, responseType)))!;
|
|
||||||
},
|
|
||||||
lifetime
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(THandler).GetInterface(typeof(IQueryHandler<,>).Name) is { } queryContract)
|
|
||||||
{
|
|
||||||
if (queryContract.GetGenericArguments() is { Length: 2 } arguments)
|
|
||||||
{
|
|
||||||
Type requestType = arguments[0];
|
|
||||||
Type responseType = arguments[1];
|
|
||||||
|
|
||||||
Type wrapperType = typeof(QueryClassHandlerWrapper<,>).MakeGenericType(requestType, responseType);
|
|
||||||
|
|
||||||
serviceCollection.TryAdd(new ServiceDescriptor(typeof(THandler), typeof(THandler), lifetime));
|
|
||||||
serviceCollection.Add(new ServiceDescriptor(wrapperType,
|
|
||||||
sp =>
|
|
||||||
{
|
|
||||||
return sp.GetService<IServiceFactory>()?.Create(wrapperType, sp.GetRequiredService<THandler>(), sp.GetServices(typeof(IPipelineBehavior<,>).MakeGenericType(requestType, responseType)))!;
|
|
||||||
},
|
|
||||||
lifetime
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return serviceCollection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IServiceCollection AddWritableConfiguration<TConfiguration>(this IServiceCollection serviceCollection, IConfiguration configuration) where TConfiguration : class, new()
|
|
||||||
{
|
|
||||||
serviceCollection.Configure<TConfiguration>(configuration);
|
|
||||||
serviceCollection.AddTransient<IConfigurationWriter<TConfiguration>>(provider => provider.GetService<IServiceFactory>()?.Create< ConfigurationWriter<TConfiguration>>(configuration is IConfigurationSection section ? section.Path : "")!);
|
|
||||||
serviceCollection.AddTransient(provider => provider.GetService<IOptionsMonitor<TConfiguration>>()!.CurrentValue);
|
|
||||||
serviceCollection.AddHandler<WriteHandler<TConfiguration>>();
|
|
||||||
serviceCollection.AddTransient<ConfigurationInitializer<TConfiguration>>();
|
|
||||||
|
|
||||||
return serviceCollection;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public static class IServiceFactoryExtensions
|
|
||||||
{
|
|
||||||
public static T? Create<T>(this IServiceFactory serviceFactory, params object?[] parameters)
|
|
||||||
{
|
|
||||||
return serviceFactory.Create<T>(typeof(T), parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static object? Create(this IServiceFactory serviceFactory, Type type)
|
|
||||||
{
|
|
||||||
ServiceFactoryDescriptor? descriptor = new(serviceFactory);
|
|
||||||
return descriptor.Create(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.FileProviders;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public static class WritableJsonConfigurationExtensions
|
|
||||||
{
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile(null, path, false, false, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path,
|
|
||||||
Action<IWritableJsonConfigurationBuilder>? factoryDelegate)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile(null, path, false, false, factoryDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path,
|
|
||||||
bool optional)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile(null, path, optional, false, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path,
|
|
||||||
bool optional,
|
|
||||||
Action<IWritableJsonConfigurationBuilder>? factoryDelegate)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile(null, path, optional, false, factoryDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path,
|
|
||||||
bool optional,
|
|
||||||
bool reloadOnChange)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile( null, path, optional, reloadOnChange, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
string path,
|
|
||||||
bool optional,
|
|
||||||
bool reloadOnChange,
|
|
||||||
Action<IWritableJsonConfigurationBuilder>? factoryDelegate)
|
|
||||||
{
|
|
||||||
return builder.AddWritableJsonFile(null, path, optional, reloadOnChange, factoryDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder,
|
|
||||||
IFileProvider? provider,
|
|
||||||
string path,
|
|
||||||
bool optional,
|
|
||||||
bool reloadOnChange, Action<IWritableJsonConfigurationBuilder>? writableJsonConfigurationDelegate)
|
|
||||||
{
|
|
||||||
IWritableJsonConfigurationBuilder writableJsonConfigurationBuilder = new WritableJsonConfigurationBuilder();
|
|
||||||
writableJsonConfigurationDelegate?.Invoke(writableJsonConfigurationBuilder);
|
|
||||||
|
|
||||||
return builder.AddWritableJsonFile(configuration =>
|
|
||||||
{
|
|
||||||
configuration.FileProvider = provider;
|
|
||||||
configuration.Path = path;
|
|
||||||
configuration.Optional = optional;
|
|
||||||
configuration.ReloadOnChange = reloadOnChange;
|
|
||||||
configuration.Factory = writableJsonConfigurationBuilder;
|
|
||||||
configuration.ResolveFileProvider();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfigurationBuilder AddWritableJsonFile(this IConfigurationBuilder builder, Action<WritableJsonConfigurationSource> configureSource) => builder.Add(configureSource);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<AssemblyName>Toolkit.Framework.Foundation</AssemblyName>
|
|
||||||
<RootNamespace>Toolkit.Framework.Foundation</RootNamespace>
|
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="JsonPatch.Net" Version="2.0.4" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
|
||||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public struct KeyValueAccumulator
|
|
||||||
{
|
|
||||||
private Dictionary<string, StringValues> accumulator;
|
|
||||||
private Dictionary<string, List<string>> expandingAccumulator;
|
|
||||||
|
|
||||||
public void Append(string key, string value)
|
|
||||||
{
|
|
||||||
accumulator ??= new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
if (accumulator.TryGetValue(key, out StringValues values))
|
|
||||||
{
|
|
||||||
if (values.Count == 0)
|
|
||||||
{
|
|
||||||
expandingAccumulator[key].Add(value);
|
|
||||||
}
|
|
||||||
else if (values.Count == 1)
|
|
||||||
{
|
|
||||||
accumulator[key] = new string[] { values[0]!, value };
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accumulator[key] = default;
|
|
||||||
|
|
||||||
expandingAccumulator ??= new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
List<string> list = new(8);
|
|
||||||
string?[] array = values.ToArray();
|
|
||||||
|
|
||||||
list.Add(array[0]!);
|
|
||||||
list.Add(array[1]!);
|
|
||||||
list.Add(value);
|
|
||||||
|
|
||||||
expandingAccumulator[key] = list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
accumulator[key] = new StringValues(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasValues => ValueCount > 0;
|
|
||||||
|
|
||||||
public int KeyCount => accumulator?.Count ?? 0;
|
|
||||||
|
|
||||||
public int ValueCount { get; private set; }
|
|
||||||
|
|
||||||
public Dictionary<string, StringValues> GetResults()
|
|
||||||
{
|
|
||||||
if (expandingAccumulator != null)
|
|
||||||
{
|
|
||||||
foreach (var entry in expandingAccumulator)
|
|
||||||
{
|
|
||||||
accumulator[entry.Key] = new StringValues(entry.Value.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return accumulator ?? new Dictionary<string, StringValues>(0, StringComparer.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public static class QueryHelpers
|
|
||||||
{
|
|
||||||
public static Dictionary<string, StringValues>? ParseNullableQuery(string? queryString)
|
|
||||||
{
|
|
||||||
KeyValueAccumulator accumulator = new();
|
|
||||||
QueryStringEnumerable enumerable = new(queryString);
|
|
||||||
|
|
||||||
foreach (QueryStringEnumerable.EncodedNameValuePair pair in enumerable)
|
|
||||||
{
|
|
||||||
accumulator.Append(pair.DecodeName().ToString(), pair.DecodeValue().ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!accumulator.HasValues)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return accumulator.GetResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dictionary<string, StringValues> ParseQuery(string? queryString)
|
|
||||||
{
|
|
||||||
Dictionary<string, StringValues>? result = ParseNullableQuery(queryString);
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
return new Dictionary<string, StringValues>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
using System.Buffers;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Runtime.Intrinsics;
|
|
||||||
|
|
||||||
readonly struct QueryStringEnumerable
|
|
||||||
{
|
|
||||||
private readonly ReadOnlyMemory<char> queryString;
|
|
||||||
|
|
||||||
public QueryStringEnumerable(string? queryString) : this(queryString.AsMemory())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public QueryStringEnumerable(ReadOnlyMemory<char> queryString)
|
|
||||||
{
|
|
||||||
this.queryString = queryString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Enumerator GetEnumerator() => new(queryString);
|
|
||||||
|
|
||||||
public readonly struct EncodedNameValuePair
|
|
||||||
{
|
|
||||||
internal EncodedNameValuePair(ReadOnlyMemory<char> encodedName, ReadOnlyMemory<char> encodedValue)
|
|
||||||
{
|
|
||||||
EncodedName = encodedName;
|
|
||||||
EncodedValue = encodedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public readonly ReadOnlyMemory<char> EncodedName { get; }
|
|
||||||
|
|
||||||
public readonly ReadOnlyMemory<char> EncodedValue { get; }
|
|
||||||
|
|
||||||
public ReadOnlyMemory<char> DecodeName() => Decode(EncodedName);
|
|
||||||
|
|
||||||
public ReadOnlyMemory<char> DecodeValue() => Decode(EncodedValue);
|
|
||||||
|
|
||||||
private static ReadOnlyMemory<char> Decode(ReadOnlyMemory<char> chars)
|
|
||||||
{
|
|
||||||
return chars.Length < 16 && chars.Span.IndexOfAny('%', '+') < 0 ? chars : Uri.UnescapeDataString(SpanHelper.ReplacePlusWithSpace(chars.Span)).AsMemory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct Enumerator
|
|
||||||
{
|
|
||||||
private ReadOnlyMemory<char> query;
|
|
||||||
|
|
||||||
internal Enumerator(ReadOnlyMemory<char> query)
|
|
||||||
{
|
|
||||||
Current = default;
|
|
||||||
this.query = query.IsEmpty || query.Span[0] != '?' ? query : query[1..];
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncodedNameValuePair Current { get; private set; }
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
while (!query.IsEmpty)
|
|
||||||
{
|
|
||||||
ReadOnlyMemory<char> segment;
|
|
||||||
var delimiterIndex = query.Span.IndexOf('&');
|
|
||||||
if (delimiterIndex >= 0)
|
|
||||||
{
|
|
||||||
segment = query[..delimiterIndex];
|
|
||||||
query = query[(delimiterIndex + 1)..];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
segment = query;
|
|
||||||
query = default;
|
|
||||||
}
|
|
||||||
|
|
||||||
int equalIndex = segment.Span.IndexOf('=');
|
|
||||||
if (equalIndex >= 0)
|
|
||||||
{
|
|
||||||
Current = new EncodedNameValuePair(segment[..equalIndex], segment[(equalIndex + 1)..]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (!segment.IsEmpty)
|
|
||||||
{
|
|
||||||
Current = new EncodedNameValuePair(segment, default);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Current = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SpanHelper
|
|
||||||
{
|
|
||||||
private static readonly SpanAction<char, IntPtr> replacePlusWithSpace = ReplacePlusWithSpaceCore;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe string ReplacePlusWithSpace(ReadOnlySpan<char> span)
|
|
||||||
{
|
|
||||||
fixed (char* ptr = &MemoryMarshal.GetReference(span))
|
|
||||||
{
|
|
||||||
return string.Create(span.Length, (IntPtr)ptr, replacePlusWithSpace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static unsafe void ReplacePlusWithSpaceCore(Span<char> buffer, IntPtr state)
|
|
||||||
{
|
|
||||||
fixed (char* ptr = &MemoryMarshal.GetReference(buffer))
|
|
||||||
{
|
|
||||||
ushort* input = (ushort*)state.ToPointer();
|
|
||||||
ushort* output = (ushort*)ptr;
|
|
||||||
|
|
||||||
nint i = 0;
|
|
||||||
nint n = (nint)(uint)buffer.Length;
|
|
||||||
|
|
||||||
if (Vector256.IsHardwareAccelerated && n >= Vector256<ushort>.Count)
|
|
||||||
{
|
|
||||||
Vector256<ushort> vecPlus = Vector256.Create((ushort)'+');
|
|
||||||
Vector256<ushort> vecSpace = Vector256.Create((ushort)' ');
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Vector256<ushort> vec = Vector256.Load(input + i);
|
|
||||||
Vector256<ushort> mask = Vector256.Equals(vec, vecPlus);
|
|
||||||
Vector256<ushort> res = Vector256.ConditionalSelect(mask, vecSpace, vec);
|
|
||||||
res.Store(output + i);
|
|
||||||
i += Vector256<ushort>.Count;
|
|
||||||
} while (i <= n - Vector256<ushort>.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Vector128.IsHardwareAccelerated && n - i >= Vector128<ushort>.Count)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
Vector128<ushort> vec = Vector128.Load(input + i);
|
|
||||||
Vector128<ushort> vecPlus = Vector128.Create((ushort)'+');
|
|
||||||
Vector128<ushort> mask = Vector128.Equals(vec, vecPlus);
|
|
||||||
Vector128<ushort> vecSpace = Vector128.Create((ushort)' ');
|
|
||||||
Vector128<ushort> res = Vector128.ConditionalSelect(mask, vecSpace, vec);
|
|
||||||
res.Store(output + i);
|
|
||||||
i += Vector128<ushort>.Count;
|
|
||||||
} while (i <= n - Vector128<ushort>.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; i < n; ++i)
|
|
||||||
{
|
|
||||||
if (input[i] != '+')
|
|
||||||
{
|
|
||||||
output[i] = input[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output[i] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class AppService : IHostedService
|
|
||||||
{
|
|
||||||
private readonly IMediator mediator;
|
|
||||||
|
|
||||||
public AppService(IMediator mediator)
|
|
||||||
{
|
|
||||||
this.mediator = mediator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
await mediator.Send(new Initialize());
|
|
||||||
await mediator.Send(new Initialized());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class CommandClassHandlerWrapper<TRequest, TResponse> where TRequest : class, ICommand<TResponse>
|
|
||||||
{
|
|
||||||
private readonly MessageHandlerDelegate<TRequest, TResponse> handler;
|
|
||||||
|
|
||||||
public CommandClassHandlerWrapper(ICommandHandler<TRequest, TResponse> concreteHandler,
|
|
||||||
IEnumerable<IPipelineBehavior<TRequest, TResponse>> pipelineBehaviours)
|
|
||||||
{
|
|
||||||
MessageHandlerDelegate<TRequest, TResponse> handler = concreteHandler.Handle;
|
|
||||||
|
|
||||||
foreach (IPipelineBehavior<TRequest, TResponse>? pipeline in pipelineBehaviours.Reverse())
|
|
||||||
{
|
|
||||||
MessageHandlerDelegate<TRequest, TResponse> handlerCopy = handler;
|
|
||||||
IPipelineBehavior<TRequest, TResponse> pipelineCopy = pipeline;
|
|
||||||
handler = (TRequest message, CancellationToken cancellationToken) => pipelineCopy.Handle(message, cancellationToken, handlerCopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValueTask<TResponse> Handle(TRequest request, CancellationToken cancellationToken) => handler(request, cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Reactive.Disposables;
|
|
||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class Disposer : IDisposer
|
|
||||||
{
|
|
||||||
private readonly ConditionalWeakTable<object, CompositeDisposable> subjects = new();
|
|
||||||
|
|
||||||
public void Add(object subject, params object[] objects)
|
|
||||||
{
|
|
||||||
CompositeDisposable disposables = subjects.GetOrCreateValue(subject);
|
|
||||||
foreach (IDisposable disposable in objects.OfType<IDisposable>())
|
|
||||||
{
|
|
||||||
disposables.Add(disposable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TDisposable Replace<TDisposable>(object subject, IDisposable disposer, TDisposable replacement) where TDisposable : IDisposable
|
|
||||||
{
|
|
||||||
CompositeDisposable disposables = subjects.GetOrCreateValue(subject);
|
|
||||||
if (disposer is not null)
|
|
||||||
{
|
|
||||||
disposables.Remove(disposer);
|
|
||||||
}
|
|
||||||
|
|
||||||
disposables.Add(replacement);
|
|
||||||
return replacement;
|
|
||||||
}
|
|
||||||
public void Remove(object subject, IDisposable disposer)
|
|
||||||
{
|
|
||||||
CompositeDisposable disposables = subjects.GetOrCreateValue(subject);
|
|
||||||
if (disposer is not null)
|
|
||||||
{
|
|
||||||
disposables.Remove(disposer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose(object subject)
|
|
||||||
{
|
|
||||||
if (subjects.TryGetValue(subject, out CompositeDisposable disposables))
|
|
||||||
{
|
|
||||||
disposables.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface ICache
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface ICommand<out TResponse> : IMessage { }
|
|
||||||
public interface ICommand : ICommand<Unit> { }
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface ICommandHandler<in TCommand> : ICommandHandler<TCommand, Unit> where TCommand : ICommand<Unit> { }
|
|
||||||
|
|
||||||
public interface ICommandHandler<in TCommand, TResponse> where TCommand : ICommand<TResponse>
|
|
||||||
{
|
|
||||||
ValueTask<TResponse> Handle(TCommand command, CancellationToken cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IDisposer
|
|
||||||
{
|
|
||||||
void Add(object subject, params object[] objects);
|
|
||||||
|
|
||||||
void Remove(object subject, IDisposable disposer);
|
|
||||||
|
|
||||||
void Dispose(object subject);
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IInitializable
|
|
||||||
{
|
|
||||||
Task InitializeAsync();
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IInitialization
|
|
||||||
{
|
|
||||||
Task InitializeAsync();
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IMediator
|
|
||||||
{
|
|
||||||
ValueTask Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification;
|
|
||||||
|
|
||||||
ValueTask<TResponse> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
ValueTask<TResponse> Send<TResponse>(ICommand<TResponse> command, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
ValueTask<TResponse> Send<TResponse>(IQuery<TResponse> query, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
ValueTask<object?> Send(object message, CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
void Subscribe(object subscriber);
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IMessage { }
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface INotification : IMessage { }
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface INotificationHandler<in TNotification> where TNotification : INotification
|
|
||||||
{
|
|
||||||
ValueTask Handle(TNotification notification, CancellationToken cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IPipelineBehavior<TMessage, TResponse> where TMessage : notnull, IMessage
|
|
||||||
{
|
|
||||||
ValueTask<TResponse> Handle(
|
|
||||||
TMessage message,
|
|
||||||
CancellationToken cancellationToken,
|
|
||||||
MessageHandlerDelegate<TMessage, TResponse> next
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IQuery<out TResponse> : IMessage { }
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IQueryHandler<in TQuery, TResponse> where TQuery : IQuery<TResponse>
|
|
||||||
{
|
|
||||||
ValueTask<TResponse> Handle(TQuery query, CancellationToken cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IRequest : IRequest<Unit> { }
|
|
||||||
|
|
||||||
public interface IRequest<out TResponse> : IMessage { }
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public interface IRequestHandler<in TRequest> : IRequestHandler<TRequest, Unit> where TRequest : IRequest<Unit>
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IRequestHandler<in TRequest, TResponse> where TRequest : IRequest<TResponse>
|
|
||||||
{
|
|
||||||
ValueTask<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public class Initialization : IInitialization
|
|
||||||
{
|
|
||||||
private readonly Func<IEnumerable<IInitializable?>> factory;
|
|
||||||
|
|
||||||
public Initialization(Func<IEnumerable<IInitializable?>> factory)
|
|
||||||
{
|
|
||||||
this.factory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
|
||||||
{
|
|
||||||
foreach (IInitializable? initializer in factory())
|
|
||||||
{
|
|
||||||
if (initializer is not null)
|
|
||||||
{
|
|
||||||
await initializer.InitializeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
namespace Toolkit.Framework.Foundation;
|
|
||||||
|
|
||||||
public record Initialize : IRequest;
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user