示例#1
0
        /// <summary>
        /// Returns the only instance of skill factory.
        /// </summary>
        /// <returns></returns>
        public static SkillFactory GetInstance(ITurnContext context,
                                               IConversationStateProvider conversationStateProvider)
        {
            if (_factory == null)
            {
                lock (padlock)
                {
                    //
                    _conversationStateProvider = conversationStateProvider;
                    //
                    _factory = _factory ?? new SkillFactory();
                    // Check, if skill set is empty
                    if (_skills.Count == 0)
                    {
                        var knownSkills      = new[] { "greetings", "retorts" }; //, "questions" };
                        var greetingInstance = Greetings.Instance(context, conversationStateProvider);
                        var retortsInstance  = Retorts.Instance(context, conversationStateProvider);
                        //var questionsInstance = Questions.Instance(context, conversationStateProvider);
                        //
                        _skills.Add("greetings", greetingInstance);
                        _skills.Add("retorts", retortsInstance);
                        //_skills.Add("questions", questionsInstance);
                    }
                }
            }

            return(_factory);
        }
示例#2
0
 /// <summary>
 /// Creates new instance of skill.
 /// </summary>
 /// <param name="context">current dialog context</param>
 /// <param name="conversationStateProvider">provider for passing the state from context</param>>
 /// <returns>instance of retorts</returns>
 public static Retorts Instance(ITurnContext context, IConversationStateProvider conversationStateProvider)
 {
     if (_instance != null)
     {
         return(_instance);
     }
     // Start initializing an instance
     lock (padlock)
         if (_instance == null)
         {
             _instance = new Retorts(context, conversationStateProvider);
         }
     return(_instance);
 }
示例#3
0
        /// <summary>
        /// Returns wanted skill, if there exist one with such a name.
        /// </summary>
        /// <param name="key">skill's name</param>
        /// <param name="context">used context</param>
        /// <param name="conversationStateProvider">given conversation provider to access BrainState</param>
        /// <returns>wanted skill, if found, null otherwise</returns>
        public ISkill GetSkill(string key, ITurnContext context, IConversationStateProvider conversationStateProvider)
        {
            // if it does exist, read it and return it
            if (_skills.TryGetValue(key, out ISkill instance))
            {
                instance = _skills[key];
            }
            else
            {
                // First time - call to init an instance
                switch (key)
                {
                // TODO if would be nice, if this would be classfiles processor on directory - not to type every single skill in factory
                case "greetings":
                    instance = Greetings.Instance(context, conversationStateProvider);
                    break;

                case "retorts":
                    instance = Retorts.Instance(context, conversationStateProvider);
                    break;

                /*case "questions":
                 *  instance = Questions.Instance(context, conversationStateProvider);
                 *  break;*/
                case "unknowns":
                    instance = Unknowns.Instance(context, conversationStateProvider);
                    break;
                }
                // If obtained instance, add it to known skills
                if (instance != null)
                {
                    _skills.Add(key, instance);
                }
            }
            return(instance);
        }