Skip to content

Commit

Permalink
Add new background queue
Browse files Browse the repository at this point in the history
  • Loading branch information
pomianowski committed Feb 21, 2025
1 parent 510fcb3 commit 053438a
Show file tree
Hide file tree
Showing 44 changed files with 794 additions and 81 deletions.
18 changes: 15 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<PropertyGroup>
<Version>3.1.0</Version>
<AssemblyVersion>3.0.0</AssemblyVersion>
<Version>4.0.0</Version>
<AssemblyVersion>4.0.0</AssemblyVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -37,7 +37,7 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>

<!--
Expand All @@ -52,6 +52,14 @@
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsCoreProject Condition="$(IsTestProject)">False</IsCoreProject>
<IsCoreProject Condition="'$(IsCoreProject)' == ''">True</IsCoreProject>
<IsBelowNet8 Condition="'$(TargetFramework)' == 'netstandard2.0'
Or '$(TargetFramework)' == 'netstandard2.1'
Or '$(TargetFramework)' == 'net462'
Or '$(TargetFramework)' == 'net472'
Or '$(TargetFramework)' == 'net481'
Or '$(TargetFramework)' == 'net5.0'
Or '$(TargetFramework)' == 'net6.0'
Or '$(TargetFramework)' == 'net7.0'">True</IsBelowNet8>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -60,6 +68,10 @@
<ContinuousIntegrationBuild>$(TF_BUILD)</ContinuousIntegrationBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(IsBelowNet8)' == 'false'">
<DefineConstants>$(DefineConstants);NET8_0_OR_GREATER</DefineConstants>
</PropertyGroup>

<Choose>
<When Condition="$(IsCoreProject)">
<PropertyGroup>
Expand Down
9 changes: 7 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
<PackageVersion Include="Castle.Windsor" Version="6.0.0" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="AwesomeAssertions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Ninject" Version="3.0.1.10" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="PolySharp" Version="1.13.1" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="6.0.0" />
<PackageVersion Include="System.Threading.Channels" Version="9.0.0" />
<PackageVersion Include="Unity" Version="5.11.10" />
<PackageVersion Include="Unity.Abstractions" Version="4.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="WPF-UI" Version="4.0.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Leszek Pomianowski and ReflectionEventing Contributors. https://dev.lepo.co/
Copyright (c) 2024-2025 Leszek Pomianowski and ReflectionEventing Contributors. <https://dev.lepo.co/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Leszek Pomianowski and ReflectionEventing Contributors. https://dev.lepo.co/
Copyright (c) 2024-2025 Leszek Pomianowski and ReflectionEventing Contributors. https://dev.lepo.co/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions src/ReflectionEventing.Autofac/ContainerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// All Rights Reserved.

using Autofac;
using ReflectionEventing.Queues;

namespace ReflectionEventing.Autofac;

Expand Down Expand Up @@ -36,6 +37,8 @@ Action<EventBusBuilder> configure
.As<IConsumerTypesProvider>()
.SingleInstance();

_ = builder.RegisterType<EventsQueue>().As<IEventsQueue>().SingleInstance();

_ = builder
.RegisterType<AutofacConsumerProvider>()
.As<IConsumerProvider>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<PackageId>ReflectionEventing.Autofac</PackageId>
<TargetFrameworks>netstandard2.0;netstandard2.1;net462;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net6.0;netstandard2.0;net462;net472</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<CommonTags>$(CommonTags);autofac;module</CommonTags>
<Description>Autofac Container module with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications.</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PropertyGroup Condition="'$(IsBelowNet8)' == 'false'">
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<OptimizationPreference>Speed</OptimizationPreference>
Expand Down
2 changes: 2 additions & 0 deletions src/ReflectionEventing.Castle.Windsor/EventBusInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using ReflectionEventing.Queues;

namespace ReflectionEventing.Castle.Windsor;

Expand Down Expand Up @@ -35,6 +36,7 @@ public void Install(IWindsorContainer container, IConfigurationStore store)
.For<IConsumerTypesProvider>()
.Instance(builder.BuildTypesProvider())
.LifestyleScoped(),
Component.For<IEventsQueue>().ImplementedBy<EventsQueue>().LifestyleSingleton(),
Component
.For<IConsumerProvider>()
.ImplementedBy<WindsorConsumerProvider>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<PackageId>ReflectionEventing.Castle.Windsor</PackageId>
<TargetFrameworks>netstandard2.0;netstandard2.1;net462;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net9.0;net8.0;net6.0;netstandard2.0;net462;net472</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<CommonTags>$(CommonTags);castle;windsor;installer</CommonTags>
<Description>Castle Windsor installer with ReflectionEventing, which promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications.</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PropertyGroup Condition="'$(IsBelowNet8)' == 'false'">
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<OptimizationPreference>Speed</OptimizationPreference>
Expand Down
8 changes: 8 additions & 0 deletions src/ReflectionEventing.Demo.Wpf/Events/AsyncQueuedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors.
// All Rights Reserved.

namespace ReflectionEventing.Demo.Wpf.Events;

public sealed record AsyncQueuedEvent;
34 changes: 28 additions & 6 deletions src/ReflectionEventing.Demo.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,34 @@
IsDesignTimeCreatable=True}"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock Grid.Column="0" Text="Current tick:" />
<TextBlock Grid.Column="1" Text="{Binding ViewModel.CurrentTick, Mode=OneWay}" />
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0" Text="Current tick:" />
<TextBlock Grid.Column="1" Text="{Binding ViewModel.CurrentTick, Mode=OneWay}" />
</Grid>

<Grid Grid.Row="1" Margin="0,24,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Button
HorizontalAlignment="Left"
Command="{Binding ViewModel.SendToQueueCommand, Mode=OneWay}"
Content="Add to queue" />

<TextBlock Grid.Row="1" Text="{Binding ViewModel.QueueCount, Mode=OneWay}" />
</Grid>
</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UseWPF>true</UseWPF>
<IsPackable>false</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public Task StopAsync(CancellationToken cancellationToken)

private async Task TickInBackground(CancellationToken cancellationToken)
{
await eventBus.PublishAsync(new OtherEvent(), cancellationToken);
await eventBus.SendAsync(new OtherEvent(), cancellationToken);

Random random = new();

while (!cancellationToken.IsCancellationRequested)
{
await eventBus.PublishAsync(
await eventBus.SendAsync(
new BackgroundTicked(random.Next(10, 1001)),
cancellationToken
);
Expand Down
27 changes: 25 additions & 2 deletions src/ReflectionEventing.Demo.Wpf/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors.
// All Rights Reserved.

using CommunityToolkit.Mvvm.Input;
using ReflectionEventing.Demo.Wpf.Events;

namespace ReflectionEventing.Demo.Wpf.ViewModels;

public partial class MainWindowViewModel(ILogger<MainWindowViewModel> logger)
public partial class MainWindowViewModel(IEventBus eventBus, ILogger<MainWindowViewModel> logger)
: ViewModel,
IConsumer<ITickedEvent>,
IConsumer<OtherEvent>
IConsumer<OtherEvent>,
IConsumer<AsyncQueuedEvent>
{
[ObservableProperty]
private int _currentTick;

[ObservableProperty]
private int _queueCount;

/// <inheritdoc />
public async Task ConsumeAsync(ITickedEvent payload, CancellationToken cancellationToken)
{
Expand All @@ -36,4 +41,22 @@ public async Task ConsumeAsync(OtherEvent payload, CancellationToken cancellatio

await Task.CompletedTask;
}

/// <inheritdoc />
public async Task ConsumeAsync(AsyncQueuedEvent payload, CancellationToken cancellationToken)
{
await DispatchAsync(
() =>
{
QueueCount++;
},
cancellationToken
);
}

[RelayCommand]
private void OnSendToQueue()
{
eventBus.PublishAsync(new AsyncQueuedEvent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and ReflectionEventing Contributors.
// All Rights Reserved.

namespace ReflectionEventing.DependencyInjection.Configuration;

/// <summary>
/// Provides configuration options for the event bus, specifically the tick rate.
/// </summary>
public sealed class QueueProcessorOptionsProvider(TimeSpan tickRate, TimeSpan errorTickRate)
{
/// <summary>
/// Gets the tick rate for the event bus queue.
/// </summary>
public TimeSpan TickRate
{
get => tickRate;
}

/// <summary>
/// Gets the error tick rate for the event bus queue.
/// </summary>
public TimeSpan ErrorTickRate
{
get => errorTickRate;
}
}
Loading

0 comments on commit 053438a

Please sign in to comment.