Beispiel #1
0
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            BoundUrl url = this._parsedRoute.Bind(requestContext.RouteData.Values, values, this.Defaults, this.Constraints);

            if (url == null)
            {
                return(null);
            }
            if (!this.ProcessConstraints(requestContext.HttpContext, url.Values, RouteDirection.UrlGeneration))
            {
                return(null);
            }
            VirtualPathData data = new VirtualPathData(this, url.Url);

            if (this.DataTokens != null)
            {
                foreach (KeyValuePair <string, object> pair in this.DataTokens)
                {
                    data.DataTokens[pair.Key] = pair.Value;
                }
            }
            return(data);
        }
Beispiel #2
0
        public BoundUrl Bind(RouteValueDictionary currentValues, RouteValueDictionary values, RouteValueDictionary defaultValues, RouteValueDictionary constraints)
        {
            StringBuilder builder;
            StringBuilder builder2;
            bool          flag2;
            bool          flag3;
            BoundUrl      url;
            int           num;

            if (currentValues == null)
            {
                currentValues = new RouteValueDictionary();
            }
            if (values == null)
            {
                values = new RouteValueDictionary();
            }
            if (defaultValues == null)
            {
                defaultValues = new RouteValueDictionary();
            }
            RouteValueDictionary acceptedValues  = new RouteValueDictionary();
            HashSet <string>     unusedNewValues = new HashSet <string>(values.Keys, StringComparer.OrdinalIgnoreCase);

            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment) {
                object obj2;
                object obj3;
                string parameterName = parameterSubsegment.ParameterName;
                bool flag            = values.TryGetValue(parameterName, out obj2);
                if (flag)
                {
                    unusedNewValues.Remove(parameterName);
                }
                bool flag22 = currentValues.TryGetValue(parameterName, out obj3);
                if ((flag & flag22) && !RoutePartsEqual(obj3, obj2))
                {
                    return(false);
                }
                if (flag)
                {
                    if (IsRoutePartNonEmpty(obj2))
                    {
                        acceptedValues.Add(parameterName, obj2);
                    }
                }
                else if (flag22)
                {
                    acceptedValues.Add(parameterName, obj3);
                }
                return(true);
            });
            foreach (KeyValuePair <string, object> pair in values)
            {
                if (IsRoutePartNonEmpty(pair.Value) && !acceptedValues.ContainsKey(pair.Key))
                {
                    acceptedValues.Add(pair.Key, pair.Value);
                }
            }
            foreach (KeyValuePair <string, object> pair2 in currentValues)
            {
                string key = pair2.Key;
                if (!acceptedValues.ContainsKey(key) && (GetParameterSubsegment(this.PathSegments, key) == null))
                {
                    acceptedValues.Add(key, pair2.Value);
                }
            }
            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment) {
                object obj2;
                if (!acceptedValues.ContainsKey(parameterSubsegment.ParameterName) && !IsParameterRequired(parameterSubsegment, defaultValues, out obj2))
                {
                    acceptedValues.Add(parameterSubsegment.ParameterName, obj2);
                }
                return(true);
            });
            if (!ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment) {
                object obj2;
                return(!IsParameterRequired(parameterSubsegment, defaultValues, out obj2) || acceptedValues.ContainsKey(parameterSubsegment.ParameterName));
            }))
            {
                return(null);
            }
            RouteValueDictionary otherDefaultValues = new RouteValueDictionary(defaultValues);

            ForEachParameter(this.PathSegments, delegate(ParameterSubsegment parameterSubsegment) {
                otherDefaultValues.Remove(parameterSubsegment.ParameterName);
                return(true);
            });
            using (Dictionary <string, object> .Enumerator enumerator3 = otherDefaultValues.GetEnumerator())
            {
                while (true)
                {
                    if (enumerator3.MoveNext())
                    {
                        object obj2;
                        KeyValuePair <string, object> current = enumerator3.Current;
                        if (!values.TryGetValue(current.Key, out obj2))
                        {
                            continue;
                        }
                        unusedNewValues.Remove(current.Key);
                        if (RoutePartsEqual(obj2, current.Value))
                        {
                            continue;
                        }
                        url = null;
                    }
                    else
                    {
                        builder  = new StringBuilder();
                        builder2 = new StringBuilder();
                        flag2    = false;
                        flag3    = false;
                        num      = 0;
                        goto TR_0049;
                    }
                    break;
                }
            }
            return(url);

TR_001B:
            num++;
TR_0049:
            while (true)
            {
                if (num >= this.PathSegments.Count)
                {
                    if (flag2 && (builder2.Length > 0))
                    {
                        if (flag3)
                        {
                            return(null);
                        }
                        builder.Append(builder2.ToString());
                    }
                    if (constraints != null)
                    {
                        foreach (KeyValuePair <string, object> pair4 in constraints)
                        {
                            unusedNewValues.Remove(pair4.Key);
                        }
                    }
                    if (unusedNewValues.Count > 0)
                    {
                        bool flag6 = true;
                        foreach (string str2 in unusedNewValues)
                        {
                            object obj5;
                            if (acceptedValues.TryGetValue(str2, out obj5))
                            {
                                builder.Append(flag6 ? '?' : '&');
                                flag6 = false;
                                builder.Append(Uri.EscapeDataString(str2));
                                builder.Append('=');
                                builder.Append(Uri.EscapeDataString(Convert.ToString(obj5, CultureInfo.InvariantCulture)));
                            }
                        }
                    }
                    BoundUrl url1 = new BoundUrl();
                    url1.Url    = builder.ToString();
                    url1.Values = acceptedValues;
                    return(url1);
                }
                PathSegment segment = this.PathSegments[num];
                if (segment is SeparatorPathSegment)
                {
                    if (flag2 && (builder2.Length > 0))
                    {
                        if (flag3)
                        {
                            return(null);
                        }
                        builder.Append(builder2.ToString());
                        builder2.Length = 0;
                    }
                    flag2 = false;
                    if ((builder2.Length <= 0) || (builder2[builder2.Length - 1] != '/'))
                    {
                        builder2.Append("/");
                    }
                    else
                    {
                        if (flag3)
                        {
                            return(null);
                        }
                        builder.Append(builder2.ToString(0, builder2.Length - 1));
                        builder2.Length = 0;
                        flag3           = true;
                    }
                    goto TR_001B;
                }
                else
                {
                    ContentPathSegment segment2 = segment as ContentPathSegment;
                    if (segment2 != null)
                    {
                        bool flag4 = false;
                        using (IEnumerator <PathSubsegment> enumerator4 = segment2.Subsegments.GetEnumerator())
                        {
                            while (true)
                            {
                                if (enumerator4.MoveNext())
                                {
                                    object            obj3;
                                    object            obj4;
                                    PathSubsegment    current     = enumerator4.Current;
                                    LiteralSubsegment subsegment3 = current as LiteralSubsegment;
                                    if (subsegment3 != null)
                                    {
                                        flag2 = true;
                                        builder2.Append(UrlEncode(subsegment3.Literal));
                                        continue;
                                    }
                                    ParameterSubsegment subsegment4 = current as ParameterSubsegment;
                                    if (subsegment4 == null)
                                    {
                                        continue;
                                    }
                                    if (flag2 && (builder2.Length > 0))
                                    {
                                        if (flag3)
                                        {
                                            url = null;
                                            break;
                                        }
                                        builder.Append(builder2.ToString());
                                        builder2.Length = 0;
                                        flag4           = true;
                                    }
                                    flag2 = false;
                                    if (acceptedValues.TryGetValue(subsegment4.ParameterName, out obj3))
                                    {
                                        unusedNewValues.Remove(subsegment4.ParameterName);
                                    }
                                    defaultValues.TryGetValue(subsegment4.ParameterName, out obj4);
                                    if (RoutePartsEqual(obj3, obj4))
                                    {
                                        builder2.Append(UrlEncode(Convert.ToString(obj3, CultureInfo.InvariantCulture)));
                                    }
                                    else
                                    {
                                        if (flag3)
                                        {
                                            url = null;
                                            break;
                                        }
                                        if (builder2.Length > 0)
                                        {
                                            builder.Append(builder2.ToString());
                                            builder2.Length = 0;
                                        }
                                        builder.Append(UrlEncode(Convert.ToString(obj3, CultureInfo.InvariantCulture)));
                                        flag4 = true;
                                    }
                                    continue;
                                }
                                if (flag4 && (builder2.Length > 0))
                                {
                                    if (flag3)
                                    {
                                        return(null);
                                    }
                                    builder.Append(builder2.ToString());
                                    builder2.Length = 0;
                                }
                                goto TR_001B;
                            }
                        }
                        break;
                    }
                    goto TR_001B;
                }
                break;
            }
            return(url);
        }