/// <summary> /// Deletes the child. /// </summary> /// <param name="node">The node.</param> /// <param name="name">The name.</param> public void DeleteChild(IDriverNode node, string name) { // We first make sure node exists. WeakReference childRef; if (children.TryGetValue(name, out childRef)) { // We must make sure it is not managed or transparent. ManagedCommonNode n = childRef.Target as ManagedCommonNode; if (n != null) { if (n.CurrentVersion.IsMountPoint || n.CurrentVersion.IsTransparentNode) { throw new InvalidOperationException("Cannot delete a managed node " + name + ", it is needed for mounting."); } // Dispose all versions. n.Dispose(); } // Remove name. children.Remove(name); } // We check if not cached. else if (node.Find(name) == null) { throw new InvalidOperationException("The child with name " + name + " does not exist."); } // We can now delete it. node.DeleteChild(name); }
/// <summary> /// Creates the child. /// </summary> /// <param name="node">The node.</param> /// <param name="name">The name.</param> /// <param name="defaultType">Type of the default.</param> /// <param name="options">The options.</param> /// <returns></returns> public ManagedNode CreateChild(IDriverNode node, string name, string defaultType, StreamOptions options) { // We first check if it exists already. WeakReference childRef; if (children.TryGetValue(name, out childRef)) { if (childRef.IsAlive) { throw new InvalidNameException("The child with name " + name + " already exists."); } } // We check node for such child. IDriverNode child = node.Find(name); if (child != null) { // Will not use child anymore. throw new InvalidNameException("The child with name " + name + " already exists."); } // We can create new child. IDriverNode driverChild = node.CreateChild(name, defaultType, options); ManagedCommonNode commonChildNode = new ManagedCommonNode(this, name, driverChild, manager); children.Add(name, new WeakReference(commonChildNode)); // We return current version return(commonChildNode.CurrentVersion); }
/// <summary> /// Create a transparent node. /// </summary> /// <param name="name">The name of node.</param> /// <returns>The managed node.</returns> public ManagedNode CreateTransparent(string name) { ManagedCommonNode c = new ManagedCommonNode(this, name, null, manager); if (transparentChildren == null) { transparentChildren = new List <ManagedNode>(); } transparentChildren.Add(c.CurrentVersion); children.Add(name, new WeakReference(c)); return(c.CurrentVersion); }
/// <summary> /// Adds the transparent and mount point. /// </summary> /// <param name="s">The s.</param> public void AddTransparentAndMountPoint(StringCollection s) { foreach (KeyValuePair <string, WeakReference> m in children) { ManagedCommonNode node = m.Value.Target as ManagedCommonNode; if (node != null) { if (node.CurrentVersion.IsMountPoint || node.CurrentVersion.IsTransparentNode) { s.Add(m.Key); } } } }
public ManagedCommonNode(ManagedCommonNode parent, string name, IDriverNode driverNode, ManagedDatabaseManager manager) { ulong version = 1; if (driverNode != null) { version = driverNode.Version; } this.parent = parent; this.name = name; this.manager = manager; this.currentVersion = new ManagedNode(driverNode, version, this); this.versions[version] = new WeakReference(this.currentVersion); }
/// <summary> /// Obtains child of this node. /// </summary> /// <param name="n">Internal node if not in cache, can be null for some nodes.</param> /// <param name="name">The name of child.</param> /// <returns></returns> public ManagedNode GetChild(IDriverNode n, string name) { ManagedCommonNode child; // We first search in children. WeakReference childRef; if (children.TryGetValue(name, out childRef)) { // We extract child. child = childRef.Target as ManagedCommonNode; // It may still be null, if discared meanwhile. if (child != null) { return(child.currentVersion); } } if (n == null) { return(null); } // We have to do the search in node. IDriverNode childNode = n.Find(name); // We cannot return it. if (childNode == null) { return(null); } // Create the child, with the same name reference. child = new ManagedCommonNode(this, name, childNode, manager); // Add it to cache. children[name] = new WeakReference(child); // Return most current version. return(child.currentVersion); }
/// <summary> /// A version constructor. /// </summary> /// <param name="node">The node.</param> /// <param name="version">The version.</param> /// <param name="common">The common.</param> internal ManagedNode(IDriverNode node, ulong version, ManagedCommonNode common) { this.node = node; this.version = version; this.common = common; }
/// <summary> /// Creates new node. /// </summary> /// <returns></returns> internal static ManagedNode CreateNew(ManagedDatabaseManager manager) { ManagedCommonNode node = new ManagedCommonNode(null, "", null, manager); return(node.CurrentVersion); }