2021-12-20 23:04:53 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
2021-12-19 18:44:03 +00:00
|
|
|
|
using Selector.Model;
|
|
|
|
|
|
|
|
|
|
namespace Selector.Events
|
2021-12-19 13:44:22 +00:00
|
|
|
|
{
|
|
|
|
|
public class UserEventBus: IEventBus
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<UserEventBus> Logger;
|
|
|
|
|
|
|
|
|
|
public event EventHandler<ApplicationUser> UserChange;
|
2021-12-19 18:44:03 +00:00
|
|
|
|
public event EventHandler<SpotifyLinkChange> SpotifyLinkChange;
|
|
|
|
|
public event EventHandler<LastfmChange> LastfmCredChange;
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
2021-12-21 22:22:52 +00:00
|
|
|
|
public event EventHandler<CurrentlyPlayingDTO> CurrentlyPlaying;
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
|
|
|
|
public UserEventBus(ILogger<UserEventBus> logger)
|
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnUserChange(object sender, ApplicationUser args)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogTrace("Firing user event [{usernamne}]", args?.UserName);
|
|
|
|
|
UserChange?.Invoke(sender, args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 18:44:03 +00:00
|
|
|
|
public void OnSpotifyLinkChange(object sender, SpotifyLinkChange args)
|
2021-12-19 13:44:22 +00:00
|
|
|
|
{
|
2021-12-19 18:44:03 +00:00
|
|
|
|
Logger.LogTrace("Firing user Spotify event [{usernamne}]", args?.UserId);
|
2021-12-19 13:44:22 +00:00
|
|
|
|
SpotifyLinkChange?.Invoke(sender, args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 18:44:03 +00:00
|
|
|
|
public void OnLastfmCredChange(object sender, LastfmChange args)
|
2021-12-19 13:44:22 +00:00
|
|
|
|
{
|
2021-12-19 18:44:03 +00:00
|
|
|
|
Logger.LogTrace("Firing user Last.fm event [{usernamne}]", args?.UserId);
|
2021-12-19 13:44:22 +00:00
|
|
|
|
LastfmCredChange?.Invoke(sender, args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 22:22:52 +00:00
|
|
|
|
public void OnCurrentlyPlayingChange(object sender, CurrentlyPlayingDTO args)
|
2021-12-19 13:44:22 +00:00
|
|
|
|
{
|
2021-12-21 22:22:52 +00:00
|
|
|
|
Logger.LogTrace("Firing currently playing event [{usernamne}/{userId}]", args?.Username, args.UserId);
|
|
|
|
|
CurrentlyPlaying?.Invoke(sender, args);
|
2021-12-19 13:44:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|