Example #1
0
        private static TextWriter CreateTextWriter(IItem item, BodyType type, bool update, out HtmlUpdateBodyCallback htmlUpdateBodyCallback)
        {
            Body body = IrmUtils.GetBody(item);
            BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(type.ToStorageType());

            if (update && type == BodyType.Html)
            {
                htmlUpdateBodyCallback = new HtmlUpdateBodyCallback(item);
                bodyWriteConfiguration.SetHtmlOptions(HtmlStreamingFlags.None, htmlUpdateBodyCallback);
                return(body.OpenTextWriter(bodyWriteConfiguration));
            }
            htmlUpdateBodyCallback = null;
            return(body.OpenTextWriter(bodyWriteConfiguration));
        }
Example #2
0
        internal static ItemBody GetEntityBody(this IItem input, char[] buffer)
        {
            Body     body;
            BodyType bodyType;

            try
            {
                body = IrmUtils.GetBody(input);
                BodyFormat format = body.Format;
                bodyType = format.ToEntityType();
            }
            catch (PropertyErrorException ex)
            {
                ExTraceGlobals.CommonTracer.TraceDebug <string, string>(0L, "[BodyConverter::GetEntityBody] Encountered exception - Class: {0}; Message: {1}", ex.GetType().FullName, ex.Message);
                throw new CorruptDataException(Strings.ErrorItemCorrupt, ex);
            }
            catch (StoragePermanentException ex2)
            {
                if (ex2.InnerException is MapiExceptionNoSupport)
                {
                    throw new CorruptDataException(Strings.ErrorItemCorrupt, ex2);
                }
                ExTraceGlobals.CommonTracer.TraceDebug(0L, "[BodyConverter::GetEntityBody] Encountered exception - Class: {0}, Message: {1} Inner exception was not MapiExceptionNoSupport but rather Class: {2}; Message: {3}", new object[]
                {
                    ex2.GetType().FullName,
                    ex2.Message,
                    (ex2.InnerException == null) ? "<NULL>" : ex2.InnerException.GetType().FullName,
                    (ex2.InnerException == null) ? "<NULL>" : ex2.InnerException.Message
                });
                throw;
            }
            ItemBody itemBody = new ItemBody
            {
                ContentType = bodyType
            };

            using (TextWriter textWriter = new StringWriter())
            {
                if (bodyType == BodyType.Html)
                {
                    BodyConverter.WriteHtmlContent(textWriter, input, buffer);
                }
                else
                {
                    BodyConverter.WriteTextContent(textWriter, body, buffer);
                }
                itemBody.Content = textWriter.ToString();
            }
            return(itemBody);
        }
Example #3
0
        private static void WriteHtmlContent(TextWriter writer, IItem item, char[] charBuffer)
        {
            BodyReadConfiguration bodyReadConfiguration = new BodyReadConfiguration(BodyFormat.TextHtml, "utf-8");

            bodyReadConfiguration.HtmlFlags &= ~HtmlStreamingFlags.FilterHtml;
            item.Load(StoreObjectSchema.ContentConversionProperties);
            bodyReadConfiguration.ConversionCallback = new DefaultHtmlCallbacks(item, true);
            Body body = IrmUtils.GetBody(item);

            using (Stream stream = body.OpenReadStream(bodyReadConfiguration))
            {
                using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8))
                {
                    BodyConverter.CopyContent(streamReader, writer, charBuffer);
                }
            }
        }