< Summary - Jellyfin

Information
Class: MediaBrowser.Common.Events.EventHelper
Assembly: MediaBrowser.Common
File(s): /srv/git/jellyfin/MediaBrowser.Common/Events/EventHelper.cs
Line coverage
50%
Covered lines: 13
Uncovered lines: 13
Coverable lines: 26
Total lines: 64
Line coverage: 50%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
QueueEventIfNotNull(...)0%620%
QueueEventIfNotNull(...)100%22100%

File(s)

/srv/git/jellyfin/MediaBrowser.Common/Events/EventHelper.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using Microsoft.Extensions.Logging;
 4
 5namespace MediaBrowser.Common.Events
 6{
 7    /// <summary>
 8    /// Class EventHelper.
 9    /// </summary>
 10    // TODO: @bond Remove
 11    public static class EventHelper
 12    {
 13        /// <summary>
 14        /// Fires the event.
 15        /// </summary>
 16        /// <param name="handler">The handler.</param>
 17        /// <param name="sender">The sender.</param>
 18        /// <param name="args">The <see cref="EventArgs" /> instance containing the event data.</param>
 19        /// <param name="logger">The logger.</param>
 20        public static void QueueEventIfNotNull(EventHandler? handler, object sender, EventArgs args, ILogger logger)
 21        {
 022            if (handler is not null)
 23            {
 024                Task.Run(() =>
 025                {
 026                    try
 027                    {
 028                        handler(sender, args);
 029                    }
 030                    catch (Exception ex)
 031                    {
 032                        logger.LogError(ex, "Error in event handler");
 033                    }
 034                });
 35            }
 036        }
 37
 38        /// <summary>
 39        /// Queues the event.
 40        /// </summary>
 41        /// <typeparam name="T">Argument type for the <c>handler</c>.</typeparam>
 42        /// <param name="handler">The handler.</param>
 43        /// <param name="sender">The sender.</param>
 44        /// <param name="args">The args.</param>
 45        /// <param name="logger">The logger.</param>
 46        public static void QueueEventIfNotNull<T>(EventHandler<T>? handler, object sender, T args, ILogger logger)
 47        {
 5648            if (handler is not null)
 49            {
 5650                Task.Run(() =>
 5651                {
 5652                    try
 5653                    {
 5654                        handler(sender, args);
 5655                    }
 5656                    catch (Exception ex)
 5657                    {
 5658                        logger.LogError(ex, "Error in event handler");
 5659                    }
 5660                });
 61            }
 5662        }
 63    }
 64}