示例#1
0
        public void PrintMessage(string message)
        {
            var formattedMessage = new ColoredMessageBuilder()
                                   .With(message)
                                   .Build();

            ChatBlock.Document.Blocks.Add(formattedMessage);
            ChatBlock.ScrollToEnd();
        }
示例#2
0
        private void PrintUserLine(string user, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            var formattedMessage = new ColoredMessageBuilder()
                                   .With(user + ": ", Brushes.RoyalBlue)
                                   .With(message)
                                   .Build();

            ChatBlock.Document.Blocks.Add(formattedMessage);
            ChatBlock.ScrollToEnd();
        }
示例#3
0
        public void tail()
        {
            taskBool = true;
            string lastLine;
            var    helper = new FlashWindowHelper(Application.Current);

            try
            {
                FileStream   fs = new FileStream(settings.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader sr = new StreamReader(fs);
                sr.BaseStream.Seek(0, SeekOrigin.End);

                while (taskBool)
                {
                    try
                    {
                        lastLine = sr.ReadLine();

                        if (lastLine == null || lastLine == "")
                        {
                            Task.Delay(1000);
                            continue;
                        }
                        else if (lastLine.Contains("] @From") || settings.keywords.Any(lastLine.ToUpper().Contains))
                        {
                            MESSAGES_COUNT++;
                            var count     = settings.keywords.Count();
                            var superlist = settings.keywords;

                            lastLine = lastLine.Split(new string[] { "] " }, StringSplitOptions.None)[1];
                            ChatBlock.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                            {
                                var lineRegex = UNHUMAN_REGEX.Match(lastLine);
                                LAST_NICKNAME = lineRegex.Groups["sas"].ToString();
                                LAST_MESSAGE  = lineRegex.Groups["text"].ToString();
                                ChatBlock.AppendText(lastLine + "\n");
                                MainScroll.ScrollToEnd();
                                helper.FlashApplicationWindow();
                            }
                                                                                                                       ));
                            MessagesCountLabel.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                            {
                                MessagesCountLabel.Text = MESSAGES_COUNT.ToString();
                            }
                                                                                                                                ));
                            CreateToast(LAST_NICKNAME, LAST_MESSAGE);
                        }
                    }
                    catch (System.IndexOutOfRangeException)
                    {
                        ChatBlock.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            TextRange tr = new TextRange(ChatBlock.Document.ContentEnd, ChatBlock.Document.ContentEnd)
                            {
                                Text = "Wrong data range \n"
                            };
                            tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);
                            helper.FlashApplicationWindow();
                        }
                                                                                                                   ));
                        continue;
                    }
                }
            }
            catch (FileNotFoundException)
            {
                taskBool = false;
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                {
                    BtnStart.IsEnabled = true;
                    BtnStop.IsEnabled  = false;
                }
                                                                                                 ));
                MessageBox.Show("Please choose proper client.txt file", "File not found", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }