Exemplo n.º 1
0
        private static MidFunc GetStream(AllStreamResource allStream) => async(context, next) =>
        {
            var options = new ReadAllStreamOperation(context.Request);

            var response = await allStream.Get(options, context.RequestAborted);

            await context.WriteResponse(response);
        };
        public static IApplicationBuilder UseAllStreamOptions(this IApplicationBuilder builder, IStreamStore streamStore)
        {
            var allStream         = new AllStreamResource(streamStore, false);
            var allStreamMessages = new AllStreamMessageResource(streamStore);

            return(builder
                   .MapWhen(IsAllStream, ConfigureOptions(allStream))
                   .MapWhen(IsAllStreamMessage, ConfigureOptions(allStreamMessages)));
        }
Exemplo n.º 3
0
        private static MidFunc GetStreamMessage(AllStreamResource allStream) => next => async env =>
        {
            var context = new OwinContext(env);

            var resource = await allStream.GetMessage(
                new ReadAllStreamMessageOptions(context.Request),
                context.Request.CallCancelled);

            await context.WriteHalResponse(resource);
        };
Exemplo n.º 4
0
        public static IApplicationBuilder UseReadAllStream(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options)
        {
            var allStream         = new AllStreamResource(streamStore, options.UseCanonicalUrls);
            var allStreamMessages = new AllStreamMessageResource(streamStore);

            return(builder
                   .MapWhen(IsAllStream, inner => inner.Use(GetStream(allStream)))
                   .MapWhen(IsAllStreamMessage, inner => inner.Use(GetStreamMessage(allStreamMessages))));
        }
Exemplo n.º 5
0
        private static MidFunc GetStream(AllStreamResource allStream) => next => async env =>
        {
            var context = new OwinContext(env);

            var options = new ReadAllStreamOperation(context.Request);

            var response = await allStream.GetPage(options, context.Request.CallCancelled);

            using (new OptionalHeadRequestWrapper(context))
            {
                await context.WriteHalResponse(response);
            }
        };
Exemplo n.º 6
0
        public static IApplicationBuilder UseSqlStreamStoreHal(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options = default)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (streamStore == null)
            {
                throw new ArgumentNullException(nameof(streamStore));
            }

            options = options ?? new SqlStreamStoreMiddlewareOptions();

            var index             = new IndexResource(streamStore, options.ServerAssembly);
            var allStream         = new AllStreamResource(streamStore, options.UseCanonicalUrls);
            var allStreamMessages = new AllStreamMessageResource(streamStore);
            var streamBrowser     = new StreamBrowserResource(streamStore);
            var streams           = new StreamResource(streamStore);
            var streamMetadata    = new StreamMetadataResource(streamStore);
            var streamMessages    = new StreamMessageResource(streamStore);
            var documentation     = new DocsResource(
                index,
                allStream,
                allStreamMessages,
                streams,
                streamMessages,
                streamMetadata,
                streamBrowser);

            s_Log.Info(index.ToString);

            return(builder
                   .UseExceptionHandling()
                   .Use(Rfc1738)
                   .Use(HeadRequests)
                   .UseRouter(router => router
                              .MapMiddlewareRoute($"{Constants.Paths.Docs}/{{doc}}", inner => inner.UseDocs(documentation))
                              .MapMiddlewareRoute(Constants.Paths.AllStream, inner => inner.UseAllStream(allStream))
                              .MapMiddlewareRoute($"{Constants.Paths.AllStream}/{{position:long}}",
                                                  inner => inner.UseAllStreamMessage(allStreamMessages))
                              .MapMiddlewareRoute(Constants.Paths.Streams, inner => inner.UseStreamBrowser(streamBrowser))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}", inner => inner.UseStreams(streams))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}/{Constants.Paths.Metadata}",
                                                  inner => inner.UseStreamMetadata(streamMetadata))
                              .MapMiddlewareRoute($"{Constants.Paths.Streams}/{{streamId}}/{{p}}",
                                                  inner => inner.UseStreamMessages(streamMessages))
                              .MapMiddlewareRoute(string.Empty, inner => inner.UseIndex(index))));
        }
Exemplo n.º 7
0
        public static MidFunc UseStreamStore(IStreamStore streamStore)
        {
            var allStream         = new AllStreamResource(streamStore);
            var allStreamMessages = new AllStreamMessageResource(streamStore);

            var builder = new AppBuilder()
                          .MapWhen(IsAllStream, inner => inner.Use(GetStream(allStream)))
                          .MapWhen(IsAllStreamMessage, inner => inner.Use(GetStreamMessage(allStreamMessages)));

            return(next =>
            {
                builder.Run(ctx => next(ctx.Environment));

                return builder.Build();
            });
        }
Exemplo n.º 8
0
        public static MidFunc UseStreamStore(IStreamStore streamStore)
        {
            var allStream         = new AllStreamResource(streamStore);
            var allStreamMessages = new AllStreamMessageResource(streamStore);

            var builder = new AppBuilder()
                          .MapWhen(IsAllStream, ConfigureOptions(allStream))
                          .MapWhen(IsAllStreamMessage, ConfigureOptions(allStreamMessages));

            return(next =>
            {
                builder.Run(context => next(context.Environment));

                return builder.Build();
            });
        }
Exemplo n.º 9
0
        public static IApplicationBuilder UseSqlStreamStoreHal(
            this IApplicationBuilder builder,
            IStreamStore streamStore,
            SqlStreamStoreMiddlewareOptions options = default)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (streamStore == null)
            {
                throw new ArgumentNullException(nameof(streamStore));
            }

            options = options ?? new SqlStreamStoreMiddlewareOptions();

            var index             = new IndexResource(streamStore, options.ServerAssembly);
            var allStream         = new AllStreamResource(streamStore, options.UseCanonicalUrls);
            var allStreamMessages = new AllStreamMessageResource(streamStore);
            var streamBrowser     = new StreamBrowserResource(streamStore);
            var streams           = new StreamResource(streamStore);
            var streamMetadata    = new StreamMetadataResource(streamStore);
            var streamMessages    = new StreamMessageResource(streamStore);
            var documentation     = new DocsResource(
                index,
                allStream,
                allStreamMessages,
                streams,
                streamMessages,
                streamMetadata,
                streamBrowser);

            s_Log.Info(index.ToString);

            return(builder
                   .UseExceptionHandling()
                   .Use(CaseSensitiveQueryStrings)
                   .Use(HeadRequests)
                   .UseDocs(documentation)
                   .UseIndex(index)
                   .UseAllStream(allStream)
                   .UseAllStreamMessage(allStreamMessages)
                   .UseStreamBrowser(streamBrowser)
                   .UseStreams(streams)
                   .UseStreamMetadata(streamMetadata)
                   .UseStreamMessages(streamMessages));
        }
Exemplo n.º 10
0
        public static MidFunc UseStreamStore(IReadonlyStreamStore streamStore)
        {
            var allStream = new AllStreamResource(streamStore);

            var builder = new AppBuilder()
                          .MapWhen(context => !context.Request.Path.HasValue, inner => inner.Use(GetStream(allStream)))
                          .MapWhen(context =>
            {
                long _;
                return(long.TryParse(context.Request.Path.Value?.Remove(0, 1), out _));
            },
                                   inner => inner.Use(GetStreamMessage(allStream)));

            return(next =>
            {
                builder.Run(ctx => next(ctx.Environment));

                return builder.Build();
            });
        }