Beispiel #1
0
            /// <summary>
            /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
            /// </summary>
            /// <param name="x">The first object to compare.</param>
            /// <param name="y">The second object to compare.</param>
            /// <returns>
            /// Value
            /// Condition
            /// Less than zero
            /// <paramref name="x"/> is less than <paramref name="y"/>.
            /// Zero
            /// <paramref name="x"/> equals <paramref name="y"/>.
            /// Greater than zero
            /// <paramref name="x"/> is greater than <paramref name="y"/>.
            /// </returns>
            public int Compare(StringCommandParserCommandData <T> x, StringCommandParserCommandData <T> y)
            {
                var a = x.Method;
                var b = y.Method;

                var nonStringX = a.GetParameters().Count(_countFuncDelegate);
                var nonStringY = b.GetParameters().Count(_countFuncDelegate);

                return(nonStringX.CompareTo(nonStringY));
            }
Beispiel #2
0
            /// <summary>
            /// Handles when a command with the valid parameters was found, but <see cref="StringCommandParser{T}.AllowInvokeMethod"/>
            /// returned false for the given <see cref="binder"/>.
            /// </summary>
            /// <param name="binder">The object to invoke the method on. If the method handling the command is static,
            /// this is ignored and can be null.</param>
            /// <param name="cd">The <see cref="StringCommandParserCommandData{T}"/> for the command that the
            /// <paramref name="binder"/> was rejected from
            /// invoking.</param>
            /// <param name="args">Arguments used to invoke the command. Can be null.</param>
            /// <returns>A string containing a message about why the command failed to be handled.</returns>
            protected override string HandleCommandInvokeDenied(object binder, StringCommandParserCommandData <U> cd, string[] args)
            {
                var sayCommands = binder as ISayCommands <T>;

                if (sayCommands == null)
                {
                    const string errmsg = "Was expecting the binder `{0}` to be type ISayCommands<T>, but was `{1}`.";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, binder, binder != null ? binder.GetType().ToString() : "NULL");
                    }
                    Debug.Fail(string.Format(errmsg, binder, binder != null ? binder.GetType().ToString() : "NULL"));
                    return(string.Empty);
                }

                return(_sayHandlerBase.GetCommandNotAllowedMessage(sayCommands.User, cd));
            }
Beispiel #3
0
            /// <summary>
            /// When overridden in the derived class, gets if the <paramref name="binder"/> is allowed to invoke the method
            /// defined by the given <see cref="StringCommandParserCommandData{T}"/> using the given set of <paramref name="args"/>.
            /// </summary>
            /// <param name="binder">The object to invoke the method on. If the method handling the command is static,
            /// this is ignored and can be null.</param>
            /// <param name="cmdData">The <see cref="StringCommandParserCommandData{T}"/>
            /// containing the method to invoke and the corresponding attribute
            /// that is attached to it.</param>
            /// <param name="args">The casted arguments to use to invoke the method.</param>
            /// <returns></returns>
            protected override bool AllowInvokeMethod(object binder, StringCommandParserCommandData <U> cmdData, object[] args)
            {
                var sayCommands = binder as ISayCommands <T>;

                if (sayCommands == null)
                {
                    const string errmsg = "Was expecting the binder `{0}` to be type ISayCommands<T>, but was `{1}`.";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, binder, binder != null ? binder.GetType().ToString() : "NULL");
                    }
                    Debug.Fail(string.Format(errmsg, binder, binder != null ? binder.GetType().ToString() : "NULL"));
                    return(false);
                }

                return(_sayHandlerBase.AllowInvokeCommand(sayCommands.User, cmdData));
            }
Beispiel #4
0
 /// <summary>
 /// Gets the message to display when the user is not allowed to invoke a command.
 /// </summary>
 /// <param name="user">The user invoking the command.</param>
 /// <param name="commandData">The information about the command to be invoked.</param>
 /// <returns>The message to display to the <paramref name="user"/>, or null or empty to display nothing.</returns>
 protected virtual string GetCommandNotAllowedMessage(T user, StringCommandParserCommandData <U> commandData)
 {
     return("You are not allowed to do that.");
 }
Beispiel #5
0
 /// <summary>
 /// Gets if the given <paramref name="user"/> is allowed to invoke the given command.
 /// </summary>
 /// <param name="user">The user invoking the command.</param>
 /// <param name="commandData">The information about the command to be invoked.</param>
 /// <returns>True if the command can be invoked; otherwise false.</returns>
 protected virtual bool AllowInvokeCommand(T user, StringCommandParserCommandData <U> commandData)
 {
     return(true);
 }