Saturday, June 15, 2013

Introduction to Microsoft Sync Framework

Overview
Microsoft Sync Framework is a comprehensive synchronization platform that enables collaboration and offline access for applications, services, and devices. It features technologies and tools that enable roaming, sharing, and taking data offline. Using Microsoft Sync Framework, developers can build sync ecosystems that integrate any application, with any data from any store using any protocol over any network.

Benefits of Synchronization

Synchronization can be described as the process of bringing together two end points or data stores. When the contents of the two data stores are the same, they are known to be in sync with each other. For example, if you want to synchronize two databases manually,
you do the following.

1      1    Determine changes in the source database.
  2     Send the changes to the destination database.
  3      Apply the source’s changes to the destination database.
  4   Repeat the previous steps by swapping the source and destination databases.


·         Takes the application, store, or services offline: The biggest advantage of synchronization is that it enables you to take your application offline. If you build synchronization into your application, users of the application can interact with their local data stores until they need the items that are not contained in a local repository or until the application is back online.

·         Builds a faster and richer user interface: Building synchronization into the application allows you to build a richer user interface without worrying about the performance of the application. Because data is usually fetched from a local store, your application can provide faster responses.

·         Reduces the network cost: Sync-enabled applications or services upload and download only incremental changes, thereby reducing the amount of the data that needs to be sent over the network.

Now that you understand the need for synchronization, the next section examines some issues associated with synchronization and how Sync Framework can resolve them.

Life Before Sync Framework

The importance of Sync Framework can’t be understood without discussing problems
involved while implementing synchronization, including the following:

·    Storage and application errors and failover handling: Imagine that you’re synchronizing two databases, and an application error such as a connection timeout or a constraint violation occurs while changes to the destination database are applied. What happens to the record that needs to be synchronized? It is the responsibility of the Sync Framework to recover from such application and storage errors. 


   •   Network failure: Imagine the same example of synchronizing two databases. What
happens if one of the databases is downloading changes from another and suddenly
the Internet connection goes down? Sync Framework can recover the network
failures.
  •   Conflict detection: A conflict is said to occur if the same item was modified at both
end points at the same time. The Sync Framework should be able to detect the
conflicts and provide a mechanism to resolve or log the conflicts.

Installing Microsoft Sync Framework

At the time of writing, Microsoft Sync Framework 1.0 was the latest release. You can get a
copy of the Microsoft Sync Framework software development kit (SDK) in three ways:

   • Sync Framework ships with Microsoft SQL Server 2008.

  • Sync Framework ships with Microsoft Visual Studio 2008 Service Pack 1.

  • You can download the Sync Framework from the Microsoft download page:

www.microsoft.com/downloads/details.aspx?FamilyId=C88BA2D1-CEF3-4149-
B301-9B056E7FB1E6&displaylang=en.

Core Components

The Sync Framework comes with support for ADO.NET, file systems, RSS, Atom feeds,
and even custom data stores. You can divide the components of the Sync Framework into
the following three categories:

  • Microsoft Sync Framework runtime: This SDK allows developers to use the built-in
sync providers and create their own sync providers.

   • Metadata services: Provide the necessary infrastructure to store the sync metadata.
Sync metadata is used by the Sync Framework runtime during the synchronization.
The Sync Framework ships with the built-in Microsoft SQL Server Compact Edition
(CE) that can be used to store the metadata.
  • Built-in providers: The Sync Framework ships with the following three built-in
providers:

o    Synchronization services for ADO.NET provide offline and collaboration support
for ADO.NET enabled data stores.
o    Synchronization services for SSEs are the built-in providers for synchronizing RSS
and Atom feeds.
o    Synchronization services for file systems are the built-in providers for synchronizing
files and folders on Win32-compatible file systems. 




Synchronization Flow:

Synchronization providers enable you to synchronize data between different replicas.
Replicas are also known as end points or data stores. The actual data is stored in the replica. You need to have one sync provider for each replica for the replica to synchronize its data with other replicas. A replica synchronizes its data with another replica by establishing a sync session.


As shown in below screen shot, synchronization providers communicate with each other using a sync session. The two sync providers are attached to the sync agent, and the sync application initiates the communication between the two providers using the sync agent. The sync agent is responsible for establishing and managing the sync session. Sync providers can receive and apply changes to the replicas. There are two sync providers on the top of the Sync Framework runtime: the source sync provider and destination sync provider, respectively.

After being invoked by a sync agent, the destination sync provider sends its knowledge
to the source sync provider. The source provider uses this knowledge to determine the
changes and sends its knowledge to the destination. The destination provider compares
its knowledge with the source, resolves the conflicts, and then sends the request to the
source provider for changed data. The source provider sends the changes to the destination
provider, and the destination provider applies the changes to the destination replica.
Within a sync session, synchronization flow is always in one direction. What this means is
that the source provider and the destination provider cannot work simultaneously. At any
given point within a sync session, information flows between the source and destination
replicas or between destination and source replicas, but doesn’t flow simultaneously
between both.

In its simple form, a sync session contains a sync agent and two sync providers. One of the providers is a source provider that sends the changes; the other is a destination provider that receives and applies the changes. Of course, the sync agent controls this flow.

The sync providers shown in below screen shot illustrate a scenario in which the metadata is
stored in the built-in metadata store provided by the Sync Framework, which is very easy
to use and is built on top of the SQL Server.




Click here to create sample application using Microsoft sync framework.

















No comments:

Post a Comment