Windows Engine Services

Topics described in this article require User File System v10 or later.

Programming Synchronization Services

Windows Engine is provided with a number of services that synchronize client and server.

Services are organised a tree with Engine being a root service and subservices added to the Services property.

You can create your custom services, such as remote storage monitor service, to hook them to the chain of Engine execution and start/stop as part of the Engine or its sub-services.

Accessing Services

Services are added to the list of services accessed via EngineWindows.Services property. By default the Engine is supplied with the following services, added to this list by default:

  • File System Monitor
  • Timer Service. Contains the following sub-services:
    • Incoming Synchronization Service
    • Outgoing Synchronization Service
    • Hydration Service
    • Locking Service
  • Windows Explorer Monitor

In addition to the Services property you can access each service using Engine properties:

 

Starting and Stopping Services

To start a service, call the StartAsync() method. It provides a boolean parameter indication if all child services must be started automatically: 

engine.StartAsync(true);

...

engine.StopAsync(true);

If you do not want to start child services, you can start and stop each service one-by-one:

// Start monitoring file system calls: 
// on-demand population, hydration, creation, update, move, deletion.
await Engine.FileSystemMonitor.StartAsync();

// Start monitoring Windows Explorer navigation and listing events.
await Engine.WindowsExplorer.StartAsync();

// Start synching any lost changes.
await Engine.WindowsExplorer.SyncService.StartAsync();

Service State

Each service has a State property that indicates service state. After you call the StartAsync() method, the service is transfered into Starting state and than to Idle or Synchronizing state. the service can transfer between Idle and Synchronizing many times during the service lifecycle, depending on the service implementation. The StopAsync method transfers the service into Stopping and than into Disabled state.

A typical sync state sequence is: Disabled -> Starting -> Idle -> Synchronizing -> Stopping -> Disabled.

If during start or stop operation an error is occurred, for example any subservice did not start, the service is transferred into the Error state.

Service Events

Each service provides a StateChanged event that is fired when the service is transferred from one state to another. This event provides old state, new state, execution context and root item of the service.

  

File System Monitor Service

This service hooks to the file system callbacks and calls Engine IFile and IFolder interfaces when file system functions are called. This service is responsible for on-demand folders population, files hydration, deletion and move operations.

You can filter which operations you want to process by setting 

FileSystemMonitor.ChangesNotificationFilter property. For example if you want to trigger incoming and outgoing synchronization manually, you will typically enable only population and hydration, disabling all other operations:

// Monitor only on-demand folders population and files hydration.
// You will sync all other changes (Creation, update, move and deletion) manually.
FileSystemMonitor.ChangesNotificationFilter = 

await Engine.FileSystemMonitor.StartAsync();

Sync Service

This service contains a subset of services that sync all changes from client to the server or from server to client. This service can run on timer or you can run it manually, when needed.

Because changes may fail to sync for various reasons, such as server being unavailable, authentication failure, file being blocked by an application or system process, etc, in many cases you would want to sync such changes based on timer or based on other events, such as login/authentication, network reconnection, application startup, etc. 

Running One-time Processing

To process all changes one time call the ProcessAsync() method:

await SyncService.ProcessAsync()

To run all changes on timer set the interval and start the service:

engine.SysnService.SyncIntervalMs = 60000; // Run sync every 60 sec.
await engine.SysnService.StartAsync();

 

Incoming Synchronization Service

Syncs all changes from server to client.

This service is supplied with overloaded ProcessAsync() method with a number of parameters that allow granular synchronization and population.

In case the synchronization mode is set to Timer, this service runs automatically. In case

Depending of which parameters you specify in your ProcessAsync() call, this service may consume a lot of system resources on the client side, server side or both. In many cases instead of calling ProcessAsync() you will use the Sync ID algorithm or implement remote storage monitor service or both. Alternatively you can also hook into Windows Explorer and sync a content of a single folder using a Windows Explorer Refresh button. 

Outgoing Synchronization Service

This service syncs all changes from client to the server that were not synched for any reason. 

Hydration Service

Monitors pinned and unpinned file attributes by traversing file system and hydrates and dehydrates files.

Locking Service

Releases files locked by Microsoft Office, AutoCAD and other applications. 

Windows Explorer Monitor Service

This service hooks into Windows Explorer and monitors navigation and listing events. You will use it to:

  • Update folder content when user clicks on the Refresh button in Windows Explorer
  • Set Windows Explorer view mode and sorting column. 
  • Update data in your custom properties displayed by Windows Explorer.
engine.WindowsExplorer.FolderNavigation += UpdateExplorerColumns;
engine.WindowsExplorer.FolderListing += UpdateExplorerColumns;
await engine.WindowsExplorer.StartAsync();

Remote Storage Monitor Service

Remote storage monitor syncs changes from your remote storage to user file system. Typically you will use web sockets or other push notifications to trigger event(s) and update the client file system.

You will program remote storage monitor and add to the list of services using Add() method. 

public RemoteStorageMonitor : ISyncService
{

}
...

var rsMonitor = new RemoteStorageMonitor("htts://server/");
engine.Services.Add(rsMonitor);

// Start the Engine and remote storage monitor.
await engine.StartAsync(true);