예제 #1
0
        public void GetMessages(TcpClient client)
        {
            HoldingVariable values = new HoldingVariable();
            NetworkStream   ns     = client.GetStream();
            XmlDocument     el;

            byte[] receivedBytes = new byte[154624];
            int    byte_count;

            while ((byte_count = ns.Read(receivedBytes, 0, receivedBytes.Length)) > 0)
            {
                lock (_lock)
                    el = ConvertByteArrayToXml(receivedBytes);

                // Creates list of nodes inside of xml element between root nodes
                XmlNodeList both = el.SelectNodes("/Root");

                foreach (XmlNode item in both)
                {
                    values.Name    = item["Name"].InnerText;
                    values.Time    = item["Time"].InnerText;
                    values.Message = item["Message"].InnerText;

                    if (item["File"].InnerText != null)
                    {
                        values.File     = item["File"].InnerText;
                        values.FileName = item["FileName"].InnerText;
                    }
                }

                GotMessage(values);
            }
        }
예제 #2
0
        void ReceiveData(object sender, HoldingVariable e)
        {
            if (connected == false)
            {
                return;
            }

            Test   data = null;
            string temp = "";

            if (e.File.Length == 0)
            {
                temp = string.Format("{0} by user {1}: {2}", e.Time, e.Name, e.Message);
                data = new NormalMessage()
                {
                    SpecialMessage = "Normal", Name = temp
                };
            }
            else if (e.FileName.Contains(".exe"))
            {
                file = e.File;
                temp = string.Format("{0} {1} send file {2} with message {3}", e.Time, e.Name, e.FileName, e.Message);
                data = new GotFile()
                {
                    SpecialMessage = "File", Name = temp, File = e.File
                };
            }
            else if (e.FileName.Contains("sound"))
            {
                file = e.File;
                temp = string.Format("{0} {1} send voice message {2} with message {3}", e.Time, e.Name, e.FileName, e.Message);
                data = new VoiceMessage()
                {
                    SpecialMessage = "Voice", Name = temp, File = e.File
                };
            }

            // Update list from another thread
            OutputMessage.Dispatcher.BeginInvoke(new Action(delegate()
            {
                // Insert item on top of the list
                lock (_lock)
                    OutputMessage.Items.Insert(0, data);
            }));
        }
예제 #3
0
 /// <summary>
 /// triggers event to display information
 /// from holding variable class
 /// </summary>
 public void GotMessage(HoldingVariable e)
 {
     MessageRecived(this, e);
 }