Rebex
Products Downloads Buy Support Contact
Show / Hide Table of Contents

ReadWriteFileSystemProvider.GetChildren Method

Namespace: Rebex.IO.FileSystem
Assembly: Rebex.FileSystem.dll (version 8.0.9673)

GetChildren(DirectoryNode, NodeType)

Override this method to implement getting a collection of DirectoryNode and/or FileNode objects that are located in the parent and value of their property NodeType is contained in the nodeType.

When the virtual file system is used in the FileServer component, the server session, which contains information about the user and the active connection, can be accessed using Current property.

Inherited from ReadOnlyFileSystemProvider.
Declaration
protected abstract IEnumerable<NodeBase> GetChildren(DirectoryNode parent, NodeType nodeType)
Parameters
Type Name Description
DirectoryNode parent

Parent DirectoryNode of the requested children.

NodeType nodeType

Required type(s) of the returned children.

Returns
Type Description
IEnumerable<NodeBase>

A collection of DirectoryNode and/or FileNode objects that are contained in the parent and value of their property NodeType is contained in the flag nodeType, or empty IEnumerable<T> if the parent does not have children.

Remarks

Even if the method returns lazy enumerable, virtual file system infrastructure by default converts lazy enumerable to eager enumerable to prevent strange behavior/bugs in custom VFS providers.

For example:

1) If a lambda in the LINQ operator captures a custom VFS provider mutable state, then you are responsible for access to the custom VFS provider being safe. The state must not be corrupted when the enumeration continues.

2) If the underlying node collection in custom VFS provider is modified while the enumeration from the collection is still in progress, you might encounter an InvalidOperationException with the message 'Collection was modified; enumeration operation may not execute'. For example, the Delete method in the VFS core recursively enumerates directory and deletes all children. Suppose that custom VFS provider uses List<T> as the collection that contains NodeBase instances, and the GetChildren method returns children for Parent1. Lazy enumeration contains 'NestedFile1, NestedFile2, NestedFile3'. The Delete method enumerates NestedFile1 and deletes it. The underlying collection, List<T> instance, has changed. The Delete method calls MoveNext on the IEnumerator, and the InvalidOperationException may be thrown.

If a lazy enumeration is required, and the implementation of enumeration is known to be safe:

1) Create new instance of the FileSystemProviderSettings class.

2) Set the EnableLazyEnumerationForGetChildrenMethod property to true.

3) Provide the instance of the FileSystemProviderSettings class to the ReadOnlyFileSystemProvider(FileSystemProviderSettings) constructor.

Examples
protected override IEnumerable <NodeBase> GetChildren(DirectoryNode parent, NodeType nodeType)
{
    var parentPath = getFullPath(parent.Path);
    var retChildren = Enumerable.Empty<NodeBase>();

    if ((nodeType & NodeType.Directory) == NodeType.Directory)
    {
        retChildren = retChildren.Union(Directory.EnumerateDirectories(parentPath)
            .Select(dirPath => new DirectoryNode(getNodeName(dirPath), parent)));
    }

    if ((nodeType & NodeType.File) == NodeType.File)
    {
        retChildren = retChildren.Union(Directory.GetFiles(parentPath)
            .Select(filePath => new FileNode(getNodeName(filePath), parent)));
    }

    return retChildren;
}
See Also
EnableLazyEnumerationForGetChildrenMethod
In This Article
© REBEX ČR s.r.o. Back to top
Privacy policy
Manage cookies