public override void Execute(TriggerBase trigger)
        {
            var str = trigger.Args.NextWord();

            SubCommand command;

            if (!TryGetSubCommand(IgnoreCommandCase ? str.ToLower() : str, out command) || !trigger.CanAccessCommand(command))
            {
                HelpCommand.DisplayFullCommandDescription(trigger, this);
                return;
            }

            if (trigger.BindToCommand(command))
            {
                command.Execute(trigger);
            }
        }
        public override void Execute(TriggerBase trigger)
        {
            string     text = trigger.Args.NextWord();
            SubCommand subCommand;

            if (!this.TryGetSubCommand(CommandBase.IgnoreCommandCase ? text.ToLower() : text, out subCommand) || subCommand.RequiredRole > trigger.UserRole)
            {
                HelpCommand.DisplayFullCommandDescription(trigger, this);
            }
            else
            {
                if (trigger.BindToCommand(subCommand))
                {
                    subCommand.Execute(trigger);
                }
            }
        }
Esempio n. 3
0
        public void HandleCommand(TriggerBase trigger)
        {
            var cmdstring = trigger.Args.NextWord();

            if (CommandBase.IgnoreCommandCase)
            {
                cmdstring = cmdstring.ToLower();
            }

            var cmd = this[cmdstring];

            if (cmd != null && trigger.CanAccessCommand(cmd))
            {
                try
                {
                    if (trigger.BindToCommand(cmd))
                    {
                        cmd.Execute(trigger);
                    }
                    trigger.Log();
                }
                catch (Exception ex)
                {
                    trigger.ReplyError("Raised exception (error-index:{0}) : {1}", trigger.RegisterException(ex), ex.Message);

                    if (ex.InnerException != null)
                    {
                        trigger.ReplyError(" => " + ex.InnerException.Message);
                    }
                }
            }
            else
            {
                if (cmdstring.Length > 0)
                {
                    trigger.ReplyError("La commande \"{0}\" est incorrecte, <b>.help</b> pour avoir la liste des commandes.", cmdstring);
                }
            }
        }
        public void HandleCommand(TriggerBase trigger)
        {
            string text = trigger.Args.NextWord();

            if (CommandBase.IgnoreCommandCase)
            {
                text = text.ToLower();
            }
            CommandBase commandBase = this[text];

            if (commandBase != null && trigger.CanAccessCommand(commandBase))
            {
                try
                {
                    if (trigger.BindToCommand(commandBase))
                    {
                        commandBase.Execute(trigger);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    trigger.ReplyError("Raised exception (error-index:{0}) : {1}", new object[]
                    {
                        trigger.RegisterException(ex),
                        ex.Message
                    });
                    if (ex.InnerException != null)
                    {
                        trigger.ReplyError(" => " + ex.InnerException.Message);
                    }
                    return;
                }
            }
            trigger.ReplyError("Incorrect Command \"{0}\". Type commandslist or help for command list.", new object[]
            {
                text
            });
        }
Esempio n. 5
0
        public void HandleCommand(TriggerBase trigger)
        {
            var cmdstring = trigger.Args.NextWord();

            if (CommandBase.IgnoreCommandCase)
            {
                cmdstring = cmdstring.ToLower();
            }

            var cmd = this[cmdstring];

            if (cmd != null && trigger.CanAccessCommand(cmd))
            {
                try
                {
                    if (trigger.BindToCommand(cmd))
                    {
                        cmd.Execute(trigger);
                    }

                    //Log command
                    trigger.Log();
                }
                catch (Exception ex)
                {
                    trigger.ReplyError("Raised exception (error-index:{0}) : {1}", trigger.RegisterException(ex), ex.Message);

                    if (ex.InnerException != null)
                    {
                        trigger.ReplyError(" => " + ex.InnerException.Message);
                    }
                }
            }
            else
            {
                trigger.ReplyError("Incorrect Command \"{0}\". Type commandslist or help for command list.", cmdstring);
            }
        }
        public object ConvertString(string value, TriggerBase trigger)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(DefaultValue);
            }

            if (Converter != null && trigger != null)
            {
                return(Converter(value, trigger));
            }

            if (ValueType == typeof(string))
            {
                return(value);
            }

            if (ValueType.HasInterface(typeof(IConvertible)))
            {
                return(Convert.ChangeType(value, typeof(T)));
            }

            return(ValueType.IsEnum ? Enum.Parse(ValueType, value) : DefaultValue);
        }
Esempio n. 7
0
 public void SetDefaultValue(TriggerBase trigger)
 {
     this.Value     = (T)((object)this.Definition.ConvertString(string.Empty, trigger));
     this.IsDefined = false;
 }
Esempio n. 8
0
 public void SetValue(string str, TriggerBase trigger)
 {
     this.Value     = (T)((object)this.Definition.ConvertString(str, trigger));
     this.IsDefined = true;
 }
 public abstract void Execute(TriggerBase trigger);
Esempio n. 10
0
        public bool BindToCommand(CommandBase command)
        {
            this.BoundCommand = command;
            bool result;

            if (command is SubCommandContainer)
            {
                result = true;
            }
            else
            {
                List <IParameter>           list  = new List <IParameter>();
                List <IParameterDefinition> list2 = new List <IParameterDefinition>(this.BoundCommand.Parameters);
                if (list2.Count == 1 && list2[0].ValueType == typeof(string) && !list2[0].IsOptional)
                {
                    IParameter parameter = list2[0].CreateParameter();
                    parameter.SetValue(this.Args.NextWords(), this);
                    list.Add(parameter);
                    list2.Remove(list2[0]);
                }
                if (this.BoundCommand.Parameters.Count == 0)
                {
                    result = true;
                }
                else
                {
                    string text = this.Args.NextWord();
                    bool   flag = false;
                    while (!string.IsNullOrEmpty(text) && list.Count < this.BoundCommand.Parameters.Count)
                    {
                        if (text.StartsWith("\"") && text.EndsWith("\""))
                        {
                            text = text.Remove(text.Length - 1, 1).Remove(0, 1);
                        }
                        bool flag2 = false;
                        if (text.StartsWith("-"))
                        {
                            string name  = null;
                            string text2 = null;
                            Match  match = this.m_regexIsNamed.Match(text);
                            if (match.Success)
                            {
                                name  = match.Groups[1].Value;
                                text2 = match.Groups[2].Value;
                                if (text2.StartsWith("\"") && text2.EndsWith("\""))
                                {
                                    text2 = text2.Remove(text2.Length - 1, 1).Remove(0, 1);
                                }
                            }
                            else
                            {
                                Match match2 = this.m_regexVar.Match(text);
                                if (match2.Success)
                                {
                                    name  = match2.Groups[1].Value;
                                    text2 = string.Empty;
                                    flag  = true;
                                }
                            }
                            if (!string.IsNullOrEmpty(name))
                            {
                                IParameterDefinition parameterDefinition = list2.SingleOrDefault((IParameterDefinition entry) => TriggerBase.CompareParameterName(entry, name, CommandBase.IgnoreCommandCase));
                                if (parameterDefinition != null)
                                {
                                    IParameter parameter2 = parameterDefinition.CreateParameter();
                                    try
                                    {
                                        if (flag && parameterDefinition.ValueType == typeof(bool))
                                        {
                                            text2 = "true";
                                        }
                                        parameter2.SetValue(text2, this);
                                    }
                                    catch (ConverterException ex)
                                    {
                                        this.ReplyError(ex.Message);
                                        result = false;
                                        return(result);
                                    }
                                    catch (Exception ex2)
                                    {
                                        this.ReplyError("Cannot parse : {0} as {1} (error-index:{2})", new object[]
                                        {
                                            text,
                                            parameterDefinition.ValueType,
                                            this.RegisterException(ex2)
                                        });
                                        result = false;
                                        return(result);
                                    }
                                    list.Add(parameter2);
                                    list2.Remove(parameterDefinition);
                                    flag2 = true;
                                }
                            }
                        }
                        if (!flag2)
                        {
                            IParameterDefinition parameterDefinition = list2.First <IParameterDefinition>();
                            IParameter           parameter2          = parameterDefinition.CreateParameter();
                            try
                            {
                                parameter2.SetValue(text, this);
                            }
                            catch (ConverterException ex)
                            {
                                this.ReplyError(ex.Message);
                                result = false;
                                return(result);
                            }
                            catch (Exception ex2)
                            {
                                this.ReplyError("Cannot parse : {0} as {1} (error-index:{2})", new object[]
                                {
                                    text,
                                    parameterDefinition.ValueType,
                                    this.RegisterException(ex2)
                                });
                                result = false;
                                return(result);
                            }
                            list.Add(parameter2);
                            list2.Remove(parameterDefinition);
                        }
                        text = this.Args.NextWord();
                    }
                    foreach (IParameterDefinition current in list2)
                    {
                        if (!current.IsOptional)
                        {
                            this.ReplyError("{0} is not defined", new object[]
                            {
                                current.Name
                            });
                            result = false;
                            return(result);
                        }
                        IParameter parameter2 = current.CreateParameter();
                        parameter2.SetDefaultValue(this);
                        list.Add(parameter2);
                    }
                    this.CommandsParametersByName      = list.ToDictionary((IParameter entry) => entry.Definition.Name);
                    this.CommandsParametersByShortName = list.ToDictionary((IParameter entry) => (!string.IsNullOrEmpty(entry.Definition.ShortName)) ? entry.Definition.ShortName : entry.Definition.Name);
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 11
0
        public void SetDefaultValue(TriggerBase trigger)
        {
            Value = (T)Definition.ConvertString(string.Empty, trigger);

            IsDefined = false;
        }
Esempio n. 12
0
        public void SetValue(string str, TriggerBase trigger)
        {
            Value = (T)Definition.ConvertString(str, trigger);

            IsDefined = true;
        }