Using the new Synchronize()

601
4
08-23-2010 04:46 AM
StephenStarke
New Contributor
We are upgrading from 9.3 to 10.0 and have a problem implementing the new Synchronize() method.
Using the available information we have implemented the following code segment to replace the GetDataAsynch() method:

if (!mobileCache1.IsOpen)
{
   mobileCache1.Close();
}

mobileCache1.Storagepath= localStoragePath;
mobileCache1.DeleteCache();
mobileServiceConnection1.Url = <server url>;
mobileServiceConnection1.WebClientProtocolType=WebClientProtocolType.BinaryWebService;
mobileSync = new MobileCacheSyncAgent(mobileCache1, mobileServiceConnection1);

mobileServiceConnection1.CreateCache(mobileCache1);
mobileCachre1.Open()
mobileSync.Synchronize();
map1.MapLayers.AddRange(mobileCache1);
map1.Refresh();

This code creates the cache on the mobile device but with the follwoing undesirable side effects:

1) When the synchronization starts, the moble device map shows a blank map with only the word "Map" displayed.
2) The "ScaleBar" is not displayed, so there is not visual feedback to indicate that the Synchronization is running.

Once the synchronization completes the map is displayed properly.

What do we need to do to our code to make the new Synchronize() method display as the deprecated GetDataAsync() method?
0 Kudos
4 Replies
ATSIT
by
New Contributor
Hi Stephen,

Did you find solution to this problem. I am in the same situation.

When Calling Synchornize() while posting EDITS on server there is no indication that sychronization is taking place as this is Sycn operation and NOt ASynch.
0 Kudos
StephenDickinson
Esri Contributor
Hi,

On a per layer basis, try using FeatureLayerSyncAgent and its Synchronize method.  I believe this is still synchronous but provides feedback via ProgressChanged and StateChanged events.  It also provides a FeatureLayerSyncResults object as the return result of calling Synchronize.

Thanks,
Steve
0 Kudos
StevenSchuldt
New Contributor
After you've created your cache, loop through the layers you want to sync and add them to a  MobileCacheSyncAgent, then you can call BeginDownloadExtent on the MobileCacheSyncAgent and it will do async downloads for you.

Sorry it's not complete code - I just pulled bits and pieces to show the concepts.



                //property for mobile sync agent
  public MobileCacheSyncAgent SyncMaster { get; set; }

                //snippet which initializes the sync agents for download
  SyncMaster.SyncAgents.Clear();
  SetupSyncAgents();
  SyncMaster.BeginDownloadExtent(mobileCache1.GetInitialExtent(), 0, 0, DownloadExtent, Guid.NewGuid());


                //procedure to setup the sync agents for downloads
  private void SetupSyncAgents() {
   foreach (Layer l in this.mobileCache1.Layers) {
    if (l is FeatureLayer) {
     var fl = (FeatureLayer)l;
     FeatureLayerSyncAgent agent = new FeatureLayerSyncAgent(fl);
     agent.MapDocumentConnection = this.mobileServiceConnection1;
     agent.SynchronizationDirection = SyncDirection.DownloadOnly;
     SyncMaster.SyncAgents.Add(agent);
    }

    if (l is RasterLayer) {
     var rl = (RasterLayer)l;
     RasterLayerSyncAgent agent = new RasterLayerSyncAgent(rl);
     agent.Extent = this.map1.GetExtent();
     agent.MapDocumentConnection = this.mobileServiceConnection1;
     SyncMaster.SyncAgents.Add(agent);
    }
   }
  }
0 Kudos
StephenDickinson
Esri Contributor
Yes, good point, this will work for downloading data asynchronously (using the callback parameter of the BeginDownloadExtent method to indicate completion).

Just want to add in reply to the second post in this thread: My understanding is that there isn't a comparable way of uploading data asynchronously i.e. there isn't a BeginUploadExtent method.  Therefore, you might need to use FeatureLayerSyncAgent and its Synchronize method for this case.
0 Kudos