Пример #1
0
        /// <summary>
        /// Create an instance of content which contains both string and binary data representation
        /// </summary>
        public Content(ContentId id,
                       NLSMap name,
                       string stringContent,
                       byte[] binaryContent,
                       string contentType,
                       LangInfo?lang             = null,
                       string attachmentFileName = null,
                       string createUser         = null,
                       string modifyUser         = null,
                       DateTime?createDate       = null,
                       DateTime?modifyDate       = null)
        {
            if (!id.IsAssigned)
            {
                throw new CmsException($"{StringConsts.ARGUMENT_ERROR} {nameof(Content)}.ctor(id.!IsAssigned)");
            }
            m_Id            = id;
            m_Name          = name;
            m_StringContent = stringContent;
            m_BinaryContent = binaryContent;

            if (m_StringContent == null && m_BinaryContent == null)
            {
                throw new CmsException($"{StringConsts.ARGUMENT_ERROR} {nameof(Content)}.ctor(stringContent==null && binaryContent==null)");
            }

            m_ContentType        = contentType.NonBlank(nameof(contentType));
            m_Language           = LangInfo.Default(lang);
            m_AttachmentFileName = attachmentFileName;
            m_ETag       = getETag(m_ContentType, m_StringContent, m_BinaryContent);
            m_CreateDate = createDate;
            m_ModifyDate = modifyDate;
            m_CreateUser = createUser;
            m_ModifyUser = modifyUser;
        }
Пример #2
0
        /// <summary>
        /// Creates content from binary stream.
        /// The design is optimized for in-memory processing and does not use async model
        /// </summary>
        public Content(Stream stream)
        {
            var reader = new Serialization.Bix.BixReader(stream.NonNull(nameof(stream)));

            var ver = reader.ReadByte();

            if (ver != BINARY_FORMAT_VER)
            {
                throw new CmsException("Bad bin version: {0} Expected: {1}".Args(ver, BINARY_FORMAT_VER));
            }

            var portal = reader.ReadString();
            var ns     = reader.ReadString();
            var block  = reader.ReadString();

            m_Id = new ContentId(portal, ns, block);

            m_Name = reader.ReadNLSMap();

            var iso     = reader.ReadAtom();
            var isoName = reader.ReadString();

            m_Language = new LangInfo(iso, isoName);

            m_AttachmentFileName = reader.ReadString();
            m_ETag          = reader.ReadString();
            m_CreateUser    = reader.ReadString();
            m_ModifyUser    = reader.ReadString();
            m_CreateDate    = reader.ReadNullableDateTime();
            m_ModifyDate    = reader.ReadNullableDateTime();
            m_ContentType   = reader.ReadString();
            m_StringContent = reader.ReadString();
            m_BinaryContent = reader.ReadByteArray();
        }