IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string virtualPath, string physicalPath) { // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。 // 例如:/mvc/*/*.aspx 和 /mvc/* // 为了映射HTTP处理器,下面直接使用context.Request.Path string requestPath = context.Request.Path; string vPath = context.GetRealVirtualPath(); // 尝试根据请求路径获取Action ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(vPath); // 如果没有找到合适的Action,并且请求的是一个ASPX页面,则按ASP.NET默认的方式来继续处理 if (vkInfo == null) { if (requestPath.EndsWithIgnoreCase(".aspx") && System.IO.File.Exists(context.Request.PhysicalPath)) { // 调用ASP.NET默认的Page处理器工厂来处理 return(_msPageHandlerFactory.GetHandler(context, requestType, requestPath, physicalPath)); } else { ExceptionHelper.Throw404Exception(context); } } return(ActionHandlerFactory.CreateHandler(vkInfo)); }
internal IHttpHandler GetHttpHandler(HttpContext context, UrlActionInfo info) { if (context == null) { throw new ArgumentNullException("context"); } if (info == null) { throw new ArgumentNullException("info"); } // 获取内部表示的调用信息 ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(info); if (vkInfo == null) { IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context); if (handler != null) { return(handler); } else { return(null); } } // 创建能够调用Action的HttpHandler return(ActionHandlerFactory.CreateHandler(vkInfo)); }
public CanvasButtonsBuilder(GameObject canvas, ControllerResolver controllerResolver, CanvasDimensionsTransformer canvasDimensionsTransformer) : base(canvas, controllerResolver, canvasDimensionsTransformer) { this.canvas = canvas; this.controllerResolver = controllerResolver; this.canvasDimensionsTransformer = canvasDimensionsTransformer; this.button = Object.Instantiate(Resources.Load <GameObject>("Button")); this.button.transform.SetParent(this.canvas.transform, false); }
public CanvasBuilder Create(string name, int level, Vector2 position) { ControllerFactory controllerFactory = new ControllerFactory(_registryManager, _basicTypeInvoker); ControllerResolver controllerResolver = new ControllerResolver(_registryManager.ControllerRegistry, controllerFactory); GameObject canvas = (new CanvasFactory()).Create(name, level, position); CanvasDimensionsTransformer canvasDimensionsTransformer = new CanvasDimensionsTransformer(canvas); CanvasBuilder canvasBuilder = new CanvasBuilder(canvas, controllerResolver, canvasDimensionsTransformer); return(canvasBuilder); }
/// <summary> /// 实现IHttpHandlerFactory接口,从当前请求获取IHttpHandler /// </summary> /// <param name="context"></param> /// <param name="requestType"></param> /// <param name="virtualPath"></param> /// <param name="physicalPath"></param> /// <returns></returns> public IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string physicalPath) { // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。 // 例如:/Ajax/*/*.aspx 和 /Ajax/* // 为了映射HTTP处理器,下面直接使用context.Request.Path string vPath = context.GetRealVirtualPath(); // 根据请求路径,定位到要执行的Action UrlActionInfo info = ParseUrl(context, vPath); if (info == null) { IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context); if (handler != null) { return(handler); } ExceptionHelper.Throw404Exception(context); } info.SetHttpcontext(context); // 获取内部表示的调用信息 ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(info); if (vkInfo == null) { IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context); if (handler != null) { return(handler); } ExceptionHelper.Throw404Exception(context); } // 创建能够调用Action的HttpHandler return(ActionHandlerFactory.CreateHandler(vkInfo)); }
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string virtualPath, string physicalPath) { // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。 // 例如:/mvc/*/*.aspx 和 /mvc/* // 为了映射HTTP处理器,下面直接使用context.Request.Path string requestPath = context.Request.Path; string vPath = context.GetRealVirtualPath(); // 尝试根据请求路径获取Action ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(vPath); // 如果没有找到合适的Action,并且请求的是一个ASPX页面,则按ASP.NET默认的方式来继续处理 if (vkInfo == null) { if (requestPath.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase)) { // 调用ASP.NET默认的Page处理器工厂来处理 try { return(_msPageHandlerFactory.GetHandler(context, requestType, requestPath, physicalPath)); } catch (Exception ex) { if (controllerResolver.DiagnoseResult != null) { controllerResolver.DiagnoseResult.ErrorMessages.Add("System.Web.UI.PageHandlerFactory不能根据指定的URL地址创建IHttpHandler实例。"); controllerResolver.DiagnoseResult.ErrorMessages.Add(ex.Message); return(Http404DebugModule.TryGetHttp404PageHandler(context)); } throw; } } } return(ActionHandlerFactory.CreateHandler(vkInfo)); }
internal IHttpHandler GetHttpHandler(HttpContext context, UrlActionInfo info) { if( context == null ) throw new ArgumentNullException("context"); if( info == null ) throw new ArgumentNullException("info"); // 获取内部表示的调用信息 ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(info); if( vkInfo == null ) { IHttpHandler handler = Http404DebugModule.TryGetHttp404PageHandler(context); if( handler != null ) return handler; else return null; } // 创建能够调用Action的HttpHandler return ActionHandlerFactory.CreateHandler(vkInfo); }
public void Init(ServiceLocator sl, ref PluginSetting setting) { if (!setting.Enable) { sl.AddComponent("kiss.XmlUrlMappingProvider", typeof(IUrlMappingProvider), typeof(XmlUrlMappingProvider)); sl.AddComponent("kiss.defaultHost", typeof(IHost), typeof(Kiss.Web.Host)); return; } sl.AddComponent("kiss.Areahost", typeof(IHost), typeof(Host)); sl.AddComponent("kiss.AreaUrlMappingProvider", typeof(IUrlMappingProvider), typeof(AreaUrlMappingProvider)); Areas.Add(@"/", AreaConfig.Instance); ControllerResolver resolver = ControllerResolver.Instance; load_areas(resolver); HttpRuntime.Cache.Insert(kCACHE_KEY, "dummyValue", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration); logger.Debug("AreaInitializer done."); }
IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string virtualPath, string physicalPath) { // 说明:这里不使用virtualPath变量,因为不同的配置,这个变量的值会不一样。 // 例如:/mvc/*/*.aspx 和 /mvc/* // 为了映射HTTP处理器,下面直接使用context.Request.Path string requestPath = context.Request.Path; string vPath = context.GetRealVirtualPath(); // 尝试根据请求路径获取Action ControllerResolver controllerResolver = new ControllerResolver(context); InvokeInfo vkInfo = controllerResolver.GetActionInvokeInfo(vPath); // 如果没有找到合适的Action,并且请求的是一个ASPX页面,则按ASP.NET默认的方式来继续处理 if( vkInfo == null ) { if( requestPath.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase) ) { // 调用ASP.NET默认的Page处理器工厂来处理 try { return _msPageHandlerFactory.GetHandler(context, requestType, requestPath, physicalPath); } catch(Exception ex) { if( controllerResolver.DiagnoseResult != null ) { controllerResolver.DiagnoseResult.ErrorMessages.Add("System.Web.UI.PageHandlerFactory不能根据指定的URL地址创建IHttpHandler实例。"); controllerResolver.DiagnoseResult.ErrorMessages.Add(ex.Message); return Http404DebugModule.TryGetHttp404PageHandler(context); } throw; } } } return ActionHandlerFactory.CreateHandler(vkInfo); }
public CanvasLayoutBuilder(GameObject canvas, ControllerResolver controllerResolver, CanvasDimensionsTransformer canvasDimensionsTransformer) : base(canvas, controllerResolver, canvasDimensionsTransformer) { this.canvas = canvas; this.controllerResolver = controllerResolver; this.canvasDimensionsTransformer = canvasDimensionsTransformer; }
internal UrlActionInfo GetUrlActionInfo(RouteData routeData, HttpContext context) { if( routeData == null ) throw new ArgumentNullException("routeData"); if( context == null ) throw new ArgumentNullException("context"); // 采用ASP.NET Routing后,这三个参数都应该可以直接获取到, // 如果URL没有指定,可以通过默认值,或者DataToken指定, // 所以不需要像RestServiceModule那样重新计算 string nspace = GetRouteString(routeData, "namespace"); string className = GetRouteString(routeData, "controller"); string action = GetRouteString(routeData, "action"); if( string.IsNullOrEmpty(className) || string.IsNullOrEmpty(action) ) { DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context); if( diagnoseResult != null ) diagnoseResult.ErrorMessages.Add("不能从URL中提取到controller和action信息"); return null; } if( action == "{HttpMethod}" ) // 允许定义这个特殊变量 action = context.Request.HttpMethod; ControllerResolver controllerResolver = new ControllerResolver(context); UrlActionInfo info = new UrlActionInfo(); info.RoutePattern = (routeData.Route as Route).Url; // 转换失败?? info.Namesapce = controllerResolver.GetNamespaceMap(nspace); info.ClassName = className; info.MethodName = action; info.Action = action; info.Controller = s_recognizer.GetServiceFullName(info); // 将路由提取到的其它URL参数,保存到UrlActionInfo实例中。 foreach( KeyValuePair<string, object> kvp in routeData.Values ) { // 排除3个特定名字。 if( kvp.Key.IsSame("namespace") || kvp.Key.IsSame("controller") || kvp.Key.IsSame("action") ) continue; string value = kvp.Value as string; if( string.IsNullOrEmpty(value) == false ) info.AddParam(kvp.Key, value); } return info; }
private static void load_areas(ControllerResolver resolver) { List <string> privateBins = new List <string>() { "bin" }; MethodInfo m = null, funsion = null; // check if i am running under mono at runtime. bad coding style bool isMono = Type.GetType("Mono.Runtime") != null; if (!isMono) { m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static); funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance); } foreach (var dir in Directory.GetDirectories(ServerUtil.MapPath("~"))) { string areaName = Path.GetFileName(dir).ToLowerInvariant(); if (IGNORES_DIR.Contains(areaName)) { continue; } // check if the dir is a valid area string configfile = Path.Combine(dir, "area.config"); if (!File.Exists(configfile)) { continue; } // load area config XmlNode node = null; using (XmlTransformableDocument x = new XmlTransformableDocument()) { x.Load(configfile); string localfile = Path.Combine(dir, "area.local.config"); if (File.Exists(localfile)) { using (XmlTransformation t = new XmlTransformation(localfile)) { t.Apply(x); } } node = x.DocumentElement; } AreaConfig config = AreaConfig.GetConfig(node); config.VP = "/" + areaName; config.AreaKey = areaName; Areas.Add(@"/" + areaName, config); // load assemblies string bindir = Path.Combine(dir, "bin"); if (Directory.Exists(bindir)) { privateBins.Add(bindir); if (!isMono) { // hack !!! if (m != null && funsion != null) { m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", privateBins.Join(";") }); m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "SHADOW_COPY_DIRS", privateBins.Join(";") }); } } List <Assembly> assemblies = new List <Assembly>(); foreach (var item in Directory.GetFiles(bindir, "*.dll", SearchOption.TopDirectoryOnly)) { try { if (isMono) { assemblies.Add(Assembly.Load(File.ReadAllBytes(item))); } else { assemblies.Add(AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(item))); } } catch (BadImageFormatException) { } } Dictionary <string, Type> types = new Dictionary <string, Type>(); foreach (var asm in assemblies) { foreach (var item in resolver.GetsControllerFromAssembly(asm)) { types[item.Key] = item.Value; } } resolver.SetSiteControllers(areaName, types); } } }
internal UrlActionInfo GetUrlActionInfo(RouteData routeData, HttpContext context) { if (routeData == null) { throw new ArgumentNullException("routeData"); } if (context == null) { throw new ArgumentNullException("context"); } // 采用ASP.NET Routing后,这三个参数都应该可以直接获取到, // 如果URL没有指定,可以通过默认值,或者DataToken指定, // 所以不需要像RestServiceModule那样重新计算 string nspace = GetRouteString(routeData, "namespace"); string className = GetRouteString(routeData, "controller"); string action = GetRouteString(routeData, "action"); if (string.IsNullOrEmpty(className) || string.IsNullOrEmpty(action)) { DiagnoseResult diagnoseResult = Http404DebugModule.TryGetDiagnoseResult(context); if (diagnoseResult != null) { diagnoseResult.ErrorMessages.Add("不能从URL中提取到controller和action信息"); } return(null); } if (action == "{HttpMethod}") // 允许定义这个特殊变量 { action = context.Request.HttpMethod; } ControllerResolver controllerResolver = new ControllerResolver(context); UrlActionInfo info = new UrlActionInfo(); info.RoutePattern = (routeData.Route as Route).Url; // 转换失败?? info.Namesapce = controllerResolver.GetNamespaceMap(nspace); info.ClassName = className; info.MethodName = action; info.Action = action; info.Controller = s_recognizer.GetServiceFullName(info); // 将路由提取到的其它URL参数,保存到UrlActionInfo实例中。 foreach (KeyValuePair <string, object> kvp in routeData.Values) { // 排除3个特定名字。 if (kvp.Key.IsSame("namespace") || kvp.Key.IsSame("controller") || kvp.Key.IsSame("action")) { continue; } string value = kvp.Value as string; if (string.IsNullOrEmpty(value) == false) { info.AddParam(kvp.Key, value); } } return(info); }
public ManipuladorRequisicaoController(IContainer container) { _controllerResolver = new ControllerResolver(container); }
public static void Initialize(RouteSettings settings) { resolver = new ControllerResolver(); urlCreator = new UrlCreator(settings.RootUrl); }
public IActionResult Submit([FromBody] string result) { return(RedirectToRoutePermanent( nameof(ResultsController.Index), ControllerResolver.GetUrlName(typeof(ResultsController)))); }