public void TestPassThrough()
        {
            string sCopyFile = TESTFILE_DIR + "copy.docx";
            if (File.Exists(sCopyFile))
                File.Delete(sCopyFile);

            try
            {
                using (Stream str = File.Open(TESTFILE_DIR + "test002.docx", FileMode.Open))
                {
                    DocumentProcessor dp = new DocumentProcessor(str);

                    using (dp.Output = File.Open(sCopyFile, FileMode.CreateNew))
                    {

                        dp.Process(DocumentProcessingActions.PassThrough);
                    }
                }
                Assert.IsTrue(CommonTestUtilities.AreZipFilesEqual(TESTFILE_DIR + "test002.docx", sCopyFile));
            }
            finally
            {
                File.Delete(sCopyFile);
            }
        }
Exemple #2
0
        public byte[] Run(Stream docxTemplate, Model model, EngineConfig engineConfig)
        {
            var processor = new DocumentProcessor(engineConfig);

            processor.Logger = this.Logger ?? NullLogger.Instance;

            using (var ms = new MemoryStream())
            {
                docxTemplate.CopyTo(ms);

                using (var docx = WordprocessingDocument.Open(ms, true))
                {
                    processor.Process(docx, model);
                }

                return(ms.ToArray());
            }
        }
Exemple #3
0
        public BookVersion GetXmlMetadata(Stream xlmData)
        {
            var bookVersion = new BookVersion();

            using (var xmlReader = new XmlTextReader(xlmData)
            {
                WhitespaceHandling = WhitespaceHandling.None
            })
            {
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.IsStartElement() &&
                        xmlReader.LocalName.Equals(m_documentProcessor.XmlRootName))
                    {
                        m_documentProcessor.Process(bookVersion, xmlReader);
                    }
                }
            }
            return(bookVersion);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Wyam.Common.Tracing.Trace.Level = SourceLevels.Verbose;
            Wyam.Common.Tracing.Trace.AddListener(new TextWriterTraceListener(Console.Out));

            var configBuilder = new ConfigurationBuilder();

            configBuilder.AddJsonFile("config.json");

            var config = new RootConfig();

            configBuilder.Build().Bind(config);

            var processor = new DocumentProcessor(config);

            processor.Process();

            Console.ReadLine();

            //
        }
        static void Main(string[] args)
        {
            TextDocument document = new TextDocument("Test", "blaaaaaaa");

            //withour generics
            ITextDocumentTranslator translator = new TextDocumentTranslatorwithoutGenerics();
            TextDocumentProcessor   processor  = new TextDocumentProcessor(translator);

            processor.Process(document);

            //With generics
            var processor2 = new DocumentProcessor <TextDocument>(
                new TextDocumentTranslator());

            processor2.Process(document);

            //WithMoreGenerics
            var genericTranslator = new GenericDocumentTranslator <TextDocument>(
                new TextContentExtractor());

            genericTranslator.Translate(document, "EN");
        }
        public void TestNoContentTypeForExternalRels()
        {
            string sCopyFile = TESTFILE_DIR + "copy.docx";
            if (File.Exists(sCopyFile))
                File.Delete(sCopyFile);

            try
            {
                using (Stream str = File.Open(TESTFILE_DIR + "test002.docx", FileMode.Open))
                {
                    using (DocumentProcessor dp = new DocumentProcessor(str))
                    {

                        using (dp.Output = File.Open(sCopyFile, FileMode.CreateNew))
                        {

                            dp.Process(DocumentProcessingActions.PassThrough);
                        }
                    }
                }

                using (OPCPackage package = new OPCPackage(File.Open(sCopyFile, FileMode.Open)))
                {
                    List<ContentTypeInfo> ctilist = package.GetContentTypes();
                    foreach (ContentTypeInfo cti in ctilist)
                    {
                        Assert.IsFalse(cti.Name.StartsWith("file://"));
                        Assert.IsFalse(cti.Name.StartsWith("http://"));
                    }
                }
            }
            finally
            {
                File.Delete(sCopyFile);
            }
        }