Example #1
0
        public override IDocument Render(IDictionary<string, object> context)
        {
            Debug.Assert(this.engine != null);

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            //执行主要内容的渲染过程
            using (var inStream = new MemoryStream(base.GetBuffer(), false))
            using (var reader = new StreamReader(inStream, Encoding.UTF8))
            using (var ws = new MemoryStream())
            using (var writer = new StreamWriter(ws))
            {
                //执行渲染
                this.engine.Evaluate(context, reader, writer);
                writer.Flush();
                ws.Flush();
                var resultDoc = new WordMLTemplate();
                resultDoc.PutBuffer(ws.ToArray());
                return resultDoc;
            }
        }
Example #2
0
 private static void WriteCompiledMainContent(WordMLTemplate t, XmlDocument xml)
 {
     using (var ms = new MemoryStream())
     using (var writer = new XmlTextWriter(ms, Encoding.UTF8))
     {
         writer.Formatting = Formatting.None;
         xml.WriteTo(writer);
         writer.Flush();
         ms.Flush();
         t.PutBuffer(ms.ToArray());
     }
 }