Ejemplo n.º 1
0
        public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
        {
            if (other == null)
            {
                return(false);
            }
            if (!ignoreTrailingSlash && (base.EndsWithSlash != other.EndsWithSlash))
            {
                return(false);
            }
            UriTemplateCompoundPathSegment segment = other as UriTemplateCompoundPathSegment;

            if (segment == null)
            {
                return(false);
            }
            if (this.varLitPairs.Count != segment.varLitPairs.Count)
            {
                return(false);
            }
            if (StringComparer.OrdinalIgnoreCase.Compare(this.firstLiteral, segment.firstLiteral) != 0)
            {
                return(false);
            }
            for (int i = 0; i < this.varLitPairs.Count; i++)
            {
                VarAndLitPair pair  = this.varLitPairs[i];
                VarAndLitPair pair2 = segment.varLitPairs[i];
                if (StringComparer.OrdinalIgnoreCase.Compare(pair.Literal, pair2.Literal) != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
        private static void Add(UriTemplateTrieNode root, KeyValuePair <UriTemplate, object> kvp)
        {
            UriTemplateTrieNode node = root;
            UriTemplate         key  = kvp.Key;
            bool flag = ((key.segments.Count == 0) || key.HasWildcard) || key.segments[key.segments.Count - 1].EndsWithSlash;

            for (int i = 0; i < key.segments.Count; i++)
            {
                if (i >= key.firstOptionalSegment)
                {
                    node.endOfPath.Items.Add(kvp);
                }
                UriTemplatePathSegment segment = key.segments[i];
                if (!segment.EndsWithSlash)
                {
                    switch (segment.Nature)
                    {
                    case UriTemplatePartType.Literal:
                        node.AddFinalLiteralSegment(segment as UriTemplateLiteralPathSegment, kvp);
                        break;

                    case UriTemplatePartType.Compound:
                        node.AddFinalCompoundSegment(segment as UriTemplateCompoundPathSegment, kvp);
                        break;

                    case UriTemplatePartType.Variable:
                        node.finalVariableSegment.Items.Add(kvp);
                        break;
                    }
                }
                else
                {
                    switch (segment.Nature)
                    {
                    case UriTemplatePartType.Literal:
                        node = node.AddNextLiteralSegment(segment as UriTemplateLiteralPathSegment);
                        break;

                    case UriTemplatePartType.Compound:
                        node = node.AddNextCompoundSegment(segment as UriTemplateCompoundPathSegment);
                        break;

                    case UriTemplatePartType.Variable:
                        node = node.AddNextVariableSegment();
                        break;
                    }
                }
            }
            if (flag)
            {
                if (key.HasWildcard)
                {
                    node.star.Items.Add(kvp);
                }
                else
                {
                    node.endOfPath.Items.Add(kvp);
                }
            }
        }
Ejemplo n.º 3
0
 public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
 {
     if (other == null)
     {
         return(false);
     }
     if (!ignoreTrailingSlash && (base.EndsWithSlash != other.EndsWithSlash))
     {
         return(false);
     }
     return(other.Nature == UriTemplatePartType.Variable);
 }
 public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
 {
     if (other == null)
     {
         return false;
     }
     if (!ignoreTrailingSlash && (base.EndsWithSlash != other.EndsWithSlash))
     {
         return false;
     }
     return (other.Nature == UriTemplatePartType.Variable);
 }
 public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
 {
     if (other == null)
     {
         Fx.Assert("why would we ever call this?");
         return false;
     }
     if (!ignoreTrailingSlash && (this.EndsWithSlash != other.EndsWithSlash))
     {
         return false;
     }
     return (other.Nature == UriTemplatePartType.Variable);
 }
Ejemplo n.º 6
0
 public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
 {
     if (other == null)
     {
         Fx.Assert("why would we ever call this?");
         return(false);
     }
     if (!ignoreTrailingSlash && (this.EndsWithSlash != other.EndsWithSlash))
     {
         return(false);
     }
     return(other.Nature == UriTemplatePartType.Variable);
 }
        public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
        {
            if (other == null)
            {
                return(false);
            }
            if (other.Nature != UriTemplatePartType.Literal)
            {
                return(false);
            }
            UriTemplateLiteralPathSegment segment = other as UriTemplateLiteralPathSegment;

            return(this.IsMatch(segment, ignoreTrailingSlash));
        }
        public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
        {
            if (other == null)
            {
                Fx.Assert("why would we ever call this?");
                return(false);
            }
            if (other.Nature != UriTemplatePartType.Literal)
            {
                return(false);
            }
            UriTemplateLiteralPathSegment otherAsLiteral = other as UriTemplateLiteralPathSegment;

            Fx.Assert(otherAsLiteral != null, "The nature requires that this will be OK");
            return(IsMatch(otherAsLiteral, ignoreTrailingSlash));
        }
        public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash)
        {
            if (other == null)
            {
                Fx.Assert("why would we ever call this?");
                return(false);
            }
            if (!ignoreTrailingSlash && (this.EndsWithSlash != other.EndsWithSlash))
            {
                return(false);
            }
            UriTemplateCompoundPathSegment otherAsCompound = other as UriTemplateCompoundPathSegment;

            if (otherAsCompound == null)
            {
                // if other can't be cast as a compound then it can't be equivalent
                return(false);
            }
            if (this.varLitPairs.Count != otherAsCompound.varLitPairs.Count)
            {
                return(false);
            }
            if (StringComparer.OrdinalIgnoreCase.Compare(this.firstLiteral, otherAsCompound.firstLiteral) != 0)
            {
                return(false);
            }
            for (int pairIndex = 0; pairIndex < this.varLitPairs.Count; pairIndex++)
            {
                if (StringComparer.OrdinalIgnoreCase.Compare(this.varLitPairs[pairIndex].Literal,
                                                             otherAsCompound.varLitPairs[pairIndex].Literal) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
 public abstract bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash);
Ejemplo n.º 11
0
 public abstract bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash);
Ejemplo n.º 12
0
        static void Add(UriTemplateTrieNode root, KeyValuePair <UriTemplate, object> kvp)
        {
            // Currently UTT doesn't support teplates with ignoreTrailingSlash == true; thus we
            //  don't care about supporting it in the trie as well.
            UriTemplateTrieNode current    = root;
            UriTemplate         ut         = kvp.Key;
            bool needProcessingOnFinalNode = ((ut.segments.Count == 0) || ut.HasWildcard ||
                                              ut.segments[ut.segments.Count - 1].EndsWithSlash);

            for (int i = 0; i < ut.segments.Count; ++i)
            {
                if (i >= ut.firstOptionalSegment)
                {
                    current.endOfPath.Items.Add(kvp);
                }
                UriTemplatePathSegment ps = ut.segments[i];
                if (!ps.EndsWithSlash)
                {
                    Fx.Assert(i == ut.segments.Count - 1, "only the last segment can !EndsWithSlash");
                    Fx.Assert(!ut.HasWildcard, "path star cannot have !EndsWithSlash");
                    switch (ps.Nature)
                    {
                    case UriTemplatePartType.Literal:
                        current.AddFinalLiteralSegment(ps as UriTemplateLiteralPathSegment, kvp);
                        break;

                    case UriTemplatePartType.Compound:
                        current.AddFinalCompoundSegment(ps as UriTemplateCompoundPathSegment, kvp);
                        break;

                    case UriTemplatePartType.Variable:
                        current.finalVariableSegment.Items.Add(kvp);
                        break;

                    default:
                        Fx.Assert("Invalid value as PathSegment.Nature");
                        break;
                    }
                }
                else
                {
                    Fx.Assert(ps.EndsWithSlash, "ps.EndsWithSlash");
                    switch (ps.Nature)
                    {
                    case UriTemplatePartType.Literal:
                        current = current.AddNextLiteralSegment(ps as UriTemplateLiteralPathSegment);
                        break;

                    case UriTemplatePartType.Compound:
                        current = current.AddNextCompoundSegment(ps as UriTemplateCompoundPathSegment);
                        break;

                    case UriTemplatePartType.Variable:
                        current = current.AddNextVariableSegment();
                        break;

                    default:
                        Fx.Assert("Invalid value as PathSegment.Nature");
                        break;
                    }
                }
            }
            if (needProcessingOnFinalNode)
            {
                // if the last segment ended in a slash, there is still more to do
                if (ut.HasWildcard)
                {
                    // e.g. "path1/path2/*"
                    current.star.Items.Add(kvp);
                }
                else
                {
                    // e.g. "path1/path2/"
                    current.endOfPath.Items.Add(kvp);
                }
            }
        }