/// <summary> /// Constructs an instance of the BlogMlWriter for the specified blogId. /// </summary> private BlogMLWriter(IBlogMLProvider provider, IBlogMLContext context) { this.provider = provider; this.blogId = context.BlogId; this.conversionStrategy = provider.IdConversion; if (this.conversionStrategy == null) this.conversionStrategy = IdConversionStrategy.Empty; }
private static IList GetPostAttachments(BlogMLPost bmlPost, IBlogMLContext bmlContext) { IList attachments = new ArrayList(); string[] attachmentUrls = BlogMLWriterBase.SgmlUtil.GetAttributeValues(bmlPost.Content.Text, "img", "src"); if (attachmentUrls.Length > 0) { bool embed = bmlContext.EmbedAttachments; foreach (string attachmentUrl in attachmentUrls) { string blogHostUrl = Config.CurrentBlog.HostFullyQualifiedUrl.ToString().ToLower(CultureInfo.InvariantCulture); // If the URL for the attachment is local then we'll want to build a new BlogMLAttachment // add add it to the list of attchements for this post. if (BlogMLWriterBase.SgmlUtil.IsRootUrlOf(blogHostUrl, attachmentUrl.ToLower(CultureInfo.InvariantCulture))) { BlogMLAttachment attachment = new BlogMLAttachment(); string attachVirtualPath = attachmentUrl.Replace(blogHostUrl, "/"); // If we are embedding attachements then we need to get the data stream // for the attachment, else the datastream can be null. if (embed) { string attachPhysicalPath = HttpUtility.UrlDecode(HttpContext.Current.Server.MapPath(attachVirtualPath)); //using (Stream attachStream = new StreamReader(attachPhysicalPath).BaseStream) using (FileStream attachStream = File.OpenRead(attachPhysicalPath)) { using (BinaryReader reader = new BinaryReader(attachStream)) { reader.BaseStream.Position = 0; byte[] data = reader.ReadBytes((int)attachStream.Length); attachment.Data = data; } } } attachment.Embedded = embed; attachment.MimeType = BlogMLWriter.GetMimeType(attachmentUrl); attachment.Path = attachVirtualPath; attachment.Url = attachmentUrl; attachments.Add(attachment); } } } return attachments; }