-
Notifications
You must be signed in to change notification settings - Fork 0
IStorageObject Interface
Represents a general abstraction for a storage object, such as a file or directory, providing access to metadata, path information, and change notifications.
Namespace: Rheo.Storage.Contracts
Assembly: Rheo.Storage.dll
public interface IStorageObject : IDisposable| Property | Type | Description |
|---|---|---|
| Information | IStorageInformation | Gets metadata information about the storage object, such as size, attributes, and timestamps. |
| Name | String | Gets the name of the storage object, typically the file or directory name. |
| ParentDirectory | String | Gets the full path of the parent directory for the current file or directory. |
| FullPath | String | Gets the full path of the file or directory. |
| IsDisposed | Boolean | Gets a value indicating whether this storage object has been disposed. |
| Event | Description |
|---|---|
| Changed | Occurs when the storage content changes. |
| Method | Description |
|---|---|
| GetBufferSize() | Calculates the recommended buffer size based on the current storage information. |
| ThrowIfDisposed() | Throws an ObjectDisposedException if this storage object has been disposed. |
| Dispose() | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. |
Implementations of this interface provide a unified way to interact with storage entities, allowing consumers to retrieve metadata, monitor changes, and manage resource lifetimes. The interface supports event-driven notifications for content changes and enforces proper disposal patterns. Thread safety and event handling behavior may vary by implementation; callers should consult specific documentation for details.
Gets metadata information about the storage object, such as size, attributes, and timestamps.
IStorageInformation Information { get; }An object containing detailed metadata about the storage item.
Implementations typically return platform-specific storage information, such as FileInformation or DirectoryInformation, which provide file system metadata including creation time, modification time, attributes, and size.
Gets the name of the storage object, typically the file or directory name.
string Name { get; }The name of the file or directory without the path.
For a file at C:\Documents\Report.pdf, this property returns Report.pdf.
Gets the full path of the parent directory for the current file or directory.
string ParentDirectory { get; }The absolute path to the parent directory.
For a file at C:\Documents\Reports\Annual.pdf, this property returns C:\Documents\Reports.
Gets the full path of the file or directory.
string FullPath { get; }The complete absolute path to the storage object.
Gets a value indicating whether this storage object has been disposed.
bool IsDisposed { get; }true if the object has been disposed; otherwise, false.
Use this property to check the disposal state before performing operations. Most methods will throw an ObjectDisposedException if called after disposal.
Occurs when the storage content changes.
event EventHandler<StorageChangedEventArgs>? ChangedEventHandler<StorageChangedEventArgs>
Subscribers are notified whenever an item is added, removed, or updated in the storage. The event provides details about the change through the StorageChangedEventArgs parameter. This event is typically raised on the thread where the change occurs; callers should ensure thread safety when handling the event.
Calculates the recommended buffer size based on the current storage information.
int GetBufferSize()An integer representing the recommended buffer size in bytes.
This method provides an optimal buffer size for I/O operations based on the storage object's characteristics. The recommended buffer size may vary depending on the file size, storage type, and platform.
Throws an ObjectDisposedException if this storage object has been disposed.
void ThrowIfDisposed()Thrown if the object has already been disposed.
This method is typically called at the beginning of public methods to ensure the object is in a valid state before performing operations.
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
void Dispose()Inherited from IDisposable. After calling this method, the object should not be used. Always call Dispose() when finished with an instance to ensure proper cleanup of resources.
The following example demonstrates using IStorageObject to handle both files and directories:
using Rheo.Storage;
using Rheo.Storage.Contracts;
void ProcessStorageObject(IStorageObject storage)
{
Console.WriteLine($"Name: {storage.Name}");
Console.WriteLine($"Path: {storage.FullPath}");
Console.WriteLine($"Parent: {storage.ParentDirectory}");
Console.WriteLine($"Size: {storage.Information.FormattedSize}");
Console.WriteLine($"Created: {storage.Information.CreationTime}");
}
using var file = new FileObject(@"C:\Documents\file.txt");
using var directory = new DirectoryObject(@"C:\Documents");
ProcessStorageObject(file);
ProcessStorageObject(directory);The following example shows how to subscribe to change notifications:
using Rheo.Storage;
using Rheo.Storage.Contracts;
void MonitorDirectory(string path)
{
using var dir = new DirectoryObject(path);
dir.Changed += (sender, e) =>
{
Console.WriteLine($"Change detected: {e.ChangeType}");
Console.WriteLine($"Path: {e.StorageObject?.FullPath}");
};
// Keep the application running to monitor changes
Console.WriteLine("Monitoring directory. Press Enter to exit.");
Console.ReadLine();
}
MonitorDirectory(@"C:\Documents");The following example demonstrates checking disposal state:
using Rheo.Storage;
using Rheo.Storage.Contracts;
IStorageObject storage = new FileObject(@"C:\Documents\file.txt");
if (!storage.IsDisposed)
{
Console.WriteLine($"Processing: {storage.Name}");
}
storage.Dispose();
if (storage.IsDisposed)
{
Console.WriteLine("Object has been disposed.");
}
// This would throw ObjectDisposedException
try
{
storage.ThrowIfDisposed();
}
catch (ObjectDisposedException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}The following example shows using the recommended buffer size for I/O operations:
using Rheo.Storage;
using var file = new FileObject(@"C:\Documents\large-file.dat");
int bufferSize = file.GetBufferSize();
Console.WriteLine($"Recommended buffer size: {bufferSize} bytes");
// Use the buffer size for reading
using var stream = file.Read();
byte[] buffer = new byte[bufferSize];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
// Process data
}The following example demonstrates working with multiple storage objects:
using Rheo.Storage;
using Rheo.Storage.Contracts;
void CompareStorageObjects(IStorageObject obj1, IStorageObject obj2)
{
Console.WriteLine("Comparison:");
Console.WriteLine($" {obj1.Name}: {obj1.Information.Size} bytes");
Console.WriteLine($" {obj2.Name}: {obj2.Information.Size} bytes");
if (obj1.Information.Size > obj2.Information.Size)
{
Console.WriteLine($"{obj1.Name} is larger.");
}
else
{
Console.WriteLine($"{obj2.Name} is larger or equal.");
}
}
using var file1 = new FileObject(@"C:\Documents\file1.txt");
using var file2 = new FileObject(@"C:\Documents\file2.txt");
CompareStorageObjects(file1, file2);Thread safety guarantees are implementation-specific. Consult the documentation for concrete implementations such as FileObject and DirectoryObject.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress