コード例 #1
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TestDocumentIsValidAfterCallingBookmarkRange()
 {
     OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks);
     target.BookmarkRange(new OxmlRange(0,1,2), "testbookmark");
     bool expected = true;
     bool actual = target.IsValid();
     Assert.AreEqual(expected, actual);
 }
コード例 #2
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TesBookmarkRange_DoesNotModifyInnerText()
 {
     OxmlDocument target = new OxmlDocument(this.oxml);
     target.BookmarkRange(new OxmlRange(0, 5, 7), "1");
     target.BookmarkRange(new OxmlRange(0, 9, 11), "2");
     target.BookmarkRange(new OxmlRange(0, 12, 15), "3");
     string expected = this.paragraphText_1;
     string actual = target.GetNextOxmlBlock().Text;
     Assert.AreEqual(expected, actual);
 }
コード例 #3
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TestBookmarkRange_HandlesNestedRuns()
 {
     OxmlDocument doc = new OxmlDocument(this.oxml);
     doc._paragraphs[0] = new Paragraph();
     Run run1 = new Run();
     Run run2 = new Run();
     Hyperlink hyp = new Hyperlink();
     hyp.AppendChild<Run>(run2);
     doc._paragraphs[0].AppendChild<Run>(run1);
     doc._paragraphs[0].AppendChild<Hyperlink>(hyp);
     run1.AppendChild<Text>(new Text("This is a "));
     run2.AppendChild<Text>(new Text("test string."));
     doc.BookmarkRange(new OxmlRange_Accessor(0, 4, 15), "testbookmark");
     Assert.AreEqual(4, doc._paragraphs[0].Descendants<Run>().ToArray().Length);
     Assert.AreEqual(1, doc._paragraphs[0].Descendants<BookmarkStart>().ToArray().Length);
     Assert.AreEqual(1, doc._paragraphs[0].Descendants<BookmarkEnd>().ToArray().Length);
 }
コード例 #4
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TestBookmarkRange_AddsBookmarkToDocument()
 {
     OxmlDocument target = new OxmlDocument(this.oxmlWithBookmarks);
     target.BookmarkRange(new OxmlRange(0, 1, 2), "testbookmark");
     int expected = this.numberOfBookmarks + 1;
     int actual = target.CountBookmarks();
     Assert.AreEqual(expected, actual);
 }
コード例 #5
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TestBookmarkRange_AddsBookmarkStartBeforeRangeStart_StartIsFirstIndex()
 {
     OxmlDocument doc = new OxmlDocument(this.oxml);
     doc._paragraphs[0] = new Paragraph();
     Run run1 = new Run();
     Run run2 = new Run();
     doc._paragraphs[0].AppendChild<Run>(run1);
     doc._paragraphs[0].AppendChild<Run>(run2);
     run1.AppendChild<Text>(new Text("This is a "));
     run2.AppendChild<Text>(new Text("test string."));
     doc.BookmarkRange(new OxmlRange_Accessor(0, 10, 15), "testbookmark");
     string expected = "This is a ";
     string actual = doc._paragraphs[0].GetFirstChild<BookmarkStart>()
         .PreviousSibling<Run>().InnerText;
     Assert.AreEqual(expected, actual);
 }
コード例 #6
0
ファイル: OxmlDocumentTest.cs プロジェクト: cthiange/eagle
 public void TestBookmarkRange_AddsBookmarkEndAfterRangeEnd_StartEndInSameRun()
 {
     OxmlDocument doc = new OxmlDocument(this.oxml);
     doc._paragraphs[0] = new Paragraph();
     Run run1 = new Run();
     doc._paragraphs[0].AppendChild<Run>(run1);
     run1.AppendChild<Text>(new Text("This is a test string."));
     doc.BookmarkRange(new OxmlRange_Accessor(0, 4, 15), "testbookmark");
     string expected = "string.";
     string actual = doc._paragraphs[0].GetFirstChild<BookmarkEnd>()
         .NextSibling<Run>().InnerText;
     Assert.AreEqual(expected, actual);
 }
コード例 #7
0
ファイル: ThisAddIn.cs プロジェクト: cthiange/eagle
        /*-----------------------------------------------------------------------------------------*/
        /* Background worker                                                                       */
        /*-----------------------------------------------------------------------------------------*/
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            OxmlDocument doc = new OxmlDocument(this.GetOXML());
            Scope scope = new Scope(Properties.Settings.Default.ScopeSize);
            scope.MinimumTokenLength = Properties.Settings.Default.MinimumTokenLength;

            doc.PurgeShading();
            doc.PurgeBookmarks();

            // Load ignore list

            if (!String.IsNullOrEmpty(_ignoreListName))
            {
                IgnoreList IgnoreList = new IgnoreList(GetListPath(_ignoreListName));
                scope.IgnoreWords(IgnoreList.LoadWords(_language));
            }

            // Analyse document

            int blockCount = 0;
            float numberOfBlocks = (float)doc.GetNumberOfBlocks();
            var block = doc.GetNextOxmlBlock();

            while (block != null)
            {
                var tokens = block.GenerateOxmlTokens();
                foreach (var token in tokens)
                {
                    scope.FeedToken(token);
                }
                block = doc.GetNextOxmlBlock();

                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }

                int progress = (int)(++blockCount / numberOfBlocks * 100);
                worker.ReportProgress(progress);
            }

            // Add bookmarks to document

            var conflicts = scope.GetConflicts();
            foreach (var root in conflicts.Keys)
            {
                foreach (var conflict in conflicts[root])
                {
                    foreach (var token in conflict)
                    {
                        Debug.WriteLine(String.Format("Adding bookmark {0} for root '{1}' with text '{2}' and range {3}",
                            token.BookmarkName, token.Root, token.Text, token.Range.ToString()));
                        doc.BookmarkRange(token.Range, token.BookmarkName);
                    }
                }
            }

            // Update OXML only if it is valid

            string oxml = doc.ToOxml();

            if (oxml != null)
            {
                this._conflicts = conflicts;
                this.SetOXML(doc.ToOxml());
            }
            else
            {
                MessageBox.Show("An error occured while processing this document.", "Eagle Add-In");
            }
        }