示例#1
0
 public System.Web.Http.Controllers.IHttpController Create(
     System.Net.Http.HttpRequestMessage request,
     System.Web.Http.Controllers.HttpControllerDescriptor controllerDescriptor,
     Type controllerType)
 {
     using (_container.BeginScope())
     {
         var controller = (System.Web.Http.Controllers.IHttpController)_container.GetInstance(controllerType);
         return(controller);
     }
 }
        public void Initialize(System.Web.Http.Controllers.HttpControllerSettings settings,
                               System.Web.Http.Controllers.HttpControllerDescriptor descriptor)
        {
            // Remove the JSON formatter.
            var jsonFormatter = settings.Formatters.JsonFormatter;

            settings.Formatters.Remove(jsonFormatter);

            // Add a custom json media-type formatter.
            var formatter = new JsonNetFormatter();

            settings.Formatters.Insert(0, formatter);
        }
示例#3
0
        private static bool MatchesNamespace(this TRoute route, string controllerNamespace)
        {
            if (string.IsNullOrEmpty(controllerNamespace))
            {
                return(true);
            }

            TActionDescriptor[] actionDescriptors = (TActionDescriptor[])route.DataTokens[RouteDataTokenKeys.Actions];

            TControllerDescriptor controllerDescriptor = actionDescriptors.First().ControllerDescriptor;

            return(controllerDescriptor.ControllerType.Namespace == controllerNamespace);
        }
示例#4
0
文件: Config.cs 项目: ZQuanLi/Test
        public static bool GetApiShow(System.Web.Http.Controllers.HttpControllerDescriptor actionContext, string project)
        {
            string prefix = "";
            var    obj    = actionContext.GetCustomAttributes <System.Web.Http.RoutePrefixAttribute>();

            if (obj != null)
            {
                foreach (System.Web.Http.RoutePrefixAttribute md in obj)
                {
                    prefix = md.Prefix;
                }
            }
            return(prefix.ToLower().Contains(project.ToLower()));
        }
		public IReadOnlyList<RouteEntry> GetDirectRoutes(TControllerDescriptor controllerDescriptor,
			IReadOnlyList<TActionDescriptor> actionDescriptors, IInlineConstraintResolver constraintResolver)
		{
			IReadOnlyCollection<RouteEntry> controllerDirectRoutes = DirectRouteProvider.GetDirectRoutes(controllerDescriptor,
				actionDescriptors, constraintResolver);

			// Wrap routes with LocalizationCollectionRoute
			List<RouteEntry> routeEntries =
				controllerDirectRoutes.Select(x => new RouteEntry(x.Name, new LocalizationCollectionRoute(x.Route))).ToList();

			// Store routes for later processing
			LocalizationCollectionRoutes.AddRange(routeEntries);

			return routeEntries;
		}
示例#6
0
        public IReadOnlyList <RouteEntry> GetDirectRoutes(TControllerDescriptor controllerDescriptor,
                                                          IReadOnlyList <TActionDescriptor> actionDescriptors, IInlineConstraintResolver constraintResolver)
        {
            IReadOnlyCollection <RouteEntry> controllerDirectRoutes = DirectRouteProvider.GetDirectRoutes(controllerDescriptor,
                                                                                                          actionDescriptors, constraintResolver);

            // Wrap routes with LocalizationCollectionRoute
            List <RouteEntry> routeEntries =
                controllerDirectRoutes.Select(x => new RouteEntry(x.Name, new LocalizationCollectionRoute(x.Route))).ToList();

            // Store routes for later processing
            LocalizationCollectionRoutes.AddRange(routeEntries);

            return(routeEntries);
        }
        public System.Web.Http.Controllers.IHttpController Create(System.Net.Http.HttpRequestMessage request, System.Web.Http.Controllers.HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            try
            {
                return(_default.Create(request, controllerDescriptor, controllerType));
            }
            catch (InvalidOperationException e)
            {
                if (e.InnerException is ArgumentNullException)
                {
                    var x = 1;
                    //DO SOMETHING WITH THE ORIGIONAL ERROR!
                }

                //DO SOMETHING WITH THE ORIGIONAL ERROR!
                return(null);
            }
        }