Exemplo n.º 1
0
        protected static string GetRenderedText(ConsoleBuffer buffer)
        {
            var target = new TextRenderTarget();

            target.Render(buffer);
            string text = target.OutputText;

            return(text.Length > 0 ? text.Remove(text.Length - 2) : text);
        }
        public void RenderDocumentToString()
        {
            var doc = new Document {
                Children = { new Span("Foo") }
            };
            var target = new TextRenderTarget();

            ConsoleRenderer.RenderDocument(doc, target, new Rect(0, 0, 3, 1));

            target.OutputText.Should().Be($"Foo{Environment.NewLine}");
        }
Exemplo n.º 3
0
        protected static string GetRenderedText([NotNull] ConsoleBuffer buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            var target = new TextRenderTarget();

            target.Render(buffer);
            string text = target.OutputText;

            return(text.Length > 0 ? text.Remove(text.Length - 2) : text);
        }
Exemplo n.º 4
0
        public void NullArguments()
        {
            var type        = GetType();
            var assembly    = type.GetAssembly();
            var stream      = Stream.Null;
            var dataContext = new object();
            var document    = new Document();
            var target      = new TextRenderTarget();
            var buffer      = new ConsoleBuffer(80);
            var renderRect  = Rect.Empty;

          #if XAML
            var resourceName = "";

            new Action(() => ConsoleRenderer.ReadElementFromStream <Br>(null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(stream));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>((Assembly)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(assembly));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>(assembly, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>((Type)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(type));
            new Action(() => ConsoleRenderer.ReadElementFromResource <Br>(type, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadDocumentFromStream(null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(stream));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource((Assembly)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(assembly));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource(assembly, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource((Type)null, resourceName, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(type));
            new Action(() => ConsoleRenderer.ReadDocumentFromResource(type, null, dataContext))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(resourceName));
          #endif
            new Action(() => ConsoleRenderer.RenderDocument(null))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToBuffer(null, buffer, renderRect))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToBuffer(document, null, renderRect))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(buffer));
            new Action(() => ConsoleRenderer.RenderDocumentToText(null, target))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(document));
            new Action(() => ConsoleRenderer.RenderDocumentToText(document, null))
            .Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(target));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Renders the specified report.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="plainText">if set to <c>true</c> [plain text].</param>
        public static void Render(Report report, bool plainText = false)
        {
            var doc = new Document
            {
                Background = ConsoleColor.Black,
                Color      = ConsoleColor.Gray,
                Children   =
                {
                    new Grid
                    {
                        StrokeColor = ConsoleColor.DarkGray,
                        Columns     =
                        {
                            new Column {
                                Width = GridLength.Auto, MinWidth = 25
                            },                                                                               // PLAYER
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // LEVEL 2
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // LEVEL 3
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // PAID
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // SCORE
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // REQUIRED
                            new Column {
                                Width = GridLength.Auto
                            },                                                                // STATUS
                            new Column {
                                Width = GridLength.Auto
                            }                                                                // DEBT
                        },
                        Children =
                        {
                            new Cell("PLAYER")
                            {
                                Color = ConsoleColor.White
                            },
                            new Cell("LEVEL 2")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("LEVEL 3+")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("PAID")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("SCORE")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("REQUIRED")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("STATUS")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            new Cell("DEBT")
                            {
                                Color = ConsoleColor.White, Align = Align.Center
                            },
                            report.LazyPlayers.Select(
                                x => new []
                            {
                                // PLAYER
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Color    = ConsoleColor.Yellow,
                                    Children ={ x                                     }
                                },
                                // LEVEL 2
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.DarkGray,
                                    Children ={                                     0 }
                                },
                                // LEVEL 3+
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.DarkGray,
                                    Children ={                                     0 }
                                },
                                // PAID
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.DarkGray,
                                    Children ={                                     0 }
                                },
                                // SCORE
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.Red,
                                    Children ={                                     0 }
                                },
                                // REQUIRED
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.Yellow,
                                    Children ={ report.TotalScore                     }
                                },
                                // STATUS
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.Red,
                                    Children ={ "BAD"                                 }
                                },
                                // DEBT
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Children ={ report.TotalScore                     }
                                }
                            }),
                            report.Items.OrderByDescending(x => x.Debt).Select(
                                x => new[]
                            {
                                // PLAYER
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Color    = ConsoleColor.Yellow,
                                    Children ={ x.PlayerName                          }
                                },
                                // LEVEL 2
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = x.Lvl2 == 0 ? ConsoleColor.DarkGray : (ConsoleColor?)null,
                                    Children ={ x.Lvl2                                }
                                },
                                // LEVEL 3+
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = x.Lvl3 == 0 ? ConsoleColor.DarkGray : (ConsoleColor?)null,
                                    Children ={ x.Lvl3                                }
                                },
                                // PAID
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = x.Paid == 0 ? ConsoleColor.DarkGray : (ConsoleColor?)null,
                                    Children ={ x.Paid                                }
                                },
                                // SCORE
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = x.Score == 0 ? ConsoleColor.Red : (ConsoleColor?)null,
                                    Children ={ x.Score                               }
                                },
                                // REQUIRED
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = ConsoleColor.Yellow,
                                    Children ={ report.TotalScore                     }
                                },
                                // STATUS
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Color    = x.Debt == 0 ? ConsoleColor.Green : ConsoleColor.Red,
                                    Children ={ x.Status                              }
                                },
                                // DEBT
                                new Cell
                                {
                                    Stroke   = StrokeRight,
                                    Align    = Align.Center,
                                    Children ={ x.Debt == 0 ? "-" : x.Debt.ToString() }
                                }
                            })
                        }
                    }
                }
            };

            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var renderRect = new Rect(0, 0, Console.WindowWidth - 1, Size.Infinity);

            var ts = report.DateTo - report.DateFrom;

            if (ts.HasValue)
            {
                Console.WriteLine("REPORT INTERVAL: {0:d} - {1:d} ({2} DAY(S)), MEMBERS: {3}",
                                  report.DateFrom, report.DateTo?.AddDays(-1), ts.Value.Days,
                                  report.Items.Count);
            }

            if (plainText)
            {
                var target = new TextRenderTarget();
                var s      = ConsoleRenderer.RenderDocumentToText(doc, target, renderRect);
                Console.Write(s);
            }
            else
            {
                ConsoleRenderer.RenderDocument(doc, null, renderRect);
            }
        }