Click or drag to resize

IFolder Interface

IT Hit User File System
Represents a folder in the user file system. In addition to metods provided by IFileSystemItem provides GetChildrenAsync(String, IOperationContext, IFolderListingResultContext) method for enumerating this folder content.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 1.4.4298.0
Syntax
public interface IFolder : IFileSystemItem

The IFolder type exposes the following members.

Methods
  NameDescription
Public methodCode exampleDeleteAsync
Called when a file or a folder is deleted from user file system.
(Inherited from IFileSystemItem.)
Public methodGetChildrenAsync
Gets list of files and folders contained in this folder that match a search pattern.
Public methodCode exampleMoveToAsync
Called when a file or a folder is being moved to a new location or renamed.
(Inherited from IFileSystemItem.)
Top
Remarks
All methods of this interface has 60 sec timout. To process longer requests report progress using the ReportProgress(Int64, Int64) method of the IResultContext interface passed as a parameter to each method.
Examples

The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.

C#
internal class VfsFolder : VfsFileSystemItem, IFolder
{
    public VfsFolder(string path, ILogger logger, VfsEngine engine) : base(path, logger, engine)
    {

    }

    public async Task GetChildrenAsync(string pattern, IOperationContext operationContext, IFolderListingResultContext resultContext)
    {
        // This method has a 60 sec timeout. 
        // To process longer requests and reset the timout timer call one of the following:
        // - resultContext.ReturnChildren() method.
        // - resultContext.ReportProgress() method.

        Logger.LogMessage($"IFolder.GetChildrenAsync({pattern})", UserFileSystemPath);

        IEnumerable<FileSystemItemBasicInfo> children = await new UserFolder(UserFileSystemPath).EnumerateChildrenAsync(pattern);

        // Filtering existing files/folders. This is only required to avoid extra errors in the log.
        List<IFileSystemItemBasicInfo> newChildren = new List<IFileSystemItemBasicInfo>();
        foreach (IFileSystemItemBasicInfo child in children)
        {
            string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name);
            if (!FsPath.Exists(userFileSystemItemPath))
            {
                Logger.LogMessage("Creating", child.Name);
                newChildren.Add(child);
            }
        }

        // To signal that the children enumeration is completed 
        // always call ReturnChildren(), even if the folder is empty.
        resultContext.ReturnChildren(newChildren.ToArray(), newChildren.Count());


        // Create ETags.
        // ETags must correspond with a server file/folder, NOT with a client placeholder. 
        // It should NOT be moved/deleted/updated when a placeholder in the user file system is moved/deleted/updated.
        // It should be moved/deleted when a file/folder in the remote storage is moved/deleted.
        foreach (FileSystemItemBasicInfo child in children)
        {
            string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name);
            await ETag.SetETagAsync(userFileSystemItemPath, child.ETag);
        }
    }
}
C#
internal class VfsFolder : VfsFileSystemItem, IFolder
{
    public VfsFolder(string path, ILogger logger, VfsEngine engine) : base(path, logger, engine)
    {

    }

    public async Task GetChildrenAsync(string pattern, IOperationContext operationContext, IFolderListingResultContext resultContext)
    {
        // This method has a 60 sec timeout. 
        // To process longer requests and reset the timout timer call one of the following:
        // - resultContext.ReturnChildren() method.
        // - resultContext.ReportProgress() method.

        Logger.LogMessage($"IFolder.GetChildrenAsync({pattern})", UserFileSystemPath);

        IEnumerable<FileSystemItemBasicInfo> children = await new UserFolder(UserFileSystemPath).EnumerateChildrenAsync(pattern);

        // Filtering existing files/folders. This is only required to avoid extra errors in the log.
        List<IFileSystemItemBasicInfo> newChildren = new List<IFileSystemItemBasicInfo>();
        foreach (IFileSystemItemBasicInfo child in children)
        {
            string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name);
            if (!FsPath.Exists(userFileSystemItemPath))
            {
                Logger.LogMessage("Creating", child.Name);
                newChildren.Add(child);
            }
        }

        // To signal that the children enumeration is completed 
        // always call ReturnChildren(), even if the folder is empty.
        resultContext.ReturnChildren(newChildren.ToArray(), newChildren.Count());


        // Save ETags and set "locked by another user" icon.
        foreach (FileSystemItemBasicInfo child in children)
        {
            string userFileSystemItemPath = Path.Combine(UserFileSystemPath, child.Name);

            // Create ETags.
            // ETags must correspond with a server file/folder, NOT with a client placeholder. 
            // It should NOT be moved/deleted/updated when a placeholder in the user file system is moved/deleted/updated.
            // It should be moved/deleted when a file/folder in the remote storage is moved/deleted.
            ETag.SetETagAsync(userFileSystemItemPath, child.ETag);

            // Set the lock icon and read-only attribute, to indicate that the item is locked by another user.
            new UserFileSystemRawItem(userFileSystemItemPath).SetLockedByAnotherUserAsync(child.LockedByAnotherUser);
        }
    }
}
See Also