I make synchronization between two SQL Express DB, one is server other one is client.
I have next code what make synchronization:
/// <summary>
/// Sync to Providers
/// </summary>
/// <param name="localProvider">can be RelationalProvider Proxy !!! (WCF)</param>
/// <param name="remoteProvider">RelationalProvider Proxy !!! (WCF)</param>
/// <param name="syncDirectionOrder"></param>
/// <returns></returns>
private SyncOperationStatistics SynchronizeProviders(KnowledgeSyncProvider localProvider, KnowledgeSyncProvider remoteProvider, SyncDirectionOrder syncDirectionOrder)
{
localProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.RenameDestination;
localProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins;
remoteProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.RenameSource;
remoteProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.DestinationWins;
SubscribeResultEvent(localProvider);
SyncOrchestrator orchestrator = new SyncOrchestrator
{
LocalProvider = localProvider,
RemoteProvider = remoteProvider,
Direction = syncDirectionOrder
};
SyncOperationStatistics stats = orchestrator.Synchronize();
return stats;
}
I do not know why but my server db is always win, does not matter server is localProvider
or
RemoteProvider
, and rewrite client data, but I want to make setting what client is always win.
But I can't understand how MS Sync Framework do it.
What I need to setup ?
thanks !
In Sync Framework you can specify the conflict resolution policy on the synchronization providers, as described on MSDN:
Microsoft Sync Framework supports some simple conflict resolution by default. You can configure the conflict resolution policy of the provider and the Sync Framework will perform conflict resolution for you. By default, the Sync Framework supports the following five types of conflict resolution policy.
Source wins: the source replica always wins if there is a conflict.
Destination wins: the destination replica always wins if there is a conflict.
Merge: the changes from both source and destination are merged to form a new version of the item, which is then sent to the destination to be applied.
Log: conflicts are ignored and the conflicting item information is sent to the SaveConflict event of the class implementing INotifyingChangeApplierTarget.
Defer: completely ignore the conflicts and the destination store will not receive information regarding the conflicts.
All of these conflict resolution policies are applicable at item level but only source wins and destination wins apply to session. Sync policy is specified for the provider by setting the ConflictResolutionPolicy property.
destinationProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.DestinationWins;
So you can't specify directly whether you want the client or server to win all the time, because it depends on the direction the data is being synchronized as to which provider is the source/destination.
You can also write a custom provider and override the conflict resolution event to specify more complex custom conflict handling. A discussion of that can be found here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317247%28v=VS.85%29.aspx.