The Microsoft Sync Framework defines a basic set of functionality that must to be provided in order to synchronize information from different data sources (AKA replicas). head over to http://msdn.microsoft.com/en-us/sync/default.aspx to get some more information. There documentation is improving... at least compared to when i looked at it a year ago.
By default the sync framework comes with a handful of replica providers, one being a file synchronization provider. below is a snippet of code from the application I am writing that performs the synchronization to my NAS.
1: using (var sourceProvider = new FileSyncProvider(SourceDirectory.FullName, SyncFilter, SyncOptions))
2: using (var destinationProvider = new FileSyncProvider(DestinationDirectory.FullName, SyncFilter, SyncOptions))
3: {
4: SyncOrchestrator agent = new SyncOrchestrator();
5: agent.LocalProvider = sourceProvider;
6: agent.RemoteProvider = destinationProvider;
7: agent.Direction = SyncDirectionOrder.Upload;
8: sourceProvider.DetectChanges();
9: destinationProvider.DetectChanges();
10: agent.Synchronize();
11: }
Although there is a lot of context missing around this code, this is the core of what gets a synchronization session done. In order to perform synchronization between two replicas you must have a source provider and a destination provider (lines 1 and 2). For file synchronization, the sync framework 4.0 provides the FileSyncProvider class. On line 4 a sync orchestrator is constructed. This object controls the interaction and flow of communication between the two providers. Line 8 and 9 are optional depending on the sync options provided in the provider, but essentially this tells the provider to make sure the replicas they represent are up to date with their knowledge (what files were changed, when, etc). There is a bit of overhead for file system providers so I decided to manually execute this. In the actual code implementation, there is some progress notifications associated with detecting changes. Line 10 tells the agent to start the synchronization. I was pretty impressed with how simple this was to setup. I put my current project up on codeplex if you want to take a look, or even better let me know if you want to contribution rights. I am going to add a couple final features, but it is mostly meeting my basic requirements.Code was a quick write, let me know if you are interested in something and I will try to add it. I hope to have enough time to actually make this thing more usable over the next month. Currently I just have it setup as a windows scheduled task to perform my sync nightly… or I can always manually run it. download and compile from http://foldersyncer.codeplex.com/
Hopefully the Mesh team enables NAS sync as I am positive it will go through a whole host of testing that I did not do.