示例#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);
        }
示例#2
0
        protected void RegisterCommand(string path, Action <IDictionary <string, string> > action, string description = null)
        {
            if (string.IsNullOrWhiteSpace(path) || action == null)
            {
                return;
            }

            var commandKey = RouteKey.CreateCommandKey(path);
            var command    = new CommandActionRoute(path, action, description);

            CommandRouteDictionary[commandKey] = command;
        }
示例#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);
        }
示例#4
0
        private void AddRoute(string path, RequestActionRoute route)
        {
            var actionKey = RouteKey.CreateRequestKey(path);

            ActionRouteDictionary[actionKey] = route;
        }