/// <summary> /// Copies content of the bookmark and adds it to the end of the specified node. /// The destination node can be in a different document. /// </summary> /// <param name="importer">Maintains the import context </param> /// <param name="srcBookmark">The input bookmark</param> /// <param name="dstNode">Must be a node that can contain paragraphs (such as a Story).</param> private static void AppendBookmarkedText(NodeImporter importer, Bookmark srcBookmark, CompositeNode dstNode) { // This is the paragraph that contains the beginning of the bookmark. Paragraph startPara = (Paragraph)srcBookmark.BookmarkStart.ParentNode; // This is the paragraph that contains the end of the bookmark. Paragraph endPara = (Paragraph)srcBookmark.BookmarkEnd.ParentNode; if ((startPara == null) || (endPara == null)) throw new InvalidOperationException("Parent of the bookmark start or end is not a paragraph, cannot handle this scenario yet."); // Limit ourselves to a reasonably simple scenario. if (startPara.ParentNode != endPara.ParentNode) throw new InvalidOperationException("Start and end paragraphs have different parents, cannot handle this scenario yet."); // We want to copy all paragraphs from the start paragraph up to (and including) the end paragraph, // therefore the node at which we stop is one after the end paragraph. Node endNode = endPara.NextSibling; // This is the loop to go through all paragraph-level nodes in the bookmark. for (Node curNode = startPara; curNode != endNode; curNode = curNode.NextSibling) { // This creates a copy of the current node and imports it (makes it valid) in the context // of the destination document. Importing means adjusting styles and list identifiers correctly. Node newNode = importer.ImportNode(curNode, true); // Now we simply append the new node to the destination. dstNode.AppendChild(newNode); } }
/// <summary> /// Replaces the merge field with the evaluated text. /// </summary> public override void Evaluate() { // This will clear out the literal area of the field. this.ClearLiteral(); // Recursively evaluate each of the child fields before the parent is evaluated. foreach (WordField wordField in this) { wordField.Evaluate(); } // Evaluate the MERGEFIELD field using the document's dictionary. CompositeNode compositeNode = this.FieldStart.ParentNode as CompositeNode; if (compositeNode != null) { // The documents dictionary is used to provide values for the fields. if (this.MergeDocument.Dictionary.TryGetValue(this.Reference, out this.value)) { // Null values are automatically interpreted as empty strings. The literal area was cleared out at the start of this evaluation. It is // now filled in with the data that matches the fields' tag. this.value = value == null ? String.Empty : value; Run run = new Run(this.FieldStart.Document, String.Format(this.format, this.value)); compositeNode.InsertAfter(run, this.FieldSeperator); } else { // When a field can't be found, this error text is placed in the document. this.value = String.Format("Error! MergeField was not found in header record of data source."); Run run = new Run(this.FieldStart.Document, this.value.ToString()); compositeNode.InsertAfter(run, this.FieldSeperator); } } }
public void RemoveSequence(Node start, Node end) { Node curNode = start.NextPreOrder(start.Document); while (curNode != null && !curNode.Equals(end)) { //Move to next node Node nextNode = curNode.NextPreOrder(start.Document); //Check whether current contains end node if (curNode.IsComposite) { CompositeNode curComposite = (CompositeNode)curNode; if (!curComposite.GetChildNodes(NodeType.Any, true).Contains(end) && !curComposite.GetChildNodes(NodeType.Any, true).Contains(start)) { nextNode = curNode.NextSibling; curNode.Remove(); } } else { curNode.Remove(); } curNode = nextNode; } }
private ArrayList FindChildSplitPositions(CompositeNode node) { // A node may span across multiple pages so a list of split positions is returned. // The split node is the first node on the next page. ArrayList splitList = new ArrayList(); int startingPage = mPageNumberFinder.GetPage(node); Node[] childNodes = node.NodeType == NodeType.Section ? ((Section)node).Body.ChildNodes.ToArray() : node.ChildNodes.ToArray(); foreach (Node childNode in childNodes) { int pageNum = mPageNumberFinder.GetPage(childNode); // If the page of the child node has changed then this is the split position. Add // this to the list. if (pageNum > startingPage) { splitList.Add(childNode); startingPage = pageNum; } if (mPageNumberFinder.PageSpan(childNode) > 1) { mPageNumberFinder.AddPageNumbersForNode(childNode, pageNum, pageNum); } } // Split composites backward so the cloned nodes are inserted in the right order. splitList.Reverse(); return(splitList); }
/// <summary> /// Inserts all the nodes of another document after a paragraph or table. /// </summary> private static void InsertDocument(Node insertionDestination, Document docToInsert) { if (insertionDestination.NodeType == NodeType.Paragraph || insertionDestination.NodeType == NodeType.Table) { CompositeNode dstStory = insertionDestination.ParentNode; NodeImporter importer = new NodeImporter(docToInsert, insertionDestination.Document, ImportFormatMode.KeepSourceFormatting); foreach (Section srcSection in docToInsert.Sections.OfType <Section>()) { foreach (Node srcNode in srcSection.Body) { // Skip the node if it is the last empty paragraph in a section. if (srcNode.NodeType == NodeType.Paragraph) { Paragraph para = (Paragraph)srcNode; if (para.IsEndOfSection && !para.HasChildNodes) { continue; } } Node newNode = importer.ImportNode(srcNode, true); dstStory.InsertAfter(newNode, insertionDestination); insertionDestination = newNode; } } } else { throw new ArgumentException("The destination node must be either a paragraph or table."); } }
public void EnumSourceBinding() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(FileAccess), "name", FileAccess.Read)); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "Read")); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "2")); Assert.AreEqual(FileAccess.Write, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 1)); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 2)); Assert.AreEqual(FileAccess.Write, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "")); Assert.AreEqual(null, binder.BindParameter(typeof(FileAccess), "name", node)); }
public MainWindow(IContainer container) { InitializeComponent(); _background = new SolidColorBrush(Color.FromRgb(0x24, 0x27, 0x28)); // _background = // new ImageBrush(new BitmapImage(new Uri(@"Images/grid.jpg", UriKind.Relative))) // { // Stretch = Stretch.None, // TileMode = TileMode.Tile, // AlignmentX = AlignmentX.Left, // AlignmentY = AlignmentY.Top, // Viewport = new Rect(0, 0, 128, 128), // ViewportUnits = BrushMappingMode.Absolute // }; Application.Current.Resources["Dunno"] = Application.Current.Resources["Dunno1"]; var compositeNode = new CompositeNode(new NodeDispatcher("Graph Dispatcher"));// TestNodes.Test3(new NodeDispatcher("Graph Dispatcher")); _compositeNodeViewModel = new CompositeNodeViewModel(compositeNode, new Vector(), new ControlTypesResolver()); MainNode.DataContext = _compositeNodeViewModel; var contextMenu = new ContextMenu(); MainNode.ContextMenu = contextMenu; var nodeTypes = container != null ? container.ResolveNamed<IEnumerable<Type>>("NodeTypes") : Enumerable.Empty<Type>(); foreach (var nodeType in nodeTypes) { var menuItem = new MenuItem { Header = nodeType.Name }; menuItem.Click += (sender, args) => MenuItemOnClick(nodeType, MainNode.TranslatePosition(menuItem.TranslatePoint(new Point(), this))); contextMenu.Items.Add(menuItem); } }
public CompositeNode BuildNode(XDocument doc) { var rootNode = new CompositeNode("root"); rootNode.AddChildNode(ProcessElement(doc.Root)); return(rootNode); }
public void TwoLevels() { var args = new NameValueCollection(); args.Add("customer.name", "hammett"); args.Add("customer.age", "26"); args.Add("customer.location.code", "pt-br"); args.Add("customer.location.country", "55"); var builder = new TreeBuilder(); CompositeNode root = builder.BuildSourceNode(args); Assert.IsNotNull(root); var node = (CompositeNode)root.GetChildNode("customer"); Assert.IsNotNull(root); var locationNode = (CompositeNode)node.GetChildNode("location"); Assert.IsNotNull(locationNode); Assert.AreEqual("pt-br", ((LeafNode)locationNode.GetChildNode("code")).Value); Assert.AreEqual("55", ((LeafNode)locationNode.GetChildNode("country")).Value); }
public void IndexedContent() { var args = new NameValueCollection(); args.Add("customer[0].name", "hammett"); args.Add("customer[0].age", "26"); args.Add("customer[0].all", "yada yada yada"); args.Add("customer[10].name", "frasier"); args.Add("customer[10].age", "50"); args.Add("customer[10].all", "yada"); var builder = new TreeBuilder(); CompositeNode root = builder.BuildSourceNode(args); var node = (IndexedNode)root.GetChildNode("customer"); Assert.IsNotNull(node); Assert.AreEqual(2, node.ChildrenCount); var cnode = (CompositeNode)node.GetChildNode("0"); Assert.AreEqual("hammett", ((LeafNode)cnode.GetChildNode("name")).Value); Assert.AreEqual("26", ((LeafNode)cnode.GetChildNode("age")).Value); Assert.AreEqual("yada yada yada", ((LeafNode)cnode.GetChildNode("all")).Value); cnode = (CompositeNode)node.GetChildNode("10"); Assert.AreEqual("frasier", ((LeafNode)cnode.GetChildNode("name")).Value); Assert.AreEqual("50", ((LeafNode)cnode.GetChildNode("age")).Value); Assert.AreEqual("yada", ((LeafNode)cnode.GetChildNode("all")).Value); }
public void SimpleBinding_String() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "hammett")); Assert.AreEqual("hammett", binder.BindParameter(typeof(String), "name", node)); }
private NodeDesigner CreateNode(Debugger designer, BaseNode node) { NodeDesigner nodeDesigner = new NodeDesigner(); nodeDesigner.baseNode = node; nodeDesigner.NodeData = node.NodeData; nodeDesigner.Rect = new Rect(nodeDesigner.NodeData.X, nodeDesigner.NodeData.Y, BehaviorTreeEditorStyles.StateWidth, BehaviorTreeEditorStyles.StateHeight); designer.Nodes.Add(nodeDesigner); if (node is CompositeNode) { CompositeNode compositeNode = node as CompositeNode; for (int i = 0; i < compositeNode.Childs.Count; i++) { BaseNode childNode = compositeNode.Childs[i]; NodeDesigner childNodeDesigner = CreateNode(designer, childNode); Transition transition = new Transition(); transition.FromNode = nodeDesigner; transition.ToNode = childNodeDesigner; nodeDesigner.Transitions.Add(transition); } } return(nodeDesigner); }
// Token: 0x0600000D RID: 13 RVA: 0x00002480 File Offset: 0x00000680 private static void InsertDocument(Node insertAfterNode, Document srcDoc) { if (!insertAfterNode.NodeType.Equals(NodeType.Paragraph) & !insertAfterNode.NodeType.Equals(NodeType.Table)) { throw new ArgumentException("The destination node should be either a paragraph or table."); } CompositeNode parentNode = insertAfterNode.ParentNode; NodeImporter nodeImporter = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting); foreach (object obj in srcDoc.Sections) { Section section = (Section)obj; foreach (object obj2 in section.Body) { Node node = (Node)obj2; if (node.NodeType.Equals(NodeType.Paragraph)) { Paragraph paragraph = (Paragraph)node; if (paragraph.IsEndOfSection && !paragraph.HasChildNodes) { continue; } } Node node2 = nodeImporter.ImportNode(node, true); parentNode.InsertAfter(node2, insertAfterNode); insertAfterNode = node2; } } }
public void CompositeEntries() { var nameValueColl = new NameValueCollection(); nameValueColl.Add("customer.name", "hammett"); nameValueColl.Add("customer.age", "27"); nameValueColl.Add("customer.age", "28"); var builder = new TreeBuilder(); CompositeNode root = builder.BuildSourceNode(nameValueColl); Assert.IsNotNull(root); Assert.AreEqual(1, root.ChildrenCount); var node = (CompositeNode)root.GetChildNode("customer"); Assert.IsNotNull(node); Assert.AreEqual("customer", node.Name); Assert.AreEqual(NodeType.Composite, node.NodeType); var entry = (LeafNode)node.GetChildNode("name"); Assert.IsNotNull(entry); Assert.IsFalse(entry.IsArray); Assert.AreEqual("name", entry.Name); Assert.AreEqual(NodeType.Leaf, entry.NodeType); Assert.AreEqual("hammett", entry.Value); entry = (LeafNode)node.GetChildNode("age"); Assert.IsNotNull(entry); Assert.IsTrue(entry.IsArray); Assert.AreEqual("age", entry.Name); Assert.AreEqual(NodeType.Leaf, entry.NodeType); Assert.AreEqual(new[] { "27", "28" }, entry.Value); }
public void EntriesStartingWithDotShouldBeConsideredSimple() { var nameValueColl = new NameValueCollection(); nameValueColl.Add(".name", "hammett"); nameValueColl.Add(".age", "27"); var builder = new TreeBuilder(); CompositeNode root = builder.BuildSourceNode(nameValueColl); Assert.IsNotNull(root); Assert.AreEqual(2, root.ChildrenCount); var entry = (LeafNode)root.GetChildNode(".name"); Assert.IsNotNull(entry); Assert.IsFalse(entry.IsArray); Assert.AreEqual(".name", entry.Name); Assert.AreEqual(NodeType.Leaf, entry.NodeType); Assert.AreEqual("hammett", entry.Value); entry = (LeafNode)root.GetChildNode(".age"); Assert.IsNotNull(entry); Assert.IsFalse(entry.IsArray); Assert.AreEqual(".age", entry.Name); Assert.AreEqual(NodeType.Leaf, entry.NodeType); Assert.AreEqual("27", entry.Value); }
public object BindObject(Type targetType, string prefix, string exclude, string allow, string expect, CompositeNode treeRoot) { expectCollPropertiesList = CreateNormalizedList(expect); return(BindObject(targetType, prefix, exclude, allow, treeRoot)); }
public static T Last <T>(this CompositeNode node, string textoContido = null) { if ((!node.HasChildNodes)) { return(default(T)); } Node[] nodes = node.GetChildNodes(NodeType.Any, true).ToArray(); if (String.IsNullOrEmpty(textoContido)) { return(nodes.OfType <T>().LastOrDefault()); } T retorno = nodes.OfType <T>().LastOrDefault(item => { string valor = (item as Node).ToTxt(); if (String.IsNullOrEmpty(valor)) { return(false); } valor = valor.Replace("\n", "").Replace("\r", ""); if (valor.IndexOf(textoContido, StringComparison.InvariantCultureIgnoreCase) < 0) { return(false); } return(true); }); return(retorno); }
/// <summary> /// The main entry point for the application. /// </summary> public static void Main() { string dataDir = Path.GetFullPath("../../../Data/"); // Load the source document. Document srcDoc = new Document(dataDir + "Template.doc"); // This is the bookmark whose content we want to copy. Bookmark srcBookmark = srcDoc.Range.Bookmarks["ntf010145060"]; // We will be adding to this document. Document dstDoc = new Document(); // Let's say we will be appending to the end of the body of the last section. CompositeNode dstNode = dstDoc.LastSection.Body; // It is a good idea to use this import context object because multiple nodes are being imported. // If you import multiple times without a single context, it will result in many styles created. NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting); // Do it once. AppendBookmarkedText(importer, srcBookmark, dstNode); // Do it one more time for fun. AppendBookmarkedText(importer, srcBookmark, dstNode); // Save the finished document. dstDoc.Save(dataDir + "Template Out.doc"); }
void GenerateQuery(CompositeNode rootnode) { RootNode = rootnode; var version = LuceneSearchHelper.LuceneVersion; var analyser = new StandardAnalyzer(version); var props = Fields.Where(s => !s.EndsWith(".Id") && s != "Id").ToArray(); var termsphrase = rootnode.GetParameter("term"); var terms = termsphrase.ParseTerm(); if (!string.IsNullOrEmpty(terms)) { Querystring["term"] = termsphrase; var query = new MultiFieldQueryParser(version, props, analyser).Parse(terms); BaseQuery.Add(query, BooleanClause.Occur.MUST); } var anys = rootnode.GetParameter("any").SplitAndTrim(LuceneSearchHelper.Escape) .Select(s => s.Replace("\"", "")); if (anys.HasItems()) { Querystring["any"] = anys.Join(" "); var any = anys.Select(s => s + "~").Join(" "); var query = new MultiFieldQueryParser(version, props, analyser).Parse(any); BaseQuery.Add(query, BooleanClause.Occur.SHOULD); Querystring["any"] = any; } var exacts = rootnode.GetParameter("exact").SplitAndTrim(LuceneSearchHelper.Escape) .Select(s => s.Replace("\"", "")); if (exacts.HasItems()) { Querystring["exact"] = exacts.Join(" "); var exact = "\"" + exacts.Join(" ") + "\"~"; var query = new MultiFieldQueryParser(version, props, analyser).Parse(exact); BaseQuery.Add(query, BooleanClause.Occur.MUST); } var mustnot = rootnode.GetParameter("mustnot"); if (!string.IsNullOrEmpty(mustnot)) { mustnot = mustnot.Replace("\"", "").Split(' ').Join(" "); var query = new MultiFieldQueryParser(version, props, analyser).Parse(mustnot); BaseQuery.Add(query, BooleanClause.Occur.MUST_NOT); Querystring["mustnot"] = mustnot; } foreach (var node in rootnode.ChildNodes) { RecursiveFilter(rootnode, node, Metadata); } DoRangeQueries(); DoPagesize(); }
void FilterLeafNode(CompositeNode parent, LeafNode leafnode, IClassMetadata metadata) { if (string.IsNullOrEmpty(leafnode.Value.ToString())) { return; } if (leafnode.IsArray && string.IsNullOrEmpty(((string[])leafnode.Value).Join(""))) { return; } if (leafnode.Value.ToString() == "all") { return; } var fieldname = leafnode.FullName.Replace("root.", ""); if (Fields.Contains(fieldname)) { StraightLeafNode(parent, leafnode, fieldname); } else { RangeLeafNode(leafnode, metadata); } }
private object ObtainPrimaryKeyValue(ActiveRecordModel model, CompositeNode node, String prefix, out PrimaryKeyModel pkModel) { pkModel = ObtainPrimaryKey(model); var pkPropName = pkModel.Property.Name; var idNode = node.GetChildNode(pkPropName); if (idNode == null) { return(null); } if (idNode != null && idNode.NodeType != NodeType.Leaf) { throw new BindingException("Expecting leaf node to contain id for ActiveRecord class. " + "Prefix: {0} PK Property Name: {1}", prefix, pkPropName); } var lNode = (LeafNode)idNode; if (lNode == null) { throw new BindingException("ARDataBinder autoload failed as element {0} " + "doesn't have a primary key {1} value", prefix, pkPropName); } bool conversionSuc; return(Converter.Convert(pkModel.Property.PropertyType, lNode.ValueType, lNode.Value, out conversionSuc)); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Note.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("Some task here", "New Text Here"); // Load the document into Aspose.Note. Document oneFile = new Document(dataDir + "Aspose.one"); IList <Node> pageNodes = oneFile.GetChildNodes(NodeType.Page); CompositeNode <Page> compositeNode = (CompositeNode <Page>)pageNodes[0]; // Get all RichText nodes IList <Node> textNodes = compositeNode.GetChildNodes(NodeType.RichText); foreach (Node node in textNodes) { foreach (KeyValuePair <string, string> kvp in replacements) { RichText richText = (RichText)node; if (richText != null && richText.Text.Contains(kvp.Key)) { // Replace text of a shape richText.Text = richText.Text.Replace(kvp.Key, kvp.Value); } } } // Save to any supported file format oneFile.Save(dataDir + "Output.pdf", SaveFormat.Pdf); }
public CompositeNode BuildNode(XmlDocument doc) { CompositeNode rootNode = new CompositeNode("root"); rootNode.AddChildNode(ProcessElement(doc.DocumentElement)); return(rootNode); }
public void SimpleBinding_Int_Invalid() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", long.MaxValue.ToString())); binder.BindParameter(typeof(int), "name", node); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithBookmarks(); string fileName = "Template.doc"; // Load the source document. Document srcDoc = new Document(dataDir + fileName); // This is the bookmark whose content we want to copy. Bookmark srcBookmark = srcDoc.Range.Bookmarks["ntf010145060"]; // We will be adding to this document. Document dstDoc = new Document(); // Let's say we will be appending to the end of the body of the last section. CompositeNode dstNode = dstDoc.LastSection.Body; // It is a good idea to use this import context object because multiple nodes are being imported. // If you import multiple times without a single context, it will result in many styles created. NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting); // Do it once. AppendBookmarkedText(importer, srcBookmark, dstNode); // Do it one more time for fun. AppendBookmarkedText(importer, srcBookmark, dstNode); dataDir = dataDir + RunExamples.GetOutputFilePath(fileName); // Save the finished document. dstDoc.Save(dataDir); Console.WriteLine("\nBookmark copied successfully.\nFile saved at " + dataDir); }
public void IndexedFlatEntries() { var nameValueColl = new NameValueCollection(); nameValueColl.Add("emails[0]", "*****@*****.**"); nameValueColl.Add("emails[1]", "*****@*****.**"); nameValueColl.Add("emails[2]", "*****@*****.**"); var builder = new TreeBuilder(); CompositeNode root = builder.BuildSourceNode(nameValueColl); Assert.IsNotNull(root); Assert.AreEqual(1, root.ChildrenCount); var indexNode = (IndexedNode)root.GetChildNode("emails"); Assert.IsNotNull(indexNode); Assert.AreEqual(3, indexNode.ChildrenCount); Node[] entries = indexNode.ChildNodes; Assert.IsNotNull(entries); Assert.AreEqual(3, entries.Length); Assert.AreEqual("*****@*****.**", ((LeafNode)entries[0]).Value); Assert.AreEqual("*****@*****.**", ((LeafNode)entries[1]).Value); Assert.AreEqual("*****@*****.**", ((LeafNode)entries[2]).Value); }
// Token: 0x0600000C RID: 12 RVA: 0x0000235C File Offset: 0x0000055C public static void InsertDocument(Node insertAfterNode, Document mainDoc, Document srcDoc) { if (insertAfterNode.NodeType != NodeType.Paragraph & insertAfterNode.NodeType != NodeType.Table) { throw new Exception("The destination node should be either a paragraph or table."); } CompositeNode parentNode = insertAfterNode.ParentNode; while (srcDoc.LastSection.Body.LastParagraph != null && !srcDoc.LastSection.Body.LastParagraph.HasChildNodes) { srcDoc.LastSection.Body.LastParagraph.Remove(); } NodeImporter nodeImporter = new NodeImporter(srcDoc, mainDoc, ImportFormatMode.KeepSourceFormatting); int count = srcDoc.Sections.Count; for (int i = 0; i < count; i++) { Section section = srcDoc.Sections[i]; int count2 = section.Body.ChildNodes.Count; for (int j = 0; j < count2; j++) { Node srcNode = section.Body.ChildNodes[j]; Node node = nodeImporter.ImportNode(srcNode, true); parentNode.InsertAfter(node, insertAfterNode); insertAfterNode = node; } } }
/// <summary> /// Recursively searches the composite node for fields and constructs a hierarchical organization of those fields. /// </summary> /// <param name="compositeNode">A node that can be composed of other nodes.</param> /// <param name="wordFields">A hierarchical list of the Word fields found in the composite node or it's descendants.</param> private static void ParseFields(CompositeNode parentNode, List <WordField> wordFields) { // This will recursively search the document object model for any fields at any depth and constructs a hierarchical organization of the fields // found. Node childNode = parentNode.FirstChild; while (childNode != null) { // Composite nodes will be searched recursively for child fields. if (childNode.IsComposite) { MergeDocument.ParseFields(childNode as CompositeNode, wordFields); } // When a field is identified based on the starting node, a new WordField is generated from the stream of nodes in the document. These fields // classes are easier to manage than an distinguised stream of nodes. if (childNode.NodeType == NodeType.FieldStart) { WordField wordField = WordField.CreateField(childNode as FieldStart); wordFields.Add(wordField); childNode = wordField.FieldEnd; } // Test the next node in the stream for the presence of a field. childNode = childNode.NextSibling; } }
private static CompositeNode GetParamsNode(int expectedValue) { var paramsNode = new CompositeNode("root"); var listNode = new IndexedNode("myList"); paramsNode.AddChildNode(listNode); listNode.AddChildNode(new LeafNode(typeof (int), "", expectedValue)); return paramsNode; }
public CompositeNode BuildSourceNode(NameValueCollection nameValueCollection) { var root = new CompositeNode("root"); PopulateTree(root, nameValueCollection); return(root); }
public static CompositeNode CreateNode() { CompositeNode asset = ScriptableObject.CreateInstance <CompositeNode>(); AssetDatabase.CreateAsset(asset, "Assets/CompositeNode.asset"); AssetDatabase.SaveAssets(); return(asset); }
public void ArrayBindingWithIndexedNodes() { var node = new CompositeNode("unnamed"); var indexNode = new IndexedNode("emails"); node.AddChildNode(indexNode); indexNode.AddChildNode(new LeafNode(typeof (String), "", "e1")); indexNode.AddChildNode(new LeafNode(typeof (String), "", "e2")); Assert.AreEqual(new[] {"e1", "e2"}, binder.BindParameter(typeof (String[]), "emails", node)); }
private static CompositeNode GetParamsNode(int expectedValue) { var paramsNode = new CompositeNode("root"); var listNode = new IndexedNode("myList"); paramsNode.AddChildNode(listNode); listNode.AddChildNode(new LeafNode(typeof(int), "", expectedValue)); return(paramsNode); }
public void CanBindToGenericList() { int expectedValue = 32; var binder = new DataBinder(); CompositeNode paramsNode = GetParamsNode(expectedValue); var myList = (List <int>)binder.BindObject(typeof(List <int>), "myList", paramsNode); Assert.AreEqual(expectedValue, myList[0]); }
/// <summary> /// Converts any fields of the specified type found in the descendants of the node into static text. /// </summary> /// <param name="compositeNode">The node in which all descendants of the specified FieldType will be converted to static text.</param> /// <param name="targetFieldType">The FieldType of the field to convert to static text.</param> public static void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType) { string originalNodeText = compositeNode.ToString(SaveFormat.Text); //ExSkip FieldsHelper helper = new FieldsHelper(targetFieldType); compositeNode.Accept(helper); Debug.Assert(originalNodeText.Equals(compositeNode.ToString(SaveFormat.Text)), "Error: Text of the node converted differs from the original"); //ExSkip foreach (Node node in compositeNode.GetChildNodes(NodeType.Any, true)) //ExSkip Debug.Assert(!(node is FieldChar && ((FieldChar)node).FieldType.Equals(targetFieldType)), "Error: A field node that should be removed still remains."); //ExSkip }
public static void AssertXml(this Document document, CompositeNode target, string expectedXml) { var actualXml = document.Export(target, DocumentTextFormat.Xml); var expected = string.Join("\r\n", expectedXml.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(l => l.Trim()).Where(s => s.Length > 0)); var actual = string.Join("\r\n", actualXml.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(l => l.Trim()).Where(s => s.Length > 0)); AssertLines.Match(expected, actual, "\r\n"); }
public void ArrayBindingWithEmptyNode() { CompositeNode node = new CompositeNode("unnamed"); Assert.AreEqual(new String[0], binder.BindParameter(typeof(String[]), "name", node)); Assert.AreEqual(new String[0], binder.BindParameter(typeof(String[]), "name", node)); Assert.AreEqual(new int[0], binder.BindParameter(typeof(int[]), "name", node)); Assert.AreEqual(new int[0], binder.BindParameter(typeof(int[]), "name", node)); }
public void ArrayBindingWithSimpleEntries() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof (String[]), "name", new[] {"1", "2"})); Assert.AreEqual(new[] {"1", "2"}, binder.BindParameter(typeof (String[]), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof (String), "name", "1")); Assert.AreEqual(new[] {"1"}, binder.BindParameter(typeof (String[]), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof (String[]), "name", new[] {"1", "2"})); Assert.AreEqual(new[] {1, 2}, binder.BindParameter(typeof (int[]), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof (String), "name", "1")); Assert.AreEqual(new[] {1}, binder.BindParameter(typeof (int[]), "name", node)); }
public void SimpleBinding_Int() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "200")); Assert.AreEqual(200, binder.BindParameter(typeof(int), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 200)); Assert.AreEqual(200, binder.BindParameter(typeof(int), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(float), "name", 200.1f)); Assert.AreEqual(200, binder.BindParameter(typeof(int), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "")); Assert.AreEqual(null, binder.BindParameter(typeof(int), "name", node)); }
public Node ProcessElement(XmlElement startEl) { if (IsComplex(startEl)) { CompositeNode top = new CompositeNode(startEl.LocalName); foreach(XmlAttribute attr in startEl.Attributes) { LeafNode leaf = new LeafNode(typeof(String), attr.LocalName, attr.Value); top.AddChildNode(leaf); } foreach(XmlElement childEl in startEl.ChildNodes) { Node childNode = ProcessElement(childEl); top.AddChildNode(childNode); } return top; } else { LeafNode top = new LeafNode(typeof(String), "", ""); return top; } }
protected void CopyToCompositeNode(CompositeNode behaviourNode) { base.CopyTo(behaviourNode); foreach (IBehaviourNode child in children) { behaviourNode.AddNode(child.Clone()); } }
public void SimpleBindingWithEmptyNode() { CompositeNode node = new CompositeNode("unnamed"); Assert.AreEqual(null, binder.BindParameter(typeof(String), "name", node)); Assert.AreEqual(null, binder.BindParameter(typeof(long), "name", node)); Assert.AreEqual(null, binder.BindParameter(typeof(int), "name", node)); Assert.AreEqual(null, binder.BindParameter(typeof(float), "name", node)); }
public void SimpleBinding_String() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "hammett")); Assert.AreEqual("hammett", binder.BindParameter(typeof(String), "name", node)); }
public void DateTimeAlternativeSourceBindingWithNullableDateTime() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "nameday", "09")); node.AddChildNode(new LeafNode(typeof(String), "namemonth", "03")); node.AddChildNode(new LeafNode(typeof(String), "nameyear", "2006")); Assert.AreEqual(new DateTime?(new DateTime(2006, 03, 09)), binder.BindParameter(typeof(DateTime?), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "nameday", 9)); node.AddChildNode(new LeafNode(typeof(int), "namemonth", 3)); node.AddChildNode(new LeafNode(typeof(int), "nameyear", 2006)); Assert.AreEqual(new DateTime?(new DateTime(2006, 03, 09)), binder.BindParameter(typeof(DateTime?), "name", node)); }
public void DateTimeArrayBinding() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new String[] {"03/09/2006", "02/08/2006"})); Assert.AreEqual(new DateTime[] {new DateTime(2006, 03, 09), new DateTime(2006, 02, 08)}, binder.BindParameter(typeof(DateTime[]), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new String[] {"03/09/2006"})); Assert.AreEqual(new DateTime[] {new DateTime(2006, 03, 09)}, binder.BindParameter(typeof(DateTime[]), "name", node)); node = new CompositeNode("unnamed"); Assert.AreEqual(new DateTime[0], binder.BindParameter(typeof(DateTime[]), "name", node)); }
public void DateTimeOffsetAlternativeSourceBindingWithNullableDateTime() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "nameday", "24")); node.AddChildNode(new LeafNode(typeof(String), "namemonth", "10")); node.AddChildNode(new LeafNode(typeof(String), "nameyear", "2009")); Assert.AreEqual(new DateTimeOffset(new DateTime(2009, 10, 24)), binder.BindParameter(typeof(DateTimeOffset?), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "nameday", 24)); node.AddChildNode(new LeafNode(typeof(int), "namemonth", 10)); node.AddChildNode(new LeafNode(typeof(int), "nameyear", 2009)); Assert.AreEqual(new DateTimeOffset(new DateTime(2009, 10, 24)), binder.BindParameter(typeof(DateTimeOffset?), "name", node)); }
/// <summary> /// A simple function that will walk through all children of a specified node recursively /// and print the type of each node to the screen. /// </summary> public void TraverseAllNodes(CompositeNode parentNode) { // This is the most efficient way to loop through immediate children of a node. for (Node childNode = parentNode.FirstChild; childNode != null; childNode = childNode.NextSibling) { // Do some useful work. Console.WriteLine(Node.NodeTypeToString(childNode.NodeType)); // Recurse into the node if it is a composite node. if (childNode.IsComposite) this.TraverseAllNodes((CompositeNode)childNode); } }
public void SimpleBinding_Decimal() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "12.2")); Assert.AreEqual((decimal)12.2, binder.BindParameter(typeof(decimal), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(double), "name", 12.2)); Assert.AreEqual((decimal)12.2, binder.BindParameter(typeof(decimal), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(float), "name", 12.2f)); Assert.AreEqual((decimal)12.2, binder.BindParameter(typeof(decimal), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "")); Assert.AreEqual(null, binder.BindParameter(typeof(decimal), "name", node)); }
public void SimpleBinding_Int_Invalid() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", long.MaxValue.ToString())); binder.BindParameter(typeof(int), "name", node); }
private CompositeNode SplitCompositeAtNode(CompositeNode baseNode, Node targetNode) { CompositeNode cloneNode = (CompositeNode)baseNode.Clone(false); Node node = targetNode; int currentPageNum = mPageNumberFinder.GetPage(baseNode); // Move all nodes found on the next page into the copied node. Handle row nodes separately. if (baseNode.NodeType != NodeType.Row) { CompositeNode composite = cloneNode; if (baseNode.NodeType == NodeType.Section) { cloneNode = (CompositeNode)baseNode.Clone(true); Section section = (Section)cloneNode; section.Body.RemoveAllChildren(); composite = section.Body; } while (node != null) { Node nextNode = node.NextSibling; composite.AppendChild(node); node = nextNode; } } else { // If we are dealing with a row then we need to add in dummy cells for the cloned row. int targetPageNum = mPageNumberFinder.GetPage(targetNode); Node[] childNodes = baseNode.ChildNodes.ToArray(); foreach (Node childNode in childNodes) { int pageNum = mPageNumberFinder.GetPage(childNode); if (pageNum == targetPageNum) { cloneNode.LastChild.Remove(); cloneNode.AppendChild(childNode); } else if (pageNum == currentPageNum) { cloneNode.AppendChild(childNode.Clone(false)); if (cloneNode.LastChild.NodeType != NodeType.Cell) ((CompositeNode)cloneNode.LastChild).AppendChild(((CompositeNode)childNode).FirstChild.Clone(false)); } } } // Insert the split node after the original. baseNode.ParentNode.InsertAfter(cloneNode, baseNode); // Update the new page numbers of the base node and the clone node including its descendents. // This will only be a single page as the cloned composite is split to be on one page. int currentEndPageNum = mPageNumberFinder.GetPageEnd(baseNode); mPageNumberFinder.AddPageNumbersForNode(baseNode, currentPageNum, currentEndPageNum - 1); mPageNumberFinder.AddPageNumbersForNode(cloneNode, currentEndPageNum, currentEndPageNum); foreach (Node childNode in cloneNode.GetChildNodes(NodeType.Any, true)) mPageNumberFinder.AddPageNumbersForNode(childNode, currentEndPageNum, currentEndPageNum); return cloneNode; }
public void AddToRoot(CompositeNode rootNode, XmlDocument doc) { Node top = ProcessElement(doc.DocumentElement); rootNode.AddChildNode(top); }
private ArrayList SplitComposite(CompositeNode composite) { ArrayList splitNodes = new ArrayList(); foreach (Node splitNode in FindChildSplitPositions(composite)) splitNodes.Add(SplitCompositeAtNode(composite, splitNode)); return splitNodes; }
private bool IsCompositeAcrossPage(CompositeNode composite) { return mPageNumberFinder.PageSpan(composite) > 1; }
private ArrayList FindChildSplitPositions(CompositeNode node) { // A node may span across multiple pages so a list of split positions is returned. // The split node is the first node on the next page. ArrayList splitList = new ArrayList(); int startingPage = mPageNumberFinder.GetPage(node); Node[] childNodes = node.NodeType == NodeType.Section ? ((Section)node).Body.ChildNodes.ToArray() : node.ChildNodes.ToArray(); foreach (Node childNode in childNodes) { int pageNum = mPageNumberFinder.GetPage(childNode); // If the page of the child node has changed then this is the split position. Add // this to the list. if (pageNum > startingPage) { splitList.Add(childNode); startingPage = pageNum; } if (mPageNumberFinder.PageSpan(childNode) > 1) mPageNumberFinder.AddPageNumbersForNode(childNode, pageNum, pageNum); } // Split composites backward so the cloned nodes are inserted in the right order. splitList.Reverse(); return splitList; }
public void SimpleBinding_Bool() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "1")); Assert.AreEqual(true, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "0")); Assert.AreEqual(false, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new string[] { "1", "0" })); Assert.AreEqual(true, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new string[] { "0", "0" })); Assert.AreEqual(false, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "yes")); Assert.AreEqual(true, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "true")); Assert.AreEqual(true, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "false")); Assert.AreEqual(false, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 1)); Assert.AreEqual(true, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "")); Assert.AreEqual(false, binder.BindParameter(typeof(bool), "name", node)); node = new CompositeNode("unnamed"); Assert.AreEqual(null, binder.BindParameter(typeof(bool), "name", node)); }
public void EnumSourceFlagsBinding() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(FileAttributes), "name", FileAttributes.Device|FileAttributes.Directory)); Assert.AreEqual(FileAttributes.Device|FileAttributes.Directory, binder.BindParameter(typeof(FileAttributes), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new String[] { "Device", "Directory" })); Assert.AreEqual(FileAttributes.Device|FileAttributes.Directory, binder.BindParameter(typeof(FileAttributes), "name", node)); }
public void DateTimeOffsetArrayBinding() { var node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new[] { "10/24/2009", "07/17/1965" })); Assert.AreEqual(new[] { new DateTimeOffset(new DateTime(2009, 10, 24)), new DateTimeOffset(new DateTime(1965, 07, 17)) }, binder.BindParameter(typeof(DateTimeOffset[]), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String[]), "name", new[] { "10/24/2009" })); Assert.AreEqual(new[] { new DateTimeOffset(new DateTime(2009, 10, 24)) }, binder.BindParameter(typeof(DateTimeOffset[]), "name", node)); node = new CompositeNode("unnamed"); Assert.AreEqual(new DateTimeOffset[0], binder.BindParameter(typeof(DateTimeOffset[]), "name", node)); }
public void EnumSourceBinding() { CompositeNode node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(FileAccess), "name", FileAccess.Read)); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "Read")); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "2")); Assert.AreEqual(FileAccess.Write, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 1)); Assert.AreEqual(FileAccess.Read, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(int), "name", 2)); Assert.AreEqual(FileAccess.Write, binder.BindParameter(typeof(FileAccess), "name", node)); node = new CompositeNode("unnamed"); node.AddChildNode(new LeafNode(typeof(String), "name", "")); Assert.AreEqual(null, binder.BindParameter(typeof(FileAccess), "name", node)); }
public CompositeNode BuildNode(XmlDocument doc) { CompositeNode rootNode = new CompositeNode("root"); rootNode.AddChildNode(ProcessElement(doc.DocumentElement)); return rootNode; }
private static void ProcessMarker(CompositeNode cloneNode, ArrayList nodes, Node node, bool isInclusive, bool isStartMarker, bool isEndMarker) { // If we are dealing with a block level node just see if it should be included and add it to the list. if (!IsInline(node)) { // Don't add the node twice if the markers are the same node if (!(isStartMarker && isEndMarker)) { if (isInclusive) nodes.Add(cloneNode); } return; } // If a marker is a FieldStart node check if it's to be included or not. // We assume for simplicity that the FieldStart and FieldEnd appear in the same paragraph. if (node.NodeType == NodeType.FieldStart) { // If the marker is a start node and is not be included then skip to the end of the field. // If the marker is an end node and it is to be included then move to the end field so the field will not be removed. if ((isStartMarker && !isInclusive) || (!isStartMarker && isInclusive)) { while (node.NextSibling != null && node.NodeType != NodeType.FieldEnd) node = node.NextSibling; } } // If either marker is part of a comment then to include the comment itself we need to move the pointer forward to the Comment // node found after the CommentRangeEnd node. if (node.NodeType == NodeType.CommentRangeEnd) { while (node.NextSibling != null && node.NodeType != NodeType.Comment) node = node.NextSibling; } // Find the corresponding node in our cloned node by index and return it. // If the start and end node are the same some child nodes might already have been removed. Subtract the // difference to get the right index. int indexDiff = node.ParentNode.ChildNodes.Count - cloneNode.ChildNodes.Count; // Child node count identical. if (indexDiff == 0) node = cloneNode.ChildNodes[node.ParentNode.IndexOf(node)]; else node = cloneNode.ChildNodes[node.ParentNode.IndexOf(node) - indexDiff]; // Remove the nodes up to/from the marker. bool isSkip = false; bool isProcessing = true; bool isRemoving = isStartMarker; Node nextNode = cloneNode.FirstChild; while (isProcessing && nextNode != null) { Node currentNode = nextNode; isSkip = false; if (currentNode.Equals(node)) { if (isStartMarker) { isProcessing = false; if (isInclusive) isRemoving = false; } else { isRemoving = true; if (isInclusive) isSkip = true; } } nextNode = nextNode.NextSibling; if (isRemoving && !isSkip) currentNode.Remove(); } // After processing the composite node may become empty. If it has don't include it. if (!(isStartMarker && isEndMarker)) { if (cloneNode.HasChildNodes) nodes.Add(cloneNode); } }