コード例 #1
0
        public void Invite(ControlMessage m)
        {
            if (ClientApp.GetInstance().GetChats().ContainsKey(m.ID))
            {
                return;
            }

            Console.WriteLine(@"Invitation received from " + m.Sender + " to join " + m.ID);
            ClientApp.GetMainWindow().LaunchInviteWindow(m);
        }
コード例 #2
0
ファイル: ChatBox.cs プロジェクト: cdanielgomes/FEUP-TDIN
 private void Logout()
 {
     ClientApp.GetInstance().GetChats().Remove(this.ID);
     UnsubscibeChat();
     try
     {
         _chat.CloseChat();
     }
     catch (Exception ex)
     {
     }
 }
コード例 #3
0
        public void AcceptChat(ActiveUser user, string chatName, RemoteChat chat, string number)
        {
            if (ClientApp.GetInstance().GetChats().ContainsKey(number))
            {
                return;
            }
            if (!ClientApp.GetInstance().GetPendingChats().Remove(number))
            {
                Console.WriteLine("Not found  element");
            }

            ClientApp.GetMainWindow().StartChatBox(user, chatName, chat, number);
        }
コード例 #4
0
        public void StartChatBox(ActiveUser user, string chatName, RemoteChat chat, string number)
        {
            if (InvokeRequired)
            {
                BeginInvoke((MethodInvoker) delegate { StartChatBox(user, chatName, chat, number); });
            }
            else
            {
                ChatBox box = new ChatBox(user, chatName, chat, number);

                ClientApp.GetInstance().AddChat(number, box);
                box.Show();
            }
        }
コード例 #5
0
        private void MainWindow_FormClosed(object sender, FormClosedEventArgs e)
        {
            var chatDictionary = ClientApp.GetInstance().GetChats();

            foreach (var id in ClientApp.GetInstance().GetChatIds())
            {
                if (chatDictionary.ContainsKey(id))
                {
                    chatDictionary[id].CloseChat();
                }
            }
            LogoutSession();

            Application.Exit();
        }
コード例 #6
0
        private void Logout_Click(object sender, EventArgs e)
        {
            var chatDictionary = ClientApp.GetInstance().GetChats();

            foreach (var id in ClientApp.GetInstance().GetChatIds())
            {
                if (chatDictionary.ContainsKey(id))
                {
                    chatDictionary[id].CloseChat();
                }
            }

            ClientApp.GetInstance().GetChatIds().Clear();
            LogoutSession();
            Application.Exit();
        }
コード例 #7
0
        private void CreateChat_Click(object sender, EventArgs e)
        {
            List <ActiveUser> users = new List <ActiveUser>();

            var  selectedUsers = listView1.SelectedItems;
            bool groupChat     = selectedUsers.Count > 1;

            for (var index = 0; index < selectedUsers.Count; index++)
            {
                foreach (var contact in _onlineUsers)
                {
                    if (contact.Username.Equals(selectedUsers[index].Text))
                    {
                        users.Add(contact);

                        break;
                    }
                }
            }


            string id     = CreateID(users);
            bool   exists = ClientApp.GetInstance().GetPendingChats().Contains(id) || ClientApp.GetInstance().GetChats().ContainsKey(id);

            if (users.Count == 1 && !exists)
            {
                IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), users[0].Address);
                ClientApp.GetInstance().GetPendingChats().Add(id);
                RemoteChat chat = new RemoteChat();

                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), Client.ClientApp.GetLoggedUser().Username, chat, id));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Invitation Failed");
                        Console.WriteLine(e);
                    }
                    Console.WriteLine("success");
                });
            }
            else if (users.Count > 1 && !exists)
            {
                Form1 chatNameForm = new Form1();
                chatNameForm.ShowDialog();
                RemoteChat chat = new RemoteChat();

                foreach (var user in users)
                {
                    IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), user.Address);

                    Task.Factory.StartNew(() =>
                    {
                        Console.WriteLine(@"Invitation sent to " + user.Username + " to join " + chatNameForm.GetText);
                        try
                        {
                            friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), chatNameForm.GetText, chat, id));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Invitation Failed");
                            Console.WriteLine(e);
                        }
                        Console.WriteLine("success");
                    });
                }
            }
            else if (users.Count < 1)
            {
                MessageBox.Show("Please select a user of a group of users",
                                "No user was selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Chat already created or Invites sent", "Already Created",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #8
0
 private void registerButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (passwordBox.Text != textBox2.Text)
         {
             MessageBox.Show("Passwords do not match!", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (ClientApp.GetServer().RegisterUser(nicknameBox.Text, textBox2.Text, passwordBox.Text))
         {
             Console.WriteLine(@"Registration worked");
             ActiveUser newUser = ClientApp.GetServer().LoginUser(nicknameBox.Text, passwordBox.Text, ClientApp.GetInstance().Address);
             if (newUser != null)
             {
                 ClientApp.SetLoggedUser(newUser);
                 Console.WriteLine(@"Login worked");
                 this.Hide();
                 ClientApp.SetMainWindow(new MainWindow(newUser));
                 ClientApp.GetMainWindow().ShowDialog();
             }
         }
         else
         {
             MessageBox.Show("8 characters minimum;" + Environment.NewLine + "Can not have white spaces, <, >, \' or \"", "Password Rules", MessageBoxButtons.OK);
         }
     }
     catch (Exception ex)
     {
         ClientApp.LaunchServerError(ex.Message);
     }
 }
コード例 #9
0
 private void loginButton_Click(object sender, EventArgs e)
 {
     try
     {
         ActiveUser newUser = ClientApp.GetServer().LoginUser(nicknameBox.Text, passwordBox.Text, ClientApp.GetInstance().Address);
         if (newUser != null)
         {
             ClientApp.SetLoggedUser(newUser);
             Console.WriteLine(@"Login worked");
             this.Hide();
             ClientApp.SetMainWindow(new MainWindow(newUser));
             ClientApp.GetMainWindow().ShowDialog();
         }
         else
         {
             MessageBox.Show("Login Failed: Be sure that you were registred with those credentials",
                             "Login Failed",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             nicknameBox.Text = "";
             passwordBox.Text = "";
         }
     }
     catch (Exception ex)
     {
         ClientApp.LaunchServerError(ex.Message);
     }
 }
コード例 #10
0
 public void RejectChat(ActiveUser user, string chatName, string id)
 {
     ClientApp.GetInstance().GetPendingChats().Remove(id);
     ClientApp.GetMainWindow().RejectedChat(user, chatName);
 }