locked
Sync Framework 1.0 and vb.net RRS feed

  • Question

  •  

    Hello, I have the below code I found online. I have downloaded Microsofts SDK and everything for the Sync Framework. I have also included the imports listed as references to the project however, this code gives me nothing but errors.

    Has anybody out there had any success with the Sync Framework.

    Please help if you can...

      

    Imports Microsoft.Synchronization
    Imports Microsoft.Synchronization.Files
    Imports System.IO


    Module Module1


    Sub Main()


    'Define directories
    Dim _sourceDir As String = "c:\temp\1"
    Dim _destDir As String = "c:\temp\2"


    'Define system ids
    Dim _sourceId As SyncId = New SyncId(New Guid("A4715EAF-341E-4ebf-90C3-71E8644CA6E8"))
    Dim _destId As SyncId = New SyncId(New Guid("FF766014-0DA4-401d-BDA1-0679326ECF96"))


    'Exclude some patterns
    Dim _syncFilter As FileSyncScopeFilter = New FileSyncScopeFilter()
    _syncFilter.AttributeExcludeMask = FileAttributes.Hidden Or FileAttributes.System
    _syncFilter.FileNameExcludes.Add("DoNotCopy.txt")
    _syncFilter.SubdirectoryExcludes.Add("DoNotCopy")


    'Setup options (makes sure files aren't deleted for ever)
    Dim _syncOptions As FileSyncOptions = FileSyncOptions.RecycleDeletes Or FileSyncOptions.RecycleOverwrites


    'Do the sync
    Using _sourceProvider As FileSyncProvider = New FileSyncProvider(_sourceId, _sourceDir, _syncFilter, _syncOptions)
    Using _destinationProvider As FileSyncProvider = New FileSyncProvider(_destId, _destDir, _syncFilter, _syncOptions)


    Dim _syncAgent As SyncAgent = New SyncAgent()
    _syncAgent.LocalProvider = _sourceProvider
    _syncAgent.RemoteProvider = _destinationProvider
    _syncAgent.Direction = SyncDirection.UploadAndDownload
    _syncAgent.Synchronize()


    End Using
    End Using


    End Sub


    End Module
    Tuesday, September 16, 2008 8:26 PM

Answers

  • I looked into the issue.  It appears some of the code may have been based on an earlier CTP of the Sync Framework.  The following changes make it compile:

     

    FileSyncOptions.RecycleDeletes -> FileSyncOptions.RecycleDeletedFiles

    FileSyncOptions.RecycleOverwrites -> FileSyncOptions.RecyclePreviousFileOnUpdate

    The FileSyncProvider constructors take a Guid rather than a SyncId.

    SyncAgent should be replaced with SyncOrchestrator (SyncAgent is used for Sync Services for ADO.NET).

    SyncDirection -> SyncDirectionOrder (SyncDirection is also used for Sync Services for ADO.NET).

     

    I got the following code to compile:

     

    Code Snippet

    Imports Microsoft.Synchronization

    Imports Microsoft.Synchronization.Files

    Imports System.IO

    Module Module1

     

    Sub Main()

     

    'Define directories

    Dim _sourceDir As String = "c:\temp\1"

    Dim _destDir As String = "c:\temp\2"

     

    'Define system ids

    Dim _sourceId As Guid = New Guid("A4715EAF-341E-4ebf-90C3-71E8644CA6E8")

    Dim _destId As Guid = New Guid("FF766014-0DA4-401d-BDA1-0679326ECF96")

     

    'Exclude some patterns

    Dim _syncFilter As FileSyncScopeFilter = New FileSyncScopeFilter()

    _syncFilter.AttributeExcludeMask = FileAttributes.Hidden Or FileAttributes.System

    _syncFilter.FileNameExcludes.Add("DoNotCopy.txt")

    _syncFilter.SubdirectoryExcludes.Add("DoNotCopy")

     

    'Setup options (makes sure files aren't deleted for ever)

    Dim _syncOptions As FileSyncOptions = FileSyncOptions.RecycleDeletedFiles Or FileSyncOptions.RecyclePreviousFileOnUpdates

     

    'Do the sync

    Using _sourceProvider As FileSyncProvider = New FileSyncProvider(_sourceId, _sourceDir, _syncFilter, _syncOptions)

    Using _destinationProvider As FileSyncProvider = New FileSyncProvider(_destId, _destDir, _syncFilter, _syncOptions)

     

    Dim _syncAgent As SyncOrchestrator = New SyncOrchestrator()

    _syncAgent.LocalProvider = _sourceProvider

    _syncAgent.RemoteProvider = _destinationProvider

    _syncAgent.Direction = SyncDirectionOrder.UploadAndDownload

    _syncAgent.Synchronize()

     

    End Using

    End Using

     

    End Sub

    End Module

     

    -Aaron
    Wednesday, September 17, 2008 12:54 AM

All replies

  • I looked into the issue.  It appears some of the code may have been based on an earlier CTP of the Sync Framework.  The following changes make it compile:

     

    FileSyncOptions.RecycleDeletes -> FileSyncOptions.RecycleDeletedFiles

    FileSyncOptions.RecycleOverwrites -> FileSyncOptions.RecyclePreviousFileOnUpdate

    The FileSyncProvider constructors take a Guid rather than a SyncId.

    SyncAgent should be replaced with SyncOrchestrator (SyncAgent is used for Sync Services for ADO.NET).

    SyncDirection -> SyncDirectionOrder (SyncDirection is also used for Sync Services for ADO.NET).

     

    I got the following code to compile:

     

    Code Snippet

    Imports Microsoft.Synchronization

    Imports Microsoft.Synchronization.Files

    Imports System.IO

    Module Module1

     

    Sub Main()

     

    'Define directories

    Dim _sourceDir As String = "c:\temp\1"

    Dim _destDir As String = "c:\temp\2"

     

    'Define system ids

    Dim _sourceId As Guid = New Guid("A4715EAF-341E-4ebf-90C3-71E8644CA6E8")

    Dim _destId As Guid = New Guid("FF766014-0DA4-401d-BDA1-0679326ECF96")

     

    'Exclude some patterns

    Dim _syncFilter As FileSyncScopeFilter = New FileSyncScopeFilter()

    _syncFilter.AttributeExcludeMask = FileAttributes.Hidden Or FileAttributes.System

    _syncFilter.FileNameExcludes.Add("DoNotCopy.txt")

    _syncFilter.SubdirectoryExcludes.Add("DoNotCopy")

     

    'Setup options (makes sure files aren't deleted for ever)

    Dim _syncOptions As FileSyncOptions = FileSyncOptions.RecycleDeletedFiles Or FileSyncOptions.RecyclePreviousFileOnUpdates

     

    'Do the sync

    Using _sourceProvider As FileSyncProvider = New FileSyncProvider(_sourceId, _sourceDir, _syncFilter, _syncOptions)

    Using _destinationProvider As FileSyncProvider = New FileSyncProvider(_destId, _destDir, _syncFilter, _syncOptions)

     

    Dim _syncAgent As SyncOrchestrator = New SyncOrchestrator()

    _syncAgent.LocalProvider = _sourceProvider

    _syncAgent.RemoteProvider = _destinationProvider

    _syncAgent.Direction = SyncDirectionOrder.UploadAndDownload

    _syncAgent.Synchronize()

     

    End Using

    End Using

     

    End Sub

    End Module

     

    -Aaron
    Wednesday, September 17, 2008 12:54 AM
  • Is the GUID the ID of the devices or just a unique ID that the programmer makes up?  I am very new to this type and am wanting to put this on a program I built, but it will be mass marketed, so I need to know how would I pull up the GUID on different mobile devices?

     

    Thomas Fairris

    Wednesday, September 17, 2008 4:19 AM
  • Hi! The GUID is made up by the programmer. A GUID is used because it represents the ID for the replica. Each replica needs to have its unique ID (GUID). The replica is the metadata store (database) where the sync provider instance writes/reads the meta data to/from.

     

    Let me make an example. You create an instance of the FileSyncProvider and initialize it with a GUID. This GUID is used to create and identify the replica (the metadata store). It is always used to write and read from the meta data store. Now you close your application and restart it. Another instance of the FileSyncProvider is created and this one gets created with the same GUID. Now the new FileSyncProvider instance is able to get access to the same replica (metadata store) and pick up/alter the metadata that was generated by the previous instance because it uses the same GUID and therefore is able to pick up the same metadata.

     

    If you would generate a second GUID to create the second instance of the FileSyncProvider you would access another metadata store.

     

    The GUID is the global identifier for a concrete metadata store that contains the metadata that is used for synchronization.

     

    I hope this helps.

     

    -Christian

    Wednesday, September 17, 2008 6:48 AM
  • Thanks to all. It is working now. However I am still confused as to the GUID.

     

    1. How does the programmer make it up? What are the rules? What format does it have to follow?

     

    2. IS the GUID unique to the folder pair? Do you have to setup a GUID forevery folder pair?

     

    Thank you again....

     

    Kyle

     

    Wednesday, September 17, 2008 12:33 PM
  • I have hit one problem, visual basic 2005 will not reconize the imports microsoft.synchronization and I cannot find a way to import it in the namespace.

     

    Thursday, September 18, 2008 2:02 AM
  • Have you added Microsoft.Synchronization as reference to the project?

    Thursday, September 18, 2008 3:37 AM
  • 1) What do you mean by "format"?

    2) You probably create a new GUID for each folder pair if they point to different folders and you want them to be own replicas (meta data stores).

     

    Thursday, September 18, 2008 3:38 AM
  • Yes, I figured that out after i posted this.  Thanks.

     

    Thursday, September 18, 2008 3:42 AM