Example #1
0
        private void Bot_GotResposta(List <string> respostas)
        {
            TextBlock textBlock2;

            Label label2;

            foreach (string resposta in respostas)
            {
                textBlock2 = new TextBlock();

                label2 = new Label();

                textBlock2.HorizontalAlignment = HorizontalAlignment.Left;
                textBlock2.VerticalAlignment   = VerticalAlignment.Bottom;
                textBlock2.Background          = Brushes.LightGray; //new LinearGradientBrush(Colors.LightGray, Colors.LightGray, 0);
                textBlock2.Foreground          = Brushes.Black;
                textBlock2.IsEnabled           = false;
                textBlock2.TextWrapping        = TextWrapping.Wrap;
                label2.Content = "  ";

                textBlock2.Text = resposta;

                StackPanelChat.Children.Add(label2);
                StackPanelChat.Children.Add(textBlock2);
                ScrollViewerChat.ScrollToBottom();
            }
        }
        private void ButtonSendChat_Click(object sender, RoutedEventArgs e)
        {
            String stringSend  = null;
            String AppUserName = AppUser.Name + " " + AppUser.LastName;
            String ProfilePic  = AppUser.ProfilePic;

            stringSend = AppUserName + "#$#$" + ProfilePic + "#$#$" + TextBoxChat.Text;
            string s = TextBoxChat.Text;

            TextBoxChat.Clear();

            if (!_isConnected)
            {
                MessageBox.Show("Not conected to server"); return;
            }

            ChatBox cb = new ChatBox(false, s, "YOU", ProfilePic);

            cb.HorizontalAlignment = HorizontalAlignment.Right;
            cb.Margin = new Thickness(0, 0, 0, 3);
            StackPanelChat.Children.Add(cb);
            ScrollViewerChat.ScrollToBottom();
            _sWriter = new StreamWriter(_client.GetStream(), Encoding.ASCII);
            _sWriter.WriteLine(stringSend);
            _sWriter.Flush();
        }
        public void HandleCommunication()
        {
            _sReader     = new StreamReader(_client.GetStream(), Encoding.ASCII);
            _isConnected = true;
            String  sData = null;
            ChatBox cb;

            //detele this if u on Winforms/wpf
            //Console.WriteLine(_sReader.ReadLine().ToString());

            while (_isConnected)
            {
                // if you want to receive anything
                String sDataIncomming = _sReader.ReadLine();
                Console.WriteLine(sDataIncomming);
                //  MethodInvoker m = new MethodInvoker(() => clientForm.textBox1.Text += ("Server: " + sDataIncomming + Environment.NewLine));
                //Dispatcher.Invoke(new Action(() => chat.Text += sData));


                //split string for easier work
                String[] stuff      = sDataIncomming.Split(new string[] { "#$#$" }, StringSplitOptions.None);
                String   Nume       = stuff[0];
                String   ProfilePic = stuff[1];
                String   Message    = stuff[2];
                Console.WriteLine(Nume + "   " + Message);
                Console.WriteLine("Spawning...");
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    cb = new ChatBox(true, Message, Nume, ProfilePic);
                    cb.HorizontalAlignment = HorizontalAlignment.Left;
                    cb.Margin = new Thickness(0, 0, 0, 3);
                    StackPanelChat.Children.Add(cb);

                    Console.WriteLine("Am spawnat");
                    int i = 0;
                    if (BadgeChat.Badge.ToString() != "")
                    {
                        i = Convert.ToInt32(BadgeChat.Badge.ToString());
                    }
                    if (Drawer.IsLeftDrawerOpen == false)
                    {
                        BadgeChat.Badge = ++i;
                    }
                    else
                    {
                        ScrollViewerChat.ScrollToBottom();
                    }
                }));
            }
        }
Example #4
0
        private void SetHyperlink(string text)
        {
            if (Chat.Dispatcher.Thread == Thread.CurrentThread)
            {
                Border borderOkienka = new Border();
                if (text.Substring(0, 2) == "Ja")
                {
                    borderOkienka.Background          = new SolidColorBrush(Color.FromRgb(65, 174, 207));
                    borderOkienka.HorizontalAlignment = HorizontalAlignment.Right;
                }
                else
                {
                    borderOkienka.Background          = new SolidColorBrush(Color.FromRgb(68, 68, 68));
                    borderOkienka.HorizontalAlignment = HorizontalAlignment.Left;
                }

                borderOkienka.CornerRadius    = new CornerRadius(4);
                borderOkienka.BorderThickness = new Thickness(1);

                string[] lines = text.Split(new Char[] { '?', '!' });
                //int index = text.IndexOf("?");
                //int lastindex = text.- 1;
                //Console.WriteLine(index);
                //string text1 = text.Substring(0, index);
                //string hiperlink = text.Substring(index + 1, lastindex);
                string folderName = nr.ToString() + "_" + mynumber.ToString();
                var    h          = new Hyperlink();
                h.Inlines.Add(lines[1]);
                h.Click += (s, a) => { download(lines[1], folderName); };
                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;
                textBlock.Inlines.Add(lines[0]);
                textBlock.Inlines.Add(h);
                textBlock.Inlines.Add("\n");
                textBlock.Foreground = new SolidColorBrush(Colors.White);
                borderOkienka.Child  = textBlock;
                stackPanelBorder.Children.Add(borderOkienka);
            }
            else
            {
                Console.WriteLine("SetTextHTML");
                SetTextCallBack f = new SetTextCallBack(SetHyperlink);
                Dispatcher.Invoke(f, new object[] { text });
            }
            if (ScrollViewerChat.VerticalOffset == ScrollViewerChat.ScrollableHeight)
            {
                ScrollViewerChat.ScrollToEnd();
            }
        }
Example #5
0
 public void UpdateWhisper(string sender, string whisper, int gameID)
 {
     Dispatcher.Invoke(() => {
         if (this.gameID == gameID)
         {
             ListViewChat.Items.Add(new ChatMessage(sender, whisper, "Gray"));
             ScrollViewerChat.ScrollToBottom();
             foreach (GridViewColumn column in GridView.Columns)
             {
                 column.Width = 0;
                 column.Width = double.NaN;
             }
         }
     });
 }
Example #6
0
        private void SetTextHTML(string text)
        {
            if (Chat.Dispatcher.Thread == Thread.CurrentThread)
            {
                //   Chat.Text += text;
                // Chat.Text = Chat.Text + text;
                Border borderOkienka = new Border();
                if (text.Substring(0, 2) == "Ja")
                {
                    borderOkienka.Background          = new SolidColorBrush(Color.FromRgb(3, 145, 253));
                    borderOkienka.HorizontalAlignment = HorizontalAlignment.Right;
                }
                else
                {
                    borderOkienka.Background          = new SolidColorBrush(Color.FromRgb(68, 68, 68));
                    borderOkienka.HorizontalAlignment = HorizontalAlignment.Left;
                }

                borderOkienka.CornerRadius    = new CornerRadius(4);
                borderOkienka.BorderThickness = new Thickness(1);

                //b.BorderThickness = new Thickness{Top=1, Bottom=0, Left=1, Right=1};

                TextBlock textBlock = new TextBlock();
                textBlock.TextWrapping = TextWrapping.Wrap;
                textBlock.Text        += text;
                textBlock.Foreground   = new SolidColorBrush(Colors.White);
                borderOkienka.Child    = textBlock;
                stackPanelBorder.Children.Add(borderOkienka);
            }
            else
            {
                Console.WriteLine("SetTextHTML");
                SetTextCallBack f = new SetTextCallBack(SetTextHTML);
                Dispatcher.Invoke(f, new object[] { text });
            }
            if (ScrollViewerChat.VerticalOffset == ScrollViewerChat.ScrollableHeight)
            {
                ScrollViewerChat.ScrollToEnd();
            }
        }
Example #7
0
        private async void ButtonSend_Click(object sender, RoutedEventArgs e)
        {
            TextBlock textBlock1 = new TextBlock();
            Label     label1     = new Label();

            textBlock1.HorizontalAlignment = HorizontalAlignment.Right;

            textBlock1.VerticalAlignment = VerticalAlignment.Bottom;

            textBlock1.Background = Brushes.LightGreen; // new LinearGradientBrush(Colors.Green, Colors.Green, 0);

            textBlock1.Foreground = Brushes.Black;

            textBlock1.IsEnabled = false;

            label1.Content  = "  ";
            textBlock1.Text = TextBoxMensagem.Text;

            StackPanelChat.Children.Add(label1);
            StackPanelChat.Children.Add(textBlock1);
            ScrollViewerChat.ScrollToBottom();

            await bot.ProcuraResposta(TextBoxMensagem.Text);
        }