Пример #1
0
        public Task StartAsync <TContext>(ISunnyApplication <TContext> application)
        {
            this.Listener.Start();
            while (true)
            {
                HttpListenerContext        httpListenerContext = this.Listener.GetContext();
                HttpListenerContextFeature feature             = new HttpListenerContextFeature(httpListenerContext);
                this.Features.Set <ISunnyRequestFeature>(feature);
                this.Features.Set <ISunnyResponseFeature>(feature);

                TContext context = application.CreateContext(this.Features);
                application.ProcessRequestAsync(context)
                .ContinueWith(_ => httpListenerContext.Response.Close())
                .ContinueWith(_ => application.DisposeContext(context, _.Exception));
            }
        }
Пример #2
0
        /// <summary>
        /// Invokes the middleware.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="router">The router.</param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            AspNetCoreServerFeature feature = new AspNetCoreServerFeature(context);

            this.features.Set <ISunnyRequestFeature>(feature);
            this.features.Set <ISunnyResponseFeature>(feature);
            this.features.Set <IServiceProvidersFeature>(feature);
            DefaultSunnyApplication.Context sunnyContext = this.application.CreateContext(this.features);
            await this.application.ProcessRequestAsync(sunnyContext)
            .ContinueWith(_ => application.DisposeContext(sunnyContext, _.Exception));

            if (_next != null)
            {
                await _next(context);
            }
        }