23
Microsoft Sync Framework (part 2) A COMPREHENSIVE SYNCHRONIZATION PLATFORM THAT ENABLES COLLABORATION AND OFFLINE ACCESS FOR APPLICATIONS, SERVICES, AND DEVICES WITH SUPPORT FOR ANY DATA TYPE, ANY DATA STORE, ANY TRANSFER PROTOCOL, AND ANY NETWORK TOPOLOGY by Sergij Garntsarik

Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

Embed Size (px)

Citation preview

Page 1: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

Microsoft Sync Framework (part 2)A COMPREHENSIVE SYNCHRONIZATION PLATFORM THAT ENABLES COLLABORATION AND OFFLINE ACCESS FOR APPLICATIONS,

SERVICES, AND DEVICES WITH SUPPORT FOR ANY DATA TYPE, ANY DATA STORE, ANY TRANSFER PROTOCOL, AND ANY NETWORK

TOPOLOGY

by Sergij Garntsarik

Page 2: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

2SynchronizationThe ability to support mobile and remote workers is becoming more and more important for organizations every day. It is critical that organizations ensure users have access to the same information they have when they are in the office. In most cases, these workers will have some sort of laptop, office desktop, Smartphone, or PDA. From these devices, users may be able to access their data directly through VPN connections, Web servers, or some other connectivity method into the corporate networks as seen below.

Page 3: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

3Disadvantages1. Network Requirements: In order to allow users to access their information, the

remote device needs to have a constant connection to the corporate network while accessing their data. For some workers, such as those who are working from home, this may not be a problem. For others, such as sales reps who are constantly on the move, this may be more difficult. For example, if that sales rep were visiting a customer and was unable to access inventory data because of a lack of network connectivity, it would be very difficult for this user to effectively do their job.

2. Data Access Speeds: In a typical client/server corporate environment, users have high speed networks that allow them quick access to information. Remote workers, however, are typically connected over slow, unreliable wired or wireless networks. With this solution, every piece of data this user needed would need to be downloaded every time it is requested because there is no way to persist the data on the device. For example, if a sales rep is required to download his product list every time he opens his application, he will quickly become frustrated with the time lag required to populate his application with information.

3. Single Point of Failure: With this type of solution, all users are reliant on a single server. If that database becomes unavailable due to planned server downtime or from server failures, all of the remote workers will be disconnected from their data.

4. Server Scalability: As more workers work remotely, the performance of the corporate servers will be affected, leading to a need to add additional hardware.

Page 4: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

4Occasionally Connected Application (OCA)OCA allows a remote worker to continue to access their data, but unlike the previous scenario where the user accessed the corporate database directly, the information the worker requires is stored locally on the user’s device

Page 5: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

5SQL Server 2008 Change TrackingThe concept behind change tracking is that an administrator marks certain tables to be monitored for changes. From that point SQL Server 2008 keeps tracks of any inserts, updates, or deletes that are made

✎ No schema changes are required to be able to track changes.✎ Triggers are not required for tracking changes, which means that tracking

changes has far less of an impact on the server. ✎ All of the logic for tracking changes is internal to the SQL Server engine

and as such reduces the complexity for setting up this type of system.✎ Data consistency issues associated with long running transactions are no

longer an issue.✎ Includes integrated database administration feature such as Dynamic

Management Views and Security.

Page 6: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

6ConflictsTypes of Conflicts and Errors

Sync Framework detects the following types of conflicts. These are defined in the ConflictType enumeration:

✎ ClientInsertServerInsert conflict occurs when the client and server both insert a row with the same primary key. This type of conflict is also known as a primary key collision.

✎ ClientUpdateServerUpdate conflict occurs when the client and server change the same row. This is the most common type of conflict.

✎ ClientUpdateServerDelete conflict occurs when the client updates a row and the server deletes the same row.

✎ ClientDeleteServerUpdate conflict occurs when the client deletes a row and the server updates the same row.

✎ ErrorsOccurred conflict occurs when an error prevents a row from being applied.

Page 7: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

7Conflict and Error Resolution

The SqlCeClientSyncProvider also includes a ConflictResolver property that you can use to resolve conflicts on the client. For each type of conflict, you can set a value from the ResolveAction enumeration:

✎ ClientWins: equivalent to setting an ApplyAction of Continue.

✎ ServerWins: equivalent to setting an ApplyAction of RetryWithForceWrite.

✎ FireEvent: fire the ApplyChangeFailed event, the default, and then handle the event.

Page 8: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

8

Synchronizing FilesSYNCHRONIZE FILES AND FOLDERS IN NTFS, FAT, AND SMB FILE SYSTEMS. THE DIRECTORIES TO SYNCHRONIZE CAN BE LOCAL OR REMOTE AND DO NOT HAVE TO BE OF THE SAME FILE SYSTEM TYPE

Page 9: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

9Benefits of Using Sync Framework1. An extensible model that lets you integrate multiple data sources into a

synchronization ecosystem.

2. A managed API for all components, and a native API for select components.

3. Conflict handling for automatic and custom resolution schemes.

4. Filters that let you synchronize a subset of data, such as only those files that

contain images.

5. A compact and efficient metadata model that enables synchronization for

virtually any participant, without significant changes to the data store:✎ Any data store (applications, services, and devices)✎ Any data type✎ Any protocol✎ Any network configuration (Easily recover from network interruptions.

Reduce network traffic by efficiently selecting changes to synchronize)

Page 10: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

10Sync Framework ArchitectureElements that are written by the developer.✎ The application calls

synchronization methods, responds to events, and handles other tasks based on application requirements.

✎ The data store could be a file system, a relational database, a flat file contacts store, or any other data store that needs to be synchronized.

✎ The data transfer protocol determines how data changes are transmitted between two providers.

Elements that are provided by Sync Framework.

✎ Depending on whether native code or managed code is used, the application communicates with a synchronization session or a synchronization orchestrator, which then communicates with each synchronization provider.

✎ The synchronization runtime drives the synchronization process and communicates status, conflicts, and errors to the client application.

Elements that are either written by the developer or provided by Sync Framework, depending on the scenario.

✎ The provider is specific to the type of data that is being synchronized. In some situations, an application requires a custom provider that the developer must write. Sync Framework provides a number of APIs to make this process more straightforward.

✎ How metadata is stored and worked with depends on which provider is used. For example, providers for databases typically store metadata in tracking tables in the same database as the data store. For custom providers, you can create a metadata store or use a service that is included with Sync Framework.

Page 11: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

11Controlling Which Files Are SynchronizedExcluded and Unsupported File and Folder Types✎ Thumbs.db when the hidden and system attributes are set.✎ Desktop.ini when the hidden and system attributes are set.✎ The metadata file that was specified when the provider was initialized.✎ A file that has the offline or device attribute set.✎ A folder that has the reparse point attribute set.Static Filters ( FileSyncScopeFilter )Static filters can be set to exclude files by name (including wildcard names) and by attribute. Static filters can also be set to exclude the contents of whole subfolders, but wildcards are not supported for subfolders

Skipping Files (SkipChange property)Files can be dynamically skipped during synchronization by handling an event raised by the provider. This event occurs during change application

Page 12: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

12Understanding File SynchronizationTo synchronize files between two folders, an application completes the following basic steps:

Creates an FileSyncProvider object to represent

each folder.

Passes the two providers to an

SyncOrchestrator object, and specifies one as the source provider and the other as the destination provider.

Calls Synchronize to start the

synchronization session.

Page 13: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

13Setting Synchronization Options

Performing Change Detection

Page 14: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

14Specifying a Static Filter

Handling Conflicts

Page 15: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

15

Synchronizing Two Replicas

After options and filters are set, the application synchronizes the two replicas by instantiating a SyncOrchestrator, and calling the Synchronize method

SyncDirectionOrder Enumeration

UploadAndDownload Upload followed by download.

DownloadAndUpload Download followed by upload.

Upload Upload only.

Download Download only.

Page 16: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

16

Custom Synchronization ProvidersSYNC FRAMEWORK INCLUDES PROVIDERS FOR SEVERAL STANDARD SYNCHRONIZATION SCENARIOS, BUT IN SOME SITUATIONS A CUSTOM PROVIDER IS NECESSARY

Page 17: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

17Sync Framework Architecture

Elements that are written by the developer.

✎ The application starts synchronization, responds to events, and handles other tasks based on application requirements.

✎ The provider manages the metadata for a replica and works with Sync Framework to enumerate changes and detect conflicts. The provider also works with the data store of a replica to send item data when the provider is acting as the source provider, and to apply changes when the provider is acting as the destination provider.

Elements that are provided by Sync Framework.

✎ Depending on whether managed or unmanaged code is used, the application communicates with a synchronization orchestrator (SyncOrchestrator) or a synchronization session (ISyncSession), which then communicates with each synchronization provider, drives the synchronization process, and communicates status, conflicts, and errors to the client application.

✎ The synchronization runtime helps the providers perform common synchronization tasks, such as metadata management, conflict detection, and change application.

Elements that are either written by the developer or provided by Sync Framework, depending on the scenario.

✎ The metadata store contains the metadata that Sync Framework uses to determine which changes each provider should select from and apply to the data store that it services. The metadata store can be separate from the data store (such a separate file or database), or integrated into the store (such an extra table in a database). Typically, the synchronization provider manages the metadata that is required for synchronization.

Page 18: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

18Understanding Sync Framework Participant TypesSync Framework can be used to synchronize data among participants of varying

functionality. A participant is a device or service that can synchronize with other systems

that are running Sync Framework.

Sync Framework supports the following types of participants:

✎ Full participant

✎ Proxy participant

✎ Partial participant

✎ Simple participant

Page 19: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

19Partial Participant

A partial participant can store synchronization metadata but cannot process it. A partial participant relies on several full participants to host the runtime and start synchronization. Data can flow through these participants because they can carry the multimaster synchronization metadata and communicate this metadata with any other full participant. Partial participants cannot take part in peer-to-peer scenarios because of their inability to process the metadata or host the runtime.

Full ParticipantA full participant locally hosts the runtime and stores metadata. Full participants can take part in peer-to-peer synchronization scenarios because both participants can start synchronization.

Page 20: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

20Simple Participant

A simple participant does not store metadata, cannot house the runtime, and might not have change tracking. Instead, a simple participant relies on a single full participant to do everything with regard to enumerating changes, applying changes, and manipulating and storing the metadata. Because a simple participant cannot store metadata, it can only act as a leaf node that is partnered with a single full participant that transfers data to and from any other participants.

Proxy Participant

A proxy participant starts synchronization for a remote provider by handling calls locally and forwarding them to the remote provider, such as a database that is stored on a server.

Security Note

Sync Framework does not provide authentication or encryption between the proxy provider and the remote provider. To help prevent unauthorized access or tampering, the communication channel between the proxy provider and the remote provider must be secured by using an appropriate mutual authentication and encryption mechanism, such as Secure Sockets Layer (SSL).

Page 21: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

21The main task when you are developing a provider is to implement the KnowledgeSyncProvider abstract class (which inherits from the SyncProvider abstract class) and the IChangeDataRetriever and INotifyingChangeApplierTarget interfaces.

Page 22: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

22

Code samples

Page 23: Microsoft Sync Framework (part 2) ABTO Software Lecture Garntsarik

23

Questions