aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-09-02 18:41:51 -0500
committerJP Dillingham <jp@dillingham.me>2024-09-02 18:41:51 -0500
commit2805a4c368e9585162f6379bb862e0951790613e (patch)
tree82955c9ebac885f99f34b52b147be5ccc94a5d46 /src
parent51836f520fe400a33ad9daab932f13c2ed24467d (diff)
downloadslskd-2805a4c368e9585162f6379bb862e0951790613e.tar.gz
rename types back :shrug:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Events/EventBus.cs5
-rw-r--r--src/slskd/Events/EventService.cs15
-rw-r--r--src/slskd/Events/Types/EventRecord.cs (renamed from src/slskd/Events/Types/Event.cs)10
-rw-r--r--src/slskd/Events/Types/Events.cs6
4 files changed, 20 insertions, 16 deletions
diff --git a/src/slskd/Events/EventBus.cs b/src/slskd/Events/EventBus.cs
index c3e418e7..e5552d2d 100644
--- a/src/slskd/Events/EventBus.cs
+++ b/src/slskd/Events/EventBus.cs
@@ -71,12 +71,12 @@ public class EventBus
/// <param name="data">The event data.</param>
/// <typeparam name="T">The Type of the event.</typeparam>
public virtual void Raise<T>(T data)
- where T : BaseEvent
+ where T : Event
{
Log.Debug("Handling {Type}: {Data}", typeof(T), data);
// save the event to the database before broadcasting to consumers
- Events.Add(Event.From<T>(data));
+ Events.Add(EventRecord.From<T>(data));
// broadcast the event in a fire-and-forget fashion
// we don't need to wait for anything, just need to kick off the tasks
@@ -148,6 +148,7 @@ public class EventBus
/// <typeparam name="T">The Type of the event.</typeparam>
/// <param name="subscriber">The unique name of the subscriber.</param>
public virtual void Unsubscribe<T>(string subscriber)
+ where T : Event
{
if (Subscriptions.TryGetValue(typeof(T), out var subscriptions))
{
diff --git a/src/slskd/Events/EventService.cs b/src/slskd/Events/EventService.cs
index 759dc8cf..188d5895 100644
--- a/src/slskd/Events/EventService.cs
+++ b/src/slskd/Events/EventService.cs
@@ -40,21 +40,24 @@ public class EventService
private ILogger Log { get; } = Serilog.Log.ForContext<EventService>();
/// <summary>
- /// Adds the specified event <paramref name="event"/>.
+ /// Adds the specified event <paramref name="eventRecord"/>.
/// </summary>
- /// <param name="event">The record to add.</param>
+ /// <remarks>
+ /// To ensure proper construction of the record, use <see cref="EventRecord.From"/>.
+ /// </remarks>
+ /// <param name="eventRecord">The record to add.</param>
/// <exception cref="ArgumentNullException">Thrown when the specified record is null.</exception>
- public virtual void Add(Event @event)
+ public virtual void Add(EventRecord eventRecord)
{
- if (@event is null)
+ if (eventRecord is null)
{
- throw new ArgumentNullException(nameof(@event));
+ throw new ArgumentNullException(nameof(eventRecord));
}
try
{
using var context = ContextFactory.CreateDbContext();
- context.Add(@event);
+ context.Add(eventRecord);
context.SaveChanges();
}
catch (Exception ex)
diff --git a/src/slskd/Events/Types/Event.cs b/src/slskd/Events/Types/EventRecord.cs
index 5b57aa5d..921daa4e 100644
--- a/src/slskd/Events/Types/Event.cs
+++ b/src/slskd/Events/Types/EventRecord.cs
@@ -28,7 +28,7 @@ using Microsoft.EntityFrameworkCore;
[Index(nameof(Timestamp))]
[Index(nameof(Type))]
-public record Event
+public record EventRecord
{
public DateTime Timestamp { get; init; } = DateTime.UtcNow;
public string Type { get; private set; }
@@ -46,7 +46,7 @@ public record Event
};
/// <summary>
- /// Converts the specified event <paramref name="e"/> into an instance of <see cref="Event"/>
+ /// Converts the specified event <paramref name="e"/> into an instance of <see cref="EventRecord"/>
/// for the purpose of database storage.
/// </summary>
/// <remarks>
@@ -58,8 +58,8 @@ public record Event
/// <param name="e">The Event to convert.</param>
/// <typeparam name="T">The specific type of the Event.</typeparam>
/// <returns>The converted EventRecord.</returns>
- public static Event From<T>(BaseEvent e)
- where T : BaseEvent
+ public static EventRecord From<T>(Event e)
+ where T : Event
{
// this will be 'slskd.NameOfEvent'; we want to chop off 'slskd.' and 'Event' = 'NameOf'
var type = e.GetType().Name.Split('.').TakeLast(1).First();
@@ -73,7 +73,7 @@ public record Event
data.Remove(nameof(Id).ToLower());
data.Remove(nameof(Data).ToLower());
- return new Event
+ return new EventRecord
{
Timestamp = e.Timestamp,
Type = type,
diff --git a/src/slskd/Events/Types/Events.cs b/src/slskd/Events/Types/Events.cs
index 416074e6..20ec3f9f 100644
--- a/src/slskd/Events/Types/Events.cs
+++ b/src/slskd/Events/Types/Events.cs
@@ -20,20 +20,20 @@ namespace slskd.Events;
using System;
using slskd.Transfers;
-public abstract record BaseEvent
+public abstract record Event
{
public Guid Id { get; } = Guid.NewGuid();
public DateTime Timestamp { get; init; } = DateTime.UtcNow;
}
-public sealed record DownloadFileCompleteEvent : BaseEvent
+public sealed record DownloadFileCompleteEvent : Event
{
public string LocalFilename { get; init; }
public string RemoteFilename { get; init; }
public Transfer Transfer { get; init; }
}
-public sealed record DownloadDirectoryCompleteEvent : BaseEvent
+public sealed record DownloadDirectoryCompleteEvent : Event
{
public string LocalDirectoryName { get; init; }
public string RemoteDirectoryName { get; init; }