示例#1
0
        public async Task <bool> OnAuthorization(HttpContext context, HttpServerMessageSender sender, string messageId, IEnumerable <IAuthorizationFilter> filters)
        {
            foreach (var filter in filters)
            {
                var path         = HttpUtility.UrlDecode(GetRoutePath(context.Request.Path.ToString()));
                var serviceRoute = await _serviceRouteProvider.GetRouteByPathRegex(path);

                if (serviceRoute == null)
                {
                    serviceRoute = await _serviceRouteProvider.GetLocalRouteByPathRegex(path);
                }
                context.Items.Add("route", serviceRoute);
                var filterContext = new AuthorizationFilterContext
                {
                    Path    = path,
                    Context = context,
                    Route   = serviceRoute
                };
                await filter.OnAuthorization(filterContext);

                if (filterContext.Result != null)
                {
                    await sender.SendAndFlushAsync(new TransportMessage(messageId, filterContext.Result));

                    return(false);
                }
            }
            return(true);
        }
 private void AppResolve(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.UseMvc();
     _moduleProvider.Initialize(new ApplicationInitializationContext(app, _moduleProvider.Modules,
                                                                     _moduleProvider.VirtualPaths,
                                                                     AppConfig.Configuration));
     app.Run(async(context) =>
     {
         var messageId = Guid.NewGuid().ToString("N");
         var sender    = new HttpServerMessageSender(_serializer, context);
         try
         {
             var filters   = app.ApplicationServices.GetServices <IAuthorizationFilter>();
             var isSuccess = await OnAuthorization(context, sender, messageId, filters);
             if (isSuccess)
             {
                 var actionFilters = app.ApplicationServices.GetServices <IActionFilter>();
                 await OnReceived(sender, messageId, context, actionFilters);
             }
         }
         catch (Exception ex)
         {
             var filters = app.ApplicationServices.GetServices <IExceptionFilter>();
             WirteDiagnosticError(messageId, ex);
             await OnException(context, sender, messageId, ex, filters);
         }
     });
 }
 private void AppResolve(IApplicationBuilder app)
 {
     app.Run(async(context) =>
     {
         var sender = new HttpServerMessageSender(_serializer, context);
         await OnReceived(sender, context);
     });
 }
 private void AppResolve(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.UseMvc();
     _moduleProvider.Initialize(app);
     app.Run(async(context) =>
     {
         var sender = new HttpServerMessageSender(_serializer, context);
         await OnReceived(sender, context);
     });
 }
示例#5
0
 private void AppResolve(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.UseMvc();
     _moduleProvider.Initialize(new ApplicationInitializationContext(app, _moduleProvider.Modules,
                                                                     _moduleProvider.VirtualPaths,
                                                                     AppConfig.Configuration));
     app.Run(async(context) =>
     {
         var sender = new HttpServerMessageSender(_serializer, context);
         await OnReceived(sender, context);
     });
 }
示例#6
0
        private void AppResolve(IApplicationBuilder app)
        {
            app.UseStaticFiles();
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "DemoApi");
            });

            app.Run(async(context) =>
            {
                var sender = new HttpServerMessageSender(_serializer, context);
                await OnReceived(sender, context);
            });
        }
        private void AppResolve(IApplicationBuilder app)
        {
            app.UseStaticFiles();
            app.UseMvc();
            if (AppConfig.SwaggerOptions != null)
            {
                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint($"/swagger/{AppConfig.SwaggerOptions.Version}/swagger.json", AppConfig.SwaggerOptions.Title);
                });
            }

            app.Run(async(context) =>
            {
                var sender = new HttpServerMessageSender(_serializer, context);
                await OnReceived(sender, context);
            });
        }
 private void AppResolve(IApplicationBuilder app)
 {
     app.UseStaticFiles();
     app.UseMvc();
     _moduleProvider.Initialize(new ApplicationInitializationContext(app, _moduleProvider.Modules,
                                                                     _moduleProvider.VirtualPaths,
                                                                     AppConfig.Configuration));
     app.Run(async(context) =>
     {
         var filters   = app.ApplicationServices.GetServices <IAuthorizationFilter>();
         var sender    = new HttpServerMessageSender(_serializer, context);
         var isSuccess = await OnAuthorization(context, sender, filters);
         if (isSuccess)
         {
             var actionFilters = app.ApplicationServices.GetServices <IActionFilter>();
             await OnReceived(sender, context, actionFilters);
         }
     });
 }
示例#9
0
        public async Task <bool> OnException(HttpContext context, HttpServerMessageSender sender, string messageId, Exception exception, IEnumerable <IExceptionFilter> filters)
        {
            foreach (var filter in filters)
            {
                var path          = HttpUtility.UrlDecode(GetRoutePath(context.Request.Path.ToString()));
                var filterContext = new ExceptionContext
                {
                    RoutePath = path,
                    Context   = context,
                    Exception = exception
                };
                await filter.OnException(filterContext);

                if (filterContext.Result != null)
                {
                    await sender.SendAndFlushAsync(new TransportMessage(messageId, filterContext.Result));

                    return(false);
                }
            }
            return(true);
        }
        private void AppResolve(IApplicationBuilder app)
        {
            app.UseStaticFiles();
            app.UseMvc();
            var info = AppConfig.SwaggerConfig.Info == null
                 ? AppConfig.SwaggerOptions : AppConfig.SwaggerConfig.Info;

            if (info != null)
            {
                app.UseSwagger();
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint($"/swagger/{info.Version}/swagger.json", info.Title);
                    c.SwaggerEndpoint(_serviceEntryProvider.GetALLEntries());
                });
            }

            app.Run(async(context) =>
            {
                var sender = new HttpServerMessageSender(_serializer, context);
                await OnReceived(sender, context);
            });
        }