Unmanaged NTFS Provider Sample
The NTFSProvider sample shows how you can use C++ to implement a synchronization provider that synchronizes files in a file folder. For simplicity, this sample does not handle subfolders.
Security Note |
---|
This sample code is provided to illustrate a concept. Because the sample might not use the safest coding practices, the code should not be used in applications or Web sites. Microsoft assumes no liability for incidental or consequential damages if the sample code is used for purposes other than as intended. |
File Location
The files for this sample are located where the Sync Framework is installed. The default location is C:\Program Files (x86)\Microsoft SDKs\Microsoft Sync Framework\v1.0\Samples\NTFSSample.
Contents
This sample contains two projects in a Microsoft Visual Studio solution:
NTFSProvider. Is the synchronization provider implementation.
SampleTest. Is a simple synchronization application.
Files
The NTFSProvider project contains the following files.
Source file | Description |
---|---|
MetadataStore.h, MetadataStore.cpp |
A helper class that the sample uses to store synchronization metadata in the file system. |
MyStore.h, MyStore.cpp |
The synchronization provider class. This implements IKnowledgeSyncProvider, ISyncProvider, ISynchronousDataRetriever, and ISynchronousNotifyingChangeApplierTarget to participate in synchronization. |
MyTransferMechanism.h, MyTransferMechanism.cpp |
A class that encapsulates a file stream and implements IUnknown. An instance of this class is passed from one provider to another and is used to copy the actual file data during synchronization. |
The SampleTest project contains the following files.
Source file | Description |
---|---|
SyncController.h, SyncController.cpp |
A class that creates and hosts the synchronization session object. This class also implements ISyncCallback and registers to receive synchronization events from the session object. |
SyncMain.cpp |
The entry point to the application. This parses the command line, instantiates the providers and the controller object, connects them all to each other, and starts synchronization. |
Interfaces
This sample demonstrates the following Sync Framework interfaces:
IKnowledgeSyncProvider |
IEnumSyncChanges |
ISyncProvider |
ISyncChange |
ISynchronousDataRetriever |
IForgottenKnowledge |
ISynchronousNotifyingChangeApplierTarget |
ISynchronousNotifyingChangeApplier |
ISyncCallback |
ILoadChangeContext |
ISyncKnowledge |
ISaveChangeContext |
ISyncChangeBatch |
IApplicationSyncServices |
IProviderSyncServices |
ISyncSession |
Requirements
To build and run this sample, the following software must be installed:
- Microsoft Visual Studio 2005 or Visual Studio 2008
Building the Sample
To build the sample by using Visual Studio
Open the NTFSProvider.sln file.
On the Build menu, select BuildSolution.
Running the Sample
To run SampleTest.exe
In the root folder, create two folders: Folder1 andr Folder2.
Add some content, such as text files, to the folders. Make sure that the contents of Folder1 are different from the contents of Folder2.
To run the sample at a command prompt, open a Command Prompt window and locate the folder that contains SampleTest.exe. At the command prompt, type: SampleTest.exe C:\Folder1 C:\Folder2.
To run the sample in Visual Studio, open the Property Pages for the SampleTest project. In the Debugging Command Arguments field, type: C:\Folder1 C:\Folder2. On the Debug menu, click Start Debugging.
When the sample finishes, Folder1 and Folder2 contain the same set of files. The folders also contain files that contain synchronization metadata, such as Knowledge.Sync, Metadata.Sync, Replica.Sync, and TickCount.Sync.
See Also
Concepts
Sync Framework Core Components