Esempio n. 1
0
        /// <summary>
        /// String extension that consumes a string and formats it
        /// as a short debug message (denoting when we enter or exit a method).
        /// </summary>
        /// <param name="methodName">The method name called as a string</param>
        /// <param name="msgType">The message type (have we entered or exited a method for example) as a enum. Defaulted to DebugMsgType.MethodEntered.</param>
        /// <returns></returns>
        public static string MethodDebugMsg(DebugMsgType msgType = DebugMsgType.MethodEntered, [CallerMemberName] string methodName = "")
        {
            //If a valid method name is not provided simply return an empty string
            if (string.IsNullOrEmpty(methodName))
            {
                return(string.Empty);
            }

            //Use the DebugMsgType provided to return a formatted string (Have we entered/exited the given method name). Default = string.Empty
            switch (msgType)
            {
            case DebugMsgType.MethodEntered:
            {
                return(string.Format("Entered the {0} method.", methodName));
            }

            case DebugMsgType.MethodLeft:
            {
                return(string.Format("Exited {0} method.", methodName));
            }

            default:
            {
                return(string.Empty);
            }
            }
        }
        // TODO: Refactor this method or maybe the packet notifier?
        public void SendDebugMsgFormatted(DebugMsgType type, string message = "")
        {
            Game _game         = Program.ResolveDependency <Game>();
            var  formattedText = new StringBuilder();
            int  fontSize      = 20; // Big fonts seem to make the chatbox buggy

            // This may need to be removed.
            switch (type)
            {
            case DebugMsgType.ERROR:     // Tag: [ERROR], Color: Red
                formattedText.Append("<font size=\"" + fontSize + "\" color =\"#FF0000\"><b>[ERROR]</b><font color =\"#AFBF00\">: ");
                formattedText.Append(message);
                _game.PacketNotifier.notifyDebugMessage(formattedText.ToString());
                break;

            case DebugMsgType.INFO:     // Tag: [INFO], Color: Green
                formattedText.Append("<font size=\"" + fontSize + "\" color =\"#00D90E\"><b>[INFO]</b><font color =\"#AFBF00\">: ");
                formattedText.Append(message);
                _game.PacketNotifier.notifyDebugMessage(formattedText.ToString());
                break;

            case DebugMsgType.SYNTAX:     // Tag: [SYNTAX], Color: Blue
                formattedText.Append("<font size=\"" + fontSize + "\" color =\"#006EFF\"><b>[SYNTAX]</b><font color =\"#AFBF00\">: ");
                formattedText.Append(message);
                _game.PacketNotifier.notifyDebugMessage(formattedText.ToString());
                break;

            case DebugMsgType.SYNTAXERROR:     // Tag: [ERROR], Color: Red
                formattedText.Append("<font size=\"" + fontSize + "\" color =\"#FF0000\"><b>[ERROR]</b><font color =\"#AFBF00\">: ");
                formattedText.Append("Incorrect command syntax");
                _game.PacketNotifier.notifyDebugMessage(formattedText.ToString());
                break;

            case DebugMsgType.NORMAL:     // No tag, no format
                _game.PacketNotifier.notifyDebugMessage(message);
                break;
            }
        }