本文整理匯總了C#中System.Web.OData.Routing.ODataPath類的典型用法代碼示例。如果您正苦於以下問題:C# ODataPath類的具體用法?C# ODataPath怎麽用?C# ODataPath使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ODataPath類屬於System.Web.OData.Routing命名空間,在下文中一共展示了ODataPath類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ODataDeltaFeedSerializerTests
public ODataDeltaFeedSerializerTests()
{
_model = SerializationTestsHelpers.SimpleCustomerOrderModel();
_customerSet = _model.EntityContainer.FindEntitySet("Customers");
_model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
_path = new ODataPath(new EntitySetPathSegment(_customerSet));
_customers = new[] {
new Customer()
{
FirstName = "Foo",
LastName = "Bar",
ID = 10,
},
new Customer()
{
FirstName = "Foo",
LastName = "Bar",
ID = 42,
}
};
_deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType());
newCustomer.TrySetPropertyValue("ID", 10);
newCustomer.TrySetPropertyValue("FirstName", "Foo");
_deltaFeedCustomers.Add(newCustomer);
_customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();
_writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path };
}
示例2: SelectAction
public string SelectAction(
ODataPath odataPath,
HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
return null;
}
示例3: SelectAction
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
var controllerType = controllerContext.ControllerDescriptor.ControllerType;
if (typeof(CustomersController) == controllerType)
{
if (odataPath.PathTemplate.Equals("~/entityset/key/navigation")) //POST OR GET
{
controllerContext.RouteData.Values["orderID"] = (odataPath.Segments[1] as KeyValuePathSegment).Value;
return controllerContext.Request.Method.ToString();
}
}
else if (typeof(OrdersController) == controllerType)
{
if (odataPath.PathTemplate.Equals("~/entityset/key/navigation")) //POST OR GET
{
controllerContext.RouteData.Values["customerID"] = (odataPath.Segments[1] as KeyValuePathSegment).Value;
return controllerContext.Request.Method.ToString();
}
if (odataPath.PathTemplate.Equals("~/entityset/key/navigation/key")) //PATCH OR DELETE
{
controllerContext.RouteData.Values["customerID"] = (odataPath.Segments[1] as KeyValuePathSegment).Value;
controllerContext.RouteData.Values["key"] = (odataPath.Segments[3] as KeyValuePathSegment).Value;
return controllerContext.Request.Method.ToString();
}
}
return base.SelectAction(odataPath, controllerContext, actionMap);
}
示例4: SelectAction
/// <summary>
/// Selects the appropriate action based on the parsed OData URI.
/// </summary>
/// <param name="odataPath">Parsed OData URI</param>
/// <param name="controllerContext">Context for HttpController</param>
/// <param name="actionMap">Mapping from action names to HttpActions</param>
/// <returns>String corresponding to controller action name</returns>
public string SelectAction(
ODataPath odataPath,
HttpControllerContext controllerContext,
ILookup<string, HttpActionDescriptor> actionMap)
{
// TODO GitHubIssue#44 : implement action selection for $ref, navigation scenarios, etc.
Ensure.NotNull(odataPath, "odataPath");
Ensure.NotNull(controllerContext, "controllerContext");
Ensure.NotNull(actionMap, "actionMap");
if (!(controllerContext.Controller is RestierController))
{
// RESTier cannot select action on controller which is not RestierController.
return null;
}
HttpMethod method = controllerContext.Request.Method;
if (method == HttpMethod.Get && !IsMetadataPath(odataPath))
{
return MethodNameOfGet;
}
ODataPathSegment lastSegment = odataPath.Segments.LastOrDefault();
if (lastSegment != null && lastSegment.SegmentKind == ODataSegmentKinds.UnboundAction)
{
return MethodNameOfPostAction;
}
// Let WebAPI select default action
return null;
}
示例5: SelectAction
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
var action = base.SelectAction(odataPath, controllerContext, actionMap);
if (action != null)
{
var routeValues = controllerContext.RouteData.Values;
if (routeValues.ContainsKey(ODataRouteConstants.Key))
{
var keyRaw = routeValues[ODataRouteConstants.Key] as string;
IEnumerable<string> compoundKeyPairs = keyRaw.Split(',');
if (compoundKeyPairs == null || !compoundKeyPairs.Any())
{
return action;
}
foreach (var compoundKeyPair in compoundKeyPairs)
{
string[] pair = compoundKeyPair.Split('=');
if (pair == null || pair.Length != 2)
{
continue;
}
var keyName = pair[0].Trim();
var keyValue = pair[1].Trim();
routeValues.Add(keyName, keyValue);
}
}
}
return action;
}
示例6: PathTemplateWithOneUnboundFunctionPathSegment
public void PathTemplateWithOneUnboundFunctionPathSegment()
{
// Arrange
ODataPath path = new ODataPath(new UnboundFunctionPathSegment("TopFunction", null));
// Act & Assert
Assert.Equal("~/unboundfunction", path.PathTemplate);
}
示例7: SelectController
public string SelectController(ODataPath odataPath, HttpRequestMessage request)
{
if (odataPath != null && odataPath.PathTemplate == "~/$swagger")
{
return "Swagger";
}
return null;
}
示例8: GetNavigationProperty
private static IEdmNavigationProperty GetNavigationProperty(ODataPath path)
{
if (path == null)
{
throw new SerializationException(SRResources.ODataPathMissing);
}
return path.GetNavigationProperty();
}
示例9: SelectAction
public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath != null && odataPath.PathTemplate == "~/$swagger")
{
return "GetSwagger";
}
return null;
}
示例10: Link
/// <summary>
/// Converts an instance of <see cref="ODataPath" /> into an OData link.
/// </summary>
/// <param name="path">The OData path to convert into a link.</param>
/// <returns>
/// The generated OData link.
/// </returns>
public virtual string Link(ODataPath path)
{
if (path == null)
{
throw Error.ArgumentNull("path");
}
return path.ToString();
}
示例11: SelectAction
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
string result = base.SelectAction(odataPath, controllerContext, actionMap);
IDictionary<string, object> conventionStore = controllerContext.Request.ODataProperties().RoutingConventionsStore;
if (result != null && conventionStore != null)
{
conventionStore["keyAsCustomer"] = new BindCustomer { Id = (int)controllerContext.RouteData.Values["key"] };
}
return result;
}
示例12: SelectController
/// <summary>
/// Returns the controller names with the version suffix.
/// For example: request from route V1 can be dispatched to ProductsV1Controller.
/// </summary>
public string SelectController(ODataPath odataPath, HttpRequestMessage request)
{
var baseControllerName = _innerRoutingConvention.SelectController(odataPath, request);
if (baseControllerName != null)
{
return string.Concat(baseControllerName, _versionSuffix);
}
return null;
}
示例13: SelectController
/// <summary>
/// Selects OData controller based on parsed OData URI
/// </summary>
/// <param name="odataPath">Parsed OData URI</param>
/// <param name="request">Incoming HttpRequest</param>
/// <returns>Prefix for controller name</returns>
public string SelectController(ODataPath odataPath, HttpRequestMessage request)
{
string result = null;
if (IsMediadataPath(odataPath))
{
result = "Restier";
}
return result;
}
示例14: AddLinkInfoToRouteData
private static void AddLinkInfoToRouteData(IHttpRouteData routeData, ODataPath odataPath)
{
KeyValuePathSegment keyValueSegment = odataPath.Segments.OfType<KeyValuePathSegment>().First();
routeData.Values[ODataRouteConstants.Key] = keyValueSegment.Value;
KeyValuePathSegment relatedKeySegment = odataPath.Segments.Last() as KeyValuePathSegment;
if (relatedKeySegment != null)
{
routeData.Values[ODataRouteConstants.RelatedKey] = relatedKeySegment.Value;
}
}
示例15: SelectAction
public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
{
if (odataPath == null)
{
throw new ArgumentNullException("odataPath");
}
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
if (actionMap == null)
{
throw new ArgumentNullException("actionMap");
}
HttpMethod requestMethod = controllerContext.Request.Method;
if (odataPath.PathTemplate == "~/entityset/key/navigation/$ref"
|| odataPath.PathTemplate == "~/entityset/key/cast/navigation/$ref"
|| odataPath.PathTemplate == "~/entityset/key/navigation/key/$ref"
|| odataPath.PathTemplate == "~/entityset/key/cast/navigation/key/$ref")
{
var actionName = string.Empty;
if ((requestMethod == HttpMethod.Post) || (requestMethod == HttpMethod.Put))
{
actionName += "CreateRefTo";
}
else if (requestMethod == HttpMethod.Delete)
{
actionName += "DeleteRefTo";
}
else
{
return null;
}
var navigationSegment = odataPath.Segments.OfType<NavigationPathSegment>().Last();
actionName += navigationSegment.NavigationPropertyName;
var castSegment = odataPath.Segments[2] as CastPathSegment;
if (castSegment != null)
{
var actionCastName = string.Format("{0}On{1}", actionName, castSegment.CastType.Name);
if (actionMap.Contains(actionCastName))
{
AddLinkInfoToRouteData(controllerContext.RouteData, odataPath);
return actionCastName;
}
}
if (actionMap.Contains(actionName))
{
AddLinkInfoToRouteData(controllerContext.RouteData, odataPath);
return actionName;
}
}
return null;
}