示例#1
0
        /// <summary>
        /// Searches the CustomTag collection and processes the AIML if an appropriate tag handler is found
        /// </summary>
        /// <param name="user">the user who originated the request</param>
        /// <param name="query">the query that produced this node</param>
        /// <param name="request">the request from the user</param>
        /// <param name="result">the result to be sent to the user</param>
        /// <param name="node">the node to evaluate</param>
        /// <returns>the output string</returns>
        public AIMLTagHandler GetBespokeTags(User user, SubQuery query, Request request, Result result, XmlNode node)
        {
            if (_config.CustomTags.ContainsKey(node.Name.ToLower()))
            {
                TagHandler customTagHandler = _config.CustomTags[node.Name.ToLower()];

                AIMLTagHandler newCustomTag = customTagHandler.Instantiate(_config.LateBindingAssemblies);
                if (object.Equals(null, newCustomTag))
                {
                    return(null);
                }
                else
                {
                    //TODO: Need to figure out design pattern where only necessary objects are passed to object
                    //newCustomTag.user = user;
                    //newCustomTag.query = query;
                    //newCustomTag.request = request;
                    //newCustomTag.result = result;
                    //newCustomTag.templateNode = node;
                    //newCustomTag.bot = this;
                    return(newCustomTag);
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Loads any custom tag handlers found in the dll referenced in the argument
        /// </summary>
        /// <param name="pathToDLL">the path to the dll containing the custom tag handling code</param>
        public void LoadCustomTagHandlers(string pathToDLL)
        {
            Assembly tagDLL = Assembly.LoadFrom(pathToDLL);

            Type[] tagDLLTypes = tagDLL.GetTypes();
            for (int i = 0; i < tagDLLTypes.Length; i++)
            {
                object[] typeCustomAttributes = tagDLLTypes[i].GetCustomAttributes(false);
                for (int j = 0; j < typeCustomAttributes.Length; j++)
                {
                    if (typeCustomAttributes[j] is CustomTagAttribute)
                    {
                        // We've found a custom tag handling class
                        // so store the assembly and store it away in the Dictionary<,> as a TagHandler class for
                        // later usage

                        // store Assembly
                        if (!_config.LateBindingAssemblies.ContainsKey(tagDLL.FullName))
                        {
                            _config.LateBindingAssemblies.Add(tagDLL.FullName, tagDLL);
                        }

                        // create the TagHandler representation
                        TagHandler newTagHandler = new TagHandler
                        {
                            AssemblyName = tagDLL.FullName,
                            ClassName    = tagDLLTypes[i].FullName,
                            TagName      = tagDLLTypes[i].Name.ToLower()
                        };
                        if (_config.CustomTags.ContainsKey(newTagHandler.TagName))
                        {
                            throw new Exception("ERROR! Unable to add the custom tag: <" + newTagHandler.TagName + ">, found in: " + pathToDLL + " as a handler for this tag already exists.");
                        }
                        else
                        {
                            _config.CustomTags.Add(newTagHandler.TagName, newTagHandler);
                        }
                    }
                }
            }
        }