Skip to content

Commit

Permalink
Address PushEnvelope TODOs (#3991)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 7, 2024
1 parent b1b6eea commit a8f80d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
Expand Up @@ -89,30 +89,29 @@ public SignalrStarter(MyContext context)
.Build();
}

void ConnectionOnReceived(JsonElement jElement)
void EnvelopeReceived(JsonElement jElement)
{
var s = jElement.ToString();
if (s.IndexOf("\"CustomCheckFailed\"") > 0)
if (s.IndexOf("\"CustomCheckFailed\"", StringComparison.Ordinal) <= 0)
{
context.SignalrData = s;
context.SignalrEventReceived = true;
return;
}

context.SignalrData = s;
context.SignalrEventReceived = true;
}

protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default)
{
// We might also be able to strongly type this to match instead of just getting a string?
connection.On<JsonElement>("PushEnvelope", ConnectionOnReceived);
connection.On<JsonElement>("PushEnvelope", EnvelopeReceived);

await connection.StartAsync(cancellationToken);

context.SignalrStarted = connection.State == HubConnectionState.Connected;
}

protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default)
{
return connection.StopAsync(cancellationToken);
}
protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken);

readonly MyContext context;
readonly HubConnection connection;
Expand Down
Expand Up @@ -42,10 +42,7 @@ public class MyContext : ScenarioContext

public class EndpointThatUsesSignalR : EndpointConfigurationBuilder
{
public EndpointThatUsesSignalR()
{
EndpointSetup<DefaultServer>(c => c.EnableFeature<EnableSignalR>());
}
public EndpointThatUsesSignalR() => EndpointSetup<DefaultServer>(c => c.EnableFeature<EnableSignalR>());

class EnableSignalR : Feature
{
Expand All @@ -66,33 +63,28 @@ public SignalrStarter(MyContext context)
.Build();
}

// TODO rename to better match what this is actually doing
void ConnectionOnReceived(JsonElement jElement)
void EnvelopeReceived(JsonElement jElement)
{
var s = jElement.ToString();
if (s.IndexOf("\"EventLogItemAdded\"") > 0)
if (s.IndexOf("\"EventLogItemAdded\"", StringComparison.Ordinal) <= 0 ||
s.IndexOf("EventLogItem/CustomChecks/CustomCheckFailed", StringComparison.Ordinal) <= 0)
{
if (s.IndexOf("EventLogItem/CustomChecks/CustomCheckFailed") > 0)
{
context.SignalrData = s;
context.SignalrEventReceived = true;
}
return;
}

context.SignalrData = s;
context.SignalrEventReceived = true;
}

protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken = default)
{
// TODO Align this name with the one chosen for GlobalEventHandler
// We might also be able to strongly type this to match instead of just getting a string?
connection.On<JsonElement>("PushEnvelope", ConnectionOnReceived);
connection.On<JsonElement>("PushEnvelope", EnvelopeReceived);

return connection.StartAsync(cancellationToken);
}

protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default)
{
return connection.StopAsync(cancellationToken);
}
protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken);

readonly MyContext context;
readonly HubConnection connection;
Expand Down
Expand Up @@ -300,29 +300,26 @@ public SignalRStarter(MyContext context)

protected override async Task OnStart(IMessageSession session, CancellationToken cancellationToken = default)
{
// TODO Align this name with the one chosen for GlobalEventHandler
// We might also be able to strongly type this to match instead of just getting a string?
connection.On<JsonElement>("PushEnvelope", ConnectionOnReceived);
connection.On<JsonElement>("PushEnvelope", EnvelopeReceived);

await connection.StartAsync(cancellationToken);

await session.Send(new MyMessage(), cancellationToken);
}

protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default)
{
return connection.StopAsync(cancellationToken);
}
protected override Task OnStop(IMessageSession session, CancellationToken cancellationToken = default) => connection.StopAsync(cancellationToken);

// TODO rename to better match what this is actually doing
void ConnectionOnReceived(JsonElement jElement)
void EnvelopeReceived(JsonElement jElement)
{
var s = jElement.ToString();
if (s.IndexOf("\"MessageFailuresUpdated\"") > 0)
if (s.IndexOf("\"MessageFailuresUpdated\"", StringComparison.Ordinal) <= 0)
{
context.SignalrData = s;
context.SignalrEventReceived = true;
return;
}

context.SignalrData = s;
context.SignalrEventReceived = true;
}

readonly MyContext context;
Expand Down

0 comments on commit a8f80d7

Please sign in to comment.