Пример #1
0
        public HttpResponseMessage Routes()
        {
            var routes = new SortedDictionary <string, RouteInfo>();

            foreach (var route in ControllerContext.Configuration.Routes)
            {
                var inner = route as IEnumerable <IHttpRoute>;
                if (inner == null)
                {
                    continue;
                }

                foreach (var httpRoute in inner)
                {
                    var key = httpRoute.RouteTemplate;

                    if (key == string.Empty)
                    {
                        // ignore RavenRoot url to avoid issues with empty key in routes dictionary
                        continue;
                    }

                    bool forDatabase = false;
                    if (key.StartsWith("databases/{databaseName}/"))
                    {
                        key         = key.Substring("databases/{databaseName}/".Length);
                        forDatabase = true;
                    }
                    var data = new RouteInfo(key);
                    if (routes.ContainsKey(key))
                    {
                        data = routes[key];
                    }

                    if (forDatabase)
                    {
                        data.CanRunForSpecificDatabase = true;
                    }

                    var actions = ((IEnumerable)httpRoute.DataTokens["actions"]).OfType <ReflectedHttpActionDescriptor>();

                    foreach (var reflectedHttpActionDescriptor in actions)
                    {
                        foreach (var httpMethod in reflectedHttpActionDescriptor.SupportedHttpMethods)
                        {
                            if (data.Methods.Any(method => method.Name == httpMethod.Method))
                            {
                                continue;
                            }

                            string description          = null;
                            var    descriptionAttribute =
                                reflectedHttpActionDescriptor.MethodInfo.CustomAttributes.FirstOrDefault(attributeData => attributeData.AttributeType == typeof(DescriptionAttribute));
                            if (descriptionAttribute != null)
                            {
                                description = descriptionAttribute.ConstructorArguments[0].Value.ToString();
                            }

                            data.Methods.Add(new Method
                            {
                                Name        = httpMethod.Method,
                                Description = description
                            });
                        }
                    }

                    routes[key] = data;
                }
            }

            return(GetMessageWithObject(routes));
        }
Пример #2
0
		public HttpResponseMessage Routes()
		{
			var routes = new SortedDictionary<string, RouteInfo>();

			foreach (var route in ControllerContext.Configuration.Routes)
			{
				var inner = route as IEnumerable<IHttpRoute>;
				if (inner == null) continue;

				foreach (var httpRoute in inner)
				{
					var key = httpRoute.RouteTemplate;
					bool forDatabase = false;
					if (key.StartsWith("databases/{databaseName}/"))
					{
						key = key.Substring("databases/{databaseName}/".Length);
						forDatabase = true;
					}
					var data = new RouteInfo(key);
					if (routes.ContainsKey(key))
						data = routes[key];

					if (forDatabase)
						data.CanRunForSpecificDatabase = true;

					var actions = ((IEnumerable)httpRoute.DataTokens["actions"]).OfType<ReflectedHttpActionDescriptor>();

					foreach (var reflectedHttpActionDescriptor in actions)
					{

						foreach (var httpMethod in reflectedHttpActionDescriptor.SupportedHttpMethods)
						{
							if (data.Methods.Any(method => method.Name == httpMethod.Method))
								continue;

							string description = null;
							var descriptionAttibute =
								reflectedHttpActionDescriptor.MethodInfo.CustomAttributes.FirstOrDefault(attributeData => attributeData.AttributeType == typeof(DescriptionAttribute));
							if (descriptionAttibute != null)
								description = descriptionAttibute.ConstructorArguments[0].Value.ToString();

							data.Methods.Add(new Method
							{
								Name = httpMethod.Method,
								Description = description
							});
						}
					}

					routes[key] = data;
				}
			}

			return GetMessageWithObject(routes);
		}