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

Commit 342b363

Browse files
reorg
1 parent 3dcd1ea commit 342b363

27 files changed

Lines changed: 617 additions & 495 deletions

src/SqlStreamStore.HAL.Tests/StreamMetadataTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
namespace SqlStreamStore.HAL.Tests
22
{
3-
using System;
4-
using System.Collections;
53
using System.Collections.Generic;
64
using System.Linq;
75
using System.Net;

src/SqlStreamStore.HAL/AllStreamResource.cs

Lines changed: 0 additions & 183 deletions
This file was deleted.

src/SqlStreamStore.HAL/AppendStreamMiddleware.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SqlStreamStore.HAL
33
using Microsoft.Owin;
44
using Microsoft.Owin.Builder;
55
using Owin;
6+
using SqlStreamStore.HAL.Resources;
67
using MidFunc = System.Func<System.Func<System.Collections.Generic.IDictionary<string, object>,
78
System.Threading.Tasks.Task
89
>, System.Func<System.Collections.Generic.IDictionary<string, object>,

src/SqlStreamStore.HAL/DeleteStreamMiddleware.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace SqlStreamStore.HAL
33
using Microsoft.Owin;
44
using Microsoft.Owin.Builder;
55
using Owin;
6+
using SqlStreamStore.HAL.Resources;
67
using MidFunc = System.Func<System.Func<System.Collections.Generic.IDictionary<string, object>,
78
System.Threading.Tasks.Task
89
>, System.Func<System.Collections.Generic.IDictionary<string, object>,

src/SqlStreamStore.HAL/OptionalHeadRequestWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Dispose()
2626
_context.Response.Body = _originalBody;
2727
}
2828

29-
class HeadRequestStream : Stream
29+
private class HeadRequestStream : Stream
3030
{
3131
private long _length;
3232

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
namespace SqlStreamStore.HAL
22
{
3-
using System.Net.Http;
4-
using System.Threading.Tasks;
53
using Microsoft.Owin;
64
using Microsoft.Owin.Builder;
75
using Owin;
6+
using SqlStreamStore.HAL.Resources;
87
using MidFunc = System.Func<System.Func<System.Collections.Generic.IDictionary<string, object>,
98
System.Threading.Tasks.Task
109
>, System.Func<System.Collections.Generic.IDictionary<string, object>,
@@ -16,12 +15,11 @@ internal static class ReadAllStreamMiddleware
1615
public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
1716
{
1817
var allStream = new AllStreamResource(streamStore);
18+
var allStreamMessages = new AllStreamMessageResource(streamStore);
1919

2020
var builder = new AppBuilder()
2121
.MapWhen(IsAllStream, inner => inner.Use(GetStream(allStream)))
22-
.MapWhen(IsStreamOptions, inner => inner.Use(GetStreamOptions))
23-
.MapWhen(IsAllStreamMessage, inner => inner.Use(GetStreamMessage(allStream)))
24-
.MapWhen(IsStreamMessageOptions, inner => inner.Use(GetStreamMessageOptions));
22+
.MapWhen(IsAllStreamMessage, inner => inner.Use(GetStreamMessage(allStreamMessages)));
2523

2624
return next =>
2725
{
@@ -34,14 +32,9 @@ public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
3432
private static bool IsAllStream(IOwinContext context)
3533
=> context.IsGetOrHead() && context.Request.Path.IsAllStream();
3634

37-
private static bool IsStreamOptions(IOwinContext context)
38-
=> context.IsOptions() && context.Request.Path.IsAllStream();
39-
4035
private static bool IsAllStreamMessage(IOwinContext context)
4136
=> context.IsGetOrHead() && context.Request.Path.IsAllStreamMessage();
4237

43-
private static bool IsStreamMessageOptions(IOwinContext context)
44-
=> context.IsOptions() && context.Request.Path.IsAllStreamMessage();
4538

4639
private static MidFunc GetStream(AllStreamResource allStream) => next => async env =>
4740
{
@@ -57,23 +50,11 @@ private static MidFunc GetStream(AllStreamResource allStream) => next => async e
5750
}
5851
};
5952

60-
private static MidFunc GetStreamOptions => next => env =>
61-
{
62-
var context = new OwinContext(env);
63-
64-
context.SetStandardCorsHeaders(
65-
HttpMethod.Get,
66-
HttpMethod.Head,
67-
HttpMethod.Options);
68-
69-
return Task.CompletedTask;
70-
};
71-
72-
private static MidFunc GetStreamMessage(AllStreamResource allStream) => next => async env =>
53+
private static MidFunc GetStreamMessage(AllStreamMessageResource allStreamMessages) => next => async env =>
7354
{
7455
var context = new OwinContext(env);
7556

76-
var response = await allStream.GetMessage(
57+
var response = await allStreamMessages.GetMessage(
7758
new ReadAllStreamMessageOptions(context.Request),
7859
context.Request.CallCancelled);
7960

@@ -82,18 +63,5 @@ private static MidFunc GetStreamMessage(AllStreamResource allStream) => next =>
8263
await context.WriteHalResponse(response);
8364
}
8465
};
85-
86-
private static MidFunc GetStreamMessageOptions => next => env =>
87-
{
88-
var context = new OwinContext(env);
89-
90-
context.SetStandardCorsHeaders(
91-
HttpMethod.Get,
92-
HttpMethod.Head,
93-
HttpMethod.Options);
94-
95-
return Task.CompletedTask;
96-
};
97-
9866
}
9967
}

src/SqlStreamStore.HAL/ReadStreamMiddleware.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace SqlStreamStore.HAL
55
using Microsoft.Owin;
66
using Microsoft.Owin.Builder;
77
using Owin;
8+
using SqlStreamStore.HAL.Resources;
89
using MidFunc = System.Func<System.Func<System.Collections.Generic.IDictionary<string, object>,
910
System.Threading.Tasks.Task
1011
>, System.Func<System.Collections.Generic.IDictionary<string, object>,
@@ -16,12 +17,11 @@ internal static class ReadStreamMiddleware
1617
public static MidFunc UseStreamStore(IStreamStore streamStore)
1718
{
1819
var streams = new StreamResource(streamStore);
19-
20+
var streamMessages = new StreamMessageResource(streamStore);
21+
2022
var builder = new AppBuilder()
21-
.MapWhen(IsStreamMessage, inner => inner.Use(GetStreamMessage(streams)))
22-
.MapWhen(IsStreamMessageOptions, inner => inner.Use(GetStreamMessageOptions))
23-
.MapWhen(IsStream, inner => inner.Use(GetStream(streams)))
24-
.MapWhen(IsStreamOptions, inner => inner.Use(GetStreamOptions));
23+
.MapWhen(IsStreamMessage, inner => inner.Use(GetStreamMessage(streamMessages)))
24+
.MapWhen(IsStream, inner => inner.Use(GetStream(streams)));
2525

2626
return next =>
2727
{
@@ -34,50 +34,30 @@ public static MidFunc UseStreamStore(IStreamStore streamStore)
3434
private static bool IsStream(IOwinContext context)
3535
=> context.IsGetOrHead() && context.Request.Path.IsStream();
3636

37-
private static bool IsStreamOptions(IOwinContext context)
38-
=> context.IsOptions() && context.Request.Path.IsStream();
39-
4037
private static bool IsStreamMessage(IOwinContext context)
4138
=> context.IsGetOrHead() && context.Request.Path.IsStreamMessage();
4239

43-
private static bool IsStreamMessageOptions(IOwinContext context)
44-
=> context.IsOptions() && context.Request.Path.IsStreamMessage();
45-
46-
private static MidFunc GetStream(StreamResource stream) => next => async env =>
40+
private static MidFunc GetStream(StreamResource streams) => next => async env =>
4741
{
4842
var context = new OwinContext(env);
4943

5044
var options = new ReadStreamOptions(context.Request);
5145

52-
var response = await stream.GetPage(options, context.Request.CallCancelled);
46+
var response = await streams.GetPage(options, context.Request.CallCancelled);
5347

5448
using(new OptionalHeadRequestWrapper(context))
5549
{
5650
await context.WriteHalResponse(response);
5751
}
5852
};
5953

60-
private static MidFunc GetStreamOptions => next => env =>
61-
{
62-
var context = new OwinContext(env);
63-
64-
context.SetStandardCorsHeaders(
65-
HttpMethod.Get,
66-
HttpMethod.Head,
67-
HttpMethod.Options,
68-
HttpMethod.Post,
69-
HttpMethod.Delete);
70-
71-
return Task.CompletedTask;
72-
};
73-
74-
private static MidFunc GetStreamMessage(StreamResource stream) => next => async env =>
54+
private static MidFunc GetStreamMessage(StreamMessageResource streamMessages) => next => async env =>
7555
{
7656
var context = new OwinContext(env);
7757

7858
var options = new ReadStreamMessageOptions(context.Request);
7959

80-
var response = await stream.GetMessage(options, context.Request.CallCancelled);
60+
var response = await streamMessages.GetMessage(options, context.Request.CallCancelled);
8161

8262
using(new OptionalHeadRequestWrapper(context))
8363
{

0 commit comments

Comments
 (0)