Beispiel #1
0
        public IDictionary <string, CommandActionRoute> GetCommandAttributeRoutes(ChromelyController controller)
        {
            if (controller == null)
            {
                return(null);
            }

            var result = new Dictionary <string, CommandActionRoute>();

            var methodInfos = controller.GetType().GetMethods()
                              .Where(m => m.GetCustomAttributes(typeof(CommandActionAttribute), false).Length > 0)
                              .ToArray();

            foreach (var item in methodInfos)
            {
                var customAttributeDelegate = CreateDelegate(controller, item) as Action <IDictionary <string, string> >;
                var attribute = item.GetCustomAttribute <CommandActionAttribute>();

                if (customAttributeDelegate != null && attribute != null)
                {
                    var key          = RouteKey.CreateCommandKey(attribute.RouteKey);
                    var commandRoute = new CommandActionRoute(attribute.RouteKey, customAttributeDelegate, attribute.Description);
                    result[key] = commandRoute;
                }
            }

            return(result);
        }
Beispiel #2
0
        public IDictionary <string, ActionRoute> GetHttpAttributeRoutes(ChromelyController controller)
        {
            if (controller == null)
            {
                return(null);
            }

            var result = new Dictionary <string, ActionRoute>();

            var methodInfos = controller.GetType().GetMethods()
                              .Where(m => m.GetCustomAttributes(typeof(HttpAttribute), false).Length > 0)
                              .ToArray();

            foreach (var item in methodInfos)
            {
                var httpAttributeDelegate = CreateDelegate(controller, item) as Func <ChromelyRequest, ChromelyResponse>;
                var attribute             = item.GetCustomAttribute <HttpAttribute>();

                if (httpAttributeDelegate != null && attribute != null)
                {
                    var routhPath = new RoutePath(attribute.Method, attribute.Route);
                    result[routhPath.Key] = new ActionRoute(attribute.Method, attribute.Route, httpAttributeDelegate);
                }
            }

            return(result);
        }
Beispiel #3
0
        public IDictionary <string, RequestActionRoute> GetActionAttributeRoutes(ChromelyController controller)
        {
            if (controller == null)
            {
                return(null);
            }

            var result = new Dictionary <string, RequestActionRoute>();

            var methodInfos = controller.GetType().GetMethods()
                              .Where(m => m.GetCustomAttributes(typeof(RequestActionAttribute), false).Length > 0)
                              .ToArray();

            foreach (var item in methodInfos)
            {
                var actionAttributeDelegate      = CreateDelegate(controller, item) as Func <IChromelyRequest, IChromelyResponse>;
                var asyncActionAttributeDelegate = CreateDelegate(controller, item) as Func <IChromelyRequest, Task <IChromelyResponse> >;
                var attribute = item.GetCustomAttribute <RequestActionAttribute>();

                var key = RouteKey.CreateRequestKey(attribute.RouteKey);

                // Sync
                if (actionAttributeDelegate != null && attribute != null)
                {
                    result[key] = new RequestActionRoute(attribute.RouteKey, actionAttributeDelegate, attribute.Description);
                }

                // Async
                if (asyncActionAttributeDelegate != null && attribute != null)
                {
                    result[key] = new RequestActionRoute(attribute.RouteKey, asyncActionAttributeDelegate, attribute.Description);
                }
            }

            return(result);
        }