public static HtmlTag ChildNodesRecursiveHtmlTag(this IDocumentNode currentNode, IDocumentNode IDocumentNode, int allExpandToLevel = 2, bool includeHidden = false, bool includeDeleted = false, string addAdminPath = "") { var ul = new HtmlTags.HtmlTag("ul"); foreach (var c in IDocumentNode.Children.Where(n => (includeDeleted || !n.IsDeleted) && (includeHidden || !n.IsHidden))) { var li = new HtmlTags.HtmlTag("li"); var path = addAdminPath + c.Url; li.Add("a").Attr("href", path).Text(c.Name); if (c == currentNode) { li.AddClass("selected"); } if (c.IsDescendantOrSameAs(currentNode)) { li.AddClass("sel"); } if (c.Children.Count > 0 && (c.Level < allExpandToLevel || c.IsDescendantOrSameAs(currentNode) || currentNode.IsDescendantOrSameAs(c))) { li.Children.Add(ChildNodesRecursiveHtmlTag(currentNode, c, allExpandToLevel, includeHidden, includeDeleted, addAdminPath)); } ul.Children.Add(li); } return(ul); }
/// <summary> /// Get the absolute path of the node <code>node</code> starting from the root. /// </summary> /// <param name="node">The node for which the path is retrieved.</param> /// <returns>The absolute path of the node. The first element is a "/" to mark this as absolute path.</returns> public static DocumentPath GetAbsolutePath(IDocumentNode node) { DocumentPath path = GetPath(node, int.MaxValue); path.IsAbsolutePath = true; return(path); }
public static HtmlString AdminTree(IDocumentNode Model, string adminUrl, string divClassName = "") { var div = new HtmlTag("div"); if (divClassName != "") { div.AddClass(divClassName); } var p = new HtmlTag("p").Append(new HtmlTag("a").Text("Root node").Attr("href", adminUrl)); var tree = HtmlBuilder.ChildNodesRecursiveHtmlTag(Model, Model.AncestorAtLevel(0), 99, true, false, adminUrl); var pInfo = new HtmlTag("p").Text("Add new child"); var form = new HtmlTag("form").Attr("method", "post").Attr("action", "#"); form.Append(new HtmlTag("label").Attr("for", "new-name").Text("Header (name)")); form.Append(new HtmlTag("input").Id("new-name").Attr("name", "new-name").Attr("type", "text")); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "insert-new").Attr("value", "Add")); div.Append(p).Append(tree).Append(pInfo).Append(form); return(new HtmlString(div.ToHtmlString())); }
public virtual void StylesOfSvgTagProcessingTest() { String svg = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n" + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n" + "<svg width=\"400\" height=\"200\"\n" + " viewBox=\"0 0 400 200\" version=\"1.1\"\n" + " xmlns=\"http://www.w3.org/2000/svg\"\n" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + " xmlns:v=\"http://schemas.microsoft.com/visio/2003/SVGExtensions/\"\n" + " class=\"st11\">\n" + " <style type=\"text/css\">\n" + " .st11 {fill:none;stroke:black;stroke-width:6}\n" + " </style>\n" + " <g >\n" + " <path d=\"M0 100 L0 50 L70 50\"/>\n" + " </g>\n" + "</svg>"; JsoupXmlParser xmlParser = new JsoupXmlParser(); IDocumentNode root = xmlParser.Parse(svg); IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root).GetRootRenderer (); PathSvgNodeRenderer pathSvgNodeRenderer = (PathSvgNodeRenderer)((IBranchSvgNodeRenderer)nodeRenderer.GetChildren ()[0]).GetChildren()[0]; IDictionary <String, String> actual = new Dictionary <String, String>(); actual.Put("stroke", pathSvgNodeRenderer.GetAttribute("stroke")); actual.Put("fill", pathSvgNodeRenderer.GetAttribute("fill")); actual.Put("d", pathSvgNodeRenderer.GetAttribute("d")); IDictionary <String, String> expected = new Dictionary <String, String>(); expected.Put("stroke", "black"); expected.Put("fill", "none"); expected.Put("d", "M0 100 L0 50 L70 50"); NUnit.Framework.Assert.AreEqual(expected, actual); }
/// <summary> /// Attaches the HTML content stored in a document node to /// an existing PDF document, using specific converter properties, /// and returning an iText /// <see cref="iText.Layout.Document"/> /// object. /// </summary> /// <param name="documentNode">the document node with the HTML</param> /// <param name="pdfDocument"> /// the /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// instance /// </param> /// <param name="converterProperties"> /// the /// <see cref="iText.Html2pdf.ConverterProperties"/> /// instance /// </param> /// <returns> /// an iText /// <see cref="iText.Layout.Document"/> /// object /// </returns> public static Document Attach(IDocumentNode documentNode, PdfDocument pdfDocument, ConverterProperties converterProperties ) { IHtmlProcessor processor = new DefaultHtmlProcessor(converterProperties); return(processor.ProcessDocument(documentNode, pdfDocument)); }
public virtual void StyleTagProcessingTest() { String svg = "<svg\n" + " width=\"210mm\"\n" + " height=\"297mm\"\n" + " viewBox=\"0 0 210 297\"\n" + " version=\"1.1\"\n" + " id=\"svg8\"\n" + " >\n" + " <style>\n" + "\tellipse{\n" + "\t\tstroke-width:1.76388889;\n" + "\t\tstroke:#da0000;\n" + "\t\tstroke-opacity:1;\n" + "\t}\n" + " </style>\n" + " <ellipse\n" + " id=\"path3699\"\n" + " cx=\"96.005951\"\n" + " cy=\"110.65774\"\n" + " rx=\"53.672619\"\n" + " ry=\"53.294643\"\n" + " style=\"fill:none;stroke-miterlimit:4;stroke-dasharray:none\" />\n" + "</svg>\n"; JsoupXmlParser xmlParser = new JsoupXmlParser(); IDocumentNode root = xmlParser.Parse(svg); IBranchSvgNodeRenderer nodeRenderer = (IBranchSvgNodeRenderer) new DefaultSvgProcessor().Process(root).GetRootRenderer (); IDictionary <String, String> actual = new Dictionary <String, String>(); //Traverse to ellipse ISvgNodeRenderer ellipse = nodeRenderer.GetChildren()[0]; actual.Put("stroke", ellipse.GetAttribute("stroke")); actual.Put("stroke-width", ellipse.GetAttribute("stroke-width")); actual.Put("stroke-opacity", ellipse.GetAttribute("stroke-opacity")); IDictionary <String, String> expected = new Dictionary <String, String>(); expected.Put("stroke-width", "1.76388889"); expected.Put("stroke", "#da0000"); expected.Put("stroke-opacity", "1"); NUnit.Framework.Assert.AreEqual(expected, actual); }
public virtual void Test06() { String htmlFileName = sourceFolder + "html06.html"; String cssFileName = sourceFolder + "css06.css"; IXmlParser htmlParser = new JsoupHtmlParser(); IDocumentNode document = htmlParser.Parse(new FileStream(htmlFileName, FileMode.Open, FileAccess.Read), "UTF-8" ); CssStyleSheet css = CssStyleSheetParser.Parse(new FileStream(cssFileName, FileMode.Open, FileAccess.Read)); IElementNode element = new JsoupElementNode(((JsoupDocumentNode)document).GetDocument().GetElementsByTag("p" ).First()); MediaDeviceDescription deviceDescription1 = new MediaDeviceDescription(MediaType.PRINT).SetBitsPerComponent (2); MediaDeviceDescription deviceDescription2 = new MediaDeviceDescription(MediaType.HANDHELD).SetBitsPerComponent (2); MediaDeviceDescription deviceDescription3 = new MediaDeviceDescription(MediaType.SCREEN).SetBitsPerComponent (1); IList <CssDeclaration> declarations1 = css.GetCssDeclarations(element, deviceDescription1); IList <CssDeclaration> declarations2 = css.GetCssDeclarations(element, deviceDescription2); IList <CssDeclaration> declarations3 = css.GetCssDeclarations(element, deviceDescription3); NUnit.Framework.Assert.IsTrue(Enumerable.SequenceEqual(declarations1, declarations2)); NUnit.Framework.Assert.AreEqual(0, declarations3.Count); NUnit.Framework.Assert.AreEqual(1, declarations1.Count); NUnit.Framework.Assert.AreEqual("color: red", declarations1[0].ToString()); }
private void ConvertProcess(IDocumentNode node) { IDictionary <TFragment, string> fragmentResults = DocumentMultiWriter.Convert(node, MergeFragments()); _conditional = true; _writing = true; foreach (TFragment fragment in MergeFragments()) { _currentConditionalWriting?.Fragments.Add(fragment); string fragmentResult = fragmentResults[fragment]; if (string.IsNullOrEmpty(fragmentResult)) { continue; } _currentConditionalWriting?.Apply(_writer); _writer.Write(fragmentResult); } _writing = false; _conditional = false; if (_currentConditionalWriting != null) { throw new InvalidOperationException(); } }
public static void UpdateContextData(this IDocumentNode documentNode, IDocumentNode parent = null) { var url = ""; documentNode.Parent = parent; if (parent != null) { url = parent.Url; documentNode.Level = parent.Level + 1; } else { documentNode.Level = 0; } if (String.IsNullOrEmpty(documentNode.UrlName)) { documentNode.UrlName = documentNode.Name.ToLower().Replace(" ", "-"); } if (url == "" && documentNode.Name == "root") { documentNode.Url = ""; } else { documentNode.Url = url + "/" + documentNode.UrlName; } foreach (var c in documentNode.Children) { c.UpdateContextData(documentNode); } }
public void Process() { foreach (ITemplateSet set in this.templateSets.Values) { set.Resolve(this); } // Later on, we will implement rewriting only if changed foreach (Mapping mapping in this.generationMapper) { Console.WriteLine("Processing mapping '{0}:{1}' -> '{2}'", mapping.Source, mapping.Template, mapping.Destination); ITemplateSet set = templateSets[mapping.Template]; IDocumentNode src = documentSources[mapping.Source]; using (Stream stream = File.Create(mapping.Destination)) { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("// This file was generated by TemplateEngine from template source '{0}'", mapping.Source); writer.WriteLine("// using template '{0}. Do not modify this file directly, modify it from template source.", mapping.Template); writer.WriteLine(); src.Emit(set, writer); } } } }
/// <summary> /// Retrieves the relative path from the node <code>startnode</code> to the node <code>endnode</code>. /// </summary> /// <param name="startnode">The node where the path begins.</param> /// <param name="endnode">The node where the path ends.</param> /// <param name="stoppernode">A object which is used as stopper. If the relative path would step down below this node in the hierarchie, /// not the relative path, but the absolute path of the endnode is returned. This is usefull for instance for serialization purposes.You can set the stopper node /// to the root object of serialization, so that path in the inner of the serialization tree are relative paths, whereas paths to objects not includes in the /// serialization tree are returned as absolute paths. The stoppernode can be null.</param> /// <returns>If the two nodes share a common root, the function returns the relative path from <code>startnode</code> to <code>endnode</code>. /// If the nodes have no common root, then the function returns the absolute path of the endnode. /// <para>If either startnode or endnode is null, then null is returned.</para></returns> public static DocumentPath GetRelativePathFromTo(IDocumentNode startnode, IDocumentNode endnode, object stoppernode) { System.Collections.Hashtable hash = new System.Collections.Hashtable(); if (startnode == null || endnode == null) { return(null); } // store the complete hierarchie of objects as keys in the hash, (values are the hierarchie depth) int endnodedepth = 0; object root = endnode; while (root != null && root is IDocumentNode) { hash.Add(root, endnodedepth); root = ((IDocumentNode)root).ParentObject; ++endnodedepth; } // the whole endnode hierarchie is now in the hash, now look to find the first node starting from startnode, which has the same root // i.e. which is contained in the hash table int startnodedepth = 0; root = startnode; while (root != null && root is IDocumentNode) { if (hash.ContainsKey(root)) { endnodedepth = (int)hash[root]; // the depth of the endnode to this root break; } if (root.Equals(stoppernode)) // stop also if the stopper node is reached { break; } root = ((IDocumentNode)root).ParentObject; ++startnodedepth; } if (!hash.ContainsKey(root)) { return(GetAbsolutePath(endnode)); // no common root -> return AbsolutePath } else { DocumentPath path; path = GetPath(endnode, endnodedepth); // path of endnode depth for (int i = 0; i < startnodedepth; i++) { path.Insert(0, ".."); // insert "root dir entries" } return(path); } }
/// <summary> /// Converts a /// <see cref="System.String"/> /// containing HTML to a /// <see cref="System.Collections.IList{E}"/> /// of /// iText objects ( /// <see cref="iText.Layout.Element.IElement"/> /// instances), using specific /// <see cref="ConverterProperties"/>. /// </summary> /// <param name="html"> /// the html in the form of a /// <see cref="System.String"/> /// </param> /// <param name="converterProperties"> /// a /// <see cref="ConverterProperties"/> /// instance /// </param> /// <returns>a list of iText building blocks</returns> public static IList <IElement> ConvertToElements(String html, ConverterProperties converterProperties) { ReflectionUtils.ScheduledLicenseCheck(); IXmlParser parser = new JsoupHtmlParser(); IDocumentNode doc = parser.Parse(html); return(Attacher.Attach(doc, converterProperties)); }
protected void Aggregate(IDocumentNode node, string afterEach) { foreach (IDocumentNode child in node.Children) { child?.Accept(this); Writer.Write(afterEach); } }
internal DocumentNode(string name, string content = null, IDocumentNode parent = null) : this() { this.name = name; this.content = content; this.parent = parent; this.dateCreated = DateTime.UtcNow; }
public virtual void MatchesRootSelectorItemTest() { CssPseudoClassRootSelectorItem item = CssPseudoClassRootSelectorItem.GetInstance(); IXmlParser htmlParser = new JsoupHtmlParser(); IDocumentNode documentNode = htmlParser.Parse("<div><p>Alexander</p><p>Alexander</p></div>"); INode headNode = documentNode.ChildNodes()[0]; NUnit.Framework.Assert.IsTrue(item.Matches(headNode)); }
public void Convert(IDocumentNode node, Stream stream) { using (var streamWriter = new StreamWriter(stream)) { _writer = streamWriter; ConvertProcess(node); _writer = null; } }
public virtual void MatchesNthOfTypeSelectorItemTestBadNodeArgument() { CssPseudoClassNthOfTypeSelectorItem item = new CssPseudoClassNthOfTypeSelectorItem("text"); IXmlParser htmlParser = new JsoupHtmlParser(); IDocumentNode documentNode = htmlParser.Parse("<div><p>Alexander</p><p>Alexander</p></div>"); INode bodyNode = documentNode.ChildNodes()[0].ChildNodes()[1]; INode divNode = bodyNode.ChildNodes()[0].ChildNodes()[0]; NUnit.Framework.Assert.IsFalse(item.Matches(divNode)); }
public virtual void MatchesEmptySelectorItemSpaceTest() { CssPseudoClassEmptySelectorItem item = CssPseudoClassEmptySelectorItem.GetInstance(); IXmlParser htmlParser = new JsoupHtmlParser(); IDocumentNode documentNode = htmlParser.Parse("<div> </div>"); INode bodyNode = documentNode.ChildNodes()[0].ChildNodes()[1]; INode divNode = bodyNode.ChildNodes()[0]; NUnit.Framework.Assert.IsFalse(item.Matches(divNode)); }
public IDocumentNode DocumentNode_Update(IDocumentNode documentNode) { var cmd = new AddOrUpdateDocumentNode() { DocumentNode = documentNode }; nodeTreeIsUpdated = true; return((IDocumentNode)liveDbEngine.Execute(cmd)); }
public virtual void MatchesFirstOfTypeSelectorItemTestNotTaggedText() { CssPseudoClassFirstOfTypeSelectorItem item = CssPseudoClassFirstOfTypeSelectorItem.GetInstance(); IXmlParser htmlParser = new JsoupHtmlParser(); IDocumentNode documentNode = htmlParser.Parse("Some text!"); INode bodyNode = documentNode.ChildNodes()[0].ChildNodes()[1]; INode divNode = bodyNode.ChildNodes()[0]; NUnit.Framework.Assert.IsFalse(item.Matches(divNode)); }
private void ConvertProcessUnconditional(IDocumentNode node) { IDictionary <TFragment, string> fragmentResults = DocumentMultiWriter.Convert(node, MergeFragments()); _writing = true; foreach (TFragment fragment in MergeFragments()) { _writer.Write(fragmentResults[fragment]); } _writing = false; }
public static T GetRootNodeImplementing <T>(IDocumentNode node) { object root = node.ParentObject; while (root != null && root is IDocumentNode && !(root is T)) { root = ((IDocumentNode)root).ParentObject; } return((root is T) ? (T)root : default(T)); }
public static IDocumentNode DocumentNodeByGuid(this IDocumentNode node, Guid guid) { if (node.Id == guid) { return(node); } else { return(node.GetDescendantNodes(n => n.Id == guid, true).FirstOrDefault()); } }
/// <summary> /// Get the first parent node of the node <code>node</code> that implements the given type <code>type.</code>. /// </summary> /// <param name="node">The node from where the search begins.</param> /// <param name="type">The type to search for.</param> /// <returns>The first parental node that implements the type <code>type.</code> /// </returns> public static object GetRootNodeImplementing(IDocumentNode node, System.Type type) { object root = node.ParentObject; while (root != null && root is IDocumentNode && !type.IsInstanceOfType(root)) { root = ((IDocumentNode)root).ParentObject; } return(type.IsInstanceOfType(root) ? root : null); }
/// <summary> /// Get the root node of the node <code>node</code>. The root node is defined as last node in the hierarchie that /// either has not implemented the <see cref="IDocumentNode"/> interface or has no parent. /// </summary> /// <param name="node">The node from where the search begins.</param> /// <returns>The root node, i.e. the last node in the hierarchie that /// either has not implemented the <see cref="IDocumentNode"/> interface or has no parent</returns> public static object GetRootNode(IDocumentNode node) { object root = node.ParentObject; while (root != null && root is IDocumentNode) { root = ((IDocumentNode)root).ParentObject; } return(root); }
private DocumentNode(SerializationInfo info, StreamingContext context) { this.id = (Guid)info.GetValue("Id", typeof(Guid)); this.name = info.GetString("Name"); this.content = info.GetString("Content"); this.dateLastModified = (DateTime?)info.GetValue("DateLastModified", typeof(DateTime?)); this.dateCreated = info.GetDateTime("DateCreated"); this.parent = (IDocumentNode)info.GetValue("Parent", typeof(IDocumentNode)); this.children = (ObservableCollection <DocumentNode>) info.GetValue("Children", typeof(ObservableCollection <DocumentNode>)); }
public virtual void NamedObjectRectangleTest() { String svgFile = sourceFolder + "namedObjectRectangleTest.svg"; Stream svg = new FileStream(svgFile, FileMode.Open, FileAccess.Read); JsoupXmlParser xmlParser = new JsoupXmlParser(); IDocumentNode root = xmlParser.Parse(svg, null); ISvgProcessorResult processorResult = new DefaultSvgProcessor().Process(root); IDictionary <String, ISvgNodeRenderer> actual = processorResult.GetNamedObjects(); NUnit.Framework.Assert.AreEqual(1, actual.Count); NUnit.Framework.Assert.IsTrue(actual.ContainsKey("MyRect")); }
public static HtmlString ChildNodesRecursive(this IDocumentNode currentNode, int fromLevel = 1, int allExpandToLevel = 2, bool includeHidden = false, bool includeDeleted = false, string addAdminPath = "") { var fromNode = currentNode.AncestorAtLevel(fromLevel); if (fromNode != null) { return(new HtmlString(ChildNodesRecursiveHtmlTag(fromNode, currentNode, allExpandToLevel, includeHidden, includeDeleted, addAdminPath).ToHtmlString())); } else { return(new HtmlString("")); } }
/// <summary> /// Converts HTML obtained from an /// <see cref="System.IO.Stream"/> /// to objects that /// will be added to a /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// , using specific /// <see cref="ConverterProperties"/> /// , /// returning a /// <see cref="iText.Layout.Document"/> /// instance. /// </summary> /// <param name="html"> /// the html in the form of a /// <see cref="System.String"/> /// </param> /// <param name="pdfDocument"> /// the /// <see cref="iText.Kernel.Pdf.PdfDocument"/> /// instance /// </param> /// <param name="converterProperties"> /// a /// <see cref="ConverterProperties"/> /// instance /// </param> /// <returns> /// a /// <see cref="iText.Layout.Document"/> /// instance /// </returns> public static Document ConvertToDocument(String html, PdfDocument pdfDocument, ConverterProperties converterProperties ) { ReflectionUtils.ScheduledLicenseCheck(); if (pdfDocument.GetReader() != null) { throw new Html2PdfException(Html2PdfException.PdfDocumentShouldBeInWritingMode); } IXmlParser parser = new JsoupHtmlParser(); IDocumentNode doc = parser.Parse(html); return(Attacher.Attach(doc, pdfDocument, converterProperties)); }
public override string Convert(IDocumentNode node) { string result; using (_mainWriter = new StringWriter()) { node.Accept(this); result = _mainWriter.ToString(); } _mainWriter = null; return(result); }
public static HtmlString AdminTree(IDocumentNode Model, string adminUrl, string divClassName = "") { var div = new HtmlTag("div"); if (divClassName != "") div.AddClass(divClassName); var p = new HtmlTag("p").Append(new HtmlTag("a").Text("Root node").Attr("href", adminUrl)); var tree = HtmlBuilder.ChildNodesRecursiveHtmlTag(Model, Model.AncestorAtLevel(0), 99, true, false, adminUrl); var pInfo = new HtmlTag("p").Text("Add new child"); var form = new HtmlTag("form").Attr("method", "post").Attr("action", "#"); form.Append(new HtmlTag("label").Attr("for", "new-name").Text("Header (name)")); form.Append(new HtmlTag("input").Id("new-name").Attr("name", "new-name").Attr("type", "text")); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "insert-new").Attr("value", "Add")); div.Append(p).Append(tree).Append(pInfo).Append(form); return new HtmlString(div.ToHtmlString()); }
public static HtmlTag ChildNodesRecursiveHtmlTag(this IDocumentNode currentNode, IDocumentNode IDocumentNode, int allExpandToLevel = 2, bool includeHidden = false, bool includeDeleted = false, string addAdminPath = "") { var ul = new HtmlTags.HtmlTag("ul"); foreach (var c in IDocumentNode.Children.Where(n => (includeDeleted || !n.IsDeleted) && (includeHidden || !n.IsHidden))) { var li = new HtmlTags.HtmlTag("li"); var path = addAdminPath + c.Url; li.Add("a").Attr("href", path).Text(c.Name); if (c == currentNode) { li.AddClass("selected"); } if (c.IsDescendantOrSameAs(currentNode)) li.AddClass("sel"); if (c.Children.Count > 0 && (c.Level < allExpandToLevel || c.IsDescendantOrSameAs(currentNode) || currentNode.IsDescendantOrSameAs(c))) { li.Children.Add(ChildNodesRecursiveHtmlTag(currentNode, c, allExpandToLevel, includeHidden, includeDeleted, addAdminPath)); } ul.Children.Add(li); } return ul; }
public void Initialize(NodeTreeCmsSettings settings) { // Control settings if (settings == null) settings = new NodeTreeCmsSettings(); if (String.IsNullOrEmpty(settings.DbPath)) settings.DbPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Cms"); if (String.IsNullOrEmpty(settings.AdminUrl)) settings.AdminUrl="/admin"; if (!settings.AdminUrl.StartsWith("/")) settings.AdminUrl = "/" + settings.AdminUrl; if (String.IsNullOrEmpty(settings.DefaultViewPath)) settings.DefaultViewPath = "Default.cshtml"; //if (String.IsNullOrEmpty(settings.ContentRootUrl)) // settings.ContentRootUrl = "/"; this.settings = settings; var path = settings.DbPath; dbProvider = new LiveDbProvider(path); nodeTree = dbProvider.DocumentNode_NodeTree(); if (nodeTree == null) InitializeDocumentNodes(); dbProvider.UpdateDatabaseImage(); }
public override void EhParentTunnelingEventHappened(IDocumentNode sender, IDocumentNode originalSource, TunnelingEventArgs e) { // since we deal with relative path, we have to watch changes to our path too if (e is Main.DocumentPathChangedEventArgs) { var node = InternalDocNode; if (null != node) { _docNodePath = RelativeDocumentPath.GetRelativePathFromTo(_parent, node); } } base.EhParentTunnelingEventHappened(sender, originalSource, e); }
/// <summary> /// Retrieves the relative path from the node <code>startnode</code> to the node <code>endnode</code>. /// </summary> /// <param name="startnode">The node where the path begins.</param> /// <param name="endnode">The node where the path ends.</param> /// <param name="stoppernode">A object which is used as stopper. If the relative path would step down below this node in the hierarchie, /// not the relative path, but the absolute path of the endnode is returned. This is usefull for instance for serialization purposes.You can set the stopper node /// to the root object of serialization, so that path in the inner of the serialization tree are relative paths, whereas paths to objects not includes in the /// serialization tree are returned as absolute paths. The stoppernode can be null.</param> /// <returns>If the two nodes share a common root, the function returns the relative path from <code>startnode</code> to <code>endnode</code>. /// If the nodes have no common root, then the function returns the absolute path of the endnode. /// <para>If either startnode or endnode is null, then null is returned.</para></returns> public static RelativeDocumentPath GetRelativePathFromTo(IDocumentLeafNode startnode, IDocumentLeafNode endnode, IDocumentNode stoppernode) { if (startnode == null) throw new ArgumentNullException(nameof(startnode)); if (endnode == null) throw new ArgumentNullException(nameof(endnode)); if (object.ReferenceEquals(startnode, endnode)) return IdentityPath; // Start node and end node are identical var currStart = startnode; var currEnd = endnode; var startNodesList = new List<IDocumentLeafNode>(Altaxo.Collections.TreeNodeExtensions.TakeFromHereToRoot(startnode)); var endNodesList = new List<IDocumentLeafNode>(Altaxo.Collections.TreeNodeExtensions.TakeFromHereToRoot(endnode)); var commonNodes = new HashSet<IDocumentLeafNode>(startNodesList); commonNodes.IntersectWith(new HashSet<IDocumentLeafNode>(endNodesList)); if (commonNodes.Count == 0) return null; // happens if either startnode or endnode are not rooted (this can happen temporarily during instance creation) int numberOfNodesDown = 0; IDocumentLeafNode commonNode = null; for (int i = 0; i < startNodesList.Count; ++i) { if (commonNodes.Contains(startNodesList[i])) { commonNode = startNodesList[i]; break; } else { numberOfNodesDown++; } } if (null == commonNodes) throw new InvalidOperationException(nameof(commonNode) + " should always be != null"); var idx = endNodesList.IndexOf(commonNode); if (idx < 0) throw new InvalidOperationException(nameof(idx) + " of commonNode in endNodesList should always be >=0"); else if (idx == 0) throw new InvalidOperationException(nameof(idx) + "=0 should not happen because this means identical startnode and endnode"); return new RelativeDocumentPath(numberOfNodesDown, endNodesList.TakeFromUpperIndexExclusiveDownToLowerIndexInclusive(idx, 0).Select(x => x.ParentObject.GetNameOfChildObject(x))); }
public IDocumentNode DocumentNode_Delete(IDocumentNode documentNode) { nodeTreeIsUpdated = true; throw new NotImplementedException(); }
public IDocumentNode DocumentNode_Update(IDocumentNode documentNode) { var cmd = new AddOrUpdateDocumentNode() { DocumentNode = documentNode }; nodeTreeIsUpdated = true; return (IDocumentNode)liveDbEngine.Execute(cmd); }
public void EhParentTunnelingEventHappened(IDocumentNode sender, IDocumentNode originalSource, TunnelingEventArgs e) { }