Ejemplo n.º 1
0
 public ColorTextBuilder AppendIf(bool condition, string text, Color?foregroundColor = null, Color?backgroundColor = null)
 {
     if (condition)
     {
         TextFragments.Add(new ColoredTextFragment(text, foregroundColor, backgroundColor));
     }
     return(this);
 }
Ejemplo n.º 2
0
        public override string ToString()
        {
            var str = string.Join("", TextFragments.Select(x => x.Text));

            if (MaxLength.HasValue)
            {
                str = str.Substring(0, MaxLength.Value);
            }
            return(str);
        }
Ejemplo n.º 3
0
        private TextFragments FormatIndex(string lineBreak)
        {
            var frags = new TextFragments();

            if (DbIndex.IsUnique)
            {
                frags.AddPrimary("UNIQUE ");
            }

            frags.AddPrimary(DbIndex.Type + " INDEX ");
            frags.AddPrimary("[" + DbIndex.Name + "]");
            frags.AddSecondary(" ON ");
            frags.AddPrimary("[" + DbIndex.Parent.SchemaName + "].[" + DbIndex.Parent.Name + "]");
            frags.Add(FormatColumns(lineBreak));
            return(frags);
        }
Ejemplo n.º 4
0
        private TextFragments FormatColumns(string lb)
        {
            var frags = new TextFragments();

            frags.AddSecondary("(" + lb);
            var isFirst  = true;
            var mainCols = DbIndex.Columns.Where(p => !p.Included).OrderBy(p => p.IndexColumnId);

            foreach (var column in mainCols)
            {
                if (!isFirst)
                {
                    frags.AddSecondary("," + lb);
                }
                isFirst = false;

                frags.AddSecondary("\t");
                frags.AddPrimary("[" + column.ColumnName + "]");
                frags.AddSecondary(column.IsDesc ? " DESC" : " ASC");
            }
            frags.AddSecondary(lb + ")" + lb);


            var includedCols = DbIndex.Columns.Where(p => p.Included).OrderBy(p => p.IndexColumnId);

            if (includedCols.Count() > 0)
            {
                frags.AddSecondary("INCLUDE (" + lb);
                isFirst = true;
                foreach (var column in includedCols)
                {
                    if (!isFirst)
                    {
                        frags.AddSecondary("," + lb);
                    }
                    isFirst = false;

                    frags.AddSecondary("\t");
                    frags.AddPrimary("[" + column.ColumnName + "]");
                }
                frags.AddSecondary(lb + ")" + lb);
            }
            return(frags);
        }
Ejemplo n.º 5
0
 public ColorTextBuilder Prepend(ColorTextBuilder builder)
 {
     TextFragments.InsertRange(0, builder.TextFragments);
     return(this);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Interlace two builders together on the Y axis
        /// </summary>
        /// <param name="builder2"></param>
        /// <param name="fixedColumnSpacing">Optional amount of spacing between lines on X axis</param>
        /// <param name="fixedColumnWidth">Optional width of fixed columns for the data being interlaced</param>
        /// <returns></returns>
        public ColorTextBuilder Interlace(ColorTextBuilder builder2, int fixedColumnSpacing = 0, int fixedColumnWidth = 0)
        {
            var interlacedBuilder = new ColorTextBuilder();

            var enumerator1 = TextFragments.GetEnumerator();
            var enumerator2 = builder2.TextFragments.GetEnumerator();

            var processedRightCount = 0;
            var currentLineWidth    = 0;

            while (enumerator1.MoveNext())
            {
                var line = enumerator1.Current;
                if (line.Text.Contains(Environment.NewLine))
                {
                    // move to the next builder
                    line.Text = line.Text.Replace(Environment.NewLine, string.Empty);
                    // add spaces to format content in a column if asked
                    if (fixedColumnWidth > 0 && line.Text.Length > fixedColumnWidth)
                    {
                        line.Text = line.Text.Substring(0, fixedColumnWidth);
                    }
                    if (fixedColumnWidth > 0 && (currentLineWidth + line.Text.Length) < fixedColumnWidth)
                    {
                        line.Text = line.Text + new string(' ', fixedColumnWidth - (currentLineWidth + line.Text.Length));
                    }
                    currentLineWidth = 0;
                    interlacedBuilder.TextFragments.Add(line);

                    // add spaces if we are requested to separate the blocks of text
                    if (fixedColumnSpacing > 0)
                    {
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(new string(' ', fixedColumnSpacing), line.ForegroundColor, line.BackgroundColor));
                    }

                    // start printing the next builder
                    var hasRightSideLines = false;
                    while (enumerator2.MoveNext())
                    {
                        processedRightCount++;
                        hasRightSideLines = true;
                        var line2 = enumerator2.Current;
                        if (line2.Text.Contains(Environment.NewLine))
                        {
                            if (fixedColumnWidth > 0 && line2.Text.Length > fixedColumnWidth)
                            {
                                line2.Text = line2.Text.Substring(0, fixedColumnWidth) + Environment.NewLine;
                            }
                            interlacedBuilder.TextFragments.Add(line2);

                            // done with this line, move back to parent builder and start the next line
                            break;
                        }
                        else
                        {
                            interlacedBuilder.TextFragments.Add(line2);
                        }
                    }
                    // if we ran out of right side items, add a line break
                    if (!hasRightSideLines)
                    {
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(Environment.NewLine));
                    }
                }
                else
                {
                    interlacedBuilder.TextFragments.Add(line);
                    currentLineWidth += line.Text.Length;
                }
            }

            // extra right side data
            if (processedRightCount < builder2.TextFragments.Count)
            {
                var startOfLine = true;
                while (enumerator2.MoveNext())
                {
                    var line2 = enumerator2.Current;
                    if (startOfLine)
                    {
                        var leftPadding = new string(' ', fixedColumnWidth + fixedColumnSpacing);
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(leftPadding));
                    }
                    if (line2.Text.Contains(Environment.NewLine))
                    {
                        if (fixedColumnWidth > 0 && line2.Text.Length - Environment.NewLine.Length > fixedColumnWidth)
                        {
                            line2.Text = line2.Text.Replace(Environment.NewLine, string.Empty)
                                         .Substring(0, fixedColumnWidth)
                                         + Environment.NewLine;
                        }
                        interlacedBuilder.TextFragments.Add(line2);
                        startOfLine = true;
                        // done with this line, move back to parent builder and start the next line
                        continue;
                    }
                    else
                    {
                        interlacedBuilder.TextFragments.Add(line2);
                    }
                    startOfLine = false;
                }
            }

            return(interlacedBuilder);
        }
Ejemplo n.º 7
0
 public ColorTextBuilder Clear()
 {
     TextFragments.Clear();
     return(this);
 }
Ejemplo n.º 8
0
 public ColorTextBuilder Append(Func <int, ColorTextBuilder> action)
 {
     TextFragments.AddRange(action.Invoke(Length).TextFragments);
     return(this);
 }
Ejemplo n.º 9
0
 public ColorTextBuilder PrependLine(ColorTextBuilder builder)
 {
     TextFragments.Insert(0, new ColoredTextFragment(Environment.NewLine));
     TextFragments.InsertRange(0, builder.TextFragments);
     return(this);
 }
Ejemplo n.º 10
0
 public ColorTextBuilder AppendLine()
 {
     TextFragments.Add(new ColoredTextFragment(Environment.NewLine));
     return(this);
 }
Ejemplo n.º 11
0
 public ColorTextBuilder AppendLine(string text, Color?foregroundColor = null, Color?backgroundColor = null)
 {
     TextFragments.Add(new ColoredTextFragment(text + Environment.NewLine, foregroundColor, backgroundColor));
     return(this);
 }
Ejemplo n.º 12
0
 public ColorTextBuilder AppendLine(ColorTextBuilder builder)
 {
     TextFragments.AddRange(builder.TextFragments);
     TextFragments.Add(new ColoredTextFragment(Environment.NewLine));
     return(this);
 }
Ejemplo n.º 13
0
 public ColorTextBuilder Append(ColorTextBuilder builder)
 {
     TextFragments.AddRange(builder.TextFragments);
     return(this);
 }
Ejemplo n.º 14
0
 public ColorTextBuilder PrependLine()
 {
     TextFragments.Insert(0, new ColoredTextFragment(Environment.NewLine));
     return(this);
 }
Ejemplo n.º 15
0
 public ColorTextBuilder Append(Func <int, string> action, Color?foregroundColor = null, Color?backgroundColor = null)
 {
     TextFragments.Add(new ColoredTextFragment(action.Invoke(Length), foregroundColor, backgroundColor));
     return(this);
 }
 public static void SetHighlightContext(DependencyObject obj, TextFragments value)
 {
     obj.SetValue(HighlightContextProperty, value);
 }
Ejemplo n.º 17
0
 public ColorTextBuilder Prepend(string text, Color?foregroundColor = null, Color?backgroundColor = null)
 {
     TextFragments.Insert(0, new ColoredTextFragment(text, foregroundColor, backgroundColor));
     return(this);
 }