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

C# HttpControllerDescriptor类代码示例

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

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



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

示例1: ShouldExploreController_MatchesRouteConstraint

        public void ShouldExploreController_MatchesRouteConstraint(bool match)
        {
            // Arrange
            var config = new HttpConfiguration();
            var ctrlDesc = new HttpControllerDescriptor(config, "sample", typeof(SampleController));
            var explorer = new MobileAppApiExplorer(config);

            var constraintMock = new Mock<IHttpRouteConstraint>();
            var constraint = constraintMock.Object;

            var routeMock = new Mock<IHttpRoute>();
            routeMock.Setup(r => r.Constraints);
            var route = routeMock.Object;

            constraintMock.Setup(c => c.Match(null, route, "controller", It.IsAny<IDictionary<string, object>>(), HttpRouteDirection.UriResolution))
                .Returns(match)
                .Callback<HttpRequestMessage, IHttpRoute, string, IDictionary<string, object>, HttpRouteDirection>((req, rt, p, cnts, rd) =>
                {
                    Assert.Equal("sample", cnts["controller"]);
                });
            routeMock.Setup(r => r.Constraints)
                .Returns(new Dictionary<string, object> { { "controller", constraint } });

            // Act
            bool actual = explorer.ShouldExploreController("sample", ctrlDesc, route);

            // Assert
            Assert.Equal(match, actual);
        }
开发者ID:RossMerr,项目名称:azure-mobile-apps-net-server,代码行数:29,代码来源:MobileAppApiExplorerTests.cs


示例2: Setting_CustomActionSelector

        public void Setting_CustomActionSelector()
        {
            // Arrange
            ApiController api = new UsersController();
            HttpControllerContext controllerContext = ContextUtil.CreateControllerContext();

            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(controllerContext.Configuration, "test", typeof(UsersController));
            controllerContext.ControllerDescriptor = controllerDescriptor;

            Mock<IHttpActionSelector> mockSelector = new Mock<IHttpActionSelector>();
            mockSelector
                .Setup(invoker => invoker.SelectAction(It.IsAny<HttpControllerContext>()))
                .Returns(() =>
                {
                    Func<HttpResponseMessage> testDelegate =
                        () => new HttpResponseMessage { Content = new StringContent("This is a test") };
                    return new ReflectedHttpActionDescriptor
                    {
                        Configuration = controllerContext.Configuration,
                        ControllerDescriptor = controllerDescriptor,
                        MethodInfo = testDelegate.Method
                    };
                });
            controllerDescriptor.Configuration.Services.Replace(typeof(IHttpActionSelector), mockSelector.Object);

            // Act
            HttpResponseMessage message = api.ExecuteAsync(
                controllerContext,
                CancellationToken.None).Result;

            // Assert
            Assert.Equal("This is a test", message.Content.ReadAsStringAsync().Result);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:33,代码来源:ApiControllerTest.cs


示例3: Initialize

 public virtual void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor) {
     var toRemove = settings.Formatters.Where(t => t is JsonMediaTypeFormatter || t is XmlMediaTypeFormatter).ToList();
     foreach (var r in toRemove) {
         settings.Formatters.Remove(r);
     }
     settings.Formatters.Add(new SkybrudJsonMediaTypeFormatter());
 }
开发者ID:pjengaard,项目名称:Skybrud.WebApi.Json,代码行数:7,代码来源:JsonOnlyConfigurationAttribute.cs


示例4: GetDescription

 public static DataControllerDescription GetDescription(HttpControllerDescriptor controllerDescriptor)
 {
     return _descriptionMap.GetOrAdd(controllerDescriptor.ControllerType, type =>
     {
         return CreateDescription(controllerDescriptor);
     });
 }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:7,代码来源:DataControllerDescription.cs


示例5: SelectAction_With_DifferentExecutionContexts

        public void SelectAction_With_DifferentExecutionContexts()
        {
            ApiControllerActionSelector actionSelector = new ApiControllerActionSelector();
            HttpControllerContext GetContext = ContextUtil.CreateControllerContext();
            HttpControllerDescriptor usersControllerDescriptor = new HttpControllerDescriptor(GetContext.Configuration, "Users", typeof(UsersController));
            usersControllerDescriptor.Configuration.Services.Replace(typeof(IHttpActionSelector), actionSelector);
            GetContext.ControllerDescriptor = usersControllerDescriptor;
            GetContext.Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get
                };
            HttpControllerContext PostContext = ContextUtil.CreateControllerContext();
            usersControllerDescriptor.Configuration.Services.Replace(typeof(IHttpActionSelector), actionSelector);
            PostContext.ControllerDescriptor = usersControllerDescriptor;
            PostContext.Request = new HttpRequestMessage
            {
                Method = HttpMethod.Post
            };

            HttpActionDescriptor getActionDescriptor = actionSelector.SelectAction(GetContext);
            HttpActionDescriptor postActionDescriptor = actionSelector.SelectAction(PostContext);

            Assert.Equal("Get", getActionDescriptor.ActionName);
            Assert.Equal("Post", postActionDescriptor.ActionName);
        }
开发者ID:RhysC,项目名称:aspnetwebstack,代码行数:25,代码来源:ApiControllerActionSelectorTest.cs


示例6: MultipleRoutesForSameMethodException

 IReadOnlyList<RouteEntry> IDirectRouteProvider.GetDirectRoutes(HttpControllerDescriptor controllerDescriptor, IReadOnlyList<HttpActionDescriptor> actionDescriptors,
     IInlineConstraintResolver constraintResolver)
 {
     var routes = _provider.GetDirectRoutes(controllerDescriptor, actionDescriptors, constraintResolver);
     var list = new List<RouteEntry>();
     foreach (var route in routes)
     {
         var newRoute = new RouteEntry(route.Name ?? Guid.NewGuid().ToString(), route.Route);
         list.Add(newRoute);
         var descs = route.Route.GetTargetActionDescriptors();
         if (descs.Length == 0)
         {
             continue;
         }
         foreach (var desc in descs)
         {
             var reflDesc = desc as ReflectedHttpActionDescriptor;
             if (reflDesc == null)
             {
                 continue;
             }
             var method = reflDesc.MethodInfo;
             RouteEntry prevEntry;
             if (_map.TryGetValue(method, out prevEntry))
             {
                 throw new MultipleRoutesForSameMethodException(reflDesc, prevEntry, newRoute);
             }
             _map.Add(method, newRoute);
         }
     }
     return list;
 }
开发者ID:modulexcite,项目名称:drum,代码行数:32,代码来源:DecoratorRouteProvider.cs


示例7: Initialize

		/// <summary>
		/// Callback invoked to set per-controller overrides for this controllerDescriptor.
		/// </summary>
		/// <param name="controllerSettings">The controller settings to initialize.</param>
		/// <param name="controllerDescriptor">The controller descriptor. Note that the <see
		/// cref="T:System.Web.Http.Controllers.HttpControllerDescriptor" /> can be associated with the derived
		/// controller type given that <see cref="T:System.Web.Http.Controllers.IControllerConfiguration" /> is
		/// inherited.</param>
		public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
		{
			if (controllerSettings == null)
			{
				throw new ArgumentNullException("controllerSettings");
			}

			if (controllerDescriptor == null)
			{
				throw new ArgumentNullException("controllerDescriptor");
			}

			ServicesContainer services = controllerSettings.Services;
			Contract.Assert(services != null);

			IContainerMetadata containerMetadata = controllerDescriptor.GetContainerMetadata();

			// Replace the action selector with one that is based on the OData routing conventions
			IHttpActionSelector originalActionSelector = services.GetActionSelector();
			IHttpActionSelector actionSelector;
			if (containerMetadata != null)
			{
				// ContainerMetadata was stored with the HttpControllerDescriptor - so use our "special" ActionSelector
				actionSelector = new EntityRepositoryActionSelector(containerMetadata, originalActionSelector);
			}
			else
			{
				// No ContainerMetadata stored with the HttpControllerDescriptor - so use the standard odata ActionSelector
				actionSelector = new ODataActionSelector(originalActionSelector);
			}
			controllerSettings.Services.Replace(typeof(IHttpActionSelector), actionSelector);
		}
开发者ID:mdabbagh88,项目名称:ODataServer,代码行数:40,代码来源:UseEntityRepositoryActionSelectorAttribute.cs


示例8: SelectController

        /// <summary>
        /// This method is called by Web API system to select the controller for this request.
        /// </summary>
        /// <param name="request">Request object</param>
        /// <returns>The controller to be used</returns>
        public override HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            if (request != null)
            {
                var routeData = request.GetRouteData();
                if (routeData != null)
                {
                    string serviceName;
                    if (routeData.Values.TryGetValue("serviceName", out serviceName))
                    {
                        string areaName;
                        if (routeData.Values.TryGetValue("areaName", out areaName))
                        {
                            var controllerName = areaName.ToPascalCase() + "/" + serviceName.ToPascalCase();

                            var controllerInfo = DynamicApiControllerManager.Find(controllerName);
                            if (controllerInfo != null)
                            {
                                var controllerDescriptor = new HttpControllerDescriptor(_configuration, controllerInfo.Name, controllerInfo.Type);
                                controllerDescriptor.Properties["__AbpDynamicApiControllerInfo"] = controllerInfo;
                                return controllerDescriptor;
                            }
                        }
                    }
                }
            }

            return base.SelectController(request);
        }
开发者ID:khachatur,项目名称:aspnetboilerplate,代码行数:34,代码来源:AbpHttpControllerSelector.cs


示例9: HttpControllerTracer

        IHttpController IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            IHttpController controller = null;

            _traceWriter.TraceBeginEnd(
                request,
                TraceCategories.ControllersCategory,
                TraceLevel.Info,
                _innerActivator.GetType().Name,
                CreateMethodName,
                beginTrace: null,
                execute: () =>
                {
                    controller = _innerActivator.Create(request, controllerDescriptor, controllerType);
                },
                endTrace: (tr) =>
                {
                    tr.Message = controller == null ? SRResources.TraceNoneObjectMessage : controller.GetType().FullName;
                },
                errorTrace: null);

            if (controller != null && !(controller is HttpControllerTracer))
            {
                controller = new HttpControllerTracer(request, controller, _traceWriter);
            }

            return controller;
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:28,代码来源:HttpControllerActivatorTracer.cs


示例10: SelectAction_WithDirectRoutes_RespectsRouteOrder

        public void SelectAction_WithDirectRoutes_RespectsRouteOrder()
        {
            // Arrange
            var actionSelector = new ApiControllerActionSelector();
            HttpControllerContext context = ContextUtil.CreateControllerContext();
            context.Request = new HttpRequestMessage { Method = HttpMethod.Get };
            var controllerDescriptor = new HttpControllerDescriptor(context.Configuration, "MultipleGet", typeof(MultipleGetController));
            context.ControllerDescriptor = controllerDescriptor;
            ReflectedHttpActionDescriptor firstDirectRouteAction = (ReflectedHttpActionDescriptor)actionSelector.GetActionMapping(controllerDescriptor)["GetA"].Single();
            HttpRouteData[] subRouteData = new HttpRouteData[2];
            subRouteData[0] = new HttpRouteData(new HttpRoute());
            subRouteData[1] = new HttpRouteData(new HttpRoute());
            context.RouteData.Values.Add(RouteCollectionRoute.SubRouteDataKey, subRouteData);
            subRouteData[0].Route.DataTokens.Add("actions", new ReflectedHttpActionDescriptor[] { firstDirectRouteAction });
            subRouteData[0].Route.DataTokens.Add("order", 1);
            ReflectedHttpActionDescriptor secondDirectRouteAction = (ReflectedHttpActionDescriptor)actionSelector.GetActionMapping(controllerDescriptor)["GetB"].Single();
            subRouteData[1].Route.DataTokens.Add("actions", new ReflectedHttpActionDescriptor[] { secondDirectRouteAction });
            subRouteData[1].Route.DataTokens.Add("order", 2);

            // Act
            HttpActionDescriptor actionDescriptor = actionSelector.SelectAction(context);

            // Assert
            Assert.Same(secondDirectRouteAction, actionDescriptor);
        }
开发者ID:khorchani,项目名称:aspnetwebstack,代码行数:25,代码来源:ApiControllerActionSelectorTest.cs


示例11: GetActionMapping

        public override ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor)
        {
            if(controllerDescriptor.ControllerType == typeof(SlimApiGhostController)) {
            var newActions = new List<HttpActionDescriptor>();
            foreach(var contrInfo in _apiConfig.ControllerInfos) {
              var methods = contrInfo.Type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
              foreach(var method in methods) {
            var dtype = method.DeclaringType;
            if (dtype == typeof(object)) //skip ToString()
              continue;
            var action = new SlimApiActionDescriptor(controllerDescriptor, method, contrInfo, _apiConfig);
            if (action.RouteTemplates.Count > 0 && action.SupportedHttpMethods.Count > 0) {
              RegisterAction(action);
              newActions.Add(action);

            }
              }
            } //foreach ct

            var lkp = newActions.ToLookup(a => a.ActionName, StringComparer.OrdinalIgnoreCase);
            return lkp;
              }
              // otherwise call base
              return base.GetActionMapping(controllerDescriptor);
        }
开发者ID:yuanfei05,项目名称:vita,代码行数:25,代码来源:SlimApiActionSelector.cs


示例12: HttpControllerContext

        /// <summary>Initializes a new instance of the <see cref="HttpControllerContext"/> class.</summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="request">The HTTP request.</param>
        /// <param name="controllerDescriptor">The controller descriptor.</param>
        /// <param name="controller">The controller.</param>
        public HttpControllerContext(HttpRequestContext requestContext, HttpRequestMessage request,
            HttpControllerDescriptor controllerDescriptor, IHttpController controller)
        {
            if (requestContext == null)
            {
                throw Error.ArgumentNull("requestContext");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (controllerDescriptor == null)
            {
                throw Error.ArgumentNull("controllerDescriptor");
            }

            if (controller == null)
            {
                throw Error.ArgumentNull("controller");
            }

            _requestContext = requestContext;
            _request = request;
            _controllerDescriptor = controllerDescriptor;
            _controller = controller;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:33,代码来源:HttpControllerContext.cs


示例13: GetDocumentation

 /// <summary>
 /// Gets the documentation based on <see cref="System.Web.Http.Controllers.HttpControllerDescriptor"/>.
 /// </summary>
 /// <param name="controllerDescriptor">The controller descriptor.</param>
 /// <returns>The documentation for the controller.</returns>
 public string GetDocumentation(HttpControllerDescriptor controllerDescriptor)
 {
     return this.sources
         .Select(source => source.GetDocumentation(controllerDescriptor))
         .Where(documentation => !string.IsNullOrEmpty(documentation))
         .FirstOrDefault();
 }
开发者ID:XopcT,项目名称:LocalizedHelpPage,代码行数:12,代码来源:MultipleSourceDocumentationProvider.cs


示例14: Initialize

 public void Initialize(HttpControllerSettings controllerSettings,
                         HttpControllerDescriptor controllerDescriptor)
 {
     controllerSettings.ParameterBindingRules.Insert(0,
         new Func<HttpParameterDescriptor, HttpParameterBinding>(
             d => new SimplePostVariableParameterBinding(d)));
 }
开发者ID:dahlbyk,项目名称:AspNetPersonaId,代码行数:7,代码来源:SimplePostVariableParameterBindingAttribute.cs


示例15: Create

 public IHttpController Create(HttpRequestMessage request
     , HttpControllerDescriptor controllerDescriptor, Type controllerType)
 {
     var controller = _container.GetInstance(controllerType) as IHttpController; 
     
     return controller;
 }
开发者ID:jenspettersson,项目名称:Mediocr,代码行数:7,代码来源:Global.asax.cs


示例16: Create

 public IHttpController Create(System.Net.Http.HttpRequestMessage request,
     HttpControllerDescriptor controllerDescriptor,
     Type controllerType)
 {
     return System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver
         .GetService(controllerType) as IHttpController;
 }
开发者ID:rsahoo-git,项目名称:SignalR-Samples,代码行数:7,代码来源:NinjectWebApiDependencyResolver.cs


示例17: Configure

        /// <inheritdoc />
        public void Configure(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
        {
            if (controllerSettings == null)
            {
                throw new ArgumentNullException("controllerSettings");
            }

            if (controllerDescriptor == null)
            {
                throw new ArgumentNullException("controllerDescriptor");
            }

            // We need to remove the xml formatter because it cannot handle the wrapped
            // results this controller produces for inline count, etc.
            controllerSettings.Formatters.Remove(controllerSettings.Formatters.XmlFormatter);

            // Add additional query related filters for the same actions with a QueryableAttribute
            // The Filter Provider ensures that the additional filters are always *after* the query filter as we
            // want the IQueryable to have been set up before we do additional work on it.
            controllerSettings.Services.Add(typeof(IFilterProvider), new TableFilterProvider());

            // Register a ContractResolver with the JSON formatter that can handle Delta<T> correctly
            JsonMediaTypeFormatter jsonFormatter = controllerSettings.Formatters.JsonFormatter;
            jsonFormatter.SerializerSettings.ContractResolver = new TableContractResolver(jsonFormatter);
        }
开发者ID:huoxudong125,项目名称:azure-mobile-apps-net-server,代码行数:26,代码来源:TableControllerConfigProvider.cs


示例18: UpdateActionDescriptor

 public UpdateActionDescriptor(HttpControllerDescriptor controllerDescriptor, MethodInfo method, Type entityType, ChangeOperation operationType)
     : base(controllerDescriptor, method)
 {
     _entityType = entityType;
     _changeOperation = operationType;
     _method = method;
 }
开发者ID:reza899,项目名称:aspnetwebstack,代码行数:7,代码来源:UpdateActionDescriptor.cs


示例19: HttpException

        IHttpController IHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            IHttpController controller;
            if (controllerType == null)
                throw new HttpException(
                        404, String.Format(
                            "The controller for path '{0}' could not be found" +
            "or it does not implement IController.",
                        request.RequestUri.PathAndQuery));

            if (!typeof(IHttpController).IsAssignableFrom(controllerType))
                throw new ArgumentException(
                        string.Format(
                            "Type requested is not a controller: {0}",
                            controllerType.Name),
                            "controllerType");
            try
            {
                controller = BusinessLogic.Core.UnityConfig.Container.Resolve(controllerType, controllerType.Name)
                                as IHttpController;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(String.Format(
                                        "Error resolving controller {0}",
                                        controllerType.Name), ex);
            }
            return controller;
        }
开发者ID:kwmcrell,项目名称:SourceManager,代码行数:29,代码来源:UnityHttpControllerActivator.cs


示例20: Create

 public IHttpController Create( HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType )
 {
     if ( controllerType == null ) {
         return null;
     }
     return this.resolver( controllerType ) as IHttpController;
 }
开发者ID:robrich,项目名称:BetaSigmaPhi,代码行数:7,代码来源:FuncControllerFactory.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# HttpCookie类代码示例发布时间:2022-05-24
下一篇:
C# HttpContextBase类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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