Microsoft Sync Framework includes a number of providers that support common data sources. The following providers are included:
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"