/// <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="bodyInfo"></param>
 /// <param name="bodyStream"></param>
 public Task SaveMessageBody(MessageBodyInfo bodyInfo, IAsyncEnumerable <char[]> bodyStream, CancellationToken cancellationToken = default)
 {
     return(Task.Run(() =>
     {
         using (MessageBody body = _dataAdapter.GetMessageBody(bodyInfo.MessageLINK))
         {
             body.ApplyInfo(bodyInfo);
             body.Value = new AsyncStreamTextReader(bodyStream);
             _dataAdapter.SaveMessageBody(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);
        }