public RichTextString(IFormattingDescriptor preformatting)
 {
     FormattingDescriptor = preformatting;
     Elements             = new List <IRichTextElement>()
     {
         ObjectFactory.CreateRichTextElement(FormattingDescriptor)
     };
 }
 public MessageElement(IFormattingDescriptor preFormattingDescriptor)
 {
     ForeColor    = preFormattingDescriptor.ForeColor;
     BackColor    = preFormattingDescriptor.BackColor;
     IsBold       = preFormattingDescriptor.IsBold;
     IsItallic    = preFormattingDescriptor.IsItallic;
     IsUnderlined = preFormattingDescriptor.IsUnderlined;
     IsStrikeout  = preFormattingDescriptor.IsStrikeout;
     IsObfuscated = preFormattingDescriptor.IsObfuscated;
 }
 public IRichTextString CreateRichTextString(IFormattingDescriptor preFormmating) => new RichTextString(preFormmating);
 public IRichTextElement CreateRichTextElement(IFormattingDescriptor preFormmating) => new RichText.RichTextString.MessageElement(preFormmating);
Ejemplo n.º 5
0
 public IRichTextString CreateRichTextString(IFormattingDescriptor preFormmating) => throw new NotImplementedException();
Ejemplo n.º 6
0
        public RichTextMessageTextBlockContainer(IRichTextMessage input)
        {
            #region Color BG
            byte   BGAlpha = (byte)(0.25f * 255);
            IColor BGColor = ObjectFactory.CreateColor(BGAlpha, 16, 16, 16);
            switch (input.Type)
            {
            case MessageType.Unknown:
            default:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 100, 0, 100);
                break;

            case MessageType.User:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 16, 16, 16);
                break;

            case MessageType.ConsoleInformation:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 0, 32, 48);
                break;

            case MessageType.DebugSummary:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 0, 100, 150);
                break;

            case MessageType.DebugDetail:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 0, 50, 100);
                break;

            case MessageType.DebugWarning:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 150, 150, 0);
                break;

            case MessageType.DebugError:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 200, 100, 0);
                break;

            case MessageType.DebugCrash:
                BGColor = ObjectFactory.CreateColor(BGAlpha, 120, 0, 0);
                break;
            }
            #endregion

            #region Message
            Message = input;
            #endregion

            #region Datestamp
            IFormattingDescriptor dateFormattingDescriptor = ObjectFactory.CreateFormattingDescriptor
                                                             (
                foreColor: SimpleColors.DarkGray.Color,
                backColor: ObjectFactory.CreateColor(16, 16, 16),
                isBold: false,
                isItallic: true,
                isUnderlined: false,
                isStrikeout: false,
                isObfuscated: false
                                                             );
            IRichTextString dateStampString = ObjectFactory.CreateRichTextString(dateFormattingDescriptor);
            dateStampString.AddFormattedString(input.Datestamp.ToSystemString());

            Datestamp = RichTextStringConverter.ToTextBlock(dateStampString).ToFormattedTextBlock(BGColor);

            #endregion
            #region Timestamp

            IFormattingDescriptor timeFormattingDescriptor = ObjectFactory.CreateFormattingDescriptor
                                                             (
                foreColor: SimpleColors.Gray.Color,
                backColor: ObjectFactory.CreateColor(16, 16, 16),
                isBold: false,
                isItallic: true,
                isUnderlined: false,
                isStrikeout: false,
                isObfuscated: false
                                                             );
            IRichTextString timeStampString = ObjectFactory.CreateRichTextString(timeFormattingDescriptor);
            timeStampString.AddFormattedString(input.Timestamp.ToSystemString());

            Timestamp = RichTextStringConverter.ToTextBlock(timeStampString).ToFormattedTextBlock(BGColor);

            #endregion
            #region User

            User = RichTextStringConverter.ToTextBlock(input.User.UserName).ToFormattedTextBlock(BGColor);

            #endregion
            #region Type

            IFormattingDescriptor typeFormattingDescriptor;
            typeFormattingDescriptor = ObjectFactory.CreateFormattingDescriptor
                                       (
                foreColor: SimpleColors.DarkGray.Color,
                backColor: ObjectFactory.CreateColor(16, 16, 16),
                isBold: false,
                isItallic: true,
                isUnderlined: false,
                isStrikeout: false,
                isObfuscated: false
                                       );
            switch (input.Type)
            {
            case MessageType.Unknown:
            default:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.White.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = true;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.User:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.White.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = false;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.ConsoleInformation:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.DarkTeal.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = true;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.DebugSummary:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.Blue.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = true;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.DebugDetail:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.DarkBlue.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = true;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.DebugWarning:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.Yellow.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(16, 16, 16);
                typeFormattingDescriptor.IsBold       = false;
                typeFormattingDescriptor.IsItallic    = false;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.DebugError:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.Gray.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(240, 200, 16);
                typeFormattingDescriptor.IsBold       = true;
                typeFormattingDescriptor.IsItallic    = false;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }

            case MessageType.DebugCrash:
            {
                typeFormattingDescriptor.ForeColor    = SimpleColors.White.Color;
                typeFormattingDescriptor.BackColor    = ObjectFactory.CreateColor(240, 16, 16);
                typeFormattingDescriptor.IsBold       = true;
                typeFormattingDescriptor.IsItallic    = false;
                typeFormattingDescriptor.IsUnderlined = false;
                typeFormattingDescriptor.IsStrikeout  = false;
                typeFormattingDescriptor.IsObfuscated = false;
                break;
            }
            }


            IRichTextString typeRichTextString = ObjectFactory.CreateRichTextString(typeFormattingDescriptor);
            string          typeString         = "???";
            switch (input.Type)
            {
            case MessageType.Unknown:
            default:
                typeString = "???";
                break;

            case MessageType.User:
                typeString = "User";
                break;

            case MessageType.ConsoleInformation:
                typeString = "Console Information";
                break;

            case MessageType.DebugSummary:
                typeString = "Debug Summary";
                break;

            case MessageType.DebugDetail:
                typeString = "Debug Detail";
                break;

            case MessageType.DebugWarning:
                typeString = "Debug Warning";
                break;

            case MessageType.DebugError:
                typeString = "Debug Error";
                break;

            case MessageType.DebugCrash:
                typeString = "Debug Crash";
                break;
            }

            typeRichTextString.AddFormattedString(typeString);

            Type = RichTextStringConverter.ToTextBlock(typeRichTextString).ToFormattedTextBlock(BGColor);

            #endregion
            #region String
            String = RichTextStringConverter.ToTextBlock(input.String).ToFormattedTextBlock(BGColor);
            #endregion
        }
 public static IRichTextString CreateRichTextString(IFormattingDescriptor preformatting) => objectFactory.CreateRichTextString(preformatting);
 public static IRichTextElement CreateRichTextElement(IFormattingDescriptor preformatting) => objectFactory.CreateRichTextElement(preformatting);
        public void AddFormattedString(string formattedstring)
        {
            List <IRichTextElement> thisElements;

            IFormattingDescriptor currentFormattingDescriptor = ObjectFactory.CreateFormattingDescriptor(
                foreColor: FormattingDescriptor.ForeColor,
                backColor: FormattingDescriptor.BackColor,
                isBold: FormattingDescriptor.IsBold,
                isItallic: FormattingDescriptor.IsItallic,
                isUnderlined: FormattingDescriptor.IsUnderlined,
                isStrikeout: FormattingDescriptor.IsStrikeout,
                isObfuscated: FormattingDescriptor.IsObfuscated
                );

            if (Elements == null)
            {
                thisElements = new List <IRichTextElement>();
            }
            else
            {
                thisElements = Elements;
            }

            if (!thisElements.Any())
            {
                thisElements.Add(new MessageElement(FormattingDescriptor));
                currentFormattingDescriptor.ForeColor    = FormattingDescriptor.ForeColor;
                currentFormattingDescriptor.BackColor    = FormattingDescriptor.BackColor;
                currentFormattingDescriptor.IsBold       = FormattingDescriptor.IsBold;
                currentFormattingDescriptor.IsItallic    = FormattingDescriptor.IsItallic;
                currentFormattingDescriptor.IsUnderlined = FormattingDescriptor.IsUnderlined;
                currentFormattingDescriptor.IsStrikeout  = FormattingDescriptor.IsStrikeout;
                currentFormattingDescriptor.IsObfuscated = FormattingDescriptor.IsObfuscated;
            }
            else
            {
                currentFormattingDescriptor.ForeColor    = Elements.Last().ForeColor;
                currentFormattingDescriptor.BackColor    = Elements.Last().BackColor;
                currentFormattingDescriptor.IsBold       = Elements.Last().IsBold;
                currentFormattingDescriptor.IsItallic    = Elements.Last().IsItallic;
                currentFormattingDescriptor.IsUnderlined = Elements.Last().IsUnderlined;
                currentFormattingDescriptor.IsStrikeout  = Elements.Last().IsStrikeout;
                currentFormattingDescriptor.IsObfuscated = Elements.Last().IsObfuscated;
            }

            char          previousChar  = ' ';
            char          currentChar   = ' ';
            StringBuilder currentString = new StringBuilder();

            for (int i = 0; i < formattedstring.Length; i++)
            {
                previousChar = i > 0 ? formattedstring[i - 1] : ' ';
                currentChar  = formattedstring[i];

                if (previousChar == '&' & currentChar == '&')
                {
                    currentString.Append('&');
                }

                if (currentChar == '&')
                {
                    goto Next;
                }

                if (previousChar == '&')
                {
                    switch (char.ToUpper(currentChar))
                    {
                    case '0':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color0.Color;
                        goto Next;

                    case '1':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color1.Color;
                        goto Next;

                    case '2':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color2.Color;
                        goto Next;

                    case '3':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color3.Color;
                        goto Next;

                    case '4':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color4.Color;
                        goto Next;

                    case '5':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color5.Color;
                        goto Next;

                    case '6':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color6.Color;
                        goto Next;

                    case '7':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color7.Color;
                        goto Next;

                    case '8':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color8.Color;
                        goto Next;

                    case '9':
                        currentFormattingDescriptor.ForeColor = SimpleColors.Color9.Color;
                        goto Next;

                    case 'A':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorA.Color;
                        goto Next;

                    case 'B':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorB.Color;
                        goto Next;

                    case 'C':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorC.Color;
                        goto Next;

                    case 'D':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorD.Color;
                        goto Next;

                    case 'E':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorE.Color;
                        goto Next;

                    case 'F':
                        currentFormattingDescriptor.ForeColor = SimpleColors.ColorF.Color;
                        goto Next;

                    case 'L':
                        currentFormattingDescriptor.IsBold = true;
                        goto Next;

                    case 'O':
                        currentFormattingDescriptor.IsItallic = true;
                        goto Next;

                    case 'N':
                        currentFormattingDescriptor.IsUnderlined = true;
                        goto Next;

                    case 'M':
                        currentFormattingDescriptor.IsStrikeout = true;
                        goto Next;

                    case 'K':
                        currentFormattingDescriptor.IsObfuscated = true;
                        goto Next;

                    case 'R':
                        currentFormattingDescriptor.ForeColor = SimpleColors.White.Color;
                        currentFormattingDescriptor.BackColor = SimpleColors.Black.Color;

                        currentFormattingDescriptor.IsBold       = false;
                        currentFormattingDescriptor.IsItallic    = false;
                        currentFormattingDescriptor.IsUnderlined = false;
                        currentFormattingDescriptor.IsStrikeout  = false;
                        currentFormattingDescriptor.IsObfuscated = false;
                        goto Next;
                    }
                }
                else
                {
                    currentString.Append(currentChar);
                }


Next:
                {
                    if (thisElements.Last().ForeColor != currentFormattingDescriptor.ForeColor |
                        thisElements.Last().BackColor != currentFormattingDescriptor.BackColor |
                        thisElements.Last().IsBold != currentFormattingDescriptor.IsBold |
                        thisElements.Last().IsItallic != currentFormattingDescriptor.IsItallic |
                        thisElements.Last().IsUnderlined != currentFormattingDescriptor.IsUnderlined |
                        thisElements.Last().IsStrikeout != currentFormattingDescriptor.IsStrikeout |
                        thisElements.Last().IsObfuscated != currentFormattingDescriptor.IsObfuscated)
                    {
                        var nextElement = new MessageElement(currentFormattingDescriptor);
                        nextElement.Message = currentString.ToString();
                        thisElements.Add(nextElement);
                        currentString.Clear();
                    }

                    previousChar = currentChar;
                }
            }

            if (previousChar == '&')
            {
                currentString.Append('&');
            }
            var finalElement = new MessageElement(currentFormattingDescriptor);

            finalElement.Message = currentString.ToString();
            thisElements.Add(finalElement);
            currentString.Clear();
            thisElements.RemoveAll(x => x.Message == "");
            Elements = thisElements;
        }