/// <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); }
/// <summary> /// Returns serializable attachment /// </summary> /// <param name="att"></param> /// <returns></returns> public static SerializableAttachment GetSerializeableAttachment(Attachment att) { if (att == null) { return(null); } var serializedAttachment = new SerializableAttachment { serializedContentDisposition = SerializableContentDisposition.GetSerializableContentDisposition(att.ContentDisposition), contentId = att.ContentId }; if (att.ContentStream != null) { var bytes = new byte[att.ContentStream.Length]; att.ContentStream.Read(bytes, 0, bytes.Length); serializedAttachment.serializedContentStream = new MemoryStream(bytes); } serializedAttachment.name = att.Name; serializedAttachment.serializedContentType = SerializableContentType.GetSerializableContentType(att.ContentType); serializedAttachment.nameEncoding = att.NameEncoding; serializedAttachment.transferEncoding = att.TransferEncoding; return(serializedAttachment); }
/// <summary> /// Returns serializable content type /// </summary> /// <param name="contentType">Original content type</param> /// <returns>serialized content type</returns> public static SerializableContentType GetSerializableContentType(ContentType contentType) { if (contentType == null) { return(null); } var serializedContentType = new SerializableContentType { name = contentType.Name, boundary = contentType.Boundary, mediaType = contentType.MediaType, charSet = contentType.CharSet, serializedColParameters = SerializableCollection.GetSerializableCollection(contentType.Parameters) }; return(serializedContentType); }
/// <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); }