Class FileSystem
Provides a base for various file system abstractions.
FileSystem abstractions are mostly useful for working with components/classes that may need to inter-operate not only with local file system
but also with distributed systems like ApacheHDFS, SVN, GIT, or Sky Cluster Big-Transactional File System (BoltFS).
Azos library provides compatibility wrapper 'Azos.IO.FileSystem.Local.LocalFileSystem' for access to local machine file system
(which is based on this class and is implemented using a traditional System.IO.* set of classes).
The FileSystem abstraction supports the following concepts: versioning, transactions, metadata, security; however it does not guarantee that
every implementation is capable of providing all of these functions. Query "GeneralCapabilities" and "InstanceCapabilities" to see what functions
are supported by a particular instance.
This class is not thread-safe unless stated otherwise on method level, however multiple threads are allowed to obtain their own FileSystemSession
object via a call to StartSession() which is thread safe
Inheritance
System.Object
FileSystem
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Azos.dll
Syntax
public abstract class FileSystem : ApplicationComponent, IFileSystemImplementation, IFileSystem, IApplicationComponent, INamed, IConfigurable, IDisposable
Constructors
FileSystem(IApplicationComponent)
Declaration
protected FileSystem(IApplicationComponent director)
Parameters
FileSystem(IApplication)
Declaration
protected FileSystem(IApplication app)
Parameters
Fields
CONFIG_DEFAULT_SESSION_CONNECT_PARAMS_SECTION
Declaration
public const string CONFIG_DEFAULT_SESSION_CONNECT_PARAMS_SECTION = "default-session-connect-params"
Field Value
Type |
Description |
System.String |
|
CONFIG_FILESYSTEM_SECTION
Declaration
public const string CONFIG_FILESYSTEM_SECTION = "file-system"
Field Value
Type |
Description |
System.String |
|
CONFIG_NAME_ATTR
Declaration
public const string CONFIG_NAME_ATTR = "name"
Field Value
Type |
Description |
System.String |
|
m_Name
Declaration
[Config]
protected string m_Name
Field Value
Type |
Description |
System.String |
|
m_Sessions
Declaration
protected List<FileSystemSession> m_Sessions
Field Value
Properties
ComponentLogTopic
Declaration
public override string ComponentLogTopic { get; }
Property Value
Type |
Description |
System.String |
|
Overrides
DefaultSessionConnectParams
Declaration
protected FileSystemSessionConnectParams DefaultSessionConnectParams { get; }
Property Value
GeneralCapabilities
Returns capabilities for this file system in general
Declaration
public abstract IFileSystemCapabilities GeneralCapabilities { get; }
Property Value
InstanceCapabilities
Returns capabilities for this file system instance, that may or may not be the same as GeneralCapabilities
Declaration
public abstract IFileSystemCapabilities InstanceCapabilities { get; }
Property Value
Name
Provides name for the file system instance
Declaration
public string Name { get; }
Property Value
Type |
Description |
System.String |
|
Sessions
Returns a list of sessions. This accessor is thread-safe
Declaration
public IEnumerable<FileSystemSession> Sessions { get; }
Property Value
Methods
CombinePaths(String, String[])
Combines two or more path segments joining them using primary file system path separator. This method is thread-safe
Declaration
public virtual string CombinePaths(string first, params string[] others)
Parameters
Type |
Name |
Description |
System.String |
first |
|
System.String[] |
others |
|
Returns
Type |
Description |
System.String |
|
Configures file system. This method is a part of lifecycle management and is intended to be called only by creating thread (not thread-safe)
Declaration
public void Configure(IConfigSectionNode node)
Parameters
Destructor()
Declaration
protected override void Destructor()
Overrides
DoBeginTransaction(FileSystemSession)
Override in particular file systems that support transactions to begin transaction in specified session.
This method may be called by multiple threads
Declaration
protected virtual IFileSystemTransactionHandle DoBeginTransaction(FileSystemSession session)
Parameters
Returns
DoBeginTransactionAsync(FileSystemSession)
Declaration
protected virtual Task<IFileSystemTransactionHandle> DoBeginTransactionAsync(FileSystemSession session)
Parameters
Returns
DoCheckCanChange(FileSystemSessionItem)
Override in particular file systems to see if item can change, i.e.
for file systems that support versioning throw exception if item is in session
which "looks" at a sealed/closed version and can not change. This method may be called by multiple threads
Declaration
protected virtual void DoCheckCanChange(FileSystemSessionItem item)
Parameters
DoCheckCanChangeAsync(FileSystemSessionItem)
Declaration
protected virtual Task DoCheckCanChangeAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoCommitTransaction(FileSystemSession)
Override in particular file systems that support transactions to commit transaction in specified session.
This method may be called by multiple threads
Declaration
protected virtual void DoCommitTransaction(FileSystemSession session)
Parameters
DoCommitTransactionAsync(FileSystemSession)
Declaration
protected virtual Task DoCommitTransactionAsync(FileSystemSession session)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
Override to perform custom configuration
Declaration
protected virtual void DoConfigure(IConfigSectionNode node)
Parameters
DoCreateDirectory(FileSystemDirectory, String)
Override to create a directory.
This method may be called by multiple threads
Declaration
protected abstract FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
Parameters
Returns
DoCreateDirectoryAsync(FileSystemDirectory, String)
Declaration
protected virtual Task<FileSystemDirectory> DoCreateDirectoryAsync(FileSystemDirectory dir, string name)
Parameters
Returns
DoCreateFile(FileSystemDirectory, String, Int32)
Override to create a file.
This method may be called by multiple threads
Declaration
protected abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
Parameters
Returns
DoCreateFile(FileSystemDirectory, String, String, Boolean)
Override to create a file from local file.
This method may be called by multiple threads
Declaration
protected abstract FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
Parameters
Type |
Name |
Description |
FileSystemDirectory |
dir |
|
System.String |
name |
|
System.String |
localFile |
|
System.Boolean |
readOnly |
|
Returns
DoCreateFileAsync(FileSystemDirectory, String, Int32)
Declaration
protected virtual Task<FileSystemFile> DoCreateFileAsync(FileSystemDirectory dir, string name, int size)
Parameters
Returns
DoCreateFileAsync(FileSystemDirectory, String, String, Boolean)
Declaration
protected virtual Task<FileSystemFile> DoCreateFileAsync(FileSystemDirectory dir, string name, string localFile, bool readOnly)
Parameters
Type |
Name |
Description |
FileSystemDirectory |
dir |
|
System.String |
name |
|
System.String |
localFile |
|
System.Boolean |
readOnly |
|
Returns
DoDeleteItem(FileSystemSessionItem)
Override to delete item.
This method may be called by multiple threads
Declaration
protected abstract void DoDeleteItem(FileSystemSessionItem item)
Parameters
DoDeleteItemAsync(FileSystemSessionItem)
Declaration
protected virtual Task DoDeleteItemAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoDirectoryDeepCopyAsync(FileSystemDirectory, FileSystemDirectory, FileSystemDirectory.DirCopyFlags, Int32, Func<FileSystemSessionItem, Boolean>, Func<FileSystemSessionItem, Boolean>)
Implements asynchronous deep copy of folders where destination folder may belong to a different file system.
The specifics of implementation may be dictated by particular file systems, i.e.: asynchronous strategies for getting file
lists may depend on the particular system.
Declaration
protected virtual Task DoDirectoryDeepCopyAsync(FileSystemDirectory dirFrom, FileSystemDirectory dirTo, FileSystemDirectory.DirCopyFlags flags = FileSystemDirectory.DirCopyFlags.Directories | FileSystemDirectory.DirCopyFlags.Files | FileSystemDirectory.DirCopyFlags.Security | FileSystemDirectory.DirCopyFlags.Metadata | FileSystemDirectory.DirCopyFlags.Timestamps | FileSystemDirectory.DirCopyFlags.Readonly | FileSystemDirectory.DirCopyFlags.FilesAndDirsOnly | FileSystemDirectory.DirCopyFlags.All, int bufferSize = 65536, Func<FileSystemSessionItem, bool> filter = null, Func<FileSystemSessionItem, bool> cancel = null)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoFlushAsync(FileSystemStream, CancellationToken)
Declaration
protected virtual Task DoFlushAsync(FileSystemStream stream, CancellationToken cancellationToken)
Parameters
Type |
Name |
Description |
FileSystemStream |
stream |
|
System.Threading.CancellationToken |
cancellationToken |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoGetCreationTimestamp(FileSystemSessionItem)
Override to get item creation timestamp.
This method may be called by multiple threads
Declaration
protected abstract DateTime? DoGetCreationTimestamp(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Nullable<System.DateTime> |
|
DoGetCreationUser(FileSystemSessionItem)
Override in particular file systems to get user who created item.
This method may be called by multiple threads
Declaration
protected virtual User DoGetCreationUser(FileSystemSessionItem item)
Parameters
Returns
DoGetCreationUserAsync(FileSystemSessionItem)
Declaration
protected virtual Task<User> DoGetCreationUserAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<User> |
|
DoGetFileNames(FileSystemDirectory, Boolean)
Override to get file names in directory. If directory is null then root is assumed.
This method may be called by multiple threads
Declaration
protected abstract IEnumerable<string> DoGetFileNames(FileSystemDirectory directory, bool recursive)
Parameters
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.String> |
|
DoGetFileNamesAsync(FileSystemDirectory, Boolean)
Declaration
protected virtual Task<IEnumerable<string>> DoGetFileNamesAsync(FileSystemDirectory directory, bool recursive)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<System.String>> |
|
DoGetFileStream(FileSystemFile, Action<FileSystemStream>)
Override to get file stream.
This method may be called by multiple threads
Declaration
protected abstract FileSystemStream DoGetFileStream(FileSystemFile file, Action<FileSystemStream> disposeAction)
Parameters
Returns
DoGetFileStreamAsync(FileSystemFile, Action<FileSystemStream>)
Declaration
protected virtual Task<FileSystemStream> DoGetFileStreamAsync(FileSystemFile file, Action<FileSystemStream> disposeAction)
Parameters
Returns
DoGetItemSize(FileSystemSessionItem)
Override to get the byte size of item (directory or file).
This method may be called by multiple threads
Declaration
protected abstract ulong DoGetItemSize(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.UInt64 |
|
DoGetItemSizeAsync(FileSystemSessionItem)
Declaration
protected virtual Task<ulong> DoGetItemSizeAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<System.UInt64> |
|
DoGetLastAccessTimestamp(FileSystemSessionItem)
Override to get item last access timestamp.
This method may be called by multiple threads
Declaration
protected abstract DateTime? DoGetLastAccessTimestamp(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Nullable<System.DateTime> |
|
DoGetLastAccessUser(FileSystemSessionItem)
Override in particular file systems to get user who was the last user accessing the item.
This method may be called by multiple threads
Declaration
protected virtual User DoGetLastAccessUser(FileSystemSessionItem item)
Parameters
Returns
DoGetLastAccessUserAsync(FileSystemSessionItem)
Declaration
protected virtual Task<User> DoGetLastAccessUserAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<User> |
|
DoGetLatestVersion(FileSystemSession)
Override in particular file systems that support versioning to get latest version object that this session can work with.
This method may be called by multiple threads
Declaration
protected virtual IFileSystemVersion DoGetLatestVersion(FileSystemSession session)
Parameters
Returns
DoGetLatestVersionAsync(FileSystemSession)
Declaration
protected virtual Task<IFileSystemVersion> DoGetLatestVersionAsync(FileSystemSession session)
Parameters
Returns
Override to get metadata stream for item (directory or file).
This method may be called by multiple threads
Declaration
protected abstract FileSystemStream DoGetMetadataStream(FileSystemSessionItem item, Action<FileSystemStream> disposeAction)
Parameters
Returns
Declaration
protected virtual Task<FileSystemStream> DoGetMetadataStreamAsync(FileSystemSessionItem item, Action<FileSystemStream> disposeAction)
Parameters
Returns
DoGetModificationTimestamp(FileSystemSessionItem)
Override to get item modification timestamp.
This method may be called by multiple threads
Declaration
protected abstract DateTime? DoGetModificationTimestamp(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Nullable<System.DateTime> |
|
DoGetModificationUser(FileSystemSessionItem)
Override in particular file systems to get user who was the last user modifying the item.
This method may be called by multiple threads
Declaration
protected virtual User DoGetModificationUser(FileSystemSessionItem item)
Parameters
Returns
DoGetModificationUserAsync(FileSystemSessionItem)
Declaration
protected virtual Task<User> DoGetModificationUserAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<User> |
|
DoGetPermissionsStream(FileSystemSessionItem, Action<FileSystemStream>)
Override to get permissions stream for item (directory or file).
This method may be called by multiple threads
Declaration
protected abstract FileSystemStream DoGetPermissionsStream(FileSystemSessionItem item, Action<FileSystemStream> disposeAction)
Parameters
Returns
DoGetPermissionsStreamAsync(FileSystemSessionItem, Action<FileSystemStream>)
Declaration
protected virtual Task<FileSystemStream> DoGetPermissionsStreamAsync(FileSystemSessionItem item, Action<FileSystemStream> disposeAction)
Parameters
Returns
DoGetReadOnly(FileSystemSessionItem)
Override to get item readonly status.
This method may be called by multiple threads
Declaration
protected abstract bool DoGetReadOnly(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Boolean |
|
DoGetSubDirectoryNames(FileSystemDirectory, Boolean)
Override to get subdirectory names of directory. If directory is null then root is assumed.
This method may be called by multiple threads
Declaration
protected abstract IEnumerable<string> DoGetSubDirectoryNames(FileSystemDirectory directory, bool recursive)
Parameters
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<System.String> |
|
DoGetSubDirectoryNamesAsync(FileSystemDirectory, Boolean)
Declaration
protected virtual Task<IEnumerable<string>> DoGetSubDirectoryNamesAsync(FileSystemDirectory directory, bool recursive)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<System.String>> |
|
DoGetVersion(FileSystemSession)
Override in particular file systems that support versioning to get version object for session.
This method may be called by multiple threads
Declaration
protected virtual IFileSystemVersion DoGetVersion(FileSystemSession session)
Parameters
Returns
DoGetVersionAsync(FileSystemSession)
Declaration
protected virtual Task<IFileSystemVersion> DoGetVersionAsync(FileSystemSession session)
Parameters
Returns
DoNavigate(FileSystemSession, String)
Override to get file or directory from specified path. Return null if item does not exist.
This method may be called by multiple threads
Declaration
protected abstract FileSystemSessionItem DoNavigate(FileSystemSession session, string path)
Parameters
Returns
DoNavigateAsync(FileSystemSession, String)
Declaration
protected virtual Task<FileSystemSessionItem> DoNavigateAsync(FileSystemSession session, string path)
Parameters
Returns
DoReadAsync(FileSystemStream, Byte[], Int32, Int32, CancellationToken)
Declaration
protected virtual Task<int> DoReadAsync(FileSystemStream stream, byte[] buffer, int offset, int count, CancellationToken ct)
Parameters
Type |
Name |
Description |
FileSystemStream |
stream |
|
System.Byte[] |
buffer |
|
System.Int32 |
offset |
|
System.Int32 |
count |
|
System.Threading.CancellationToken |
ct |
|
Returns
Type |
Description |
System.Threading.Tasks.Task<System.Int32> |
|
DoRefresh(FileSystemSessionItem)
Override to refresh item state, i.e. re-fetch remote information.
This method may be called by multiple threads
Declaration
protected virtual void DoRefresh(FileSystemSessionItem item)
Parameters
DoRefreshAsync(FileSystemSessionItem)
Declaration
protected virtual Task DoRefreshAsync(FileSystemSessionItem item)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoRenameItem(FileSystemSessionItem, String)
Override to rename item return true on success.
This method may be called by multiple threads
Declaration
protected abstract bool DoRenameItem(FileSystemSessionItem item, string newName)
Parameters
Returns
Type |
Description |
System.Boolean |
|
DoRenameItemAsync(FileSystemSessionItem, String)
Declaration
protected virtual Task<bool> DoRenameItemAsync(FileSystemSessionItem item, string newName)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task<System.Boolean> |
|
DoRollbackTransaction(FileSystemSession)
Override in particular file systems that support transactions to rollback transaction in specified session.
This method may be called by multiple threads
Declaration
protected virtual void DoRollbackTransaction(FileSystemSession session)
Parameters
DoRollbackTransactionAsync(FileSystemSession)
Declaration
protected virtual Task DoRollbackTransactionAsync(FileSystemSession session)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoSetCreationTimestamp(FileSystemSessionItem, DateTime)
Override to set item creation timestamp.
This method may be called by multiple threads
Declaration
protected abstract void DoSetCreationTimestamp(FileSystemSessionItem item, DateTime timestamp)
Parameters
DoSetCreationTimestampAsync(FileSystemSessionItem, DateTime)
Declaration
protected virtual Task DoSetCreationTimestampAsync(FileSystemSessionItem item, DateTime timestamp)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoSetLastAccessTimestamp(FileSystemSessionItem, DateTime)
Override to set item last access timestamp.
This method may be called by multiple threads
Declaration
protected abstract void DoSetLastAccessTimestamp(FileSystemSessionItem item, DateTime timestamp)
Parameters
DoSetLastAccessTimestampAsync(FileSystemSessionItem, DateTime)
Declaration
protected virtual Task DoSetLastAccessTimestampAsync(FileSystemSessionItem item, DateTime timestamp)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoSetModificationTimestamp(FileSystemSessionItem, DateTime)
Override to set item modification timestamp.
This method may be called by multiple threads
Declaration
protected abstract void DoSetModificationTimestamp(FileSystemSessionItem item, DateTime timestamp)
Parameters
DoSetModificationTimestampAsync(FileSystemSessionItem, DateTime)
Declaration
protected virtual Task DoSetModificationTimestampAsync(FileSystemSessionItem item, DateTime timestamp)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoSetReadOnly(FileSystemSessionItem, Boolean)
Override to set item readonly status.
This method may be called by multiple threads
Declaration
protected abstract void DoSetReadOnly(FileSystemSessionItem item, bool readOnly)
Parameters
DoSetReadOnlyAsync(FileSystemSessionItem, Boolean)
Declaration
protected virtual Task DoSetReadOnlyAsync(FileSystemSessionItem item, bool readOnly)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoSetVersion(FileSystemSession, IFileSystemVersion)
Override in particular file systems that support versioning to set session to specific version.
This method may be called by multiple threads
Declaration
protected virtual void DoSetVersion(FileSystemSession session, IFileSystemVersion version)
Parameters
DoSetVersionAsync(FileSystemSession, IFileSystemVersion)
Declaration
protected virtual Task DoSetVersionAsync(FileSystemSession session, IFileSystemVersion version)
Parameters
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
DoWriteAsync(FileSystemStream, Byte[], Int32, Int32, CancellationToken)
Declaration
protected virtual Task DoWriteAsync(FileSystemStream stream, byte[] buffer, int offset, int count, CancellationToken ct)
Parameters
Type |
Name |
Description |
FileSystemStream |
stream |
|
System.Byte[] |
buffer |
|
System.Int32 |
offset |
|
System.Int32 |
count |
|
System.Threading.CancellationToken |
ct |
|
Returns
Type |
Description |
System.Threading.Tasks.Task |
|
MakeSessionConfigParams(IConfigSectionNode)
Declaration
protected virtual FileSystemSessionConnectParams MakeSessionConfigParams(IConfigSectionNode node)
Parameters
Returns
StartSession(FileSystemSessionConnectParams)
Creates a new session for the user. This method is thread-safe, however the returned FileSystemSession object is not.
Every thread must obtain its own session via this method
Declaration
public abstract FileSystemSession StartSession(FileSystemSessionConnectParams cParams = null)
Parameters
Returns
ToString()
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
Implements
System.IDisposable
Extension Methods