Skip to content

Commit df6220a

Browse files
Add some documentation for FileTypeHandlers as a developer guide
1 parent d7cc4fe commit df6220a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

FileTypeHandlers.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# How to develop FileTypeHandlers in FlexBridge
2+
3+
## Overview
4+
5+
In the *[Chorus](https://github.com/sillsdev/chorus?tab=readme-ov-file#overview)* project, FileTypeHandlers are used to define custom handling logic for different types of files managed by Chorus.
6+
They are used to merge, identify conflicts, or process files specific to a part of the project data, and present conflicts to the user.
7+
These are discovered at runtime using *[MEF](https://learn.microsoft.com/en-us/dotnet/framework/mef/)*.
8+
Any plugins loaded into chorus which implement IChorusFileTypeHandler will be used during merging.
9+
10+
FlexBridge implements a single ***[IChorusFileTypeHandler](https://github.com/sillsdev/chorus/blob/master/src/LibChorus/FileTypeHandlers/IChorusFileTypeHandler.cs)***
11+
in the ***FieldWorksCommonFileHandler*** which uses MEF its self to load
12+
***[IFieldWorksFileHandler](https://github.com/sillsdev/flexbridge/blob/develop/src/LibFLExBridge-ChorusPlugin/Handling/IFieldWorksFileHandler.cs)***s
13+
for the various file types.
14+
15+
A major reason for this is to allow a single version of FlexBridge to support multiple FieldWorks model versions through use of a MetadataCache.
16+
17+
Implementations of ***IFieldWorksFileHandler*** in FlexBridge provide the different file handlers.
18+
Each ***IFieldWorksFileHandler*** has the methods for validating files, calculating differences, merging differences, and presenting the differences.
19+
20+
FlexBridge breaks the fwdata file into a model based hierarchy.
21+
Different major portions of the model are split into separate files so that merging logic can be modular and specific.
22+
FlexBridge also handles the merging of configuration files and other non-model project data.
23+
24+
## Adding a new file type
25+
26+
To handle a new file type:
27+
1. Implement the *IFieldWorksFileHandler* interface.
28+
1.1 Define logic and properties for:
29+
- File extension handled (*Extension*)
30+
- File validation support (*CanValidateFile*, *ValidateFile*) for verifying post merge content.
31+
- Merging (*Find2WayDifferences*, *Do3WayMerge*) handling both the difference detection and merging.
32+
- Change presentation (*GetChangePresenter*) for generating the user reports on the merge.
33+
2. Include thorough unit tests for your new filetype especially on any specific merge situations
34+
35+
## Debugging the merge code
36+
37+
1. The easiest way to debug is using the unit testing framework.
38+
There is an extensive library of unit tests on the existing IFieldWorksFileHandler implementations.
39+
Looking at the differences which are causing a bug (using TortoiseHg for example) should let you construct a unit test to replicate any failures.
40+
2. It is possible to modify *ChorusMerge* in Chorus to pause and allow you to attach a debugger when it is merging files.
41+
This can enable you to attach FlexBridge to the ChorusMerge.exe process while it is running and step into your merging code.
42+
This should be considered a last resort if you can't identify the problem and produce a failing unit test

ReadMe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ msbuild /t:Test FLExBridge.proj
5252

5353
Further instructions at <https://github.com/sillsdev/libpalaso/wiki/Developing-with-locally-modified-nuget-packages>
5454

55+
### Debugging or adding FileHandlers for merging
56+
See [FileTypeHandlers](./FileTypeHandlers.md) documentation.
57+
5558
## Updating Release Notes for a new version
5659

5760
FLEx Bridge is following the gitflow model for branching

0 commit comments

Comments
 (0)