IEngine Interface |
Namespace: ITHit.FileSystem
The IEngine type exposes the following members.
Name | Description | |
---|---|---|
![]() | License |
Gets or sets the license text.
|
![]() | ThrowExceptions |
Indicates if the IEngine implementation must throw exception in case of any errors in the Engine itself
or in the user code occures.
|
Name | Description | |
---|---|---|
![]() | Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.) |
![]() | FilterAsync |
Allows filtering file system items.
(Inherited from IFileSystemFilter.) |
![]() | GetFileSystemItemAsync | |
![]() ![]() | GetMenuCommandAsync |
Gets context menu command.
|
![]() | RiseError |
Rises Error event. Throws an exception if the ThrowExceptions
property is set to true.
|
![]() | ServerNotifications |
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.
|
![]() | SetRemoteStorageRootItemId |
Sets remote storage item ID for the root folder.
|
Name | Description | |
---|---|---|
![]() | Debug |
Event fired when the IEngine or user file system implementation code sends a debug message.
|
![]() | Error |
Event fired in case of any exceptions in the IEngine or user file system implementation code.
|
![]() | Message |
Event fired when the IEngine or user file system implementation code sends an informational message.
|
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].
The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.
public class VirtualEngine : EngineWindows { internal RemoteStorageMonitor RemoteStorageMonitor; public VirtualEngine(string license, string userFileSystemRootPath, string remoteStorageRootPath, LogFormatter logFormatter) : base(license, userFileSystemRootPath) { // 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; SyncService.StateChanged += SyncService_StateChanged; Error += logFormatter.LogError; Message += logFormatter.LogMessage; Debug += logFormatter.LogDebug; RemoteStorageMonitor = new RemoteStorageMonitor(remoteStorageRootPath, this, this.Logger); } public override async Task<bool> FilterAsync(SyncDirection direction, OperationType operationType, string path, FileSystemItemType itemType, string newPath = null, IOperationContext operationContext = null) { if (await new ZipFilter().FilterAsync(direction, operationType, path, itemType, newPath)) { Logger.LogDebug($"{nameof(ZipFilter)} filtered {operationType}", path, newPath, operationContext); return true; } if (await new MsOfficeFilter().FilterAsync(direction, operationType, path, itemType, newPath)) { Logger.LogDebug($"{nameof(MsOfficeFilter)} filtered {operationType}", path, newPath, operationContext); return true; } if (await new AutoCadFilter().FilterAsync(direction, operationType, path, itemType, newPath)) { Logger.LogDebug($"{nameof(AutoCadFilter)} filtered {operationType}", path, newPath, operationContext); return true; } if (await new ErrorStatusFilter().FilterAsync(direction, operationType, path, itemType, newPath)) { Logger.LogDebug($"{nameof(ErrorStatusFilter)} filtered {operationType}", path, newPath, operationContext); return true; } return false; } public override async Task<IFileSystemItem> GetFileSystemItemAsync(byte[] remoteStorageItemId, FileSystemItemType itemType, IContext context, ILogger logger = null) { string userFileSystemPath = context.FileNameHint; if (itemType == FileSystemItemType.File) { return new VirtualFile(userFileSystemPath, remoteStorageItemId, logger); } else { return new VirtualFolder(userFileSystemPath, remoteStorageItemId, logger); } } public override async Task<IMenuCommand> GetMenuCommandAsync(Guid menuGuid, IOperationContext operationContext = null) { // For this method to be called you need to register a menu command handler. // See method description for more details. throw new NotImplementedException(); } public override async Task StartAsync(bool processModified = true, CancellationToken cancellationToken = default) { await base.StartAsync(processModified, cancellationToken); await RemoteStorageMonitor.StartAsync(); } public override async Task StopAsync() { await base.StopAsync(); await RemoteStorageMonitor.StopAsync(); } private void Engine_StateChanged(Engine engine, EngineWindows.StateChangeEventArgs e) { engine.Logger.LogMessage($"{e.NewState}"); } private void SyncService_StateChanged(object sender, SynchEventArgs e) { if (e.NewState == SynchronizationState.Enabled || e.NewState == SynchronizationState.Disabled) { SyncService.Logger.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); } }
The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.
public static async Task Main(string[] args) { // Load Settings. Settings = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build().ReadSettings(); logFormatter = new LogFormatter(log, Settings.AppID, Settings.RemoteStorageRootPath); commands = new Commands(log, Settings.RemoteStorageRootPath); commands.ConfigureConsole(); // Log environment description. logFormatter.PrintEnvironmentDescription(); registrar = new Registrar(SyncRootId, Settings.UserFileSystemRootPath, log); consoleProcessor = new ConsoleProcessor(registrar, logFormatter, commands); try { // Register sync root and create app folders. await registrar.RegisterSyncRootAsync(Settings.ProductName, Path.Combine(Settings.IconsFolderPath, "Drive.ico")); using (Engine = new VirtualEngine( Settings.UserFileSystemLicense, Settings.UserFileSystemRootPath, Settings.RemoteStorageRootPath, logFormatter)) { commands.Engine = Engine; commands.RemoteStorageMonitor = Engine.RemoteStorageMonitor; // Set the remote storage item ID for the root item. It will be passed to the IEngine.GetFileSystemItemAsync() // method as a remoteStorageItemId parameter when a root folder is requested. byte[] itemId = WindowsFileSystemItem.GetItemIdByPath(Settings.RemoteStorageRootPath); Engine.SetRemoteStorageRootItemId(itemId); // Print console commands. consoleProcessor.PrintHelp(); // Print Engine config, settings, logging headers. await logFormatter.PrintEngineStartInfoAsync(Engine); // Start processing OS file system calls. await Engine.StartAsync(); G // Opens Windows File Manager with user file system folder and remote storage folder. commands.ShowTestEnvironment(); #endif // Keep this application running and reading user input. await consoleProcessor.ProcessUserInputAsync(); } } catch (Exception ex) { log.Error(ex); await consoleProcessor.ProcessUserInputAsync(); } }