Click or drag to resize

IEngine Interface

IT Hit User File System
Represents custom user file system. Listens to OS file system calls and calls user interfaces implementations when data is required.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 3.3.9602.0
Syntax
public interface IEngine : ILogger, 
	IDisposable

The IEngine type exposes the following members.

Properties
  NameDescription
Public propertyLicense
Gets or sets the license text.
Public propertyThrowExceptions
Indicates if the IEngine implementation must throw exception in case of any errors in the Engine itself or in the user code occures.
Top
Methods
  NameDescription
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from IDisposable.)
Public methodFilterAsync
Allows filtering file system items that should NOT be synched to the remote storage.
Public methodCode exampleGetFileSystemItemAsync
Gets file or folder item corresponding to the user file system path or item ID.
Public methodLogError
Logs error.
(Inherited from ILogger.)
Public methodLogMessage
Logs debug message.
(Inherited from ILogger.)
Public methodRiseError
Rises Error event. Throws an exception if the ThrowExceptions property is set to true.
Public methodServerNotifications
Creates, updates, moves and deletes files and folders in the user file system. Use object returned by this method to apply changes sent by the remote storage.
Top
Events
  NameDescription
Public eventError
Event fired in case of any exceptions in the IEngine or user file system implementation code.
Public eventMessage
Event fired when the IEngine or user file system implementation code sends an informational message.
Top
Remarks

Processes file system calls from operating system and calls user interfcaces, that implement file system, such as IFile, IFolder , etc.

This calss represents a generic file system with features supported on any operating system. The Windows implementation of this interface is located in [!:ITHit.FileSystem.Windows.EngineWindows] class. The macOS implementation of this interface is in [!:ITHit.FileSystem.Mac.EngineMac].

Examples

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

C#
public class VirtualEngine : EngineWindows
{
    private ILogger logger;

    internal RemoteStorageMonitor RemoteStorageMonitor;

    public VirtualEngine(string license, string userFileSystemRootPath, ILog log) : base(license, userFileSystemRootPath)
    {
        logger = new Logger("File System Engine", log);

        // We want our file system to run regardless of any errors.
        // If any request to file system fails in user code or in Engine itself we continue processing.
        ThrowExceptions = false;

        StateChanged += Engine_StateChanged;
        Error += Engine_Error;
        Message += Engine_Message;

        string remoteStorageRootPath = Mapping.MapPath(userFileSystemRootPath);
        RemoteStorageMonitor = new RemoteStorageMonitor(remoteStorageRootPath, this, log);
    }

    public override async Task<IFileSystemItem> GetFileSystemItemAsync(string path, FileSystemItemType itemType)
    {
        // When a file or folder is deleted, the item may be already 
        // deleted in user file system when this method is called
        // The Engine calls IFile.CloseAsync() and IFileSystemItem.DeleteCompletionAsync() methods in this case.

        // On macOS there is no access to the local file system. 
        // You should NOT try to determine item type or read local files/folders on macOS.


        if (itemType == FileSystemItemType.File)
        {
            return new VirtualFile(path, this);
        }
        else
        {
            return new VirtualFolder(path, this);
        }
    }

    public override async Task StartAsync()
    {
        await base.StartAsync();
        RemoteStorageMonitor.Start();
    }

    public override async Task StopAsync()
    {
        await base.StopAsync();
        RemoteStorageMonitor.Stop();
    }

    private void Engine_Message(IEngine sender, EngineMessageEventArgs e)
    {
        logger.LogMessage(e.Message, e.SourcePath, e.TargetPath);
    }

    private void Engine_Error(IEngine sender, EngineErrorEventArgs e)
    {
        logger.LogError(e.Message, e.SourcePath, e.TargetPath, e.Exception);
    }

    private void Engine_StateChanged(Engine engine, EngineWindows.StateChangeEventArgs e)
    {
        engine.LogMessage($"{e.NewState}");
    }


    private bool disposedValue;

    protected override void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                RemoteStorageMonitor.Dispose();
            }

            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
            // TODO: set large fields to null
            disposedValue = true;
        }
        base.Dispose(disposing);
    }
}
C#
public class VirtualEngine : EngineWindows
{
    private ILogger logger;

    internal RemoteStorageMonitor RemoteStorageMonitor;

    public VirtualEngine(string license, string userFileSystemRootPath, ILog log) : base(license, userFileSystemRootPath)
    {
        logger = new Logger("File System Engine", log);

        // We want our file system to run regardless of any errors.
        // If any request to file system fails in user code or in Engine itself we continue processing.
        ThrowExceptions = false;

        StateChanged += Engine_StateChanged;
        Error += Engine_Error;
        Message += Engine_Message;

        string remoteStorageRootPath = Mapping.MapPath(userFileSystemRootPath);
        RemoteStorageMonitor = new RemoteStorageMonitor(remoteStorageRootPath, this, log);
    }

    public override async Task<IFileSystemItem> GetFileSystemItemAsync(string userFileSystemPath, FileSystemItemType itemType, string itemId = null)
    {
        if (itemType == FileSystemItemType.File)
        {
            return new VirtualFile(userFileSystemPath, this);
        }
        else
        {
            return new VirtualFolder(userFileSystemPath, this);
        }
    }

    public override async Task StartAsync()
    {
        await base.StartAsync();
        RemoteStorageMonitor.Start();
    }

    public override async Task StopAsync()
    {
        await base.StopAsync();
        RemoteStorageMonitor.Stop();
    }

    private void Engine_Message(IEngine sender, EngineMessageEventArgs e)
    {
        logger.LogMessage(e.Message, e.SourcePath, e.TargetPath);
    }

    private void Engine_Error(IEngine sender, EngineErrorEventArgs e)
    {
        logger.LogError(e.Message, e.SourcePath, e.TargetPath, e.Exception);
    }

    private void Engine_StateChanged(Engine engine, EngineWindows.StateChangeEventArgs e)
    {
        engine.LogMessage($"{e.NewState}");
    }


    private bool disposedValue;

    protected override void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                RemoteStorageMonitor.Dispose();
            }

            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
            // TODO: set large fields to null
            disposedValue = true;
        }
        base.Dispose(disposing);
    }
}
C#
public class VirtualEngine : EngineWindows
{
    private ILogger logger;

    internal RemoteStorageMonitor RemoteStorageMonitor;

    public VirtualEngine(string license, string userFileSystemRootPath, string remoteStorageRootPath, ILog log) : base(license, userFileSystemRootPath)
    {
        logger = new Logger("File System Engine", log);

        // We want our file system to run regardless of any errors.
        // If any request to file system fails in user code or in Engine itself we continue processing.
        ThrowExceptions = false;

        StateChanged += Engine_StateChanged;
        Error += Engine_Error;
        Message += Engine_Message;

        RemoteStorageMonitor = new RemoteStorageMonitor(remoteStorageRootPath, this, log);
    }

    public override async Task<IFileSystemItem> GetFileSystemItemAsync(string userFileSystemPath, FileSystemItemType itemType, byte[] itemId = null)
    {
        if (itemType == FileSystemItemType.File)
        {
            return new VirtualFile(userFileSystemPath, itemId, this);
        }
        else
        {
            return new VirtualFolder(userFileSystemPath, itemId, this);
        }
    }

    public override async Task StartAsync()
    {
        await base.StartAsync();
        RemoteStorageMonitor.Start();
    }

    public override async Task StopAsync()
    {
        await base.StopAsync();
        RemoteStorageMonitor.Stop();
    }

    private void Engine_Message(IEngine sender, EngineMessageEventArgs e)
    {
        logger.LogMessage(e.Message, e.SourcePath, e.TargetPath);
    }

    private void Engine_Error(IEngine sender, EngineErrorEventArgs e)
    {
        logger.LogError(e.Message, e.SourcePath, e.TargetPath, e.Exception);
    }

    private void Engine_StateChanged(Engine engine, EngineWindows.StateChangeEventArgs e)
    {
        engine.LogMessage($"{e.NewState}");
    }


    private bool disposedValue;

    protected override void Dispose(bool disposing)
    {
        if (!disposedValue)
        {
            if (disposing)
            {
                RemoteStorageMonitor.Dispose();
            }

            // TODO: free unmanaged resources (unmanaged objects) and override finalizer
            // TODO: set large fields to null
            disposedValue = true;
        }
        base.Dispose(disposing);
    }
}
See Also