Example #1
0
 public void sendDataConferention(OneConferention conferention, string jid)
 {
     XDocument message = new XDocument(new XDeclaration("1.0", "windows-1251", "yes"));
     XElement users = new XElement("users");
     users.Add(conferention.users);
     XElement conf = new XElement("conf", new XAttribute("id", conferention.id), new XAttribute("name", conferention.name), new XAttribute("length", conferention.length), users);
     message.Add(conf);
     sendMessage(jid, message.ToString());
 }
Example #2
0
 private void createConference_Click(object sender, EventArgs e)
 {
     initForm2();
     string conferenceName = "конференция ёпт" + idConf;
     string createrJid = login.Text;
     List<string> users = new List<string> { "*****@*****.**", "*****@*****.**", "*****@*****.**" };
     OneConferention conf = new OneConferention(idConf.ToString(), conferenceName, createrJid, users);
     conferentions.Add(conf);
     client.sendInviteConferention(users, conf);
     createTabPage(conferenceName, createrJid + " (" + DateTime.Now.ToString() + ")"
         + Environment.NewLine + "Го! Я создал!" + Environment.NewLine + Environment.NewLine, idConf.ToString());
 }
Example #3
0
File: temp.cs Project: Khelek/XMPP
        private void createConference_Click(object sender, EventArgs e)
        {
            string conferenceName = "Конференция " + idConf;
            idConf++;//костыль, id надо хранить на серваке, либо при отсылке приглашений сравнивать на наличие id у клиентов, но это плохой план
            string createrJid = login;
            /*for (int i = 0; i < listBoxUsers.SelectedItems.Count; i++)
                users.Add(listBoxUsers.SelectedItems[i].ToString());*/

            FormCreateConferention fCreate = new FormCreateConferention(listBoxUsers.Items);
            fCreate.ShowDialog();

            List<string> users = fCreate.selectedUsers;
            if (users.Count == 0) return;
            initFormDialog();
            OneConferention conf = new OneConferention(idConf.ToString(), conferenceName, createrJid, new List<string>(users));
            conferentions.Add(conf);
            client.sendInviteConferention(users, conf.toString());
            //можно еще добавить отправку всем "Конференция создана"

            createTabPage(conferenceName, null, idConf.ToString());
        }
Example #4
0
        public void sendInviteConferention(List<string> jidUsers, OneConferention conferention)
        {
            string message = "";
            using (var stream = new MemoryStream())
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, conferention);
                byte[] b = stream.ToArray();
                message = BitConverter.ToString(b);
            }
            int x = message.Length;

            for (int i = 0; i < jidUsers.Count; i++)
            {
                sendMessage(jidUsers[i], "<conf>" + message);
            }
        }
Example #5
0
        private void HandlerOnMessege(object msg)
        {
            tabsDialog.Invoke(new MethodInvoker(delegate
            {
                Message mess = (Message)msg;
                if (client.thread == null)                                                 //если сообщение не относиться к конференции(уже существующей конференции)
                {
                    if (client.mess.Length > 5 && client.mess.Substring(0, 6) == "<conf>") //если приглашение
                    {
                        OneConferention conferention = stringToConferention();
                        if (conferention.id == null)
                        {
                            return;     // такого тащемта быть не должно
                        }

                        if (conferentions.Contains(conferention.id))    //если приглашение пришло на уже существующую конференцию
                        {
                            OneConferention conf = conferentions[conferentions.Find(conferention.id)];
                            int indexTab         = findTagPage(conf.name);
                            if (indexTab == -1)
                            {
                                createTabPage(conferention.name, null, conferention.id);    //вместо null(текст внутри tabPage) по идее должна быть история конференции,
                                //её придется передавать также, желательно с помощью функции из класса Conferentions
                            }
                            return;    //конференция уже существует
                        }

                        if (MessageBox.Show("Вас пригласили в конференцию " + conferention.name + ". Желаете принять участие?", "Приглашение", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            initFormDialog();
                            conferentions.Add(conferention);
                            createTabPage(conferention.name, null, conferention.id);    //вместо null(текст внутри tabPage) по идее должна быть история конференции,
                            //её придется передавать также, желательно с помощью функции из класса Conferentions
                        }
                    }

                    else //простое сообщение
                    {
                        initFormDialog();
                        int indexTab = findTagPage(client.from);
                        if (indexTab != -1) //если уже существует вкладка для него
                        {
                            string nameTalker = tabsDialog.TabPages[indexTab].Text;
                            ((TextBox)tabsDialog.TabPages[indexTab].Controls[0]).AppendText(nameTalker + " (" + DateTime.Now.ToString() + ")"//Controls[0] - это textBox с диалогом
                                                                                            + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);
                            tabsDialog.Focus();
                        }
                        else
                        {
                            createTabPage(client.from, client.from + " (" + DateTime.Now.ToString() + ")"
                                          + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);
                            tabsDialog.Focus();
                        }
                    }
                }
                else //сообщение к конференции
                {
                    initFormDialog();
                    int indexTab = tabsDialog.TabPages.IndexOfKey(client.thread);
                    if (indexTab != -1)
                    {//TabPages[indexTab].Control[0] - textBox с диалогом
                        ((TextBox)tabsDialog.TabPages[indexTab].Controls[0]).AppendText(client.from + " (" + DateTime.Now.ToString() + ")"
                                                                                        + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);
                        tabsDialog.Focus();
                    }
                }
            }));
        }
Example #6
0
 public void Remove(OneConferention conf)
 {
     conferentions.Remove(conf);
 }
Example #7
0
 public void Add(OneConferention conf)
 {
     conferentions.Add(conf);
 }
Example #8
0
 public void Remove(OneConferention conf)
 {
     conferentions.Remove(conf);
 }
Example #9
0
 public void Add(OneConferention conf)
 {
     conferentions.Add(conf);
 }
Example #10
0
        private void HandlerOnMessege()
        {
            tabsDialog.Invoke(new MethodInvoker(delegate
            {
                if (client.thread == null)
                {
                    int indexTab = findTagPage(client.from);
                    if (indexTab != -1)
                    {

                        ((TextBox)tabsDialog.TabPages[indexTab].Controls[0]).AppendText(tabsDialog.TabPages[indexTab].Text + " (" + DateTime.Now.ToString() + ")"
                            + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);

                    }
                    else
                    {
                        if (client.mess.Substring(0,6) == "<conf>")
                        {
                            OneConferention conferention = new OneConferention();
                            string message = client.mess.Substring(6);

                            String[] arr = message.Split('-');
                            byte[] b = new byte[arr.Length];
                            for (int i = 0; i < arr.Length; i++) b[i] = Convert.ToByte(arr[i], 16);

                            using (var stream = new MemoryStream())
                            {
                                BinaryFormatter formatter = new BinaryFormatter();
                                stream.Write(b,0, b.Length);
                                stream.Seek(0,0);
                                object ob = formatter.Deserialize(stream);
                                if (ob is OneConferention)
                                    conferention = (OneConferention)ob;
                            }

                            if (conferention.id == null);// хуи тут, а не обработка

                            if (MessageBox.Show("Вас пригласили в конференцию " + conferention.name + ". Желаете принять участие?", "Приглашение", MessageBoxButtons.OKCancel) == DialogResult.OK)
                            {
                                initForm2();
                                string conferenceName = conferention.name;
                                string createrJid = conferention.users[0];
                                List<string> users = conferention.users;
                                conferentions.Add(conferention);
                                createTabPage(conferenceName, null, conferention.id);
                            }
                            else
                            {

                            }
                        }
                        createTabPage(client.from, client.from + " (" + DateTime.Now.ToString() + ")"
                            + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);
                    }
                }
                else
                {
                    int indexTab = tabsDialog.TabPages.IndexOfKey(client.thread);
                    if (indexTab != -1)
                    {//t.TabPages[indexTab].Control[0] - textBox с диалогом
                        ((TextBox)tabsDialog.TabPages[indexTab].Controls[0]).AppendText(client.from + " (" + DateTime.Now.ToString() + ")"
                            + Environment.NewLine + client.mess + Environment.NewLine + Environment.NewLine);
                    }
                }
            }));
        }