aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Events/EventManager.cs
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2020-08-15 15:55:58 -0400
committerPatrick Barron <barronpm@gmail.com>2020-08-15 15:55:58 -0400
commit6f7d289feb6940afe1a266e8cec89c67b3b196ab (patch)
tree11c89b21864440f8d5e7565c94b1056ea40596cb /Jellyfin.Server.Implementations/Events/EventManager.cs
parentadabb4b84285cdb8df769986a681b0440b1e80bd (diff)
Create EventManager
Diffstat (limited to 'Jellyfin.Server.Implementations/Events/EventManager.cs')
-rw-r--r--Jellyfin.Server.Implementations/Events/EventManager.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Events/EventManager.cs b/Jellyfin.Server.Implementations/Events/EventManager.cs
new file mode 100644
index 000000000..d79b73106
--- /dev/null
+++ b/Jellyfin.Server.Implementations/Events/EventManager.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Threading.Tasks;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Events;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Jellyfin.Server.Implementations.Events
+{
+ /// <summary>
+ /// Handles the firing of events.
+ /// </summary>
+ public class EventManager : IEventManager
+ {
+ private readonly IServerApplicationHost _appHost;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="EventManager"/> class.
+ /// </summary>
+ /// <param name="appHost">The application host.</param>
+ public EventManager(IServerApplicationHost appHost)
+ {
+ _appHost = appHost;
+ }
+
+ /// <inheritdoc />
+ public void Publish<T>(T eventArgs)
+ where T : EventArgs
+ {
+ Task.WaitAll(PublishInternal(eventArgs));
+ }
+
+ /// <inheritdoc />
+ public async Task PublishAsync<T>(T eventArgs)
+ where T : EventArgs
+ {
+ await PublishInternal(eventArgs).ConfigureAwait(false);
+ }
+
+ private async Task PublishInternal<T>(T eventArgs)
+ where T : EventArgs
+ {
+ using var scope = _appHost.ServiceProvider.CreateScope();
+ foreach (var service in scope.ServiceProvider.GetServices<IEventConsumer<T>>())
+ {
+ await service.OnEvent(eventArgs).ConfigureAwait(false);
+ }
+ }
+ }
+}