Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SetFlag("Add");
            var client  = new TcpClient(Dns.GetHostName(), port);
            var contact = new ContactDTO
            {
                Email = tbEmail.Text,
                Name  = tbName.Text,
                Phone = tbPhone.Text
            };

            using (var stream = client.GetStream())
            {
                var serializer = new XmlSerializer(contact.GetType());
                serializer.Serialize(stream, contact);
            }
            client.Close();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var contact = new ContactDTO
            {
                Email = tbEmail.Text,
                Name  = tbName.Text,
                Phone = tbPhone.Text
            };

            SendCommand("Create");

            var client = new TcpClient(Dns.GetHostName(), PORT);

            using (var stream = client.GetStream())
            {
                var serializer = new XmlSerializer(contact.GetType());
                serializer.Serialize(stream, contact);
            }
        }
Esempio n. 3
0
        private void RefreshList()
        {
            var contact = new ContactDTO
            {
                Tag = "Read"
            };


            var client = new TcpClient(Dns.GetHostName(), port);

            try
            {
                using (var stream = client.GetStream())
                {
                    var serializer = new XmlSerializer(contact.GetType());
                    serializer.Serialize(stream, contact);
                }

                client.Close();

                Thread thread = new Thread(ListenServer);
                thread.Start();
            }
            catch (SocketException ex)
            {
                client.Close();
                MessageBox.Show(ex.Message);
            }
            catch (ThreadStateException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (System.OutOfMemoryException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (System.InvalidOperationException ex)
            {
                client.Close();
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var contact = new ContactDTO
            {
                Email = tbEmail.Text,
                Name  = tbName.Text,
                Phone = tbPhone.Text,
                Tag   = "Create"
            };

            if (contactDTOs.Where(x => x.Name == contact.Name && x.Phone == contact.Phone && x.Email == contact.Email).FirstOrDefault() == null)
            {
                var client = new TcpClient(Dns.GetHostName(), port);
                try
                {
                    using (var stream = client.GetStream())
                    {
                        var serializer = new XmlSerializer(contact.GetType());
                        serializer.Serialize(stream, contact);
                    }

                    client.Close();

                    RefreshList();
                }
                catch (SocketException ex)
                {
                    client.Close();
                    MessageBox.Show(ex.Message);
                }
                catch (System.InvalidOperationException ex)
                {
                    client.Close();
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Error: Duplicate contact.");
            }
        }