/Photopia.Web/Controllers/HomeController.cs
C# | 83 lines | 63 code | 19 blank | 1 comment | 0 complexity | 9fcfd399676f1c8922bd956aac8ff20c MD5 | raw file
- using System.Collections.Generic;
- using System.Linq;
- using System.Web.Http;
- using System.Web.Http.Description;
- using System.Web.Mvc;
- using System.Xml.Linq;
- namespace Photopia.Web.Controllers
- {
- public class ApiListViewModel
- {
- public string Name { get; set; }
- public IEnumerable<ApiDescription> ApiDescriptions { get; set; }
- }
- public class ApiDocumentation
- {
- public string Description { get; set; }
- public string JsonResponse { get; set; }
- public string HttpMethod { get; set; }
- public string Url { get; set; }
- }
- public class ApiParameter
- {
- public string Name { get; set; }
- public string Description { get; set; }
- public string Example { get; set; }
- }
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- XDocument doc = XDocument.Load(Server.MapPath("~/App_Data/ApiDoc.xml"));
- IEnumerable<XElement> memberElements = doc.Descendants("members").Descendants("member")
- .Where(x => x.Attribute("name").Value.StartsWith("M:") &&
- x.Attribute("name").Value.ToLowerInvariant().Contains("api")).ToList();
- IApiExplorer apiExplorer = GlobalConfiguration.Configuration.Services.GetApiExplorer();
- var groupedApiDescriptions = from a in apiExplorer.ApiDescriptions
- group a by a.ActionDescriptor.ControllerDescriptor.ControllerName
- into g
- select new ApiListViewModel {Name = g.Key, ApiDescriptions = g};
- foreach (var member in memberElements)
- {
- var vv = member.Attribute("name").Value;
- string ss = "fs";
- }
- foreach (var g in groupedApiDescriptions)
- {
- foreach (var desc in g.ApiDescriptions)
- {
- var actionName = ((System.Web.Http.Controllers.ReflectedHttpActionDescriptor)(desc.ActionDescriptor)).MethodInfo.Name;
- var fullName = desc.ActionDescriptor.ControllerDescriptor.ControllerType.FullName;
-
- string selector = string.Format("M:{0}.{1}", fullName, actionName).ToLower();
- XElement xElement = memberElements.Where(x => x.Attribute("name").Value.ToLower().Contains(selector)).FirstOrDefault();
- }
- }
- return View(groupedApiDescriptions.ToList());
- //http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help-page-using-apiexplorer.aspx
- return View();
- }
- public ActionResult UploadImage()
- {
- return View();
- }
- }
- }