当前位置: 首页>>代码示例>>C#>>正文


C# ODataUriParser.ParsePath方法代码示例

本文整理汇总了C#中Microsoft.OData.Core.UriParser.ODataUriParser.ParsePath方法的典型用法代码示例。如果您正苦于以下问题:C# ODataUriParser.ParsePath方法的具体用法?C# ODataUriParser.ParsePath怎么用?C# ODataUriParser.ParsePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Core.UriParser.ODataUriParser的用法示例。


在下文中一共展示了ODataUriParser.ParsePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RouteAsync

        public async Task RouteAsync(RouteContext context)
        {
            var request = context.HttpContext.Request;

            Uri uri;
            PathString remaining;
            if (!request.Path.StartsWithSegments(PathString.FromUriComponent("/" + _routePrefix), out remaining))
            {
                // Fallback to other routes.
                return;
            }

            uri = new Uri(remaining.ToString(), UriKind.Relative);
            
            context.HttpContext.ODataProperties().Model = _model;
            var parser = new ODataUriParser(_model, uri);
            var path = parser.ParsePath();
            context.HttpContext.ODataProperties().NewPath = path;
            context.HttpContext.ODataProperties().Path =
                context.HttpContext.ODataPathHandler().Parse(_model, "http://service-root/", remaining.ToString());
            context.HttpContext.ODataProperties().IsValidODataRequest = true;

            await m.RouteAsync(context);
            context.IsHandled = true;
        }
开发者ID:emreolgun,项目名称:WebApi,代码行数:25,代码来源:ODataRoute.cs

示例2: PathNavigation

        public void PathNavigation()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Customers(5)/Orders"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("CustoMERS(5)/OrDErs");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例3: PathComplex

        public void PathComplex()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Customers(-32)/HomeAddress"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("CustomErs(-32)/HOMEAddress");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例4: PathBatch

        public void PathBatch()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/$batch"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("$BATch");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例5: PathEntity

        public void PathEntity()
        {
            ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/Orders(2)"));
            var result = parser.ParsePath();
            ApprovalVerify(QueryNodeToStringVisitor.ToString(result));

            this.TestExtensions("OrDERS(2)");
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:8,代码来源:PathTests.cs

示例6: KeyAfterFunction

        private static void KeyAfterFunction()
        {
            Console.WriteLine("TestKeyAfterFunction");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/People(2)/TestNS.GetFriends(2)"));

            var path=parser.ParsePath();
            Console.WriteLine(path.ToLogString());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:11,代码来源:Program.cs

示例7: KeyContainingSpecialChar

        private static void KeyContainingSpecialChar()
        {
            Console.WriteLine("KeyContainingSpecialChar");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/Resources('w%23j')"));

            var path = parser.ParsePath();
            Console.WriteLine(path.ToLogString());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:11,代码来源:Program.cs

示例8: ParseUri

        /// <summary>
        /// Parses the specified URI and wraps the results in a QueryContext.
        /// </summary>
        /// <param name="requestUri">The URI to parse.</param>
        /// <param name="model">The data store model.</param>
        /// <returns>The parsed URI wrapped in a QueryContext.</returns>
        public static QueryContext ParseUri(Uri requestUri, IEdmModel model)
        {
            var requestUriParts = requestUri.OriginalString.Split('?');
            var queryPath = requestUriParts.First();
            if (requestUriParts.Count() > 1)
            {
                throw new NotSupportedException("Query option is not supported by the service yet.");
            }

            ODataUriParser uriParser = new ODataUriParser(model, ServiceConstants.ServiceBaseUri, new Uri(queryPath, UriKind.Absolute));
            return new QueryContext { QueryPath = uriParser.ParsePath() };
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:18,代码来源:QueryContext.cs

示例9: ParseKeyTemplateWithTemplateParserWithWithWhitespaceOutsideofTempateExpressionTest

        public void ParseKeyTemplateWithTemplateParserWithWithWhitespaceOutsideofTempateExpressionTest()
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("People(  {1} )", UriKind.Relative))
            {
                EnableUriTemplateParsing = true
            };

            var path = uriParser.ParsePath();
            var keySegment = path.LastSegment.As<KeySegment>();
            KeyValuePair<string, object> keypair = keySegment.Keys.Single();
            keypair.Key.Should().Be("ID");
            keypair.Value.As<UriTemplateExpression>().ShouldBeEquivalentTo(new UriTemplateExpression { LiteralText = "{1}", ExpectedType = keySegment.EdmType.As<IEdmEntityType>().DeclaredKey.Single().Type });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:UriTemplateParserTests.cs

示例10: PathBaseSingletonWithKeyShouldFail

 public void PathBaseSingletonWithKeyShouldFail()
 {
     ODataUriParser parser = new ODataUriParser(model, new Uri("http://www.potato.com/"), new Uri("http://www.potato.com/SpecialOrder(1)"));
     try
     {
         parser.ParsePath();
     }
     catch (ODataException e)
     {
         var expected = ODataExpectedExceptions.ODataException("RequestUriProcessor_SyntaxError");
         expected.ExpectedMessage.Verifier.VerifyMatch("RequestUriProcessor_SyntaxError", e.Message);
     }
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:SingletonPathTest.cs

示例11: ParseKeyTemplateAsSegmentWithTemplateParser

        public void ParseKeyTemplateAsSegmentWithTemplateParser()
        {
            var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://host"), new Uri("http://host/People/{1}"))
            {
                EnableUriTemplateParsing = true,
                UrlConventions = ODataUrlConventions.KeyAsSegment
            };

            var path = uriParser.ParsePath();
            var keySegment = path.LastSegment.As<KeySegment>();
            KeyValuePair<string, object> keypair = keySegment.Keys.Single();
            keypair.Key.Should().Be("ID");
            keypair.Value.As<UriTemplateExpression>().ShouldBeEquivalentTo(new UriTemplateExpression { LiteralText = "{1}", ExpectedType = keySegment.EdmType.As<IEdmEntityType>().DeclaredKey.Single().Type });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:14,代码来源:UriTemplateParserTests.cs

示例12: NoneQueryOptionShouldWork

 public void NoneQueryOptionShouldWork()
 {
     var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, FullUri);
     var path = uriParser.ParsePath();
     path.Should().HaveCount(1);
     path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
     uriParser.ParseFilter().Should().BeNull();
     uriParser.ParseSelectAndExpand().Should().BeNull();
     uriParser.ParseOrderBy().Should().BeNull();
     uriParser.ParseTop().Should().Be(null);
     uriParser.ParseSkip().Should().Be(null);
     uriParser.ParseCount().Should().Be(null);
     uriParser.ParseSearch().Should().BeNull();
     uriParser.ParseSkipToken().Should().BeNull();
     uriParser.ParseDeltaToken().Should().BeNull();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:16,代码来源:ODataUriParserTests.cs

示例13: TestCaseInsensitive

        private static void TestCaseInsensitive()
        {
            Console.WriteLine("TestCaseInsensitive");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/People(1)/Pets/TestNS.Fish?$orderby=Color"));

            var path = parser.ParsePath();
            var clause = parser.ParseOrderBy();
            Console.WriteLine(path.ToLogString());
            Console.WriteLine(clause.Expression.ToLogString());

            var parser2 = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/people(1)/pets/testns.fish?$ORDERBY=color"))
            {
                Resolver = new ODataUriResolver { EnableCaseInsensitive = true }
            };

            // Identical to path and clause
            var path2 = parser2.ParsePath();
            var clause2 = parser2.ParseOrderBy();
            Console.WriteLine(path2.ToLogString());
            Console.WriteLine(clause2.Expression.ToLogString());

            // Query option parser also supports custom resolver
            var parser3 = new ODataQueryOptionParser(
                extModel.Model,
                extModel.Fish,
                extModel.PetSet,
                new Dictionary<string, string>
                {
                    {"$orderby", "color"}
                })
            {
                Resolver = new ODataUriResolver { EnableCaseInsensitive = true }
            };
            var clause3 = parser3.ParseOrderBy();
            Console.WriteLine(clause3.Expression.ToLogString());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:42,代码来源:Program.cs

示例14: EmptyValueQueryOptionShouldWork

 public void EmptyValueQueryOptionShouldWork()
 {
     var uriParser = new ODataUriParser(HardCodedTestModel.TestModel, ServiceRoot, new Uri(FullUri, "?$filter=&$select=&$expand=&$orderby=&$top=&$skip=&$count=&$search=&$unknow=&$unknowvalue&$skiptoken=&$deltatoken="));
     var path = uriParser.ParsePath();
     path.Should().HaveCount(1);
     path.LastSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetPeopleSet());
     uriParser.ParseFilter().Should().BeNull();
     var results = uriParser.ParseSelectAndExpand();
     results.AllSelected.Should().BeTrue();
     results.SelectedItems.Should().HaveCount(0);
     uriParser.ParseOrderBy().Should().BeNull();
     Action action = () => uriParser.ParseTop();
     action.ShouldThrow<ODataException>().WithMessage(Strings.SyntacticTree_InvalidTopQueryOptionValue(""));
     action = () => uriParser.ParseSkip();
     action.ShouldThrow<ODataException>().WithMessage(Strings.SyntacticTree_InvalidSkipQueryOptionValue(""));
     action = () => uriParser.ParseCount();
     action.ShouldThrow<ODataException>().WithMessage(Strings.ODataUriParser_InvalidCount(""));
     action = () => uriParser.ParseSearch();
     action.ShouldThrow<ODataException>().WithMessage(Strings.UriQueryExpressionParser_ExpressionExpected(0, ""));
     uriParser.ParseSkipToken().Should().BeEmpty();
     uriParser.ParseDeltaToken().Should().BeEmpty();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:22,代码来源:ODataUriParserTests.cs

示例15: TestUnqualified

        private static void TestUnqualified()
        {
            Console.WriteLine("TestUnqualified");
            var parser = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/People(1)/Addr/TestNS.GetZip"));

            var path = parser.ParsePath();
            Console.WriteLine(path.ToLogString());

            var parser2 = new ODataUriParser(
                extModel.Model,
                ServiceRoot,
                new Uri("http://demo/odata.svc/People(1)/addr/getzip"))
            {
                Resolver = new UnqualifiedODataUriResolver { EnableCaseInsensitive = true }
            };

            // Identical to path
            var path2 = parser2.ParsePath();
            Console.WriteLine(path2.ToLogString());
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:23,代码来源:Program.cs


注:本文中的Microsoft.OData.Core.UriParser.ODataUriParser.ParsePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。