예제 #1
0
                protected override void PrintTable(IEnumerable <RssRuleViewModel> list)
                {
                    var doc = new Document(
                        new Grid
                    {
                        Columns =
                        {
                            new Column {
                                Width = GridLength.Star(1)
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                        },
                        Children =
                        {
                            UIHelper.Header("Name"),
                            UIHelper.Header("Enabled"),
                            list.Select(r => new[]
                            {
                                new Cell(r.Name),
                                new Cell(r.Enabled)
                            })
                        },
                        Stroke = LineThickness.Single
                    })
                              .SetColors(ColorScheme.Current.Normal);

                    ConsoleRenderer.RenderDocument(doc);
                }
예제 #2
0
 protected override void PrintTable(IEnumerable <Category> categories)
 {
     if (categories?.Any() == true)
     {
         var doc = new Document(
             new Grid
         {
             Columns =
             {
                 new Column {
                     Width = GridLength.Auto
                 },
                 new Column {
                     Width = GridLength.Star(1)
                 }
             },
             Children =
             {
                 UIHelper.Header("Name"),
                 UIHelper.Header("Save Path"),
                 categories.Select(c => new[]
                 {
                     new Cell(c.Name),
                     new Cell(c.SavePath)
                 })
             },
             Stroke = LineThickness.Single
         })
                   .SetColors(ColorScheme.Current.Normal);
         ConsoleRenderer.RenderDocument(doc);
     }
 }
                protected override void PrintTable(IEnumerable <PeerPartialInfoViewModel> peers)
                {
                    var doc = new Document(
                        new Grid
                    {
                        Columns =
                        {
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Star(1)
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                        },
                        Children =
                        {
                            UIHelper.Header("CC"),
                            UIHelper.Header("Endpoint"),
                            UIHelper.Header("Client"),
                            UIHelper.Header("Progress"),
                            UIHelper.Header("DL Speed",                            TextAlign.Center),
                            UIHelper.Header("UL Speed",                            TextAlign.Center),
                            UIHelper.Header("DL",                                  TextAlign.Center,   8),
                            UIHelper.Header("UL",                                  TextAlign.Center,   8),
                            peers.Select(p => new[]
                            {
                                new Cell(p.CountryCode),
                                new Cell(p.Endpoint),
                                new Cell(p.Client),
                                new Cell($"{p.Progress:P0}"),
                                new Cell(FormatSpeed(p.DownloadSpeed).PadLeft(10)),
                                new Cell(FormatSpeed(p.UploadSpeed).PadLeft(10)),
                                new Cell(FormatData(p.Downloaded).PadLeft(8)),
                                new Cell(FormatData(p.Uploaded).PadLeft(8)),
                            })
                        },
                        Stroke = LineThickness.Single
                    }
                        ).SetColors(ColorScheme.Current.Normal);

                    ConsoleRenderer.RenderDocument(doc);
                }
                protected override void PrintTable(IEnumerable <SearchPlugin> plugins)
                {
                    var doc = new Document(
                        new Grid
                    {
                        Columns =
                        {
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Star(1)
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                        },
                        Children =
                        {
                            UIHelper.Header("Name"),
                            UIHelper.Header("Full Name"),
                            UIHelper.Header("Enabled"),
                            plugins.Select(p => new[]
                            {
                                new Cell(p.Name),
                                new Cell(p.FullName),
                                new Cell(p.IsEnabled)
                            })
                        },
                        Stroke = LineThickness.Single
                    }
                        ).SetColors(ColorScheme.Current.Normal);

                    ConsoleRenderer.RenderDocument(doc);
                }
예제 #5
0
        public void RenderMaze(Play play)
        {
            var         headerThickness = new LineThickness(LineWidth.Single, LineWidth.Single);
            List <Cell> cells           = new List <Cell>();

            for (int i = 0; i < play.MazeSize * play.MazeSize; i++)
            {
                Cell c = new Cell(i.ToString());
                if (play.VisitedRooms.FindAll(x => x.RoomId == i).Count() > 0)
                {
                    c.Color = ConsoleColor.Green;
                }
                cells.Add(c);
            }
            var doc = new Document(
                //new Span("Steps: " + play.Steps) { Color = ConsoleColor.Yellow }, new Br(),
                //new Span("HP: " + play.HP) { Color = ConsoleColor.Yellow }, new Br(),
                //new Span("Current Room: " + play.CurrentRoom) { Color = ConsoleColor.Yellow }, new Br(),
                //new Span("Current Room Description: " + play.CurrentRoomDescription) { Color = ConsoleColor.Yellow },
                new Grid(cells)
            {
                Columns = { Enumerable.Repeat(GridLength.Star(1), play.MazeSize) }
            });

            doc.Padding = new Thickness(3);
            ConsoleRenderer.RenderDocument(doc);
        }
예제 #6
0
        public static Document HelpAllOptionsList(ILookup <BaseOptionAttribute, BaseOptionAttribute> verbsWithOptions, string instruction) =>
        new Document
        {
            Background = Black, Color = Gray
        }

        .AddChildren(
            new Span($"{instruction}\n")
        {
            Color = White
        },
            new Grid {
            Stroke = LineThickness.None
        }
            .AddColumns(GridLength.Auto, GridLength.Star(1))
            .AddChildren(
                verbsWithOptions.Select(verbWithOptions => new object[] {
            OptionNameAndHelp(verbWithOptions.Key),
            new Grid {
                Stroke = LineThickness.None, Margin = new Thickness(4, 0, 0, 0)
            }
            .Set(Grid.ColumnSpanProperty, 2)
            .AddColumns(GridLength.Auto, GridLength.Star(1))
            .AddChildren(verbWithOptions.Select(OptionNameAndHelp)),
        })
                )
            );
 public void ConvertToInstanceDescriptor()
 {
     _converter.CanConvertFrom(null, typeof(InstanceDescriptor)).Should().BeTrue();
     _converter.CanConvertTo(null, typeof(InstanceDescriptor)).Should().BeTrue();
     _converter.ConvertTo(GridLength.Star(3), typeof(InstanceDescriptor))
     .As <InstanceDescriptor>().Invoke()
     .Should().Be(GridLength.Star(3));
 }
 public void ConvertToString()
 {
     _converter.ConvertToString(GridLength.Auto).Should().Be("Auto");
     _converter.ConvertToString(GridLength.Char(1)).Should().Be("1");
     _converter.ConvertToString(GridLength.Char(5)).Should().Be("5");
     _converter.ConvertToString(GridLength.Star(1)).Should().Be("*");
     _converter.ConvertToString(GridLength.Star(5)).Should().Be("5*");
 }
 public void ConvertFromString()
 {
     _converter.ConvertFrom("Auto").Should().Be(GridLength.Auto);
     _converter.ConvertFrom("AutO").Should().Be(GridLength.Auto);
     _converter.ConvertFrom("1").Should().Be(GridLength.Char(1));
     _converter.ConvertFrom("5").Should().Be(GridLength.Char(5));
     _converter.ConvertFrom("5").Should().Be(GridLength.Char(5));
     _converter.ConvertFrom("1*").Should().Be(GridLength.Star(1));
     _converter.ConvertFrom("5*").Should().Be(GridLength.Star(5));
     _converter.ConvertFrom("5 *").Should().Be(GridLength.Star(5));
     _converter.ConvertFrom("*").Should().Be(GridLength.Star(1));
 }
예제 #10
0
        public static void PrintSettings(List <Setting> settings)
        {
            var headerThickness  = new LineThickness(LineWidth.None, LineWidth.None);
            var messageThickness = new LineThickness(LineWidth.None, LineWidth.None);


            var doc = new Document(
                new Grid
            {
                Color    = ConsoleColor.Gray,
                Columns  = { GridLength.Auto, GridLength.Auto, GridLength.Star(1) },
                Children =
                {
                    new Cell("Name ")
                    {
                        Align = Align.Center, Stroke = headerThickness, Color = ConsoleColor.Blue
                    },
                    new Cell(" ")
                    {
                        Stroke = headerThickness
                    },
                    new Cell(" State")
                    {
                        Align = Align.Left, Stroke = headerThickness
                    },

                    settings.Select(item => new object[]
                    {
                        new Cell(item.Name)
                        {
                            Align = Align.Center, Stroke = messageThickness,
                            Color = ConsoleColor.Blue
                        },
                        new Cell(" =")
                        {
                            Align = Align.Center, Stroke = messageThickness,
                            Color = ConsoleColor.Blue
                        },
                        new Cell(" " + item.State)
                        {
                            Stroke = LineThickness.None
                        },
                    })
                }
            }
                );

            Console.Clear();
            ConsoleRenderer.RenderDocument(doc);
        }
예제 #11
0
        public static void WriteInfo(string firstColumn, params string[] phrases)
        {
            var document = new Document
            {
                Background = ConsoleColor.Black,
                Color      = ConsoleColor.Gray,
                Children   =
                {
                    new Grid
                    {
                        Stroke      = new LineThickness(0, 0),
                        StrokeColor = ConsoleColor.DarkGray,
                        Columns     =
                        {
                            new Column                     {
                                Width = GridLength.Auto, MinWidth = 10
                            },
                            new Column                     {
                                Width = GridLength.Auto, MinWidth = 12
                            },
                            phrases.Select(p => new Column {
                                Width = GridLength.Star(1)
                            })
                        },
                        Children =
                        {
                            new Cell
                            {
                                Stroke   = new LineThickness(0, 0),
                                Children =                 { DateTime.Now.ToString("hh:mm:ss")}
                            },
                            new Cell
                            {
                                Stroke   = new LineThickness(0, 0),
                                Color    = ConsoleColor.Green,
                                Children =                 { firstColumn       }
                            },
                            phrases.Select(phrase => new[]
                            {
                                new Cell                   {
                                    Children =             { $" {phrase}"      }, Stroke= new LineThickness(0, 0)
                                }
                            })
                        }
                    }
                }
            };

            ConsoleRenderer.RenderDocument(document);
        }
                    protected override void PrintTable(IEnumerable <KeyValuePair <string, SaveLocation> > folders)
                    {
                        var doc = new Document(
                            new Grid
                        {
                            Columns =
                            {
                                new Column {
                                    Width = GridLength.Star(1)
                                },
                                new Column {
                                    Width = GridLength.Star(1)
                                }
                            },
                            Children =
                            {
                                UIHelper.Header("Monitored Folder"),
                                UIHelper.Header("Save Location"),
                                folders.SelectMany(p => new[]
                                {
                                    new Cell(p.Key),
                                    FormatSaveLocation(p.Value)
                                })
                            },
                            Stroke = LineThickness.Single
                        }
                            ).SetColors(ColorScheme.Current.Normal);

                        ConsoleRenderer.RenderDocument(doc);

                        Cell FormatSaveLocation(SaveLocation location)
                        {
                            switch (location.StandardFolder)
                            {
                            case StandardSaveLocation.MonitoredFolder:
                                return(new Cell("Monitored Folder"));

                            case StandardSaveLocation.Default:
                                return(new Cell("Default"));

                            case null:
                                return(new Cell(
                                           new Span("Custom: "),
                                           new Span(location.CustomFolder).SetColors(ColorScheme.Current.Strong)));

                            default:
                                return(new Cell(location.ToString()).SetColors(ColorScheme.Current.Warning));
                            }
                        }
                    }
예제 #13
0
        public static void PrintHelp()
        {
            var headerThickness  = new LineThickness(LineWidth.None, LineWidth.None);
            var messageThickness = new LineThickness(LineWidth.None, LineWidth.None);

            Tuple <string, string>[] items =
            {
                new Tuple <string, string>("/help, /h",                  "shows help"),
                new Tuple <string, string>("/open chat_ID, /o chat_ID",  "opens chat with specified ID"),
                new Tuple <string, string>("/chats, /c",                 "shows chats list"),
                new Tuple <string, string>("/redraw, /r",                "updates current view"),
                new Tuple <string, string>("/add username, /a username", "adds chat with user"),
                new Tuple <string, string>("/exit, /e, /quit, /q",       "closes app"),
                new Tuple <string, string>("any other text",             "sends message to chat")
            };

            var doc = new Document(
                new Grid
            {
                Color    = Gray,
                Columns  = { GridLength.Auto, GridLength.Star(1) },
                Children =
                {
                    new Cell("command ")
                    {
                        Align = Align.Center, Stroke = headerThickness, Color = ConsoleColor.Blue
                    },
                    new Cell("description")
                    {
                        Align = Align.Left, Stroke = headerThickness
                    },

                    items.Select(item => new object[]
                    {
                        new Cell(item.Item1 + " ")
                        {
                            Align = Align.Left, Stroke = messageThickness
                        },
                        new Cell(item.Item2)
                        {
                            Stroke = LineThickness.None
                        }
                    })
                }
            }
                );

            ConsoleRenderer.RenderDocument(doc);
        }
예제 #14
0
        public static void PrintChat(ChatData chatData)
        {
            var headerThickness  = new LineThickness(LineWidth.None, LineWidth.None);
            var messageThickness = new LineThickness(LineWidth.None, LineWidth.None);


            var doc = new Document(
                new Span("Chat with ")
            {
                Color = Yellow
            }, chatData.UserName, "\n",
                new Span("New messages: ")
            {
                Color = Yellow
            }, chatData.CountNewMes,
                new Grid
            {
                Color    = Gray,
                Columns  = { GridLength.Auto, GridLength.Star(1) },
                Children =
                {
                    new Cell("Username ")
                    {
                        Align = Align.Right, Stroke = headerThickness
                    },
                    new Cell("Message")
                    {
                        Align = Align.Center, Stroke = headerThickness
                    },

                    chatData.Messages.Select(item => new object[]
                    {
                        new Cell(item.Name + ":")
                        {
                            Align = Align.Center, Stroke = messageThickness, Color = Red
                        },
                        new Cell(" " + item.MessageText)
                        {
                            Stroke = LineThickness.None
                        },
                    })
                }
            }
                );

            Console.Clear();
            ConsoleRenderer.RenderDocument(doc);
        }
예제 #15
0
 private static Grid CreateGrid()
 {
     return(new()
     {
         Stroke = LineThickness.Single,
         StrokeColor = ConsoleColor.Blue,
         Columns =
         {
             new Column {
                 Width = GridLength.Star(1)
             },
             new Column {
                 Width = GridLength.Char(20)
             }
         }
     });
 }
예제 #16
0
 public static Document HelpOptionsList(IEnumerable <BaseOptionAttribute> options, string instruction) =>
 new Document
 {
     Background = Black, Color = Gray,
     Children   =
     {
         new Div(instruction)
         {
             Color = White
         },
         "",
         new Grid {
             Stroke   = LineThickness.None,
             Columns  = { GridLength.Auto, GridLength.Star(1) },
             Children ={ options.Select(OptionNameAndHelp) }
         }
     }
 };
예제 #17
0
        public static Document HelpOptionsList(IEnumerable <BaseOptionAttribute> options, string instruction) =>
        new Document
        {
            Background = Black, Color = Gray
        }

        .AddChildren(
            new Div {
            Color = White
        }
            .AddChildren(instruction),
            "",
            new Grid {
            Stroke = LineThickness.None
        }
            .AddColumns(GridLength.Auto, GridLength.Star(1))
            .AddChildren(options.Select(OptionNameAndHelp))
            );
            public int OnExecute(CommandLineApplication app, IConsole console)
            {
                var networkSettings = SettingsService.Instance.GetNetwork();
                var credentials     = networkSettings.Credentials;

                var doc = new Document(
                    new Grid
                {
                    Stroke  = LineThickness.Single,
                    Columns =
                    {
                        new Column {
                            Width = GridLength.Star(1), MinWidth = 20
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                    },
                    Children =
                    {
                        UIHelper.Header("URL"),
                        UIHelper.Header("Auth. Type"),
                        UIHelper.Header("Domain"),
                        UIHelper.Header("Username"),
                        credentials.Select(c => new[]
                        {
                            new Cell(c.Url.AbsoluteUri),
                            new Cell(c.AuthType),
                            new Cell(c.Domain),
                            new Cell(c.Username)
                        })
                    }
                }
                    ).SetColors(ColorScheme.Current.Normal);

                ConsoleRenderer.RenderDocument(doc);
                return(ExitCodes.Success);
            }
예제 #19
0
        static void PrintConnInfo()
        {
            Console.SetCursorPosition(0, 0);
            Console.CursorVisible = false;

            LineThickness StrokeRight  = LineThickness.Heavy;
            LineThickness StrokeHeader = LineThickness.Double;

            var doc = new Document(
                new Span("Dark Souls III: Open\n")
            {
                Color = Yellow
            },
                new Grid
            {
                Stroke      = StrokeHeader,
                StrokeColor = DarkGray,
                Columns     = { GridLength.Auto, GridLength.Auto, GridLength.Auto, GridLength.Auto,
                                GridLength.Auto,     GridLength.Auto, GridLength.Star(1) },
예제 #20
0
 protected virtual object GetSubOptions(OptionInfo option, HelpParts parts)
 {
     return(new Grid {
         Stroke = LineThickness.None,
         Columns =
         {
             new Column {
                 Width = GridLength.Auto,
                 MinWidth = OptionNameMinLength + SubOptionMargin.Left + 1,
                 MaxWidth = OptionNameMaxLength + SubOptionMargin.Left + 1,
             },
             new Column {
                 Width = GridLength.Star(1)
             },
         },
         Children =
         {
             option.SubOptions.Where(IsOptionVisible(parts)).Select(o => GetOption(o, parts, isSubOption: true))
         }
     });
 }
예제 #21
0
                protected override void PrintTable(IEnumerable <TorrentTrackerViewModel> list)
                {
                    var doc = new Document(
                        new Grid
                    {
                        Columns =
                        {
                            new Column {
                                Width = GridLength.Star(1)
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Auto
                            },
                        },
                        Children =
                        {
                            UIHelper.Header("URL"),
                            UIHelper.Header("Status"),
                            UIHelper.Header("Seeds"),
                            UIHelper.Header("Leechers"),
                            list.Select(c => new[]
                            {
                                new Cell(c.Url),
                                new Cell(c.Status),
                                new Cell(c.Seeds),
                                new Cell(c.Leeches),
                            })
                        },
                        Stroke = LineThickness.Single
                    })
                              .SetColors(ColorScheme.Current.Normal);

                    ConsoleRenderer.RenderDocument(doc);
                }
예제 #22
0
        public static void PrintAvailableChats(List <ChatData> chats)
        {
            var headerThickness  = new LineThickness(LineWidth.None, LineWidth.None);
            var messageThickness = new LineThickness(LineWidth.None, LineWidth.None);


            var doc = new Document(
                new Grid
            {
                Color    = Gray,
                Columns  = { GridLength.Auto, GridLength.Star(1) },
                Children =
                {
                    new Cell("ID ")
                    {
                        Align = Align.Right, Stroke = headerThickness
                    },
                    new Cell("Username")
                    {
                        Align = Align.Left, Stroke = headerThickness
                    },

                    chats.Select(item => new object[]
                    {
                        new Cell(item.IdUser)
                        {
                            Align = Align.Right, Stroke = messageThickness, Color = Red
                        },
                        new Cell(" " + item.UserName)
                        {
                            Stroke = LineThickness.None
                        },
                    })
                }
            }
                );

            Console.Clear();
            ConsoleRenderer.RenderDocument(doc);
        }
예제 #23
0
            protected override void PrintTable(IEnumerable <TorrentContentViewModel> list)
            {
                var doc = new Document(
                    new Grid
                {
                    Columns =
                    {
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Star(1)
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                    },
                    Children =
                    {
                        UIHelper.Header("Id"),
                        UIHelper.Header("Name"),
                        UIHelper.Header("Size"),
                        UIHelper.Header("Progress"),
                        list.Select(c => new[]
                        {
                            new Cell(c.Id),
                            new Cell(c.Name),
                            new Cell(c.Size.ToString("N0")),
                            new Cell(c.Progress.ToString("P0")),
                        })
                    },
                    Stroke = LineThickness.Single
                })
                          .SetColors(ColorScheme.Current.Normal);

                ConsoleRenderer.RenderDocument(doc);
            }
예제 #24
0
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var root = await client.GetRssItemsAsync(false);

                    var doc = new Document(RenderItem(root, true, true)).SetColors(ColorScheme.Current.Normal);

                    ConsoleRenderer.RenderDocument(doc);
                    return(ExitCodes.Success);

                    Stack RenderFolderContent(RssFolder folder)
                    {
                        return(new Stack(folder.Items.Select(
                                             (item, index) => RenderItem(item, index == folder.Items.Count - 1))));
                    }

                    object RenderFeed(RssFeed feed)
                    {
                        return(new Div(
                                   feed.Name,
                                   " ",
                                   new Span($"[{feed.Url}]").SetColors(ColorScheme.Current.Inactive)));
                    }

                    Grid RenderItem(RssItem item, bool last, bool isRoot = false)
                    {
                        var folder = item as RssFolder;

                        return(new Grid
                        {
                            Columns =
                            {
                                new Column {
                                    Width = GridLength.Char(2)
                                },
                                new Column {
                                    Width = GridLength.Star(1)
                                }
                            },
예제 #25
0
 public static Document ProcessList(IEnumerable <Process> processes) =>
 new Document
 {
     Background = Black, Color = Gray,
     Children   =
     {
         new Grid                                  {
             Stroke  = StrokeHeader, StrokeColor = DarkGray,
             Columns =
             {
                 new Column                        {
                     Width = GridLength.Auto
                 },
                 new Column                        {
                     Width = GridLength.Auto, MaxWidth = 20
                 },
                 new Column                        {
                     Width = GridLength.Star(1)
                 },
                 new Column                        {
                     Width = GridLength.Auto
                 }
             },
             Children =
             {
                 new Cell("Id")
                 {
                     Stroke = StrokeHeader, Color = White
                 },
                 new Cell("Name")
                 {
                     Stroke = StrokeHeader, Color = White
                 },
                 new Cell("Main Window Title")
                 {
                     Stroke = StrokeHeader, Color = White
                 },
                 new Cell("Private Memory")
                 {
                     Stroke = StrokeHeader, Color = White
                 },
                 processes.Select(process => new[] {
                     new Cell                      {
                         Stroke   = StrokeRight,
                         Children =                { process.Id                                 }
                     },
                     new Cell                      {
                         Stroke   = StrokeRight, Color = Yellow, TextWrap = TextWrap.NoWrap,
                         Children =                { process.ProcessName                        }
                     },
                     new Cell                      {
                         Stroke   = StrokeRight, Color = White, TextWrap = TextWrap.NoWrap,
                         Children =                { process.MainWindowTitle                    }
                     },
                     new Cell                      {
                         Stroke   = LineThickness.None, Align = Align.Right,
                         Children =                { process.PrivateMemorySize64.ToString("n0") }
                     },
                 })
             }
         }
     }
 };
예제 #26
0
        private static Element BuildFileTable(Torrent torrent)
        {
            if (torrent.Files != null)
            {
                return(new Stack(
                           $"Directory: {torrent.Files?.DirectoryName}",
                           new Grid
                {
                    Stroke = new LineThickness(LineWidth.None, LineWidth.None),
                    Columns =
                    {
                        new Column {
                            Width = GridLength.Star(1)
                        },
                        new Column {
                            Width = GridLength.Auto
                        }
                    },
                    Children =
                    {
                        UIHelper.Header("Path"),
                        UIHelper.Header("Size",  TextAlign.Center),
                        torrent.Files.Select(f => new[]
                        {
                            new Cell(f.FullPath),
                            new Cell(f.FileSize.ToString("N0"))
                            {
                                TextAlign = TextAlign.Right
                            },
                        })
                    }
                }));
            }

            if (torrent.File != null)
            {
                return(new Grid
                {
                    Stroke = new LineThickness(LineWidth.None, LineWidth.None),
                    Columns =
                    {
                        new Column {
                            Width = GridLength.Star(1)
                        },
                        new Column {
                            Width = GridLength.Auto
                        }
                    },
                    Children =
                    {
                        UIHelper.Header("Name"),
                        UIHelper.Header("Size",         TextAlign.Center),
                        new Cell(torrent.File.FileName),
                        new Cell(torrent.File.FileSize.ToString("N0"))
                        {
                            TextAlign = TextAlign.Right
                        },
                    }
                });
            }

            return(null);
        }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var response = await client.GetPeerPartialDataAsync(Hash);

                if (response == null)
                {
                    return(ExitCodes.Failure);
                }

                var peers = response.PeersChanged?.Values ?? Enumerable.Empty <PeerPartialInfo>();

                var doc = new Document(
                    new Grid
                {
                    Columns =
                    {
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Star(1)
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                        new Column {
                            Width = GridLength.Auto
                        },
                    },
                    Children =
                    {
                        UIHelper.Header("CC"),
                        UIHelper.Header("Endpoint"),
                        UIHelper.Header("Сlient"),
                        UIHelper.Header("Progress"),
                        UIHelper.Header("DL Speed",                            TextAlign.Center),
                        UIHelper.Header("UL Speed",                            TextAlign.Center),
                        UIHelper.Header("DL",                                  TextAlign.Center,   8),
                        UIHelper.Header("UL",                                  TextAlign.Center,   8),
                        peers.Select(p => new[]
                        {
                            new Cell(p.CountryCode),
                            new Cell(FormatEndpoint(p.Address,                 p.Port)),
                            new Cell(p.Client),
                            new Cell($"{p.Progress:P0}"),
                            new Cell(FormatSpeed(p.DownloadSpeed).PadLeft(10)),
                            new Cell(FormatSpeed(p.UploadSpeed).PadLeft(10)),
                            new Cell(FormatData(p.Downloaded).PadLeft(8)),
                            new Cell(FormatData(p.Uploaded).PadLeft(8)),
                        })
                    },
                    Stroke = LineThickness.Single
                }
                    ).SetColors(ColorScheme.Current.Normal);

                ConsoleRenderer.RenderDocument(doc);

                return(ExitCodes.Success);

                string FormatEndpoint(IPAddress address, int?port)
                {
                    if (address == null || port == null)
                    {
                        return(null);
                    }

                    return(new IPEndPoint(address, port.Value).ToString());
                }

                string FormatSpeed(int?speed)
                {
                    if (speed == null)
                    {
                        return(string.Empty);
                    }
                    if (speed < 1024)
                    {
                        return($"{speed}  B/s");
                    }
                    if (speed < 1024 * 1024)
                    {
                        return($"{speed / 1024} kB/s");
                    }
                    if (speed < 1024 * 1024 * 1024)
                    {
                        return($"{speed / (1024 * 1024)} MB/s");
                    }
                    return($"{speed / (1024 * 1024 * 1024)} GB/s");
                }

                string FormatData(long?amount)
                {
                    if (amount == null)
                    {
                        return(string.Empty);
                    }
                    if (amount < 1024)
                    {
                        return($"{amount}  B");
                    }
                    if (amount < 1024 * 1024)
                    {
                        return($"{amount / 1024} kB");
                    }
                    if (amount < 1024 * 1024 * 1024)
                    {
                        return($"{amount / (1024 * 1024)} MB");
                    }
                    return($"{amount / (1024 * 1024 * 1024)} GB");
                }
            }
예제 #28
0
        public static Document ToDocument <T>(T obj,
                                              IReadOnlyDictionary <string, Func <object, object> > customFormatters = null)
        {
            const string defaultFormat = "{0}";

            var properties = (
                from prop in typeof(T).GetRuntimeProperties()
                let attr = prop.GetCustomAttribute <DisplayAttribute>()
                           let name = attr?.Name ?? prop.Name
                                      let formatAttr = prop.GetCustomAttribute <DisplayFormatAttribute>()
                                                       orderby attr?.GetOrder() ?? 0
                                                       select(name, value: prop.GetValue(obj), format: formatAttr?.DataFormatString ?? defaultFormat, nullString: formatAttr?.NullDisplayText, propName: prop.Name)
                ).ToList();

            var document = new Document
            {
                Background = ColorScheme.Current.Normal.GetEffectiveBackground(),
                Color      = ColorScheme.Current.Normal.GetEffectiveForeground(),
                Children   =
                {
                    new Grid
                    {
                        Stroke  = NoneStroke,
                        Columns =
                        {
                            new Column {
                                Width = GridLength.Auto
                            },
                            new Column {
                                Width = GridLength.Star(1)
                            }
                        },
                        Children =
                        {
                            GetPairs().Select(p => Row(p.label, p.value))
                        }
                    }
                }
            };

            return(document);

            IEnumerable <(string label, object value)> GetPairs()
            {
                foreach (var property in properties)
                {
                    var label = property.name;
                    if (customFormatters != null && customFormatters.TryGetValue(property.propName, out var formatter))
                    {
                        var customValue = formatter(property.value);
                        if (customValue != null)
                        {
                            yield return(label, customValue);

                            continue;
                        }
                    }

                    var value = (property.value == null && property.nullString != null)
                        ? property.nullString
                        : string.Format(property.format, property.value);
                    yield return(label, value);
                }
            }
        }
예제 #29
0
        public static Document ProcessList(IEnumerable <Process> processes) =>
        new Document
        {
            Background = Black, Color = Gray
        }

        .AddChildren(
            new Grid {
            Stroke = StrokeHeader, StrokeColor = DarkGray
        }
            .AddColumns(
                new Column {
            Width = GridLength.Auto
        },
                new Column {
            Width = GridLength.Auto, MaxWidth = 20
        },
                new Column {
            Width = GridLength.Star(1)
        },
                new Column {
            Width = GridLength.Auto
        }
                )
            .AddChildren(
                new Cell {
            Stroke = StrokeHeader, Color = White
        }
                .AddChildren("Id"),
                new Cell {
            Stroke = StrokeHeader, Color = White
        }
                .AddChildren("Name"),
                new Cell {
            Stroke = StrokeHeader, Color = White
        }
                .AddChildren("Main Window Title"),
                new Cell {
            Stroke = StrokeHeader, Color = White
        }
                .AddChildren("Private Memory"),
                processes.Select(process => new[] {
            new Cell {
                Stroke = StrokeRight
            }
            .AddChildren(process.Id),
            new Cell {
                Stroke = StrokeRight, Color = Yellow, TextWrap = TextWrapping.NoWrap
            }
            .AddChildren(process.ProcessName),
            new Cell {
                Stroke = StrokeRight, Color = White, TextWrap = TextWrapping.NoWrap
            }
            .AddChildren(process.MainWindowTitle),
            new Cell {
                Stroke = LineThickness.None, Align = HorizontalAlignment.Right
            }
            .AddChildren(process.PrivateMemorySize64.ToString("n0")),
        })
                )
            );
예제 #30
0
 public Column()
 {
     Width    = GridLength.Star(1);
     MinWidth = 0;
     MaxWidth = Size.Infinity;
 }