• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Routing.ODataPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ODataPath类属于System.Web.OData.Routing命名空间,在下文中一共展示了ODataPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 };
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:31,代码来源:ODataDeltaFeedSerializerTests.cs


示例2: SelectAction

 public string SelectAction(
     ODataPath odataPath,
     HttpControllerContext controllerContext,
     ILookup<string, HttpActionDescriptor> actionMap)
 {
     return null;
 }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:7,代码来源:MatchAllRoutingConvention.cs


示例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);
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:30,代码来源:CustomNavigationPropertyRoutingConvention.cs


示例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;
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:39,代码来源:RestierRoutingConvention.cs


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


示例6: PathTemplateWithOneUnboundFunctionPathSegment

        public void PathTemplateWithOneUnboundFunctionPathSegment()
        {
            // Arrange
            ODataPath path = new ODataPath(new UnboundFunctionPathSegment("TopFunction", null));

            // Act & Assert
            Assert.Equal("~/unboundfunction", path.PathTemplate);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataPathTest.cs


示例7: SelectController

        public string SelectController(ODataPath odataPath, HttpRequestMessage request)
        {
            if (odataPath != null && odataPath.PathTemplate == "~/$swagger")
            {
                return "Swagger";
            }

            return null;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:SwaggerRoutingConvention.cs


示例8: GetNavigationProperty

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

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


示例9: SelectAction

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

            return null;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:SwaggerRoutingConvention.cs


示例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();
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:DefaultODataPathHandler.cs


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


示例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;
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:14,代码来源:VersionedRoutingConvention.cs


示例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;
        }
开发者ID:arcelormittalkriviyrih,项目名称:odata_unified_svc,代码行数:16,代码来源:MediadataRoutingConvention.cs


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


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


示例16: ToStringWithNoSegments

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

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

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


示例17: ToStringWithOneSegment

        public void ToStringWithOneSegment()
        {
            // Arrange
            string expectedValue = "Set";
            ODataPath path = new ODataPath(new EntitySetPathSegment(expectedValue));

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

            // Assert
            Assert.Equal(expectedValue, value);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataPathTest.cs


示例18: 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", type: typeof(ODataEntityReferenceLinks),
                    messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext),
                "ODataEntityReferenceLinksSerializer cannot write an object of type 'System.String'.");
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataEntityReferenceLinksSerializerTest.cs


示例19: SelectController

 public override string SelectController(ODataPath odataPath, HttpRequestMessage request)
 {
     // We use always use the last naviation as the controller vs. the initial entityset
     if (odataPath.PathTemplate.Contains("~/entityset/key/navigation"))
     {
         // Find controller.  Controller should be last navigation property
         return ODataSegmentKinds.Navigation == odataPath.Segments[odataPath.Segments.Count - 1].SegmentKind
             ? odataPath.Segments[odataPath.Segments.Count - 1].ToString()
             : odataPath.Segments[odataPath.Segments.Count - 2].ToString();
     }
     return base.SelectController(odataPath, request);
 }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:12,代码来源:CustomNavigationPropertyRoutingConvention.cs


示例20: ToStringWithKeyValueSegment

        public void ToStringWithKeyValueSegment()
        {
            // Arrange
            string segment = "1";
            ODataPath path = new ODataPath(new KeyValuePathSegment(segment));

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

            // Assert
            string expectedValue = "(" + segment + ")";
            Assert.Equal(expectedValue, value);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:13,代码来源:ODataPathTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestCommon.CustomersModelWithInheritance类代码示例发布时间:2022-05-26
下一篇:
C# Serialization.SelectExpandNode类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap