private void ClearCache(string id)
        {
            if (!cacheDictionary.ContainsKey(id))
            {
                cacheDictionary.AddValue(id, new Dictionary <string, string>());
            }
            var dict = cacheDictionary.GetValue(id);

            dict.Remove("next");
        }
Ejemplo n.º 2
0
        private void SetCache(string id)
        {
            if (!cacheDictionary.ContainsKey(id))
            {
                cacheDictionary.AddValue(id, new Dictionary <string, string>());
            }
            var dict = cacheDictionary.GetValue(id);

            dict["next"] = this.Name;
        }
Ejemplo n.º 3
0
        public string Execute(string id, string message, string commandName = null)
        {
            // Execute previous command (if exists)
            if (cacheDictionary.ContainsKey(id) && cacheDictionary.GetValue(id).ContainsKey("next"))
            {
                if (commandName != null && allCommands[commandName].Contains(cacheDictionary.GetValue(id)["next"]))
                {
                    return(allCommands[commandName].Execute(id, message));
                }
                else
                {
                    foreach (var command in allCommands.Values)
                    {
                        if (command.Contains(cacheDictionary.GetValue(id)["next"]))
                        {
                            return(command.Execute(id, message));
                        }
                    }
                }
            }

            // Execute command by user message (if previous command is null)
            if (commandName != null)
            {
                return(allCommands[commandName].Execute(id, message));
            }
            else
            {
                foreach (var command in allCommands.Values)
                {
                    if (command.Contains(message))
                    {
                        return(command.Execute(id, message));
                    }
                }
            }

            return("");
        }