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


C# Routing.ODataPath类代码示例

本文整理汇总了C#中System.Web.Http.OData.Routing.ODataPath的典型用法代码示例。如果您正苦于以下问题:C# ODataPath类的具体用法?C# ODataPath怎么用?C# ODataPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ODataPath类属于System.Web.Http.OData.Routing命名空间,在下文中一共展示了ODataPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
        }
开发者ID:gitter-badger,项目名称:WealthEconomy,代码行数:32,代码来源:CompositeKeyRoutingConvention.cs

示例2: SelectController

 public string SelectController(ODataPath odataPath, HttpRequestMessage request)
 {
     var controller = delegateRoutingConvention.SelectController(odataPath, request);
     return string.Equals(controller, controllerAlias, StringComparison.OrdinalIgnoreCase)
         ? targetControllerName
         : controller;
 }
开发者ID:Pliner,项目名称:TinyFeed,代码行数:7,代码来源:ControllerAliasingODataRoutingConvention.cs

示例3: SelectAction

        public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
        {
            if (odataPath.PathTemplate != "~/entityset/key/property")
            {
                return null;
            }

            var entitySetPathSegment = odataPath.Segments.OfType<EntitySetPathSegment>().Single();
            var keyValuePathSegment = odataPath.Segments.OfType<KeyValuePathSegment>().Single();
            var propertyAccessPathSegment = odataPath.Segments.OfType<PropertyAccessPathSegment>().Single();

            var actionName = string.Format(CultureInfo.InvariantCulture, "GetPropertyFrom{0}", entitySetPathSegment.EntitySetName);

            if (actionMap.Contains(actionName) && actionMap[actionName].Any(desc => MatchHttpMethod(desc, controllerContext.Request.Method)))
            {
                controllerContext.RouteData.Values.Add("propertyName", propertyAccessPathSegment.PropertyName);

                if (!CompositeODataKeyHelper.TryEnrichRouteValues(keyValuePathSegment.Value, controllerContext.RouteData.Values))
                {
                    controllerContext.RouteData.Values.Add("key", keyValuePathSegment.Value);
                }

                return actionName;
            }

            return null;
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:27,代码来源:EntitySetPropertyRoutingConvention.cs

示例4: SelectAction

        public override string SelectAction(ODataPath odataPath, HttpControllerContext context,
            ILookup<string, HttpActionDescriptor> actionMap)
        {
            if (context.Request.Method == HttpMethod.Get &&
                odataPath.PathTemplate == "~/entityset/key/navigation/key")
            {
                NavigationPathSegment navigationSegment = odataPath.Segments[2] as NavigationPathSegment;
                IEdmNavigationProperty navigationProperty = navigationSegment.NavigationProperty.Partner;
                IEdmEntityType declaringType = navigationProperty.DeclaringType as IEdmEntityType;

                string actionName = "Get" + declaringType.Name;
                if (actionMap.Contains(actionName))
                {
                    // Add keys to route data, so they will bind to action parameters.
                    KeyValuePathSegment keyValueSegment = odataPath.Segments[1] as KeyValuePathSegment;
                    context.RouteData.Values[ODataRouteConstants.Key] = keyValueSegment.Value;

                    KeyValuePathSegment relatedKeySegment = odataPath.Segments[3] as KeyValuePathSegment;
                    context.RouteData.Values[ODataRouteConstants.RelatedKey] = relatedKeySegment.Value;

                    return actionName;
                }
            }
            // Not a match.
            return null;
        }
开发者ID:webdev2,项目名称:NajranService,代码行数:26,代码来源:ODataConventions.cs

示例5: SelectController

 public string SelectController(ODataPath odataPath, HttpRequestMessage request)
 {
     if (odataPath.PathTemplate == "~/action/$count")
     {
         return controllerName;
     }
     return null;
 }
开发者ID:battenworks,项目名称:NuGet.Lucene,代码行数:8,代码来源:NonBindableActionCountRoutingConvention.cs

示例6: SelectController

 public string SelectController(ODataPath odataPath, HttpRequestMessage request)
 {
     if (odataPath.PathTemplate == "~/entityset/key/property")
     {
         return _controllerName;
     }
     return null;
 }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:8,代码来源:EntitySetPropertyRoutingConvention.cs

示例7: SelectController

 // Route all non-bindable actions to a single controller.
 public string SelectController(ODataPath odataPath, System.Net.Http.HttpRequestMessage request)
 {
     if (odataPath.PathTemplate == "~/action")
     {
         return _controllerName;
     }
     return null;
 }
开发者ID:ErikWitkowski,项目名称:Simple.OData.Client,代码行数:9,代码来源:NonBindableActionRoutingConvention.cs

示例8: SelectAction

        public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
        {
            if (controllerContext.Request.Method != HttpMethod.Get || odataPath.PathTemplate != "~/entityset/$count")
            {
                return null;
            }

            return actionMap.Contains("GetCount") ? "GetCount" : null;
        }
开发者ID:battenworks,项目名称:NuGet.Lucene,代码行数:9,代码来源:EntitySetCountRoutingConvention.cs

示例9: GetNavigationProperty

        private static IEdmNavigationProperty GetNavigationProperty(ODataPath path)
        {
            if (path == null)
            {
                throw new SerializationException(SRResources.ODataPathMissing);
            }

            return path.GetNavigationProperty();
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:9,代码来源:ODataEntityReferenceLinkDeserializer.cs

示例10: 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.Parse((string)controllerContext.RouteData.Values["key"]) };
     }
     return result;
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:10,代码来源:ODataValueProviderTests.cs

示例11: 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;
     }
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:10,代码来源:LinkRoutingConvention2.cs

示例12: 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/$links/navigation" 
                || odataPath.PathTemplate == "~/entityset/key/cast/$links/navigation"
                || odataPath.PathTemplate == "~/entityset/key/$links/navigation/key"
                || odataPath.PathTemplate == "~/entityset/key/cast/$links/navigation/key")
            {
                var actionName = string.Empty;
                if ((requestMethod == HttpMethod.Post) || (requestMethod == HttpMethod.Put))
                {
                    actionName += "CreateLinkTo";
                }
                else if (requestMethod == HttpMethod.Delete)
                {
                    actionName += "DeleteLinkTo";
                }
                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;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:55,代码来源:LinkRoutingConvention2.cs

示例13: WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri

        public void WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri()
        {
            IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First();
            ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer();
            ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty));
            ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path };

            Assert.Throws<SerializationException>(
                () => serializer.WriteObject(graph: "not uri", messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "ODataEntityReferenceLinksSerializer cannot write an object of type 'System.String'.");
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:11,代码来源:ODataEntityReferenceLinksSerializerTest.cs

示例14: SelectAction

        public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap)
        {
            var action = base.SelectAction(odataPath, controllerContext, actionMap);

            if (action != null)
            {
                controllerContext.RouteData.DecomposeKey();
            }

            return action;
        }
开发者ID:battenworks,项目名称:NuGet.Lucene,代码行数:11,代码来源:CompositeKeyPropertyRoutingConvention.cs

示例15: ToStringWithNoSegments

        public void ToStringWithNoSegments()
        {
            // Arrange
            ODataPath path = new ODataPath();

            // Act
            string value = path.ToString();

            // Assert
            Assert.Empty(value);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:11,代码来源:ODataPathTest.cs


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