/// <summary>
        /// Получить тело сообщения.
        /// </summary>
        /// <param name="msgLink"></param>
        /// <returns></returns>
        public virtual MessageBody GetMessageBody(int msgLink)
        {
            UnitOfWork work = BeginWork();

            MessageBodyInfo bodyInfo = work.Get <DAO.MessageBodyInfo>(msgLink).ToObj();

            if (bodyInfo == null)
            {
                return(null);
            }

            MessageBodyStreamBase stream = ConstructMessageBodyStream(msgLink, work, DataStreamMode.READ, bodyInfo.ContentType().Encoding());

            stream.ReadTimeout = this.ExecuteTimeout;

            if (bodyInfo.Length == null)
            {
                bodyInfo.Length = (int)stream.Length;
            }

            var body = new MessageBody();

            body.ApplyInfo(bodyInfo);
            body.Value = new MessageBodyReader(stream, this.bufferSize);

            return(body);
        }
        /// <summary>
        /// Сохранить тело сообщения.
        /// </summary>
        /// <param name="body"></param>
        public virtual void SaveMessageBody(MessageBody body)
        {
            #region Validate parameters
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }
            #endregion

            MessageBodyInfo bodyInfo    = body.BodyInfo();
            ContentType     contentType = bodyInfo.ContentType();
            Encoding        encoding    = contentType.Encoding();

            DAO.MessageBodyInfo dao = bodyInfo.ToDao();

            using (UnitOfWork work = BeginWork())
            {
                work.Update <DAO.MessageBodyInfo>(ref dao);

                using (MessageBodyStreamBase stream = ConstructMessageBodyStream(dao.MessageLINK, work, DataStreamMode.WRITE, encoding))
                {
                    stream.WriteTimeout = this.ExecuteTimeout;

                    var buffer = new char[this.bufferSize];
                    int charsReaded;
                    do
                    {
                        charsReaded = body.Value.Read(buffer, 0, buffer.Length);
                        if (charsReaded > 0)
                        {
                            stream.Write(buffer, 0, charsReaded);
                        }
                    } while (charsReaded > 0);

                    if (dao.Length == null)
                    {
                        dao.Length = (int)stream.Length;
                        work.Update <DAO.MessageBodyInfo>(ref dao);
                    }

                    work.End();
                }
            }

            bodyInfo = dao.ToObj();
            body.ApplyInfo(bodyInfo);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="bufferSize">Больше или равно 1024.</param>
        public MessageBodyReader(MessageBodyStreamBase stream, int bufferSize)
        {
            #region Validate parameters
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException("Поток не доступен для чтения.", "stream");
            }

            if (bufferSize < 1024)
            {
                throw new ArgumentException("Недостаточный размер буфера данных.", "bufferSize");
            }
            #endregion

            this.baseStream = stream;
            this.bufferSize = bufferSize;
        }