Class VirtualDirectory
Represents a virtual directory. A virtual directory functions as a container for other nodes. It can contain VirtualItem<T>, VirtualDirectory, and VirtualSymbolicLink, providing a centralized way to manage these entities.
This class supports operations such as adding, removing, updating, checking the existence of, and enumerating nodes within the directory. It serves as a fundamental component for efficiently managing the structure of the virtual storage.
Additionally, nodes can be enumerated according to the specified display conditions.
Inherited Members
Namespace: AkiraNetwork.VirtualStorageLibrary
Assembly: VirtualStorageLibrary.dll
Syntax
public class VirtualDirectory : VirtualNode, IVirtualDeepCloneable<VirtualNode>, IEnumerable<VirtualNode>, IEnumerable
Constructors
VirtualDirectory()
Initializes a new instance of the VirtualDirectory class. The node name is automatically generated by the GenerateNodeName(string) method.
Declaration
public VirtualDirectory()
VirtualDirectory(VirtualNodeName)
Initializes a new instance of the VirtualDirectory class with the specified name.
Declaration
public VirtualDirectory(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory. |
VirtualDirectory(VirtualNodeName, DateTime)
Initializes a new instance of the VirtualDirectory class with the specified name, creation date, and update date.
Declaration
public VirtualDirectory(VirtualNodeName name, DateTime createdDate)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory. |
DateTime | createdDate | The creation date. |
VirtualDirectory(VirtualNodeName, DateTime, DateTime)
Initializes a new instance of the VirtualDirectory class with the specified name, creation date, and update date.
Declaration
public VirtualDirectory(VirtualNodeName name, DateTime createdDate, DateTime updatedDate)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory. |
DateTime | createdDate | The creation date. |
DateTime | updatedDate | The update date. |
Properties
Count
Gets the total number of nodes within the directory.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
DirectoryCount
Gets the number of directories within the directory.
Declaration
public int DirectoryCount { get; }
Property Value
Type | Description |
---|---|
int |
DirectoryViewCount
Gets the number of directories based on the current display conditions.
Declaration
public int DirectoryViewCount { get; }
Property Value
Type | Description |
---|---|
int |
this[VirtualNodeName]
Gets or sets the node with the specified name using the indexer.
Declaration
public VirtualNode this[VirtualNodeName name] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the node. |
Property Value
Type | Description |
---|---|
VirtualNode | The node with the specified name. |
Exceptions
Type | Condition |
---|---|
VirtualNodeNotFoundException | Thrown if the node is not found. |
ItemCount
Gets the number of items within the directory.
Declaration
public int ItemCount { get; }
Property Value
Type | Description |
---|---|
int |
ItemViewCount
Gets the number of items based on the current display conditions.
Declaration
public int ItemViewCount { get; }
Property Value
Type | Description |
---|---|
int |
NodeNames
Enumerates all node names within the directory.
Declaration
public IEnumerable<VirtualNodeName> NodeNames { get; }
Property Value
Type | Description |
---|---|
IEnumerable<VirtualNodeName> |
NodeType
Gets the type of the node. This class always returns Directory.
Declaration
public override VirtualNodeType NodeType { get; }
Property Value
Type | Description |
---|---|
VirtualNodeType |
Overrides
Nodes
Enumerates all nodes within the directory.
Declaration
public IEnumerable<VirtualNode> Nodes { get; }
Property Value
Type | Description |
---|---|
IEnumerable<VirtualNode> |
NodesView
Gets a view of nodes based on the current display conditions.
Declaration
public IEnumerable<VirtualNode> NodesView { get; }
Property Value
Type | Description |
---|---|
IEnumerable<VirtualNode> |
NodesViewCount
Gets the number of nodes based on the current display conditions.
Declaration
public int NodesViewCount { get; }
Property Value
Type | Description |
---|---|
int |
SymbolicLinkCount
Gets the number of symbolic links within the directory.
Declaration
public int SymbolicLinkCount { get; }
Property Value
Type | Description |
---|---|
int |
SymbolicLinkViewCount
Gets the number of symbolic links based on the current display conditions.
Declaration
public int SymbolicLinkViewCount { get; }
Property Value
Type | Description |
---|---|
int |
Methods
Add(VirtualNode, bool)
Adds a node to the directory.
Declaration
public VirtualNode Add(VirtualNode node, bool allowOverwrite = false)
Parameters
Type | Name | Description |
---|---|---|
VirtualNode | node | The node to add. |
bool | allowOverwrite | If true, allows overwriting an existing node with the same name. |
Returns
Type | Description |
---|---|
VirtualNode | The added node. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if an invalid node name is specified. |
InvalidOperationException | Thrown if a node with the same name already exists. |
AddDirectory(VirtualNodeName, bool)
Adds a directory with the specified name.
Declaration
public VirtualDirectory AddDirectory(VirtualNodeName name, bool allowOverwrite = false)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory. |
bool | allowOverwrite | If true, allows overwriting an existing node with the same name. |
Returns
Type | Description |
---|---|
VirtualDirectory | The added directory. |
AddItem<T>(VirtualNodeName, T?, bool)
Adds an item with the specified name.
Declaration
public VirtualItem<T> AddItem<T>(VirtualNodeName name, T? itemData = default, bool allowOverwrite = false)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the item. |
T | itemData | The data of the item. |
bool | allowOverwrite | If true, allows overwriting an existing node with the same name. |
Returns
Type | Description |
---|---|
VirtualItem<T> | The added item. |
Type Parameters
Name | Description |
---|---|
T | The data type of the item. |
AddRange(IEnumerable<VirtualNode>, bool)
Adds multiple nodes to the directory.
Declaration
public IList<VirtualNode> AddRange(IEnumerable<VirtualNode> nodes, bool allowOverwrite = false)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<VirtualNode> | nodes | The nodes to add. |
bool | allowOverwrite | If true, allows overwriting existing nodes with the same names. |
Returns
Type | Description |
---|---|
IList<VirtualNode> | A list of the added nodes. If a node was cloned, the cloned instance is returned in the list. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if an invalid node name is specified in any of the nodes. |
InvalidOperationException | Thrown if a node with the same name already exists and overwriting is not allowed. |
AddSymbolicLink(VirtualNodeName, VirtualPath, bool)
Adds a symbolic link with the specified name.
Declaration
public VirtualSymbolicLink AddSymbolicLink(VirtualNodeName name, VirtualPath targetPath, bool allowOverwrite = false)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the symbolic link. |
VirtualPath | targetPath | The target path of the symbolic link. |
bool | allowOverwrite | If true, allows overwriting an existing node with the same name. |
Returns
Type | Description |
---|---|
VirtualSymbolicLink | The added symbolic link. |
DeepClone(bool)
Creates a deep clone of the directory.
Declaration
public override VirtualNode DeepClone(bool recursive = false)
Parameters
Type | Name | Description |
---|---|---|
bool | recursive | If true, all nodes within the directory are recursively cloned. |
Returns
Type | Description |
---|---|
VirtualNode | A deep clone of the directory. |
Overrides
DirectoryExists(VirtualNodeName)
Checks whether a directory with the specified name exists.
Declaration
public bool DirectoryExists(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory to check. |
Returns
Type | Description |
---|---|
bool | True if the directory exists; otherwise, false. |
Get(VirtualNodeName, bool)
Gets the node with the specified name.
Declaration
public VirtualNode? Get(VirtualNodeName name, bool exceptionEnabled = true)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the node. |
bool | exceptionEnabled | If true, throws an exception if the node is not found. |
Returns
Type | Description |
---|---|
VirtualNode | The node with the specified name, or null if the node does not exist. |
GetDirectory(VirtualNodeName)
Gets the directory with the specified name.
Declaration
public VirtualDirectory GetDirectory(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the directory. |
Returns
Type | Description |
---|---|
VirtualDirectory | The directory with the specified name. |
Exceptions
Type | Condition |
---|---|
VirtualNodeNotFoundException | Thrown if the node is not found. |
InvalidOperationException | Thrown if the specified node is not a directory. |
GetEnumerator()
Gets an enumerator for nodes based on the current display conditions.
Declaration
public IEnumerator<VirtualNode> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<VirtualNode> | An enumerator for filtered nodes. |
GetItem<T>(VirtualNodeName)
Gets the item with the specified name.
Declaration
public VirtualItem<T> GetItem<T>(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the item. |
Returns
Type | Description |
---|---|
VirtualItem<T> | The item with the specified name. |
Type Parameters
Name | Description |
---|---|
T | The data type of the item. |
Exceptions
Type | Condition |
---|---|
VirtualNodeNotFoundException | Thrown if the node is not found. |
InvalidOperationException | Thrown if the specified node is not an item. |
GetNodesView()
Gets a view of nodes based on the current display conditions.
Declaration
public IEnumerable<VirtualNode> GetNodesView()
Returns
Type | Description |
---|---|
IEnumerable<VirtualNode> | An enumeration of nodes based on the display conditions. |
GetSymbolicLink(VirtualNodeName)
Gets the symbolic link with the specified name.
Declaration
public VirtualSymbolicLink GetSymbolicLink(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the symbolic link. |
Returns
Type | Description |
---|---|
VirtualSymbolicLink | The symbolic link with the specified name. |
Exceptions
Type | Condition |
---|---|
VirtualNodeNotFoundException | Thrown if the node is not found. |
InvalidOperationException | Thrown if the specified node is not a symbolic link. |
ItemExists(VirtualNodeName)
Checks whether an item with the specified name exists.
Declaration
public bool ItemExists(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the item to check. |
Returns
Type | Description |
---|---|
bool | True if the item exists; otherwise, false. |
NodeExists(VirtualNodeName)
Checks whether a node with the specified name exists.
Declaration
public bool NodeExists(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the node to check. |
Returns
Type | Description |
---|---|
bool | True if the node exists; otherwise, false. |
Remove(VirtualNode)
Removes the specified node from the directory.
Declaration
public void Remove(VirtualNode node)
Parameters
Type | Name | Description |
---|---|---|
VirtualNode | node | The node to remove. |
Exceptions
Type | Condition |
---|---|
VirtualNodeNotFoundException | Thrown if the node is not found. |
SymbolicLinkExists(VirtualNodeName)
Checks whether a symbolic link with the specified name exists.
Declaration
public bool SymbolicLinkExists(VirtualNodeName name)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | name | The name of the symbolic link to check. |
Returns
Type | Description |
---|---|
bool | True if the symbolic link exists; otherwise, false. |
ToString()
Returns a string representation of the directory.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the directory. |
Overrides
Update(VirtualNode)
Updates the current directory with the data from the specified node.
Declaration
public override void Update(VirtualNode node)
Parameters
Type | Name | Description |
---|---|---|
VirtualNode | node | The node used for the update. |
Overrides
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the specified node is not a VirtualDirectory. |
Operators
operator +(VirtualDirectory, VirtualNode)
Overloads the addition operator to add a node to the directory.
Declaration
public static VirtualDirectory operator +(VirtualDirectory directory, VirtualNode node)
Parameters
Type | Name | Description |
---|---|---|
VirtualDirectory | directory | The directory to which the node is added. |
VirtualNode | node | The node to add. |
Returns
Type | Description |
---|---|
VirtualDirectory | The directory with the added node. |
operator +(VirtualDirectory, VirtualNodeName)
Overloads the addition operator to add a node to the directory.
Declaration
public static VirtualDirectory operator +(VirtualDirectory directory, VirtualNodeName nodeName)
Parameters
Type | Name | Description |
---|---|---|
VirtualDirectory | directory | The directory to which the node is added. |
VirtualNodeName | nodeName | The node name of directory to add. |
Returns
Type | Description |
---|---|
VirtualDirectory | The directory with the added node. |
operator +(VirtualDirectory, IList<VirtualNode>)
Overloads the addition operator to add multiple nodes to the directory using AddRange.
Declaration
public static VirtualDirectory operator +(VirtualDirectory directory, IList<VirtualNode> nodes)
Parameters
Type | Name | Description |
---|---|---|
VirtualDirectory | directory | The directory to which the nodes are added. |
IList<VirtualNode> | nodes | The nodes to add. |
Returns
Type | Description |
---|---|
VirtualDirectory | The directory with the added nodes. |
implicit operator VirtualDirectory(VirtualNodeName)
Implicitly converts the specified node name to a VirtualDirectory.
Declaration
public static implicit operator VirtualDirectory(VirtualNodeName nodeName)
Parameters
Type | Name | Description |
---|---|---|
VirtualNodeName | nodeName | The node name to convert. |
Returns
Type | Description |
---|---|
VirtualDirectory |
operator -(VirtualDirectory, VirtualNode)
Overloads the subtraction operator to remove a node from the directory.
Declaration
public static VirtualDirectory operator -(VirtualDirectory directory, VirtualNode node)
Parameters
Type | Name | Description |
---|---|---|
VirtualDirectory | directory | The directory from which the node is removed. |
VirtualNode | node | The node to remove. |
Returns
Type | Description |
---|---|
VirtualDirectory | The directory with the removed node. |