Exemple #1
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var appPathLower = requestContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath.ToLower();

            for (int i = 0; i < builderRegistry.Count; i++)
            {
                var brp = builderRegistry[i];
                if (brp.Regex.IsMatch(appPathLower))
                {
                    var pathData = new PathDataDictionary();
                    var match    = brp.Regex.Match(appPathLower);
                    if (match.Groups.Count > 1)
                    {
                        for (int j = 1; j < match.Groups.Count; j++)
                        {
                            pathData.Add(brp.Regex.GroupNameFromNumber(j), match.Groups[j].Value);
                        }
                    }

                    var builderInstance = BuilderFactory.Create(brp.Builder, requestContext.HttpContext, pathData);
                    builderInstance.RouteId = brp.RouteId;
                    return(builderInstance);
                }
            }

            if (RouteNotFoundBuilder != null)
            {
                return(BuilderFactory.Create(RouteNotFoundBuilder, requestContext.HttpContext, new PathDataDictionary()));
            }
            return(null);
        }
        public static BaseBuilder Create(Type builderType, HttpContextBase httpContext, PathDataDictionary pathData)
        {
            if (!builderType.IsSubclassOf(baseBuilderType))
            {
                return(null);
            }

            BuilderConstructorDelegate del;

            if (builderConstructors.TryGetValue(builderType.FullName, out del))
            {
                return(del(httpContext, pathData));
            }

            DynamicMethod dynamicMethod = new DynamicMethod("CreateBaseBuilderInstance", builderType, constructorMethodArgs, builderType);
            ILGenerator   ilGenerator   = dynamicMethod.GetILGenerator();

            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.Emit(OpCodes.Newobj, builderType.GetConstructor(constructorMethodArgs));
            ilGenerator.Emit(OpCodes.Ret);

            del = (BuilderConstructorDelegate)dynamicMethod.CreateDelegate(typeof(BuilderConstructorDelegate));
            builderConstructors.TryAdd(builderType.FullName, del);
            return(del(httpContext, pathData));
        }
        public static BaseBuilder Create(string identifier, HttpContextBase httpContext, PathDataDictionary pathData)
        {
            if (String.IsNullOrEmpty(identifier))
            {
                throw new ArgumentException("identifier can not be null or empty", identifier);
            }
            if (!builderRegistry.ContainsKey(identifier))
            {
                throw new ArgumentException("No Builder has been registered with the identifier: " + identifier);
            }

            return(Create(builderRegistry[identifier], httpContext, pathData));
        }
Exemple #4
0
 protected BaseBuilder(HttpContextBase httpContext, PathDataDictionary pathData)
     : base(httpContext)
 {
     PathData = pathData;
 }