示例#1
0
 public ChatBox(ActiveUser user, string chatName, RemoteChat chat, string id)
 {
     _user     = user;
     _messages = new SortedSet <Message>();
     files     = new List <byte[]>();
     InitializeComponent();
     nameOfTheChat.Text = chatName == user.Username ? user.Username : chatName;
     _chatName          = chatName;
     _chat = chat;
     ID    = id;
     SubscribeChat();
 }
示例#2
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);
        }
示例#3
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();
            }
        }
示例#4
0
 public InviteWindow(ActiveUser user, string chatName, RemoteChat chat, string id)
 {
     try
     {
         Console.WriteLine(user.Username, user.Address);
         InitializeComponent();
         label1.Text       += user.Username;
         nameOfTheChat.Text = user.Username != chatName ?  "Chat Name " + chatName : "";
         _iFriend           = (IClientRem)RemotingServices.Connect(typeof(IClientRem), user.Address);
         _user     = user;
         _chatName = chatName;
         _chat     = chat;
         _id       = id;
     } catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
示例#5
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);
            }
        }