Listening to a section on Teched2008 about the MSF (Microsoft Sync Framework), a framework that allows developers to create offline applications, devices, and services that can be integrated with any type of data that is applied.
There are some links on the web about this mold frame, and some friends in the garden have done the introduction. At that time the thing is good, only then will know. Today's article is a simple trial of MSF to develop Ado.net Sync Demo (of course it also supports the synchronization of files and folders, I will later write the article to introduce research experience). Because it is the first use, so there are more screenshots, of course, in the concept of understanding may also be biased, have developed experience in this area friends welcome corrections.
All right, let's start with the body.
Before you develop this application, assume that you have downloaded and installed the appropriate MSF framework service Pack and SDK, and if your friends are not installed, download and install them yourself.
I downloaded the installation is: Syncsetup_zh-chs.x86.zip (because this article vs is in Chinese, so I used the Microsoft Sync Framework v1.0-Simplified Chinese) Of course, the current version of the framework is Sync The Framework v2 CTP1 (currently there is no Chinese development package and does not support component synergy between versions 1.0 and 2.0 interoperability).
First of all, we need to understand the implementation of the framework to achieve ado.net synchronization principle. Take a look at the picture below:
We can see that there is a set of (two) Provider between the client database (SqlServerCompact3.5) and the server-side data (servers). respectively, Clientsyncprovider and Serversyncprovider, of which:
Clientsyncprovider for:
A client synchronization provider that extracts (for) communication with the client data store (SqlServerCompact3.5) and isolates the synchronization agent (SyncAgent) from the specific implementation of the data store. That's clear. This object is used to communicate with the local data store.
Serversyncprovider for:
A generic server synchronization provider that extracts (for) communication with the server data store (serverdatabase) and isolates the synchronization agent from the specific implementation of the data store. This object is used to communicate with the remote data store.
These two objects are provided by property in the following SyncAgent class: The syncagent in the diagram is used for the object organization synchronization process. of which:
The Synchronize () method synchronizes data between local and remote data stores (used below).
Localprovider property: Gets or sets an object that derives from Clientsyncprovider.
Remoteprovider property: Gets or sets an object that derives from Serversyncprovider.
The SyncTable object in the figure represents the client settings for the tables involved in the synchronization process. For example, we can set this value to represent the synchronization direction relative to the client by using the SyncDirection property, which is an enumeration, including the following values:
Bidirectional: During the first synchronization, the client typically downloads the schema and an initial dataset from the server. When a subsequent synchronization is performed, the client uploads the changes to the server and then downloads the changes from the server.
Downloadonly: During the first synchronization, the client typically downloads the schema and an initial dataset from the server. When performing subsequent synchronizations, the client downloads changes from the server.
Snapshot: The client downloads a dataset from the server. The data is completely refreshed during each synchronization (demonstrated in this article) Uploadonly: During the first synchronization, the client usually downloads the schema from the server. When a subsequent synchronization is performed, the client uploads the changes to the server.
The syncadapter in the diagram is used to provide a set of data commands that are used to obtain schema information and to retrieve and apply changes (through SQL statements or stored procedures) in the server database.
Of course, the structure in the diagram is somewhat complex and involves more classes. But we don't have to write this code by hand. This class is generated as long as you follow the steps of the navigation. The following is a snapshot of the way (Snapshot) to develop a demo to probably understand the corresponding operating procedures.