Example #1
0
        private void _completeRouteTargetCompleteActionParams(ref RouteTarget routeTarget)
        {
            RouteTarget routeTargetLocal   = null;
            bool        searchForCtrl      = routeTarget.Controller != "*";
            bool        searchForAction    = routeTarget.Action != "*";
            bool        searchForNamespace = routeTarget.Namespaces.Length > 0;
            string      searchedCtrl       = routeTarget.Controller + "Controller";

            Routing._routeTargetsLock.EnterReadLock();
            foreach (RouteTarget item in Routing._routeTargets)
            {
                if (searchForCtrl && item.Controller != searchedCtrl)
                {
                    continue;
                }
                if (searchForAction && item.Action != routeTarget.Action)
                {
                    continue;
                }
                if (searchForNamespace)
                {
                    if (routeTarget.NamespacesLower.Contains(item.NamespaceLower))
                    {
                        routeTargetLocal = item;
                        break;
                    }
                }
                else
                {
                    routeTargetLocal = item;
                    break;
                }
            }
            Routing._routeTargetsLock.ExitReadLock();
            if (routeTargetLocal is RouteTarget)
            {
                List <string> targetParams = new List <string>();
                Type          targetParamType;
                foreach (var targetParamItem in routeTargetLocal.Params)
                {
                    targetParamType = targetParamItem.Value.Type;
                    targetParams.Add(targetParamItem.Value.HtmlName + " " + targetParamItem.Key);
                }
                routeTarget.FullName += "(" + String.Join(", ", targetParams) + ")";
                routeTarget.Namespace = routeTargetLocal.Namespace;
                if (routeTarget.Namespace != Routing._defaultControllersNamespace)
                {
                    routeTarget.FullName = routeTarget.Namespace + "." + routeTarget.FullName;
                }
                routeTarget.Params = routeTargetLocal.Params;
            }
            else
            {
                routeTarget.FullName += "()";
            }
        }
Example #2
0
        private string _completeRoute(ref Route route, ref RouteTarget routeTarget, int matched)
        {
            string[] rowCssClassAndFirstColumn = Routing._completeRouteCssClassAndFirstColumn(ref route, matched);
            string   secondColumn        = Routing._completeRouteSecondColumn(route);
            string   configuredRouteName = Routing._completeRouteConfiguredRouteName(routeTarget);
            string   routeParams         = this._completeRouteParamsValuesConstraints(route);
            string   routeMatches        = String.Empty;
            string   matchedRouteName    = String.Empty;

            if (matched == 2)
            {
                routeMatches     = this._matchedCompleter.Render();
                matchedRouteName = configuredRouteName;
            }
            return(String.Format(
                       @"<tr{0}><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>",
                       rowCssClassAndFirstColumn[0],
                       rowCssClassAndFirstColumn[1],
                       secondColumn,
                       configuredRouteName + routeParams,
                       matchedRouteName + routeMatches
                       ));
        }
Example #3
0
 private static string _completeRouteConfiguredRouteName(RouteTarget routeTarget)
 {
     return(routeTarget.FullName.IndexOf(":") > -1
                         ? @"<div class=""target"">" + routeTarget.FullName + "</div>"
                         : routeTarget.FullName);
 }
Example #4
0
        private RouteTarget _completeRouteTarget(ref Route route, RouteValueDictionary dictionaryContainingCtrlAndAction)
        {
            RouteTarget result = new RouteTarget {
                Controller      = "",
                Action          = "",
                FullName        = "",
                Namespaces      = new string[] {},
                NamespacesLower = new string[] {},
                Namespace       = Routing._defaultControllersNamespace,
                Params          = new Dictionary <string, RouteTargetArg>()
            };
            bool   ctrlDefined   = false;
            bool   actionDefined = false;
            int    ctrlNameDocPos;
            string namespacePartInsideControllerName;

            if (!(route.RouteHandler is StopRoutingHandler))
            {
                if (route.DataTokens.ContainsKey("Namespaces"))
                {
                    try {
                        result.Namespaces = route.DataTokens["Namespaces"] as string[];
                    } catch { }
                    if (result.Namespaces == null)
                    {
                        result.Namespaces = new string[] { }
                    }
                    ;
                }
                if (dictionaryContainingCtrlAndAction.ContainsKey("controller"))
                {
                    if (dictionaryContainingCtrlAndAction["controller"].GetType().Name == "UrlParameter")
                    {
                        result.Controller = "*";
                    }
                    else
                    {
                        result.Controller = dictionaryContainingCtrlAndAction["controller"].ToString();
                        ctrlNameDocPos    = result.Controller.LastIndexOf(".");
                        if (ctrlNameDocPos > -1)
                        {
                            namespacePartInsideControllerName = result.Controller.Substring(0, ctrlNameDocPos);
                            result.Controller = result.Controller.Substring(ctrlNameDocPos + 1);
                            if (result.Namespaces.Length > 0)
                            {
                                for (int i = 0, l = result.Namespaces.Length; i < l; i += 1)
                                {
                                    result.Namespaces[i] += "." + result.Controller.Substring(0, ctrlNameDocPos);
                                }
                            }
                            else
                            {
                                result.Namespaces = new[] {
                                    Routing._defaultControllersNamespace + "." + namespacePartInsideControllerName
                                };
                            }
                        }
                        ctrlDefined = true;
                    }
                }
                List <string> lowerNamespaces = new List <string>();
                for (int i = 0, l = result.Namespaces.Length; i < l; i += 1)
                {
                    lowerNamespaces.Add(result.Namespaces[i].ToLower());
                }
                result.NamespacesLower = lowerNamespaces.ToArray();
                if (dictionaryContainingCtrlAndAction.ContainsKey("action"))
                {
                    if (dictionaryContainingCtrlAndAction["action"].GetType().Name == "UrlParameter")
                    {
                        result.Action = "*";
                    }
                    else
                    {
                        result.Action = dictionaryContainingCtrlAndAction["action"].ToString();
                        actionDefined = true;
                    }
                }
                result.FullName = result.Controller + ":" + result.Action;
                if (ctrlDefined && actionDefined)
                {
                    this._completeRouteTargetCompleteActionParams(ref result);
                }
                else
                {
                    result.FullName += "()";
                }
                if (result.FullName.IndexOf(Routing._defaultControllersNamespace) == 0)
                {
                    result.FullName = result.FullName.Substring(Routing._defaultControllersNamespace.Length + 1);
                }
                result.FullName = result.FullName.Replace("*", @"<span class=""type"">[Optional]</span>");
            }
            return(result);
        }
 protected ActionResult RedirectToAction(RouteTarget routeTarget)
 {
     return(Redirect(routeTarget.GetUri(Url).ToString()));
 }