public void DeleteRoot(Identifier identifier) { var stored = getStored(identifier); if (Roots.Contains(stored)) { connection.ExecutePortableSql("delete from :[dbo.nrdo_object] where :[type] = :type and :[name] = :name", cmd => setRootParams(cmd, identifier)); Subs.RemoveWhere(sub => identComparer.Equals(sub.Parent, stored)); Roots.Remove(stored); } }
public void Rename(Identifier from, Identifier to) { if (!object.Equals(from.ObjectType, to.ObjectType)) { throw new ArgumentException("Cannot rename between different object types " + from.ObjectType + " and " + to.ObjectType); } var storedFrom = getStored(from); var storedTo = getStored(to); if (!Roots.Contains(storedFrom)) { throw new ArgumentException("Cannot store rename from " + from + " to " + to + " because " + from + " does not exist in state table"); } if (Roots.Contains(storedTo)) { throw new ArgumentException("Cannot store rename from " + from + " to " + to + " because " + to + " already exists in state table"); } connection.ExecutePortableSql("insert into :[dbo.nrdo_object] (:[type], :[name]) values (:type, :name)", cmd => setRootParams(cmd, to)); Roots.Add(storedTo); connection.ExecutePortableSql("update :[dbo.nrdo_object_sub] set :[parent_name] = :toname where :[parent_type] = :type and parent_name = :fromname", cmd => { cmd.SetString("toname", "varchar", to.Name); cmd.SetString("type", "varchar", from.ObjectType.Name); cmd.SetString("fromname", "varchar", from.Name); }); var newSubs = from sub in Subs where identComparer.Equals(sub.Parent, storedFrom) select new StoredSub(storedTo, sub.Child); Subs.UnionWith(newSubs.ToImmutableList()); Subs.RemoveWhere(sub => identComparer.Equals(sub.Parent, storedFrom)); connection.ExecutePortableSql("delete from :[dbo.nrdo_object] where :[type] = :type and :[name] = :name", cmd => setRootParams(cmd, from)); Roots.Remove(storedFrom); }
/// <inheritdoc /> public void Insert(int siblingIndex, ISceneGraphNode node, ISceneGraphNode parent = null) { if (node.IsAncestorOrParentOf(parent)) { // The node is already an ancestor of the given node. Bail out. return; } if (this != node.Graph) { // Remove this node from the previous graph; if any node.Graph.Remove(node.Graph.Roots, node); // We are moving from another graph, remap our descendants to this new graph foreach (var descendant in node.GetDescendants()) { descendant.Graph = this; } } // Remove from previous parent or roots; if any if (null != node.Parent) { node.Parent.Children.Remove(node); } else { Roots.Remove(node); } node.Parent = parent; var actualIndex = InsertOrAdd(null == node.Parent ? Roots : node.Parent.Children, siblingIndex, node); // Handle any custom operations in this callback OnInsertNode(node, parent, actualIndex); Changed = true; }