Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Fine, it's EventType for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaeldui committed Feb 20, 2022
1 parent 1fee84b commit f96ba86
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -35,4 +36,21 @@ public async Task TestSomething()

await client.CloseAsync();
}

[TestMethod]
public async Task AnotherTest()
{
if (!IS_LEAGUE_CLIENT_RUNNING) Assert.Inconclusive("No running League Client found.");

using LeagueClient client = new();

client.LeagueOfLegends.ChampSelect.SessionChanged += (sender, eventArgs) =>
{
Console.WriteLine($"{eventArgs.EventType}: {eventArgs.Data.MyTeam[0].SummonerId}");
};

await Task.Delay(100000);
}
}
Expand Up @@ -6,14 +6,14 @@ namespace RiotGames.LeagueOfLegends.LeagueClient;

public class LeagueClientEventArgs<T> : RmsEventArgs<T>
{
public LeagueClientEventArgs(RmsChangeType changeType, T data) : base(changeType, data)
public LeagueClientEventArgs(RmsEventType eventType, T data) : base(eventType, data)
{
}
}

internal static class LeagueClientEventExtensions
{
internal static void Invoke<T>(this LeagueClientEventHandler<T> eventHandler, object sender,
RmsChangeType changeType, T data) =>
eventHandler.Invoke(sender, new LeagueClientEventArgs<T>(changeType, data));
RmsEventType eventType, T data) =>
eventHandler.Invoke(sender, new LeagueClientEventArgs<T>(eventType, data));
}
6 changes: 3 additions & 3 deletions RiotGames.Messaging.Client/Messages/RmsEventMessage.cs
Expand Up @@ -7,14 +7,14 @@ namespace RiotGames.Messaging;
/// <summary>
/// Will be made internal soon.
/// </summary>
[DebuggerDisplay("Topic = {Topic} ChangeType = {ChangeType} Uri = {Uri} : {Data}")]
[DebuggerDisplay("Topic = {Topic} EventType = {EventType} Uri = {Uri} : {Data}")]
public class RmsEventMessage : WampMessage<RmsTypeCode>
{
public RmsEventMessage(RmsTypeCode messageCode, params JsonElement[] elements) : base(messageCode, elements)
{
Topic = elements[0].GetString() ?? throw new RmsException("The WAMP event message didn't have any topic!");
Data = elements[1].GetProperty("data");
ChangeType = Enum.Parse<RmsChangeType>(elements[1].GetProperty("changeType").GetString());
EventType = Enum.Parse<RmsEventType>(elements[1].GetProperty("eventType").GetString());
Uri = new Uri(
elements[1].GetProperty("uri").GetString() ??
throw new RmsException("The event message didn't have any Uri."), UriKind.Relative);
Expand All @@ -28,7 +28,7 @@ public RmsEventMessage(RmsTypeCode messageCode, params JsonElement[] elements) :
/// </summary>
public JsonElement Data { get; }

public RmsChangeType ChangeType { get; }
public RmsEventType EventType { get; }

public Uri Uri { get; }
}
Expand Up @@ -2,7 +2,7 @@
namespace RiotGames.Messaging;

// TODO: Created, updated, deleted...
public enum RmsChangeType
public enum RmsEventType
{
Create,
Update,
Expand Down
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Exceptions\RmsException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\RmsChangeType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\RmsEventType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\RmsEventMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RmsClient.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RmsEventArgs.cs" />
Expand Down
6 changes: 3 additions & 3 deletions RiotGames.Messaging.Client/RmsEventArgs.cs
Expand Up @@ -2,12 +2,12 @@

public class RmsEventArgs<T> : EventArgs
{
public RmsEventArgs(RmsChangeType changeType, T data)
public RmsEventArgs(RmsEventType eventType, T data)
{
ChangeType = changeType;
EventType = eventType;
Data = data;
}

public RmsChangeType ChangeType { get; }
public RmsEventType EventType { get; }
public T Data { get; }
}
6 changes: 3 additions & 3 deletions RiotGames.Messaging.Client/RmsEventRouter.cs
Expand Up @@ -12,7 +12,7 @@ public class RmsEventRouter : IDisposable

private readonly JsonSerializerOptions _jsonSerializerOptions = new() {PropertyNameCaseInsensitive = true};
private readonly RmsClient _rmsClient;
private readonly ConcurrentDictionary<string, Action<RmsChangeType, JsonElement>> _subscriptions = new();
private readonly ConcurrentDictionary<string, Action<RmsEventType, JsonElement>> _subscriptions = new();
private CancellationTokenSource? _cancellationTokenSource = new();

public RmsEventRouter(string username, string password, ushort port)
Expand All @@ -30,7 +30,7 @@ public void Dispose()
/// <summary>
/// Will open a connection if there isn't one.
/// </summary>
public void Subscribe<TData>(string topic, Action<RmsChangeType, TData> handler)
public void Subscribe<TData>(string topic, Action<RmsEventType, TData> handler)
{
Task.Run(async () =>
{
Expand All @@ -53,7 +53,7 @@ public void Subscribe<TData>(string topic, Action<RmsChangeType, TData> handler)
Console.WriteLine("Message received");
if (!_subscriptions.TryGetValue(response.Topic, out var subscriber)) continue;
subscriber?.Invoke(response.ChangeType, response.Data);
subscriber?.Invoke(response.EventType, response.Data);
}
}, _cancellationTokenSource.Token).ConfigureAwait(false);
}
Expand Down

0 comments on commit f96ba86

Please sign in to comment.