Share via


Managed NTFS Provider Sample

The ManagedNTFSProvider sample shows how you can use C# or Microsoft Visual Basic to implement a synchronization provider that synchronizes files in a file folder. For simplicity, this sample does not handle subfolders.

Security noteSecurity 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 Sync Framework is installed. The default location is C:\Program Files\Microsoft SDKs\Microsoft Sync Framework\v1.0\Samples\ManagedNTFSSample.

Contents

This sample contains a C# and a Visual Basic implementation. Both of these are fairly similar. Each contains the following projects in a Microsoft Visual Studio solution:

  • ManagedNTFSProvider Combines a synchronization provider implementation together with a simple synchronization application

  • ManagedSampleTest Runs these components to perform synchronization.

Files

C# Implementation

The ManagedNTFSProvider project contains the following files.

Source file Description

MetadataStore.cs

A helper class that the sample uses to store synchronization metadata in the file system.

MyStore.cs

The synchronization provider class. This implements KnowledgeSyncProvider, IChangeDataRetriever, and INotifyingChangeApplierTarget to participate in synchronization.

MyTransferMechanism.cs

A class that encapsulates a file stream. This file stream is passed from one provider to another so that it can be used to copy the actual file data during synchronization.

MySyncController.cs

A class that creates and hosts the synchronization session object.

The ManagedSampleTest project contains the following file.

Source file Description

Program.cs

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.

Visual Basic Implementation

The ManagedNTFSProvider project contains the following files.

Source file Description

MetadataStore.vb

A helper class that the sample uses to store synchronization metadata in the file system.

MyStore.vb

The synchronization provider class. This implements KnowledgeSyncProvider, IChangeDataRetriever, and INotifyingChangeApplierTarget to participate in synchronization.

MyTransferMechanism.vb

A class that encapsulates a file stream. This file stream is passed from one provider to another so that it can be used to copy the actual file data during synchronization.

MySyncController.vb

A class that creates and hosts the synchronization session object.

The ManagedSampleTest project contains the following file.

Source file Description

Program.vb

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 classes and interfaces:

KnowledgeSyncProvider

ItemChange

IChangeDataRetriever

INotifyingChangeApplierTarget

NotifyingChangeApplier

SyncProvider

LoadChangeContext

SyncKnowledge

SaveChangeContext

ForgottenKnowledge

SyncOrchestrator

ChangeBatch

 

Requirements

To build and run this sample, the following software must be installed:

  • Microsoft Visual Studio 2005 or Visual Studio 2008

  • Microsoft .NET Framework 2.0 or .NET Framework 3.0

Building the Sample

To build the sample by using Visual Studio

  1. Open the ManagedNTFSProvider.sln file.

  2. On the Build menu, select BuildSolution.

Running the Sample

To run ManagedSampleTest.exe

  1. In the root folder, create two folders: Folder1 and Folder2.

  2. Add some content, such as text files, to the folders. Make sure that the contents of Folder1 are different from the contents of Folder2.

  3. To run the sample at a command prompt, open a Command Prompt window and locate the folder that contains ManagedSampleTest.exe. At the command prompt, type: ManagedSampleTest.exe C:\Folder1 C:\Folder2.

  4. To run the sample in Visual Studio, open the Property Pages for the ManagedSampleTest project. In the Debug Command line arguments field, type: C:\Folder1 C:\Folder2. On the Debug menu, click Start Debugging.

  5. 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

Reference

Microsoft.Synchronization

Other Resources

Custom Data Synchronization Samples