Microsoft Office Documents Merging
The functionality described in this article is available in Engine v8.1 Beta and later versions.
With User File System you can open MS Office document on more than one machine, receive notifications about changes and merge open documents.
When notification about changes arrives via web sockets you will update the file as usual, using IServerCollectionNotifications.ProcessChangesAsync() call, (in case of Sync ID algorithm) or using the IServerNotifications.UpdateAsync() call.
In your Engine.ItemsChanged event add the Utilities.TryNotifyUpdateAvailable() method passing a path to a file to merge with as following:
Engine.ItemsChanged += Engine_ItemsChanged; private void Engine_ItemsChanged(Engine sender, ItemsChangeEventArgs e) { foreach (ChangeEventItem item in e.Items) { // If incoming update failed becase a file is in use, // try to show merge dialog (for MS Office Word, PowerPoint etc.). if (e.Direction == SyncDirection.Incoming && e.OperationType == OperationType.UpdateContent) { switch (e.Result.Status) { case OperationStatus.FileInUse: string mergeWith = e.Result.ShadowFilePath; Utilities.TryNotifyUpdateAvailable(item.Path, mergeWith); break; } } } }
How to test merging:
- Open the Microsoft Word document on Machine 1. Note that this should not set the read-only flag on the document on other machines.
- Open the same document for editing on Machine 2.
- Edit the document on the Machine 1 and save. You will see changes merged on the Machine 2.
If the MS Office file is opened for editing it will be blocked and the UpdateAsync() call will fail. In this case, inside your Engine.ItemsChanged event handler you will receive a notification about unsuccessful update, with the OperationStatus.FileInUse status. The Engine downloads a file a temp folder and provides a path to a file that contains an updated file content, received from the remote storage in the OperationResult.ShadowFilePath property.
For merging to function your file system implementation must NOT prevent the document from being edited on more than one machine simultaneously.
Your locking implementation, if any, should NOT set the read-only flag on files opened by other users. Setting read-only flag will prevent file from being opened for editing and blocked and as a result OperationStatus.FileInUse status will NOT be returned in your ItemsChanged event.