コード例 #1
0
ファイル: WebAppHelper.cs プロジェクト: ibeae/ThinkAway.net
        internal static ControllerAction GetControllerAction(string url)
        {
            RouteResult routeResult = WebAppConfig.Router.Resolve(url);

            if (routeResult == null)
            {
                return(null);
            }

            ControllerClass controllerClass = WebAppConfig.GetControllerClass(routeResult.Controller);

            if (controllerClass != null)
            {
                ControllerAction controllerAction = new ControllerAction(controllerClass, routeResult.Action);

                foreach (KeyValuePair <string, string> param in routeResult.Parameters)
                {
                    controllerAction.Parameters.Add(param.Key, param.Value);
                }

                return(controllerAction);
            }

            return(null);
        }
コード例 #2
0
ファイル: Route.cs プロジェクト: marinehero/ThinkAway.net
		internal RouteResult Resolve(string url)
		{
			Match m = _regex.Match(url);

			if (m.Success)
			{
				RouteResult result = new RouteResult(Controller, Action, _parameters);

				foreach (string groupName in _regexGroups)
				{
					string value = m.Groups[groupName].Value;
					string searchString = "{" + groupName + "}";
					bool found = false;

                    if (result.Controller.Contains(searchString))
                    {
                        result.Controller = result.Controller.Replace(searchString, value);
                        found = true;
                    }

                    if (result.Action.Contains(searchString))
                    {
                        result.Action = result.Action.Replace(searchString, value);
                        found = true;
                    }

                    if (_parameterNames != null)
                        foreach (string paramName in _parameterNames)
                        {
                            string paramValue = result.Parameters[paramName];

                            if (paramValue.Contains(searchString))
                            {
                                result.Parameters[paramName] = paramValue.Replace(searchString, value);
                                found = true;
                            }
                        }

                    if (!found)
                        result.Parameters[groupName] = value;

                    if (_validators != null)
					    foreach (IRouteValidator validator in _validators)
						    if (validator.ShouldValidate(groupName))
						    {
						        bool ok = validator.Validate(groupName, value);

						        RouteValidationAction actionToExecute = ok ? validator.PassAction : validator.FailAction;

                                switch (actionToExecute)
                                {
                                    case RouteValidationAction.Skip:
                                        result.ValidationResult = RouteValidationResult.Skip;
                                        break;
                                    case RouteValidationAction.Error:
                                        result.ValidationResult = RouteValidationResult.Fail;
                                        break;
                                    case RouteValidationAction.Accept:
                                        result.ValidationResult = RouteValidationResult.Success;
                                        break;
                                    case RouteValidationAction.None:
                                        continue;
                                }

						        return result;
						    }

				}

				return result;
			}

			return null;
		}
コード例 #3
0
ファイル: Route.cs プロジェクト: ibeae/ThinkAway.net
        internal RouteResult Resolve(string url)
        {
            Match m = _regex.Match(url);

            if (m.Success)
            {
                RouteResult result = new RouteResult(Controller, Action, _parameters);

                foreach (string groupName in _regexGroups)
                {
                    string value        = m.Groups[groupName].Value;
                    string searchString = "{" + groupName + "}";
                    bool   found        = false;

                    if (result.Controller.Contains(searchString))
                    {
                        result.Controller = result.Controller.Replace(searchString, value);
                        found             = true;
                    }

                    if (result.Action.Contains(searchString))
                    {
                        result.Action = result.Action.Replace(searchString, value);
                        found         = true;
                    }

                    if (_parameterNames != null)
                    {
                        foreach (string paramName in _parameterNames)
                        {
                            string paramValue = result.Parameters[paramName];

                            if (paramValue.Contains(searchString))
                            {
                                result.Parameters[paramName] = paramValue.Replace(searchString, value);
                                found = true;
                            }
                        }
                    }

                    if (!found)
                    {
                        result.Parameters[groupName] = value;
                    }

                    if (_validators != null)
                    {
                        foreach (IRouteValidator validator in _validators)
                        {
                            if (validator.ShouldValidate(groupName))
                            {
                                bool ok = validator.Validate(groupName, value);

                                RouteValidationAction actionToExecute = ok ? validator.PassAction : validator.FailAction;

                                switch (actionToExecute)
                                {
                                case RouteValidationAction.Skip:
                                    result.ValidationResult = RouteValidationResult.Skip;
                                    break;

                                case RouteValidationAction.Error:
                                    result.ValidationResult = RouteValidationResult.Fail;
                                    break;

                                case RouteValidationAction.Accept:
                                    result.ValidationResult = RouteValidationResult.Success;
                                    break;

                                case RouteValidationAction.None:
                                    continue;
                                }

                                return(result);
                            }
                        }
                    }
                }

                return(result);
            }

            return(null);
        }