Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit a381983

Browse files
minor syntax improvements
1 parent e628421 commit a381983

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/SqlStreamStore.HAL/AllStreamMiddleware.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
1616
var allStream = new AllStreamResource(streamStore);
1717

1818
var builder = new AppBuilder()
19-
.MapWhen(context => !context.Request.Path.HasValue, inner => inner.Use(GetStream(allStream)))
20-
.MapWhen(context =>
21-
{
22-
long _;
23-
return long.TryParse(context.Request.Path.Value?.Remove(0, 1), out _);
24-
},
25-
inner => inner.Use(GetStreamMessage(allStream)));
19+
.MapWhen(IsStream, inner => inner.Use(GetStream(allStream)))
20+
.MapWhen(IsStreamMessage, inner => inner.Use(GetStreamMessage(allStream)));
2621

2722
return next =>
2823
{
@@ -32,6 +27,12 @@ public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
3227
};
3328
}
3429

30+
private static bool IsStream(IOwinContext context)
31+
=> !context.Request.Path.HasValue;
32+
33+
private static bool IsStreamMessage(IOwinContext context)
34+
=> long.TryParse(context.Request.Path.Value?.Remove(0, 1), out var _);
35+
3536
private static MidFunc GetStream(AllStreamResource allStream) => next => async env =>
3637
{
3738
var context = new OwinContext(env);

src/SqlStreamStore.HAL/ReadStreamMessageOptions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ public ReadStreamMessageOptions(IOwinRequest request)
1414
var pieces = request.Path.Value.Split('/').Reverse().Take(2).ToArray();
1515

1616
StreamId = pieces.LastOrDefault();
17-
int streamVersion;
1817

19-
if(int.TryParse(pieces.FirstOrDefault(), out streamVersion))
18+
if(int.TryParse(pieces.FirstOrDefault(), out var streamVersion))
2019
{
2120
StreamVersion = streamVersion;
2221
}

src/SqlStreamStore.HAL/SqlStreamStoreHalMiddleware.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public static class SqlStreamStoreHalMiddleware
3838
return next(env);
3939
}
4040

41-
var response = new Response(
42-
new HALResponse(null)
43-
.AddLinks(new Link("streamStore:stream", "stream")));
41+
var response = new Response(new HALResponse(null).AddLinks(new Link("streamStore:stream", "stream")));
4442

4543
return context.WriteHalResponse(response);
4644
};

src/SqlStreamStore.HAL/StreamMiddleware.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
1717
var streams = new StreamResource(streamStore);
1818

1919
var builder = new AppBuilder()
20-
.MapWhen(context => context.Request.Path.Value?.Split('/')?.Length == 3,
21-
inner => inner.Use(GetStreamMessage(streams)))
22-
.MapWhen(context => context.Request.Path.Value?.Length > 1, inner => inner.Use(GetStream(streams)));
20+
.MapWhen(IsStreamMessage, inner => inner.Use(GetStreamMessage(streams)))
21+
.MapWhen(IsStream, inner => inner.Use(GetStream(streams)));
2322

2423
return next =>
2524
{
@@ -29,6 +28,12 @@ public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
2928
};
3029
}
3130

31+
private static bool IsStream(IOwinContext context)
32+
=> context.Request.Path.Value?.Length > 1;
33+
34+
private static bool IsStreamMessage(IOwinContext context)
35+
=> context.Request.Path.Value?.Split('/')?.Length == 3;
36+
3237
private static MidFunc GetStream(StreamResource stream) => next => async env =>
3338
{
3439
var context = new OwinContext(env);

0 commit comments

Comments
 (0)