Ejemplo n.º 1
0
        private Endpoint BuildEndpoint(MethodInfo endpointMethodInfo, Type controllerType)
        {
            try
            {
                var    endpointAttribute = endpointMethodInfo.GetAttribute <EndpointAttribute>();
                string controllerRoute   = controllerType.GetAttribute <RouteAttribute>().Template;
                string actionRoute       = endpointMethodInfo.GetAttribute <RouteAttribute>().Template;

                Endpoint currentEntpoint = new Endpoint
                {
                    Id             = $"{controllerType.FullName.ToString().ToLower().Replace('.', '-')}-{endpointMethodInfo.Name.ToString().ToLower().Replace('.', '-')}",
                    ControllerName = controllerType.Name,
                    ActionName     = endpointMethodInfo.Name,
                    Route          = actionRoute.StartsWith("/", StringComparison.OrdinalIgnoreCase) ? actionRoute : $"{controllerRoute}{actionRoute}",
                    Method         = endpointMethodInfo.GetControllerActionHttpMethod(),
                    Authorized     = endpointMethodInfo.HasAttribute <AuthorizeAttribute>() || controllerType.HasAttribute <AuthorizeAttribute>(),
                    Response       = DescriptionExtractor.ExtractResponseDescription(endpointAttribute.ResponseType),
                    Arguments      = endpointMethodInfo
                                     .GetParameters()
                                     .Where(x => x.GetCustomAttribute <IgnoreParamAttribute>() == null)
                                     .Select(x => DescriptionExtractor.ExtractArgumentDescription(x.Name, x.ParameterType))
                                     .ToList(),
                };

                return(currentEntpoint);
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex);
                this.logger.LogErrorWithoutAnException($"{endpointMethodInfo.Name} ({controllerType.FullName})", "Error on creating endpoint from controller action.");
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public List <TypeDescription> GetAllEndpointsClasses()
        {
            var endpoints = this.GetAllEndpoints();
            var classes   = new List <TypeDescription>();

            foreach (var endpoint in endpoints)
            {
                if (!endpoint.Response.Void && endpoint.Response.Type.IsComplex)
                {
                    classes.Add(endpoint.Response.Type);
                }

                classes.AddRange(endpoint.Arguments.Where(x => x.Type.IsComplex).Select(x => x.Type).ToList());
            }

            return(DescriptionExtractor.ExtractUniqueClassesFromClasses(classes));
        }
Ejemplo n.º 3
0
        private Page BuildPage(Type pageType)
        {
            try
            {
                string fullPageName = pageType.Name;
                string pageName     = fullPageName;
                if (pageName.EndsWith("Page", StringComparison.OrdinalIgnoreCase))
                {
                    pageName = pageName.Substring(0, pageName.Length - 4);
                }

                var    routeAttribute      = pageType.GetAttribute <EmRouteAttribute>();
                string routeTemplate       = routeAttribute.Template;
                string clientRouteTemplate = this.ConvertAspNetRouteToVueRoute(routeTemplate);

                var initialStateModelType   = pageType.GetProperty("InitialStateModel").PropertyType;
                var viewModelType           = pageType.GetProperty("ViewModel").PropertyType;
                var initialStateRequestType = pageType.GetProperty("InitialStateRequest").PropertyType;

                Page currentPage = new Page
                {
                    Id                     = $"{pageType.FullName.ToString().ToLower().Replace('.', '-')}",
                    Name                   = pageName,
                    FullName               = fullPageName,
                    Authorized             = pageType.HasAttribute <AuthorizeAttribute>(),
                    Route                  = routeTemplate,
                    InitialStateModelType  = initialStateModelType,
                    InitialStateModelClass = DescriptionExtractor.ExtractTypeDescription(initialStateModelType),
                    ClientRoute            = clientRouteTemplate,
                };

                return(currentPage);
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex);
                return(null);
            }
        }