コード例 #1
0
        public OwinLayimContext(LayimStorage storage, LayimOptions options, IDictionary <string, object> environment) : base(storage, options)
        {
            Error.ThrowIfNull(environment, nameof(environment));

            Request  = new OwinLayimRequest(environment);
            Response = new OwinLayimResponse(environment);
        }
コード例 #2
0
        public static MidFunc UseLayimApi(LayimStorage storage, LayimOptions options, RouteCollection routes)
        {
            Error.ThrowIfNull(options, nameof(options));
            Error.ThrowIfNull(routes, nameof(routes));

            return(next =>
                   env =>
            {
                var owinContext = new OwinContext(env);

                var context = new OwinLayimContext(storage, options, env);

                var path = owinContext.Request.Path.Value;

                //匹配路由
                var findResult = routes.FindDispatcher(path);
                //如果没有匹配到,执行下一个
                if (findResult == null)
                {
                    return next(env);
                }

                //匹配成功之后执行 Dispatch
                context.UriMatch = findResult.Item2;
                //执行具体disptach方法,返回相应结果
                return findResult.Item1.Dispatch(context);
            });
        }
コード例 #3
0
        protected LayimContext(LayimStorage storage, LayimOptions options)
        {
            Error.ThrowIfNull(storage, nameof(storage));
            Error.ThrowIfNull(options, nameof(options));

            Storage = storage;
            Options = options;
        }
コード例 #4
0
        /// <summary>
        /// 自定义其他设置
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="pathMatch"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IAppBuilder UseLayimApi(this IAppBuilder builder, string pathMatch, LayimOptions options, LayimStorage storage)
        {
            Error.ThrowIfNull(pathMatch, nameof(pathMatch));
            Error.ThrowIfNull(options, nameof(options));

            SignatureConversions.AddConversions(builder);

            builder.Map(pathMatch, appBuilder => appBuilder
                        .UseOwin()
                        .UseLayimApi(storage, options, LayimRoutes.Routes));
            return(builder);
        }
コード例 #5
0
 /// <summary>
 /// 设置配置
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="pathMatch"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IAppBuilder UseLayimApi(this IAppBuilder builder, string pathMatch, LayimOptions options)
 {
     return(builder.UseLayimApi(pathMatch, options, LayimStorage.Current));
 }
コード例 #6
0
 public static BuildFunc UseLayimApi(this BuildFunc builder, LayimStorage storage, LayimOptions options, RouteCollection routes)
 {
     builder(_ => UseLayimApi(storage, options, routes));
     return(builder);
 }