/// <summary>
        /// The default page in the api area.
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            ApiDiscoveryManager discoveryManager = new ApiDiscoveryManager(System.Reflection.Assembly.GetExecutingAssembly());

            ApiControllersViewModel result = discoveryManager.Discover();

            return(View(result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Discover all the api endpoints in an assembly.
        /// </summary>
        /// <returns></returns>
        public ApiControllersViewModel Discover()
        {
            ApiControllersViewModel result = new ApiControllersViewModel();

            System.Type[] assemblyTypes = this.Assembly.GetTypes();

            for (long i = 0; i < assemblyTypes.LongLength; i++)
            {
                System.Type assemblyType = assemblyTypes[i];

                // get the controller base types
                if (assemblyType.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller) || assemblyType.BaseType?.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller))
                {
                    string controllerName  = string.Empty;
                    string controllerRoute = string.Empty;
                    bool   addController   = false;

                    addController = this.HasApiAttrs(assemblyType, out controllerName, out controllerRoute);

                    if (addController == true)
                    {
                        ApiControllerModel apiController = new ApiControllerModel()
                        {
                            Name = controllerName, Route = controllerRoute
                        };
                        MethodInfo[] methods = assemblyType.GetMethods();

                        // get the attributes
                        foreach (MethodInfo method in methods)
                        {
                            ApiActionModel apiActionModel = this.GetApiActionModel(method, controllerRoute);

                            if (apiActionModel != null)
                            {
                                apiController.Actions.Add(apiActionModel);
                            }
                        }

                        // Remove the route info from the route its not needed anymore.
                        if (apiController.Route.Contains("[action]"))
                        {
                            apiController.Route = apiController.Route.Replace("[action]", string.Empty);

                            if (apiController.Route.EndsWith("/"))
                            {
                                apiController.Route = apiController.Route.Substring(0, apiController.Route.Length - 1);
                            }
                        }

                        result.Controllers.Add(apiController);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// The default page in the api area.
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            ApiDiscovery discoveryManager = new ApiDiscovery(System.Reflection.Assembly.GetExecutingAssembly());

            ApiControllersViewModel result = discoveryManager.Discover();

            // Since ApiControllerViewmodel is not attached to this project I need to add a pageMeta to it
            result.PageMeta = new PageMetaModel();

            return(View(result));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Discover all the api endpoints in an assembly.
        /// </summary>
        /// <returns></returns>
        public ApiControllersViewModel Discover()
        {
            ApiControllersViewModel result = new ApiControllersViewModel();

            System.Type[] assemblyTypes = this.Assembly.GetTypes();

            for (long i = 0; i < assemblyTypes.LongLength; i++)
            {
                System.Type assemblyType = assemblyTypes[i];

                // get the controller base types
                if (assemblyType.BaseType == typeof(Microsoft.AspNetCore.Mvc.Controller))
                {
                    string controllerName  = string.Empty;
                    string controllerRoute = string.Empty;
                    bool   addController   = false;

                    addController = this.HasApiAttrs(assemblyType, out controllerName, out controllerRoute);

                    if (addController == true)
                    {
                        ApiControllerModel apiController = new ApiControllerModel()
                        {
                            Name = controllerName, Route = controllerRoute
                        };
                        MethodInfo[] methods = assemblyType.GetMethods();

                        // get the attributes
                        foreach (MethodInfo method in methods)
                        {
                            ApiActionModel apiActionModel = this.GetApiActionModel(method);

                            if (apiActionModel != null)
                            {
                                apiController.Actions.Add(apiActionModel);
                            }
                        }

                        result.Controllers.Add(apiController);
                    }
                }
            }

            return(result);
        }