示例#1
0
        /// <summary>
        /// 会話のルートの Path を登録。
        /// </summary>
        private void RegisterConversationRoute(string path, Type type, ConversationRouteAttribute routeAttr, MethodInfo methodInfo)
        {
            var pathAttr = methodInfo.GetCustomAttributes(typeof(ConversationPathAttribute), false).First() as ConversationPathAttribute;
            var subPath  = pathAttr.Path ?? string.Empty;
            var fullPath = string.Join("/", path, subPath);

            if (pathAttr.Action == ConversationAction.Start)
            {
                _startRoutes[fullPath] = new ConversationRouteInfo
                {
                    Path       = fullPath,
                    Type       = type,
                    MethodInfo = methodInfo,
                };
            }
            else if (pathAttr.Action == ConversationAction.Reply)
            {
                _replyRoutes[fullPath] = new ConversationRouteInfo
                {
                    Path       = fullPath,
                    Type       = type,
                    MethodInfo = methodInfo,
                };
            }
            _logger.LogDebug($@"RegisterConversationRoute: Mapped {fullPath} => {type.Namespace}.{type.Name}.{methodInfo.Name}");
        }
示例#2
0
        /// <summary>
        /// 会話のルートの Type を登録。
        /// </summary>
        private void RegisterConversationRoute(Type type)
        {
            var routeAttr = type.GetTypeInfo().GetCustomAttribute(typeof(ConversationRouteAttribute)) as ConversationRouteAttribute;

            type.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(ConversationPathAttribute), false).Count() > 0)
            .ToList()
            .ForEach(m =>
            {
                var path = routeAttr.Path.TrimEnd('/');
                RegisterConversationRoute(path, type, routeAttr, m);
            });

            type.GetMethods()
            .Where(m => m.GetCustomAttributes(typeof(ConversationGlobalPathAttribute), false).Count() > 0)
            .ToList()
            .ForEach(m =>
            {
                if (_globalRoute != null)
                {
                    throw new ArgumentException($"Only one {nameof(ConversationGlobalPathAttribute)} can be attributed.");
                }
                _globalRoute = new ConversationRouteInfo
                {
                    Path       = null,
                    Type       = type,
                    MethodInfo = m,
                };
            });
        }