コード例 #1
0
        /// <summary>
        /// This method deserializes the stream in to a content object.
        /// </summary>
        /// <param name="header">The header</param>
        /// <param name="pMan">The pool manaer containing the required pool.</param>
        /// <returns>Returns a deserialized object.</returns>
        protected virtual Content ContentDeserializeInternal(
            IXimuraContentFormatterCapabilities header, IXimuraPoolManager pMan)
        {
            IXimuraContentSerializationReaderWriter rwHelper = header.RWHelper;

            Type contentType = ResolveType(header.ContentType, header.AllowRelativeType);

            if (contentType == null && header.SupportsBaseType)
                contentType = ResolveType(header.ContentBaseType, header.AllowRelativeType);

            //OK, the content type is still null
            if (contentType == null)
                throw new ContentFormatterException("The content type cannot be created.");

            SerializationInfo info = PrepareSerializationInfo(header, contentType);

            Content content = null;
            if (pMan != null)
            {
                content = (Content)pMan.GetPoolManager(contentType).Get(info, Context);
            }
            else
            {
                object[] parameters = new object[] { info, Context };
                Type[] typesArray = RH.getTypesfromObjectArray(parameters);
                ConstructorInfo TypeConstruct = contentType.GetConstructor(typesArray);
                content = TypeConstruct.Invoke(parameters) as Content;
                content.OnDeserialization(null);
            }

            return content as Content;
        }
コード例 #2
0
        /// <summary>
        /// This method prepares the serialization info.
        /// </summary>
        /// <param name="header"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        protected static SerializationInfo PrepareSerializationInfo(
            IXimuraContentFormatterCapabilities header, Type contentType)
        {
            IXimuraContentSerializationReaderWriter rwHelper = header.RWHelper;
            SerializationInfo info = new SerializationInfo(contentType, new FormatterConverter());

            //Add the ids
            info.AddValue("tid", header.TypeID);
            info.AddValue("cid", header.ContentID);
            info.AddValue("vid", header.VersionID);

            //Add the dirty status
            bool contentDirty = rwHelper.ReadBool();
            info.AddValue("dirty", contentDirty);

            //Add the body count
            int bodyCount = rwHelper.ReadInt();
            info.AddValue("bodycount", bodyCount);

            //Loop through each blob and save it to the stream.
            for (int loop = 0; loop < bodyCount; loop++)
            {
                byte[] blob;
                if (header.StreamCompressed)
                    blob = rwHelper.ReadCompressedBlob();
                else
                    blob = rwHelper.ReadBlob();

                info.AddValue("body" + loop.ToString(), blob, typeof(byte[]));
            }

            return info;
        }
コード例 #3
0
        /// <summary>
        /// This method serializes the serialization info.
        /// </summary>
        /// <param name="header">The header.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="info">The serialization info.</param>
        protected virtual void ContentSerializeInternal(
            IXimuraContentFormatterCapabilities header, Content entity, SerializationInfo info)
        {
            IXimuraContentSerializationReaderWriter rwHelper = header.RWHelper;

            int bodyCount = info.GetInt32("bodycount");
            bool contentDirty = info.GetBoolean("dirty");

            //Write the content dirty status
            rwHelper.Write(contentDirty);

            //Write the blob count.
            rwHelper.Write(bodyCount);

            //Loop through each blob and save it to the stream.
            for (int loop = 0; loop < bodyCount; loop++)
            {
                byte[] blob =
                    (byte[])info.GetValue("body" + loop.ToString(), typeof(byte[]));

                if (header.StreamCompressed)
                    rwHelper.WriteCompressedBlob(blob);
                else
                    rwHelper.WriteBlob(blob);

            }
            rwHelper.BaseStream.Flush();
        }