コード例 #1
0
ファイル: SerializeMail.cs プロジェクト: thinhtp/liteweb.info
        /// <summary>
        /// Returns serializable alternate view object
        /// </summary>
        /// <param name="alternateView"></param>
        /// <returns></returns>
        public static SerializableAlternateView GetSerializableAlternateView(AlternateView alternateView)
        {
            if (alternateView == null)
            {
                return(null);
            }

            var serializedAlternateView = new SerializableAlternateView {
                serializedContentId = alternateView.ContentId, baseUri = alternateView.BaseUri
            };



            if (alternateView.ContentStream != null)
            {
                var bytes = new byte[alternateView.ContentStream.Length];
                alternateView.ContentStream.Read(bytes, 0, bytes.Length);
                serializedAlternateView.serializedContentStream = new MemoryStream(bytes);
            }

            serializedAlternateView.serializedContentType =
                SerializableContentType.GetSerializableContentType(alternateView.ContentType);

            foreach (var lr in alternateView.LinkedResources)
            {
                serializedAlternateView.serializedLinkedResources.Add(SerializableLinkedResource.GetSerializableLinkedResource(lr));
            }

            serializedAlternateView.transferEncoding = alternateView.TransferEncoding;

            return(serializedAlternateView);
        }
コード例 #2
0
ファイル: SerializeMail.cs プロジェクト: thinhtp/liteweb.info
        /// <summary>
        /// Serializable Linked Resource
        /// </summary>
        /// <param name="linkedResource">Linked Resource that needs to be serialized</param>
        /// <returns>Serializable Linked Resource</returns>
        public static SerializableLinkedResource GetSerializableLinkedResource(LinkedResource linkedResource)
        {
            if (linkedResource == null)
            {
                return(null);
            }

            var serializedLinkedResource = new SerializableLinkedResource {
                contentID = linkedResource.ContentId, contentLink = linkedResource.ContentLink
            };

            if (linkedResource.ContentStream != null)
            {
                var bytes = new byte[linkedResource.ContentStream.Length];
                linkedResource.ContentStream.Read(bytes, 0, bytes.Length);
                serializedLinkedResource.contentStream = new MemoryStream(bytes);
            }

            serializedLinkedResource.serializedContentType =
                SerializableContentType.GetSerializableContentType(linkedResource.ContentType);
            serializedLinkedResource.transferEncoding = linkedResource.TransferEncoding;

            return(serializedLinkedResource);
        }