private void WriteFixedRow(SharpNodeRow row, SharpNodeMap mapNode) { var columns = new Dictionary <string, string>(); var next = row.First; if (next.Node.IsValueNode && !next.Node.IsSingleValueNode) { if (next.Node.Parent.Path == mapNode.Parent.Path) { return; } } while (next != null) { var vr = next as SharpValueRow; if (vr != null) { columns[next.Node.Name] = SharpValue.ToString(vr.Values[0], vr.Node.ValueType); } next = next.Next; } WriteLine(columns, mapNode); }
private void WriteNodeRow(SharpNodeRow row) { if (row.Node.PackageName.ToLower() != _lastPackage) { WritePackage(row.Node.PackageName); } while (!_nodeStack.IsEmpty && _nodeStack.Top != row.Node && !_nodeStack.Top.HasDescendant(row.Node)) { _nodeStack.Dequeue(); _writer.WriteEndElement(); } if (_nodeStack.Top == row.Node) { _writer.WriteEndElement(); _writer.WriteStartElement(row.Node.Name); } else { if (!_nodeStack.IsEmpty && _nodeStack.Top != row.Node.Parent) { WriteNodeRow(new SharpNodeRow(row.Node.Parent)); } _nodeStack.Enqueue(row.Node); _writer.WriteStartElement(row.Node.Name); } }
private void WriteNodeRow(SharpNodeRow row) { if (row.Node.PackageName.ToLower() != _lastPackage) { WritePackage(row.Node.PackageName); } _writer.WriteLine(EncodeNode(row.Node)); _lastParentNode = row.Node; }
public SharpNodeRow AddRange(string nodePath, IEnumerable <ISharpObject> items, bool collapseLeafNodes = true) { var rows = new List <SharpNodeRow>(); foreach (var item in items) { AddObject(nodePath, item.GetObject(), rows); } var topNode = _nodes.GetNode(nodePath).Parent; var topRow = new SharpNodeRow(topNode); UpdateRowLinks(topRow, rows.GetEnumerator(), collapseLeafNodes); Add(topRow); return(topRow); }
public bool TryCollapseLeafNode(SharpNodeRow row) { List <SharpValueRow> columns = new List <SharpValueRow>(); SharpNodeRow prev = row; while (prev is SharpValueRow && prev.Node.IsSingleValueNode) { columns.Insert(0, prev as SharpValueRow); prev = prev.Prev; } if (columns.Count > 2) { string mapPath = string.Join(",", columns.Select(r => r.Node.Index)); var mapNode = _nodes.GetNode(mapPath) as SharpNodeMap; if (mapNode == null) { mapNode = new SharpNodeMap(columns); mapNode.Path = mapPath; mapNode.IsValueNode = true; mapNode.MapType = SharpMapType.Sequence; _nodes.Add(mapNode); } var mapRow = new SharpValueRow(mapNode, columns.Select(c => c.Values[0])); mapRow.Collection = this; mapRow.Next = row.Next; mapRow.Root = row.Root; if (prev != null) { mapRow.Prev = prev; prev.Next = mapRow; } else if (mapRow.Root != null) { mapRow.Root.First = mapRow; } return(true); } return(false); }
public bool UpdateRowLinks(SharpNodeRow root, IEnumerator <SharpRow> rows, bool collapseLeafNodes = true) { SharpNodeRow top = root; bool skipCollapseCheck = false; while (rows.MoveNext()) { rows.Current.Collection = this; var nodeRow = rows.Current as SharpNodeRow; if (nodeRow == null) { return(true); } if (!root.Node.HasDescendant(nodeRow.Node)) { return(true); } bool done = false; while (!done) { top.Collection = this; if (nodeRow.Node.Parent == top.Node) { if (top.First == null) { top.First = nodeRow; } nodeRow.Root = top; top = nodeRow; done = true; skipCollapseCheck = true; break; } while (nodeRow.Node.Parent != top.Node.Parent) { if (top.Root == null) { return(true); } top = top.Root; } if (nodeRow.Node.Parent == top.Node.Parent) { top.Next = nodeRow; nodeRow.Prev = top; nodeRow.Root = top.Root; top = nodeRow; done = true; if (collapseLeafNodes && !skipCollapseCheck && !top.Node.IsSingleValueNode && top.Prev is SharpValueRow && top.Prev.Node.IsSingleValueNode) { TryCollapseLeafNode(top.Prev); skipCollapseCheck = true; } else { skipCollapseCheck = false; } } if (!done) { if (top == root) { return(true); } if (collapseLeafNodes && !skipCollapseCheck && top.Node.IsSingleValueNode && top is SharpValueRow) { TryCollapseLeafNode(top); } top = top.Root; skipCollapseCheck = false; } } } if (collapseLeafNodes && !skipCollapseCheck && top.Node.IsSingleValueNode && top is SharpValueRow) { TryCollapseLeafNode(top); } return(false); }
public void InsertRows(IEnumerator <SharpRow> rows, bool collapseLeafNodes = true, SharpNodeRow rootRow = null, SharpNodeRow prevRow = null) { bool firstRow = true; bool autoLink = prevRow != null || rootRow != null; while (rows.MoveNext()) { rows.Current.Collection = this; var nodeRow = rows.Current as SharpNodeRow; if (nodeRow == null) { _insertRows.Add(rows.Current); continue; } while (nodeRow != null) { if (prevRow != null) { if (prevRow.Node.Parent == nodeRow.Node.Parent) { nodeRow.Prev = prevRow; if (!firstRow) { prevRow.Next = nodeRow; nodeRow.Root = prevRow.Root; } prevRow = nodeRow; } else { prevRow = null; firstRow = true; } } else if (rootRow != null) { if (nodeRow.Node.Parent == rootRow.Node) { nodeRow.Root = rootRow; firstRow = true; prevRow = nodeRow; } } if (!autoLink || nodeRow.Prev == null || firstRow) { _insertRows.Add(nodeRow); firstRow = false; } if (!UpdateRowLinks(nodeRow, rows, collapseLeafNodes)) { break; } nodeRow = rows.Current as SharpNodeRow; if (nodeRow == null) { _insertRows.Add(nodeRow); } } } }
internal void OnMemberChanged(SharpNodeRow row, SharpObject source, string fieldname, object value) { _updateRows[row] = source; }
public void OnValueChanged(SharpNodeRow row, int column, object value) { _updateRows[row] = null; }