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); }
public void TestGetNextOxmlBlock_ReturnsNullAfterLastBlock() { OxmlDocument target = new OxmlDocument(this.oxml); OxmlBlock actual; // Two paragraphs actual = target.GetNextOxmlBlock(); actual = target.GetNextOxmlBlock(); // No more paragraphs actual = target.GetNextOxmlBlock(); Assert.AreEqual(null, actual); }
public void TestGetNextOxmlBlock_ReturnsBlockWithNextBlockText() { OxmlDocument target = new OxmlDocument(this.oxml); OxmlBlock actual; // First paragraph actual = target.GetNextOxmlBlock(); Assert.AreEqual(this.paragraphText_1, actual.Text); // Second paragraph actual = target.GetNextOxmlBlock(); Assert.AreEqual(this.paragraphText_2, actual.Text); }
public void TestGetNextOxmlBlock_ReturnsBlockWithUniqueId() { OxmlDocument target = new OxmlDocument(this.oxml); // First paragraph var block1 = target.GetNextOxmlBlock(); // Second paragraph var block2 = target.GetNextOxmlBlock(); Assert.AreNotEqual(block1.Id, block2.Id); }
/*-----------------------------------------------------------------------------------------*/ /* 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"); } }