1+ namespace SqlStreamStore . HAL . StreamBrowser
2+ {
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+ using Microsoft . AspNetCore . Http ;
6+ using SqlStreamStore . Streams ;
7+
8+ internal class ListStreamsOperation : IStreamStoreOperation < ListStreamsPage >
9+ {
10+ public Pattern Pattern { get ; }
11+ public string ContinuationToken { get ; }
12+ public int MaxCount { get ; }
13+ public string PatternType { get ; }
14+ public PathString Path { get ; }
15+
16+ public ListStreamsOperation ( HttpRequest request )
17+ {
18+ Path = request . Path ;
19+ if ( request . Query . TryGetValueCaseInsensitive ( 't' , out var patternType ) )
20+ {
21+ PatternType = patternType ;
22+ }
23+
24+ if ( ! request . Query . TryGetValueCaseInsensitive ( 'p' , out var pattern ) )
25+ {
26+ Pattern = Pattern . Anything ( ) ;
27+ }
28+ else
29+ {
30+ switch ( PatternType )
31+ {
32+ case "s" :
33+ Pattern = Pattern . StartsWith ( pattern ) ;
34+ break ;
35+ case "e" :
36+ Pattern = Pattern . EndsWith ( pattern ) ;
37+ break ;
38+ default :
39+ Pattern = Pattern . Anything ( ) ;
40+ break ;
41+ }
42+ }
43+
44+ if ( request . Query . TryGetValueCaseInsensitive ( 'c' , out var continuationToken ) )
45+ {
46+ ContinuationToken = continuationToken ;
47+ }
48+
49+ MaxCount = request . Query . TryGetValueCaseInsensitive ( 'm' , out var m )
50+ && int . TryParse ( m , out var maxCount )
51+ ? maxCount
52+ : 100 ;
53+ }
54+
55+ public Task < ListStreamsPage > Invoke ( IStreamStore streamStore , CancellationToken cancellationToken )
56+ => streamStore . ListStreams ( Pattern , MaxCount , ContinuationToken , cancellationToken ) ;
57+ }
58+ }
0 commit comments