Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address PushEnvelope TODOs #3991

Merged
merged 1 commit into from Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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