本文整理汇总了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;
}
示例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");
}
示例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");
}
示例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");
}
示例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)");
}
示例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());
}
示例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());
}
示例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() };
}
示例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 });
}
示例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);
}
}
示例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 });
}
示例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();
}
示例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());
}
示例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();
}
示例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());
}