Exemplo n.º 1
0
        private async void ConnectAsync()
        {
            Connection         = new HubConnection(ServerURI);
            Connection.Closed += Connection_Closed;
            HubProxy           = Connection.CreateHubProxy("MyHub");

            HubProxy.On <string, string>("AddMessage", (name, message) =>
            {
                Invoke((Action)(() =>
                                RichTextBoxConsole.AppendText(string.Format("{0}: {1}" + Environment.NewLine, name, message))
                                ));
                string Path = PathSaved + "\\" + DateTime.Now.ToLongDateString() + new Random().Next(214421414) + ".txt";
                using (StreamWriter writer = new StreamWriter(Path))
                {
                    writer.Write(Name + ":" + message);
                }
            }

                                         );
            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                StatusText.Text = "Unable to connect to server: Start server before connecting clients.";

                return;
            }

            SignInPanel.Visible = false;
            ChatPanel.Visible   = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine);
        }
Exemplo n.º 2
0
        private void ButtonAcceptChanges_Click(object sender, EventArgs e)
        {
            try
            {
                string _MsgId       = LabelMsgIdEdited.Text;
                string _MsgPriority = TextBoxEditedPriority.Text;
                string _MsgText     = TextboxMsgEdited.Text;

                if (_MsgId.Length == 0 || _MsgPriority.Length == 0 || _MsgText.Length == 0)
                {
                    throw new Exception("Что-то поломалось.Попробуйте еще раз.");
                }

                Connector.ExecuteNonQuery("UPDATE `message` SET `msg_priority`='" + _MsgPriority + "',`msg`='" + _MsgText + "' WHERE `msg_id`='" + _MsgId + "'");

                Server.Sender("PrioritySale", 7, "Редактирование сообщения с доски.");

                PanelEditMsgBack.Visible = false;

                TextBoxMessage.Focus();
            }
            catch (System.Exception ex)
            {
                Log.log_write("[ButtonAcceptChanges_Click]" + ex.Message, "EXCEPTION", "exception");
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>
        private async void ConnectAsync()
        {
            Connection         = new HubConnection(ServerURI);
            Connection.Closed += Connection_Closed;
            HubProxy           = Connection.CreateHubProxy("MyHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            HubProxy.On <string, string>("AddMessage", (name, message) =>
                                         this.Dispatcher.Invoke(() =>
                                                                RichTextBoxConsole.AppendText(String.Format("{0}: {1}\r", name, message))
                                                                )
                                         );
            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                StatusText.Content = "Unable to connect to server: Start server before connecting clients.";
                //No connection: Don't enable Send button or show chat UI
                return;
            }

            //Show chat UI; hide login UI
            SignInPanel.Visibility = Visibility.Collapsed;
            ChatPanel.Visibility   = Visibility.Visible;
            ButtonSend.IsEnabled   = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + "\r");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and connects the connection. Only uses one controller (chat). This method
        /// is called from SignInButton_Click.
        /// </summary>
        private async void Connect()
        {
            Connection = new XSocketClient(ServerURI, Origin, "chat");
            Connection.OnDisconnected += Connection_Disconnected;
            chatController             = Connection.Controller("chat");

            //Handle incoming event from server: use Invoke to write to console from XSocket's thread
            chatController.On <string>("addMessage", message => this.Invoke((Action)(() =>
                                                                                     RichTextBoxConsole.AppendText(String.Format("{0}" + Environment.NewLine, message))
                                                                                     )));

            try
            {
                Connection.Open();
                comboBoxLocation.SelectedIndex = 0;
                //Set username
                chatController.SetProperty("username", UserName);
            }
            catch
            {
                StatusText.Text = "Unable to connect to server: Start server before connecting clients.";
                //No connection: Don't enable Send button or show chat UI
                return;
            }

            //Activate UI
            SignInPanel.Visible = false;
            ChatPanel.Visible   = true;
            ButtonSend.Enabled  = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>
        private async void ConnectAsync()
        {
            Connection = new XSocketClient(ServerURI, Origin, "chat");
            Connection.OnDisconnected += Connection_Disconnected;
            chatController             = Connection.Controller("chat");

            //Handle incoming event from server: use Invoke to write to console from XSocket's thread
            chatController.On <string>("AddMessage", (message) =>
                                       this.Dispatcher.Invoke(() =>
                                                              RichTextBoxConsole.AppendText(String.Format("{0}\r", message))
                                                              )
                                       );

            try
            {
                await Connection.Open();

                //Set username
                await chatController.SetProperty("username", UserName);
            }
            catch
            {
                StatusText.Content = "Unable to connect to server: Start server before connecting clients.";
                //No connection: Don't enable Send button or show chat UI
                return;
            }

            //Show chat UI; hide login UI
            SignInPanel.Visibility = Visibility.Collapsed;
            ChatPanel.Visibility   = Visibility.Visible;
            ButtonSend.IsEnabled   = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + "\r");
        }
Exemplo n.º 6
0
 private void ButtonSend_Click(object sender, RoutedEventArgs e)
 {
     HubProxy.Invoke("Send", UserName, TextBoxMessage.Text);
     HubProxy.Invoke("SendOtvet", UserName, TextBoxMessage.Text);
     TextBoxMessage.Text = String.Empty;
     TextBoxMessage.Focus();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>
        private async void ConnectAsync()
        {
            Console.WriteLine("Connecting to {0}", ServerURI);

            Connection         = new HubConnectionBuilder().WithUrl(ServerURI).Build();
            Connection.Closed += Connection_Closed;
            //HubProxy = Connection.Create("MyHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            Connection.On <string, string>("Send", (name, message) =>
                                           this.Invoke((Action)(() =>
                                                                RichTextBoxConsole.AppendText(String.Format("{0}: {1}" + Environment.NewLine, name, message))
                                                                ))
                                           );
            try
            {
                await Connection.StartAsync();
            }
            catch (HttpRequestException)
            {
                StatusText.Text = "Unable to connect to server: Start server before connecting clients.";
                //No connection: Don't enable Send button or show chat UI
                return;
            }

            //Activate UI
            SignInPanel.Visible = false;
            ChatPanel.Visible   = true;
            ButtonSend.Enabled  = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine);
        }
        private async void ConnectAsync()
        {
            Connection         = new HubConnection(ServerUri);
            Connection.Closed += Connection_Closed;

            // 创建一个集线器代理对象
            HubProxy = Connection.CreateHubProxy("ChatHub");

            // 供服务端调用,将消息输出到消息列表框中
            HubProxy.On <string, string>("AddMessage", (name, message) =>
                                         this.Dispatcher.Invoke(() =>
                                                                RichTextBoxConsole.AppendText(String.Format("{0}: {1}\r", name, message))
                                                                ));

            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                ChatPanel.Visibility = Visibility.Visible;
                RichTextBoxConsole.AppendText("请检查服务是否开启:" + ServerUri + "\r");
                // 连接失败
                return;
            }

            // 显示聊天控件
            ChatPanel.Visibility = Visibility.Visible;
            ButtonSend.IsEnabled = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("连上服务:" + ServerUri + "\r");
        }
Exemplo n.º 9
0
 private void ButtonExact_Click(object sender, EventArgs e)
 {
     // Si il trouve le bon nombre.
     TextBoxMessage.Clear();      // Efface le texte
     TextBoxMessage.AppendText("J'ai trouvé le nombre en " + NbTentative + " tentative(s)");
     ButtonGrand.Enabled = false; // Désactive les boutons
     ButtonPetit.Enabled = false;
 }
Exemplo n.º 10
0
        private void ButtonSend_Click(object sender, EventArgs e)
        {
            //Call the method "send" on the server
            //Username is not needed since the server knows about it.
            chatController.Invoke("Send", TextBoxMessage.Text);

            TextBoxMessage.Text = String.Empty;
            TextBoxMessage.Focus();
        }
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonSend_Click(object sender, RoutedEventArgs e)
        {
            // 通过代理来调用服务端的Send方法
            // 服务端Send方法再调用客户端的AddMessage方法将消息输出到消息框中
            HubProxy.Invoke("Send", GenerateRandomName(4), TextBoxMessage.Text.Trim());

            TextBoxMessage.Text = String.Empty;
            TextBoxMessage.Focus();
        }
Exemplo n.º 12
0
        private void buttonSend_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TextBoxMessage.Text))
            {
                return;
            }
            _user.Send(TextBoxMessage.Text);

            VisualizeNewMessage(TextBoxMessage.Text, null);
            TextBoxMessage.Clear();
        }
Exemplo n.º 13
0
        public void SubmitForm(string textboxname, string textboxmessage, int boxtextnumber)

        {
            TextBoxName.EnterText(textboxname);
            System.Threading.Thread.Sleep(3000);
            TextBoxMessage.EnterText(textboxmessage);
            System.Threading.Thread.Sleep(3000);
            BoxCaptchaNumber.FillResultField(boxtextnumber);
            System.Threading.Thread.Sleep(3000);
            ClickSubmitButton.Click();
        }
        private void ButtonSend_Click(object sender, EventArgs e)
        {
            var toId = (string)lblModel.Tag;

            toId = (toId == "ALL") ? string.Empty : toId;
            imcp = new IMCommParamMessage()
            {
                msgType = msgType.Text, fromConnId = imModel.ConnId, toConnId = toId, message = TextBoxMessage.Text, isSuccess = true
            };
            HubProxy.Invoke("SendMessage", JsonConvert.SerializeObject(imcp));
            TextBoxMessage.Text = String.Empty;
            TextBoxMessage.Focus();
        }
Exemplo n.º 15
0
        public async void Window_ContentRendered(object sender, EventArgs e)
        {
            Starting = true;
            bool result = await Task.Run(() => InitAndClosePrevious());

            if (result == false)
            {
                Close();
            }
            MotdClass = new TextBoxMessage()
            {
                textBlock     = MotdBlockControl,
                dispatchTimer = new System.Windows.Threading.DispatcherTimer()
            };
            topTextBoxClass = new TextBoxMessage()
            {
                textBlock     = TextBlockControl,
                dispatchTimer = new System.Windows.Threading.DispatcherTimer()
            };

            IsUserjgentile         = String.Compare(Environment.UserName, "jgentile", true) == 0;
            GCSettings.LatencyMode = GCLatencyMode.LowLatency;
            PSource    = PresentationSource.FromVisual(this);
            thisHandle = new WindowInteropHelper(this).Handle;

            progressBar.Visibility      = Visibility.Hidden;
            TextBlockControl.Visibility = Visibility.Hidden;
            MotdBlockControl.Visibility = Visibility.Hidden;

            dispatcherPlaying.Tick      += DisplayNextImageTimer;
            dispatcherPureSense.Tick    += MouseHide;
            dispatcherPureSense.Interval = new TimeSpan(0, 0, 0, 5, 0);

            LoadSettings();
            NotifyStart();
            Starting = false;

            if (string.IsNullOrEmpty(SlideShowDirectory) || !Directory.Exists(SlideShowDirectory))
            {
                await OpenDirCheckCancel();
            }
            else
            {
                await Task.Run(() => StartGetFiles());
                await DisplayGetNextImageWithoutCheck(1);
            }
            MenuPlay();
            dispatcherPureSense.Stop();
            dispatcherPureSense.Start();
            EnableMotdCode();
        }
Exemplo n.º 16
0
        private void buttonNouveau_Click(object sender, EventArgs e)
        {
            // Assigne une valeurs aux attributs, génére nombre Random
            NbEssais    = 20;
            NbTentative = 0;
            BorneInf    = 0;
            BorneSup    = 10000;
            Nombre      = (BorneSup - BorneInf) / 2;

            // Réactive les boutons
            ButtonExact.Enabled = true;
            ButtonGrand.Enabled = true;
            ButtonPetit.Enabled = true;
            TextBoxMessage.Clear();
            TextBoxMessage.AppendText("Votre chiffre est " + Nombre + "  ?");
        }
Exemplo n.º 17
0
 private void TrafficController_OnSuccessMessageSend(TrafficController sender, bool error)
 {
     if (messageSend)
     {
         if (!error)
         {
             TypeText("Ja", TextBoxMessage.Text, messageSendTime);
             TextBoxMessage.Clear();
             messageSend = false;
         }
         else
         {
             MessageBox.Show("Nie udało się wysłać wiadomości", "Error");
         }
     }
 }
Exemplo n.º 18
0
        private void DeleteFromMsg(string _MsgId)
        {
            string message = "Вы действительно хотите удалить сообщение с номером " + _MsgId + "?";
            string caption = "Удаление";
            var    result  = MessageBox.Show(message, caption,
                                             MessageBoxButtons.YesNo,
                                             MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                Connector.ExecuteNonQuery("DELETE FROM `message` WHERE `msg_id` = " + _MsgId);

                Server.Sender("PrioritySale", 7, "Удаление сообщения с доски.");

                TextBoxMessage.Focus();
            }
        }
Exemplo n.º 19
0
        private void ButtonPetit_Click(object sender, EventArgs e)
        {
            BorneInf = Nombre;
            Nombre   = (BorneSup - BorneInf) / 2;
            Nombre   = Nombre + BorneInf;
            TextBoxMessage.Clear();
            TextBoxMessage.AppendText("Votre chiffre est " + Nombre + "  ?");
            NbTentative++; // Incrémentation nombre de tentative
            NbEssais--;    // Décrémentation nombre d'essai

            // Si le nombre d'essai atteint 0
            if (NbEssais == 0)
            {
                TextBoxMessage.Clear();
                TextBoxMessage.AppendText("Oups j'ai perdu ! Vous êtes vraiment fort ");
            }
        }
Exemplo n.º 20
0
        private void InsertTag(string tag)
        {
            string code = TextBoxMessage.Text;

            TextBoxMessage.Text = code.Insert(CursorPosition, tag);
            TextBoxMessage.Focus();
            if (tag == "<br>" || tag == "<hr>")
            {
                TextBoxMessage.Select(CursorPosition + tag.Length, 0);
                CursorPosition += tag.Length;
            }
            else
            {
                TextBoxMessage.Select(CursorPosition + tag.Length / 2, 0);
                CursorPosition += tag.Length / 2;
            }
        }
Exemplo n.º 21
0
        public void SendMessage(string message)
        {
            if (message.IsNullOrWhiteSpace())
            {
                return;
            }

            switch ((DateTime.Now - msgTimeStamp).Ticks)
            {
            case < 10000000:
                return;
            }

            msgTimeStamp = DateTime.Now;

            IrcClient.SendMessage(Recipient, message);
            AddChatMessage(UserName, message);

            TextBoxMessage.Text = "";
            TextBoxMessage.Focus();
        }
Exemplo n.º 22
0
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>

        private async void ConnectAsync()
        {
            string ServerURI = String.Empty;

            try
            {
                ServerURI = ServerUriBuilder.GetServerUriForClient(this.textBox1.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Podany adres jest nieprawidłowy. Wyjątek: {ex.Message}");
                return;
            }

            Connection         = new HubConnection(ServerURI);
            Connection.Closed += Connection_Closed;
            HubProxy           = Connection.CreateHubProxy("MyHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            HubProxy.On <string, string>("AddMessage", (name, message) =>
                                         this.Invoke((Action)(() =>
                                                              RichTextBoxConsole.AppendText(String.Format("{0} {1}: {2}" + Environment.NewLine, name, DateTime.Now, message))
                                                              ))
                                         );
            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                StatusText.Text = "Unable to connect to server: Start server before connecting clients.";
                //No connection: Don't enable Send button or show chat UI
                return;
            }
            //Activate UI
            SignInPanel.Visible = false;
            ChatPanel.Visible   = true;
            ButtonSend.Enabled  = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine);
        }
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>
        private async void ConnectAsync()
        {
            Dictionary <string, string> hubConnParams = new Dictionary <string, string> {
                { "Param", JsonConvert.SerializeObject(imModel) }
            };

            Connection              = new HubConnection(ServerURI, hubConnParams);
            Connection.Closed      += Connection_Closed;
            Connection.Reconnected += Connection_Succeed;

            HubProxy = Connection.CreateHubProxy("MyHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            //HubProxy.On<string, string>("AddMessage", (ServiceName, Data) =>
            //    this.Invoke((Action)(() => {
            //        RichTextBoxConsole.AppendText(String.Format("Service - {0}:\n {1}" + Environment.NewLine, ServiceName, Data));
            //    }))
            //);
            HubProxy.On <string>("AddMessage", doMessage);
            try {
                await Connection.Start();

                imModel.ConnId        = Connection.ConnectionId;
                ConnectionStatus.Text = "服务器连接成功!" + imModel.ConnId;
                btnConnSrv.Text       = "重新连接";
                Connection_Succeed();
            } catch (HttpRequestException e) {
                ConnectionStatus.Text = "服务器连接失败:" + e.Message;
                //No connection: Don't enable Send button or show chat UI
                btnConnSrv.Enabled = true;
                return;
            }

            //Activate UI
            ButtonSend.Enabled = true;
            TextBoxMessage.Focus();
            RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine);
        }
Exemplo n.º 24
0
 private void btnSendAnoymous_Click(object sender, RoutedEventArgs e)
 {
     HubProxy.Invoke("Send", TextBoxMessage.Text);
     TextBoxMessage.Text = String.Empty;
     TextBoxMessage.Focus();
 }
Exemplo n.º 25
0
 private void ButtonSend_Click(object sender, RoutedEventArgs e)
 {
     chatController.Invoke("Send", TextBoxMessage.Text);
     TextBoxMessage.Text = String.Empty;
     TextBoxMessage.Focus();
 }
Exemplo n.º 26
0
 private void ButtonSend_Click(object sender, EventArgs e)
 {
     parser.SendData(TextBoxMessage.Text, tabControl.TabCount == 0 ? null : tabControl.SelectedTab.Name);
     TextBoxMessage.Clear();
 }
Exemplo n.º 27
0
 private void ButtonSend_Click(object sender, EventArgs e)
 {
     Connection.InvokeAsync("Send", UserName, TextBoxMessage.Text).Wait();
     TextBoxMessage.Text = String.Empty;
     TextBoxMessage.Focus();
 }
Exemplo n.º 28
0
        private void ButtonCancelChanges_Click(object sender, EventArgs e)
        {
            PanelEditMsgBack.Visible = false;

            TextBoxMessage.Focus();
        }