Sdílet prostřednictvím


Synchronization Applications

A synchronization application is a software component that creates a synchronization session, connects it with two synchronization providers, uses it to start synchronization, and hosts Sync Framework during synchronization. The synchronization application can also register to handle events that are reported back by Sync Framework.

Note

Sync Framework does not cover how an application obtains and instantiates providers, nor how the application determines that a provider is requesting synchronization and which provider it wants to synchronize with.

Implementing a Synchronization Application

A synchronization application can be implemented by using managed or unmanaged code.

Security noteSecurity Note

Sync Framework treats synchronization providers as trusted code. Therefore, an application that invokes a synchronization provider must establish that the provider is trusted either by having explicit knowledge of the provider or by using some other mechanism, such as a digital signature.

Implementing a Synchronization Application by Using Managed Code

An application creates and starts a synchronization session by doing the following:

  1. Creates a SyncOrchestrator object.

  2. Sets the LocalProvider and RemoteProvider properties of the orchestrator.

  3. Sets the Direction property of the orchestrator to the appropriate synchronization direction. In the Upload direction, the LocalProvider object is the source and the RemoteProvider object is the destination. In the Download direction, the LocalProvider object is the destination and the RemoteProvider object is the source. Be aware that two-way synchronization can be performed by using DownloadAndUpload or UploadAndDownload.

  4. Calls the Synchronize method of the orchestrator. This creates a session on the behalf of the application that will handle all additional synchronization tasks. If the application wants to cancel synchronization, it can call the Cancel method.

Implementing a Synchronization Application by Using Unmanaged Code

An application creates and starts a synchronization session object by doing the following:

  1. Creates an IApplicationSyncServices object. This is done by calling CoCreateInstance and passing it CLSID_SyncServices for the CLSID and IID_IApplicationSyncServices for the IID.

  2. Creates an ISyncSession object. This is done by calling the IApplicationSyncServices::CreateSyncSession method. Two providers are passed to this method: one as the destination provider and one as the source provider.

  3. Calls the ISyncSession::Start method. Then, Sync Framework handles all additional synchronization tasks. If the application wants to cancel synchronization, the ISyncSession::Cancel method can be called.

  4. After synchronization is complete, two-way synchronization can be achieved by creating another session object, reversing which provider is the source and which the destination, and calling ISyncSession::Start on the new session object.

For more information about how to create a synchronization application, see How to: Create an Unmanaged Synchronization Application.

Synchronization Events

An application can register to be notified of various events during synchronization. The two main reasons to handle events are to track progress and to implement custom conflict handling.

Managed code Implement event handler methods and register them with the SyncOrchestrator object or a SyncCallbacks object.

Unmanaged code Use the ISyncSession::RegisterCallback method to register an object that implements the ISyncCallback interface.

For more information, see Responding to Synchronization Events.

See Also

Reference

IApplicationSyncServices Interface
ISyncSession Interface
ISyncCallback Interface
SyncOrchestrator
SyncCallbacks

Concepts

Fundamentals of Data Synchronization
Responding to Synchronization Events

Other Resources

Microsoft Sync Framework