Exemplo n.º 1
0
 private void timer_Tick(object sender, EventArgs e)
 {
     if (socket.msgsList.Count > 0)
     {
         Message msg = socket.msgsList[0];
         if (msg != null)
         {
             if (msg.Key.Equals(MsgType.CHAT_MSG))
             {
                 this.addMsgOnScreen(msg);
             }
             socket.msgsList.RemoveAt(0);
         }
     }
 }
Exemplo n.º 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (clientSocket.msgsList.Count > 0)
            {
                Message message = clientSocket.msgsList[0];
                switch (message.Key)
                {
                case MsgType.REFRESH_FILES_LIST_MSG:
                {
                    UpdateFilesList();
                    clientSocket.msgsList.RemoveAt(0);
                    break;
                }

                case MsgType.FAIL_SYNC_FILES_MSG:
                {
                    InformUserAboutFailSyncFilesAfterReEstablishedConnection(message.Value);
                    clientSocket.msgsList.RemoveAt(0);
                    break;
                }

                case MsgType.AUTHORIZATION_MSG:
                {
                    clientSocket.SendMsg(new Message()
                        {
                            Key         = MsgType.AUTHORIZATION_MSG,
                            Value       = client_name,
                            Sender      = client_name,
                            Destination = "Server"
                        });
                    SetConnectionStatus(true);
                    string serializedObject = new JavaScriptSerializer().Serialize(new SynchronizeAfterConnectionEstablishedMsg()
                        {
                            filesList = filesListFromJson,
                            sender    = client_name
                        });
                    MakePostRequest("SynchronizeAfterConnectionEstablished/",
                                    new { synchMsg = serializedObject });
                    clientSocket.msgsList.RemoveAt(0);
                    break;
                }

                case MsgType.CHAT_MSG:
                {
                    if (chatForm == null)
                    {
                        chatForm = new ChatForm(client_name, message.Sender, clientSocket, this);
                    }

                    bool isOpen = false;
                    foreach (Form f in Application.OpenForms)
                    {
                        if (f.Equals(chatForm))
                        {
                            isOpen = true;
                        }
                    }
                    if (!isOpen)
                    {
                        chatForm.Show(this);
                    }

                    break;
                }
                }
            }
            if (clientSocket.isConnected() != WebSocket4Net.WebSocketState.Open)
            {
                onlineTimer.Stop();
                offlineTimer.Start();
                SetConnectionStatus(false);
            }
        }
Exemplo n.º 3
0
 public void addMsgOnScreen(Message msg)
 {
     tbChat.Text += msg.Sender + ": ";
     tbChat.Text += msg.Value + "\r\n";
 }