Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SunnyMiddleware"/> class.
 /// </summary>
 /// <param name="next">The next.</param>
 /// <param name="logger">The logger.</param>
 public SunnyMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, ISunnyApplication <DefaultSunnyApplication.Context> app
                        , ILogger <SunnyMiddleware> logger)
 {
     this._next       = next;
     this._logger     = logger;
     this.application = app;
     this.features    = new DefaultFeatureCollection();
 }
Пример #2
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));
            }
        }