Tag Archives: SyncFramework

Microsoft Sync Framework using IronRuby

25 Dic

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.

In these days we used Microsoft Sync Framework to develop some occasionally connected application. These application use Microsoft Sync Framework to synchronize their local storage with the centralized database hosted on-line.

Microsoft Sync Framework includes a number of providers that support common data sources. The following providers are included:

  • Sync Services for ADO.NET: Synchronization for ADO.NET enabled data sources
  • Sync Services for File Systems: Synchronization for files and folders
  • Sync Services for FeedSync: Synchronization for RSS and ATOM feeds

Key features of the File system provider include:

    • Incremental synchronization of changes between two file system locations specified via a local or UNC path.
    • Synchronization of file contents, file and folder names, file timestamps, and attributes.
    • Support for optional filtering of files based on filename/extensions, sub-directories, or file attributes
    • Optional use of file hashes to detect changes to file contents if file timestamps are not reliable
    • Reliable detection of conflicting changes to the same file and automatic resolution of conflicts with a no-data-loss policy
    • Allow for limited user undo operation by optionally allowing file deletes and overwrites to be moved to the Recycle Bin
    • Support for Preview mode which provides a preview of the incremental sync operation without committing changes to the file system
    • First-class support for the scenario where the user may start synchronization with equal or partially equal file hierarchies on more than one replica.
    • Support for graceful cancellation of an ongoing sync operation such that the remaining changes can be synchronized later without having to re-sync changes that were already synchronized.

An example of Sync Services for File Systems usage can be found here. In order to test IronRuby I decided to convert this sample from C# to Ruby

require "mscorlib" require "Microsoft.Synchronization.dll" require "Microsoft.Synchronization.Files.dll" include System include Microsoft::Synchronization include Microsoft::Synchronization::Files class Syncronizer def DoWork replica1RootPath, replica2RootPath idFileName = "filesync.id"; replica1Id = GetReplicaId( replica1RootPath + "/" + idFileName) replica2Id = GetReplicaId( replica2RootPath + "/" + idFileName) options = FileSyncOptions.RecycleDeletedFiles filter = FileSyncScopeFilter.new filter.FileNameExcludes.Add idFileName DetectChangesOnFileSystemReplica replica1Id, replica1RootPath, filter, options DetectChangesOnFileSystemReplica replica2Id, replica2RootPath, filter, options SyncFileSystemReplicasOneWay replica1Id, replica2Id, replica1RootPath, replica2RootPath, filter, options SyncFileSystemReplicasOneWay replica2Id, replica1Id, replica2RootPath, replica1RootPath, filter, options end def GetReplicaId path id = Guid.NewGuid if File.exist? path str = File.read path id = Guid.new(str) else File.open(path, 'w') {|f| f.write(id.ToString) } end id end def DetectChangesOnFileSystemReplica replicaId, rootPath, filter, options provider = FileSyncProvider.new(replicaId, rootPath, filter, options) provider.DetectChanges; provider.Dispose end def SyncFileSystemReplicasOneWay sourceReplicaId, destinationReplicaId, sourceReplicaRootPath, destinationReplicaRootPath, filter, options agent = SyncOrchestrator.new agent.LocalProvider = FileSyncProvider.new(sourceReplicaId, sourceReplicaRootPath, filter, options) agent.RemoteProvider = FileSyncProvider.new(destinationReplicaId, destinationReplicaRootPath, filter, options) agent.Direction = SyncDirectionOrder.Upload agent.Synchronize end end sync = Syncronizer.new sync.DoWork "D:/tmp/SyncFXSamples/A", "D:/tmp/SyncFXSamples/B"

I have uploaded a little zip here that contains all the stuff you need to get ready. If you want to run the sample you have to run the command: ir sync.rb as show below


Technorati Tag: ,