コード例 #1
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);
        }
コード例 #2
0
        // returns -1 if that chat doesnt exist, userID otherwise
        public int PrintChat(int id_targetUser)
        {
            if (!chats.Exists(x => x.IdUser == id_targetUser))
            {
                return(-1);
            }

            ChatData chosenChat = chats.Find(x => x.IdUser == id_targetUser);

            if (chosenChat.IsInitialized == false)
            {
                int messagesNum = Convert.ToInt32(Settings.GetSetting("messages to display").State);

                chosenChat.initMessages(dbHelper.GetLastMessages(messagesNum, id_currentUser, id_targetUser));
            }

            Printer.PrintChat(chosenChat);
            chosenChat.CountNewMes = 0;
            return(chosenChat.IdUser);
        }