Ejemplo n.º 1
0
    private void ParseEntries(JObject input, List <RouteEntry> entries)
    {
        var basePath = "";

        if (input["basePath"] is JProperty basePathProperty)
        {
            basePath = basePathProperty.Value <string>();
        }

        if (input["paths"] is JObject paths)
        {
            foreach (var path in paths.Properties())
            {
                foreach (var method in ((JObject)path.Value).Properties())
                {
                    var template = basePath + path.Name;
                    var parsed   = TemplateParser.Parse(template);
                    entries.Add(new RouteEntry()
                    {
                        Method     = HttpMethods.HasValue() ? method.Name.ToString() : null,
                        Template   = parsed,
                        Precedence = RoutePrecedence.ComputeInbound(parsed),
                    });
                }
            }
        }
    }
Ejemplo n.º 2
0
    private bool IsDuplicateTemplate(RouteEntry entry, List <RouteEntry> others)
    {
        for (var j = 0; j < others.Count; j++)
        {
            // This is another route with the same precedence. It is guaranteed to have the same number of segments
            // of the same kinds and in the same order. We just need to check the literals.
            var other = others[j];

            var isSame = true;
            for (var k = 0; k < entry.Template.Segments.Count; k++)
            {
                if (!string.Equals(
                        entry.Template.Segments[k].Parts[0].Text,
                        other.Template.Segments[k].Parts[0].Text,
                        StringComparison.OrdinalIgnoreCase))
                {
                    isSame = false;
                    break;
                }

                if (HttpMethods.HasValue() &&
                    !string.Equals(entry.Method, other.Method, StringComparison.OrdinalIgnoreCase))
                {
                    isSame = false;
                    break;
                }
            }

            if (isSame)
            {
                return(true);
            }
        }

        return(false);
    }