Exemple #1
0
        /// <summary>
        /// Serializes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The serialized message.</returns>
        private static byte[] Serialize(MessageContainer message)
        {
            byte[]          serialized;
            BinaryFormatter formatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                formatter.Serialize(memoryStream, message);
                serialized = memoryStream.GetBuffer();
                return(serialized);
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads the specified data.
        /// </summary>
        /// <param name="data">The data to read.</param>
        /// <returns>A message container.</returns>
        public static object Read(byte[] data)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream(data))
            {
                try
                {
                    MessageContainer messageContainer = (MessageContainer)formatter.Deserialize(memoryStream);
                    return(messageContainer.Content);
                }
                catch
                {
                    throw;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Works the specified data.
        /// </summary>
        /// <param name="data">The specified data.</param>
        private void Worker(object data)
        {
            MessageReceiverThreadArgs args = (MessageReceiverThreadArgs)data;

            while (!args.Stop)
            {
                ////try
                ////{

                MessageContainer messageContainer = (MessageContainer)this.formatter.Deserialize(this.networkStream);
                this.FireMessageReceived(this, new MessageReceivedEventArgs(messageContainer.Content));

                ////}
                ////catch
                ////{
                //// TODO: do something.
                ////throw;
                ////}

                ////Thread.Sleep(args.PollDelay);
            }
        }