Ejemplo n.º 1
0
        public void ContentBuilderTest()
        {
            var docx = new DocxFile();

            AppendBody(docx);

            Assert.AreEqual(2, docx.Body.Count);
            Assert.AreEqual("text/html", docx.Body[0].Type);
            Assert.AreEqual(".html", docx.Body[0].Extension);
            Assert.AreEqual("application/rtf", docx.Body[1].Type);
            Assert.AreEqual(".rtf", docx.Body[1].Extension);

            Assert.IsFalse(docx.HasHeader);
            Assert.IsFalse(docx.HasFooter);

            AppendHeaderFooter(docx);

            Assert.AreEqual(2, docx.Header.Count);
            Assert.AreEqual("text/html", docx.Header[0].Type);
            Assert.AreEqual(".html", docx.Header[0].Extension);
            Assert.AreEqual("application/rtf", docx.Header[1].Type);
            Assert.AreEqual(".rtf", docx.Header[1].Extension);

            Assert.AreEqual(2, docx.Footer.Count);
            Assert.AreEqual("text/html", docx.Footer[0].Type);
            Assert.AreEqual(".html", docx.Footer[0].Extension);
            Assert.AreEqual("application/rtf", docx.Footer[1].Type);
            Assert.AreEqual(".rtf", docx.Footer[1].Extension);
        }
Ejemplo n.º 2
0
        public void PackagePartTest()
        {
            var docx = new DocxFile();

            AppendBody(docx);
            AppendHeaderFooter(docx);

            var stream = new MemoryStream();

            docx.Save(stream);
            var package = Package.Open(stream);

            var parts = package.GetParts();
            HashSet <string> expectedParts =
                new HashSet <string>(
                    new string[] { "/word/altChunk1.html", "/word/altChunk2.rtf", "/word/altChunk3.html", "/word/altChunk4.rtf", "/word/altChunk5.html", "/word/altChunk6.rtf", "/word/document.xml", "/word/footer1.xml", "/word/header1.xml", "/word/_rels/document.xml.rels", "/word/_rels/footer1.xml.rels", "/word/_rels/header1.xml.rels", "/_rels/.rels" });

            foreach (PackagePart part in parts)
            {
                Assert.IsTrue(expectedParts.Remove(part.Uri.OriginalString));
            }
            Assert.IsTrue(expectedParts.Count == 0);


            package.Close();
        }
Ejemplo n.º 3
0
        public void ContentBuilderTest()
        {
            var docx = new DocxFile();
            AppendBody(docx);

            Assert.AreEqual(2, docx.Body.Count);
            Assert.AreEqual("text/html", docx.Body[0].Type);
            Assert.AreEqual(".html", docx.Body[0].Extension);
            Assert.AreEqual("application/rtf", docx.Body[1].Type);
            Assert.AreEqual(".rtf", docx.Body[1].Extension);

            Assert.IsFalse(docx.HasHeader);
            Assert.IsFalse(docx.HasFooter);

            AppendHeaderFooter(docx);

            Assert.AreEqual(2, docx.Header.Count);
            Assert.AreEqual("text/html", docx.Header[0].Type);
            Assert.AreEqual(".html", docx.Header[0].Extension);
            Assert.AreEqual("application/rtf", docx.Header[1].Type);
            Assert.AreEqual(".rtf", docx.Header[1].Extension);

            Assert.AreEqual(2, docx.Footer.Count);
            Assert.AreEqual("text/html", docx.Footer[0].Type);
            Assert.AreEqual(".html", docx.Footer[0].Extension);
            Assert.AreEqual("application/rtf", docx.Footer[1].Type);
            Assert.AreEqual(".rtf", docx.Footer[1].Extension);
        }
Ejemplo n.º 4
0
        public void PackageRelationshipTest()
        {
            var docx = new DocxFile();

            AppendBody(docx);
            AppendHeaderFooter(docx);

            var stream = new MemoryStream();

            docx.Save(stream);
            var package = Package.Open(stream);

            CheckRelationships(
                new string[] { "altChunk1.html", "altChunk2.rtf", "header1.xml", "footer1.xml" },
                package.GetPart(new Uri("/word/document.xml", UriKind.Relative)).GetRelationships());

            CheckRelationships(
                new string[] { "altChunk3.html", "altChunk4.rtf" },
                package.GetPart(new Uri("/word/header1.xml", UriKind.Relative)).GetRelationships());

            CheckRelationships(
                new string[] { "altChunk5.html", "altChunk6.rtf" },
                package.GetPart(new Uri("/word/footer1.xml", UriKind.Relative)).GetRelationships());

            package.Close();
        }
Ejemplo n.º 5
0
        private static void AppendHeaderFooter(DocxFile docx)
        {
            docx.Header.AppendText("<html><body><span style='color:blue;'>Header HTML content!</span></body></html>", ContentType.Html);
            docx.Header.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Header RTF content!}", ContentType.Rtf);

            docx.Footer.AppendText("<html><body><span style='color:blue;'>Footer HTML content!</span></body></html>", ContentType.Html);
            docx.Footer.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Footer RTF content!}", ContentType.Rtf);
        }
        public void DocxGetAuthorTest()
        {
            var file = new DocxFile(@"..\..\SampleFiles\Test.Docx");
            file.OpenFile();

            Assert.AreEqual("Test Author", file.Author);

            file.CloseFile();
        }
        public void DocxGetCompanyTest()
        {
            var file = new DocxFile(@"..\..\SampleFiles\Test.Docx");
            file.OpenFile();

            Assert.AreEqual("Test Company", file.Company);

            file.CloseFile();
        }
        public void DocxGetModifiedTimeUtcTest()
        {
            var file = new DocxFile(@"..\..\SampleFiles\Test.Docx");
            file.OpenFile();

            Assert.AreEqual(new DateTime(2016, 3, 1, 3, 56, 0, DateTimeKind.Utc), file.ModifiedTimeUtc);

            file.CloseFile();
        }
Ejemplo n.º 9
0
        public void DocxRtfResultTest()
        {
            var docx = new DocxFile();

            docx.Body.AppendFile(@"..\..\TestFiles\Font.rtf", ContentType.Rtf)
            .AppendFile(@"..\..\TestFiles\Image.rtf", ContentType.Rtf)
            .AppendFile(@"..\..\TestFiles\Table.rtf", ContentType.Rtf);

            docx.Save("DocxRtfResultTest.docx");
            Process.Start("DocxRtfResultTest.docx");
        }
Ejemplo n.º 10
0
        public void DocxHtmlResultTest()
        {
            var docx = new DocxFile();

            docx.Body.AppendFile(@"..\..\TestFiles\Font.html", ContentType.Html)
            .AppendFile(@"..\..\TestFiles\Image.html", ContentType.Html)
            .AppendFile(@"..\..\TestFiles\Table.html", ContentType.Html);

            docx.Save("DocxHtmlResultTest.docx");
            Process.Start("DocxHtmlResultTest.docx");
        }
Ejemplo n.º 11
0
        public void UpdateIndex()
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            var indexUpdateTime = DateTime.MinValue;
            if (!string.IsNullOrEmpty(config.AppSettings.Settings["IndexUpdateTime"].Value))
            {
                indexUpdateTime = DateTime.Parse(config.AppSettings.Settings["IndexUpdateTime"].Value);
            }
            var documents =
                _documentAppService.GetDocumentsWithContent().Where(p => p.UpdateTime >= indexUpdateTime).ToList();
            var documentIndexService = new UniCloud.Application.LuceneSearch.DocumentIndexService();
            documents.ForEach(p =>
            {
                if (p.UpdateTime.CompareTo(indexUpdateTime) > 0)
                {
                    indexUpdateTime = p.UpdateTime;
                }
                if (p.FileStorage != null)
                {
                    var path = AppDomain.CurrentDomain.BaseDirectory + "\\" + p.Name;
                    File.WriteAllBytes(path, p.FileStorage);
                    var content = string.Empty;
                    if (p.Extension.Contains("docx"))
                    {
                        var file = new DocxFile(path);
                        content = file.ParagraphText;
                    }
                    else if (p.Extension.Contains("pdf"))
                    {
                        content = PdfFile.ReadPdfFile(path);
                    }
                    if (p.CreateTime.CompareTo(p.UpdateTime) == 0)
                    {
                        documentIndexService.AddDocumentSearchIndex(p.DocumentId, p.DocumentTypeId, p.Name, content);
                    }
                    else
                    {
                        documentIndexService.UpdateDocumentSearchIndex(p.DocumentId, p.DocumentTypeId, p.Name, content);
                    }
                    File.Delete(path);
                }
            });
            config.AppSettings.Settings["IndexUpdateTime"].Value = indexUpdateTime.ToString("yyyy-MM-dd HH:mm:ss");
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
Ejemplo n.º 12
0
        private CustomFile GetFileForExport(string fileName, ExportType exportType = ExportType.Docx)
        {
            CustomFile file;

            switch (exportType)
            {
            case ExportType.Docx:
            {
                file = new DocxFile(fileName);
                break;
            }

            default:
            {
                throw new ArgumentNullException();
            }
            }

            return(file);
        }
Ejemplo n.º 13
0
        public void PackagePartTest()
        {
            var docx = new DocxFile();
            AppendBody(docx);
            AppendHeaderFooter(docx);

            var stream = new MemoryStream();
            docx.Save(stream);
            var package = Package.Open(stream);

            var parts = package.GetParts();
            HashSet<string> expectedParts =
                new HashSet<string>(
                    new string[] { "/word/altChunk1.html", "/word/altChunk2.rtf", "/word/altChunk3.html", "/word/altChunk4.rtf", "/word/altChunk5.html", "/word/altChunk6.rtf", "/word/document.xml", "/word/footer1.xml", "/word/header1.xml", "/word/_rels/document.xml.rels", "/word/_rels/footer1.xml.rels", "/word/_rels/header1.xml.rels", "/_rels/.rels" });

            foreach (PackagePart part in parts)
                Assert.IsTrue(expectedParts.Remove(part.Uri.OriginalString));
            Assert.IsTrue(expectedParts.Count == 0);


            package.Close();
        }
Ejemplo n.º 14
0
        public void PackageRelationshipTest()
        {
            var docx = new DocxFile();
            AppendBody(docx);
            AppendHeaderFooter(docx);

            var stream = new MemoryStream();
            docx.Save(stream);
            var package = Package.Open(stream);

            CheckRelationships(
                new string[] { "altChunk1.html", "altChunk2.rtf", "header1.xml", "footer1.xml" },
                package.GetPart(new Uri("/word/document.xml", UriKind.Relative)).GetRelationships());

            CheckRelationships(
                new string[] { "altChunk3.html", "altChunk4.rtf" },
                package.GetPart(new Uri("/word/header1.xml", UriKind.Relative)).GetRelationships());

            CheckRelationships(
                new string[] { "altChunk5.html", "altChunk6.rtf" },
                package.GetPart(new Uri("/word/footer1.xml", UriKind.Relative)).GetRelationships());

            package.Close();
        }
Ejemplo n.º 15
0
        private static void AppendHeaderFooter(DocxFile docx)
        {
            docx.Header.AppendText("<html><body><span style='color:blue;'>Header HTML content!</span></body></html>", ContentType.Html);
            docx.Header.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Header RTF content!}", ContentType.Rtf);

            docx.Footer.AppendText("<html><body><span style='color:blue;'>Footer HTML content!</span></body></html>", ContentType.Html);
            docx.Footer.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Footer RTF content!}", ContentType.Rtf);
        }
Ejemplo n.º 16
0
 private static void AppendBody(DocxFile docx)
 {
     docx.Body.AppendText("<html><body><span style='color:blue;'>Body HTML content!</span></body></html>", ContentType.Html);
     docx.Body.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Body RTF content!}", ContentType.Rtf);
 }
Ejemplo n.º 17
0
 public void DocxOpenAndCloseFileTest()
 {
     var file = new DocxFile(@"..\..\SampleFiles\Test.Docx");
     file.OpenFile();
     file.CloseFile();
 }
Ejemplo n.º 18
0
 public void TestMethod1()
 {
     var rslut = new DocxFile(new FileStream(@"C:\Users\yjdcb\Desktop\事业单位 扩展 3.docx", FileMode.Open)).ToSegmenterResult();
 }
Ejemplo n.º 19
0
 private static void AppendBody(DocxFile docx)
 {
     docx.Body.AppendText("<html><body><span style='color:blue;'>Body HTML content!</span></body></html>", ContentType.Html);
     docx.Body.AppendText(@"{\rtf1\ansi\deff0{\colortbl;\red255\green0\blue0;}\cf1 Body RTF content!}", ContentType.Rtf);
 }