private async Task SyncGeodatabase() { // Return if not ready. if (_readyForEdits != EditState.Ready) { return; } // Disable the sync button. SyncButton.IsEnabled = false; // Create parameters for the sync task. SyncGeodatabaseParameters parameters = new SyncGeodatabaseParameters() { GeodatabaseSyncDirection = SyncDirection.Bidirectional, RollbackOnFailure = false }; // Get the layer ID for each feature table in the geodatabase, then add to the sync job. foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Get the ID for the layer. long id = table.ServiceLayerId; // Create the SyncLayerOption. SyncLayerOption option = new SyncLayerOption(id); // Add the option. parameters.LayerOptions.Add(option); } // Create job. SyncGeodatabaseJob job = _gdbSyncTask.SyncGeodatabase(parameters, _resultGdb); // Subscribe to progress updates. job.ProgressChanged += (o, e) => { // Update the progress bar. UpdateProgressBar(job.Progress); }; // Show the progress bar. GenerateSyncProgressBar.Visibility = Visibility.Visible; // Start the sync. job.Start(); // Wait for the result. await job.GetResultAsync(); // Hide the progress bar. GenerateSyncProgressBar.Visibility = Visibility.Collapsed; // Do the remainder of the work. HandleSyncCompleted(job); // Re-enable the sync button. SyncButton.IsEnabled = true; }
// Synchronize edits in the local geodatabase with the service. private async void SynchronizeEdits(object sender, EventArgs e) { // Show the progress bar while the sync is working. _progressBar.Hidden = false; try { // Create a sync task with the URL of the feature service to sync. GeodatabaseSyncTask syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(SyncServiceUrl)); // Create sync parameters. SyncGeodatabaseParameters taskParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(_localGeodatabase); // Create a synchronize geodatabase job, pass in the parameters and the geodatabase. SyncGeodatabaseJob job = syncTask.SyncGeodatabase(taskParameters, _localGeodatabase); // Handle the JobChanged event for the job. job.JobChanged += (s, arg) => { InvokeOnMainThread(() => { // Update the progress bar. UpdateProgressBar(job.Progress); switch (job.Status) { // Report changes in the job status. case JobStatus.Succeeded: _statusLabel.Text = "Synchronization is complete!"; _progressBar.Hidden = true; break; case JobStatus.Failed: // Report failure. _statusLabel.Text = job.Error.Message; _progressBar.Hidden = true; break; default: _statusLabel.Text = "Sync in progress ..."; break; } }); }; // Await the completion of the job. await job.GetResultAsync(); } catch (Exception ex) { // Show the message if an exception occurred. _statusLabel.Text = "Error when synchronizing: " + ex.Message; } }
// Synchronize edits in the local geodatabase with the service public async void SynchronizeEdits(object sender, EventArgs e) { // Show the progress bar while the sync is working _progressBar.Visibility = Android.Views.ViewStates.Visible; try { // Create a sync task with the URL of the feature service to sync GeodatabaseSyncTask syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(SyncServiceUrl)); // Create sync parameters SyncGeodatabaseParameters taskParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(_localGeodatabase); // Create a synchronize geodatabase job, pass in the parameters and the geodatabase SyncGeodatabaseJob job = syncTask.SyncGeodatabase(taskParameters, _localGeodatabase); // Handle the JobChanged event for the job job.JobChanged += (s, arg) => { RunOnUiThread(() => { // Update the progress bar UpdateProgressBar(job.Progress); // Report changes in the job status if (job.Status == JobStatus.Succeeded) { _messageTextBlock.Text = "Synchronization is complete!"; _progressBar.Visibility = Android.Views.ViewStates.Gone; } else if (job.Status == JobStatus.Failed) { // Report failure ... _messageTextBlock.Text = job.Error.Message; _progressBar.Visibility = Android.Views.ViewStates.Gone; } else { // Report that the job is in progress ... _messageTextBlock.Text = "Sync in progress ..."; } }); }; // Await the completion of the job await job.GetResultAsync(); } catch (Exception ex) { // Show the message if an exception occurred _messageTextBlock.Text = "Error when synchronizing: " + ex.Message; } }
private async Task SyncGeodatabase() { // Return if not ready. if (_readyForEdits != EditState.Ready) { return; } // Disable the sync button. _syncButton.Enabled = false; // Disable editing. _myMapView.GeoViewTapped -= GeoViewTapped; // Show the progress bar. _progressBar.Hidden = false; // Create parameters for the sync task. SyncGeodatabaseParameters parameters = new SyncGeodatabaseParameters { GeodatabaseSyncDirection = SyncDirection.Bidirectional, RollbackOnFailure = false }; // Get the layer Id for each feature table in the geodatabase, then add to the sync job. foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables) { // Get the ID for the layer. long id = table.ServiceLayerId; // Create the SyncLayerOption. SyncLayerOption option = new SyncLayerOption(id); // Add the option. parameters.LayerOptions.Add(option); } // Create job. _gdbSyncJob = _gdbSyncTask.SyncGeodatabase(parameters, _resultGdb); // Subscribe to progress updates. _gdbSyncJob.ProgressChanged += Job_ProgressChanged; // Start the sync. _gdbSyncJob.Start(); // Get the result. await _gdbSyncJob.GetResultAsync(); // Do the rest of the work. HandleSyncCompleted(_gdbSyncJob); }
// Synchronize edits in the local geodatabase with the service public async void SynchronizeEdits(object sender, EventArgs e) { // Show the progress bar while the sync is working LoadingProgressBar.IsVisible = true; try { // Create a sync task with the URL of the feature service to sync GeodatabaseSyncTask syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(SyncServiceUrl)); // Create sync parameters SyncGeodatabaseParameters taskParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(_localGeodatabase); // Create a synchronize geodatabase job, pass in the parameters and the geodatabase SyncGeodatabaseJob job = syncTask.SyncGeodatabase(taskParameters, _localGeodatabase); // Handle the JobChanged event for the job job.JobChanged += (s, arg) => { // Report changes in the job status if (job.Status == JobStatus.Succeeded) { // Report success ... Device.BeginInvokeOnMainThread(() => MessageTextBlock.Text = "Synchronization is complete!"); } else if (job.Status == JobStatus.Failed) { // Report failure ... Device.BeginInvokeOnMainThread(() => MessageTextBlock.Text = job.Error.Message); } else { // Report that the job is in progress ... Device.BeginInvokeOnMainThread(() => MessageTextBlock.Text = "Sync in progress ..."); } }; // Await the completion of the job await job.GetResultAsync(); } catch (Exception ex) { // Show the message if an exception occurred MessageTextBlock.Text = "Error when synchronizing: " + ex.Message; } finally { // Hide the progress bar when the sync job is complete LoadingProgressBar.IsVisible = false; } }
// Synchronize edits in the local geodatabase with the service public async void SynchronizeEdits(object sender, RoutedEventArgs e) { // Show the progress bar while the sync is working LoadingProgressBar.Visibility = Visibility.Visible; try { // Create a sync task with the URL of the feature service to sync var syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(SyncServiceUrl)); // Create sync parameters var taskParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(_localGeodatabase); // Create a synchronize geodatabase job, pass in the parameters and the geodatabase SyncGeodatabaseJob job = syncTask.SyncGeodatabase(taskParameters, _localGeodatabase); // Handle the JobChanged event for the job job.JobChanged += async(s, arg) => { // Report changes in the job status if (job.Status == JobStatus.Succeeded) { // Report success ... await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageTextBlock.Text = "Synchronization is complete!"); } else if (job.Status == JobStatus.Failed) { // Report failure ... await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageTextBlock.Text = job.Error.Message); } else { // Report that the job is in progress ... await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => MessageTextBlock.Text = "Sync in progress ..."); } }; // Await the completion of the job var result = await job.GetResultAsync(); } catch (Exception ex) { // Show the message if an exception occurred MessageTextBlock.Text = "Error when synchronizing: " + ex.Message; } finally { // Hide the progress bar when the sync job is complete LoadingProgressBar.Visibility = Visibility.Collapsed; } }
private void syncGeodatabase() { // 同期ジョブオブヘジェクトを作成する syncJob = geodatabaseSyncTask.SyncGeodatabase(syncParams, geodatabase); syncJob.JobChanged += (s, e) => { // 同期ジョブが終了したときのステータスを検査する if (syncJob.Status == JobStatus.Succeeded) { // 同期完了から返された値を取得する var result = syncJob.GetResultAsync(); if (result != null) { // 同期結果を確認して、例えばユーザに通知する処理を作成します ShowStatusMessage(result.Status.ToString()); } } else if (syncJob.Status == JobStatus.Failed) { // エラーの場合 ShowStatusMessage(syncJob.Error.Message); } else { var statusMessage = ""; var m = from msg in syncJob.Messages select msg.Message; statusMessage += ": " + string.Join <string>("\n", m); Console.WriteLine(statusMessage); } }; syncJob.ProgressChanged += ((object sender, EventArgs e) => { this.Dispatcher.Invoke(() => { MyProgressBar.Value = syncJob.Progress / 1.0; }); }); // geodatabase 同期のジョブを開始します syncJob.Start(); }
private async Task SyncDataAsync(IEnumerable <Geodatabase> syncGeodatabases, SyncDirection syncDirection) { foreach (var geodatabase in syncGeodatabases) { IReadOnlyList <SyncLayerResult> results = null; try { Log.Debug($"{geodatabase.Path} about to start {syncDirection} sync"); if (!geodatabase.HasLocalEdits() && syncDirection == SyncDirection.Upload) { Log.Debug("No edits skipping sync"); continue; } Log.Debug($"ServiceUrl: {geodatabase.Source}"); GeodatabaseSyncTask syncTask = await GeodatabaseSyncTask.CreateAsync(geodatabase.Source); SyncGeodatabaseParameters syncParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(geodatabase); syncParameters.GeodatabaseSyncDirection = syncDirection; SyncGeodatabaseJob job = syncTask.SyncGeodatabase(syncParameters, geodatabase); results = await job.GetResultAsync(); LogResults(results); } catch (Exception e) { Log.Error(e.Message); Log.Error($"{geodatabase.Path} did not sync"); if (results != null) { LogResults(results); } } } if (syncDirection == SyncDirection.Bidirectional || syncDirection == SyncDirection.Download) { EventAggregator.GetEvent <SyncCompleteEvent>().Publish(SyncCompleteEventArgs.Empty); } }
private async Task SyncGeodatabaes(SyncDirection syncDirection) { foreach (var gdbPath in BidirectionalGdbs) { Geodatabase geodatabase = null; IReadOnlyList <SyncLayerResult> results = null; try { geodatabase = await Geodatabase.OpenAsync(gdbPath); Log.Debug($"{geodatabase.Path} about to start {syncDirection} sync"); if (!geodatabase.HasLocalEdits() && syncDirection == SyncDirection.Upload) { Log.Debug("No edits skipping sync"); continue; } Log.Debug($"ServiceUrl: {geodatabase.Source}"); GeodatabaseSyncTask syncTask = await GeodatabaseSyncTask.CreateAsync(geodatabase.Source); SyncGeodatabaseParameters syncParameters = await syncTask.CreateDefaultSyncGeodatabaseParametersAsync(geodatabase); syncParameters.GeodatabaseSyncDirection = syncDirection; SyncGeodatabaseJob job = syncTask.SyncGeodatabase(syncParameters, geodatabase); results = await job.GetResultAsync(); LogResults(results); } catch (Exception e) { Log.Error(e.Message); Log.Error($"{geodatabase?.Path} did not sync"); LogResults(results); } } }
public static async Task <Geodatabase> DownloadOrUpdateFeatureService(String serviceUrl, Extent extent, Action <double, double> ProgressUpdate) { var task = new TaskCompletionSource <Geodatabase>(); var syncTask = await GeodatabaseSyncTask.CreateAsync(new Uri(serviceUrl)); var serviceName = PullArcgisServiceName(serviceUrl); var geodatabaseFilePath = Path.Combine(CachePath, serviceName + ".gdb"); Geodatabase ret; if (File.Exists(geodatabaseFilePath)) { //add service to existing mobile geodatabase ret = await Geodatabase.OpenAsync(geodatabaseFilePath); // create sync parameters var taskParameters = new SyncGeodatabaseParameters() { RollbackOnFailure = true, GeodatabaseSyncDirection = SyncDirection.Download }; // create a synchronize geodatabase job, pass in the parameters and the geodatabase SyncGeodatabaseJob syncGdbJob = syncTask.SyncGeodatabase(taskParameters, ret); syncGdbJob.JobChanged += (async(object sender, EventArgs e) => { var job = sender as SyncGeodatabaseJob; switch (job?.Status) { case JobStatus.Succeeded: await syncTask.UnregisterGeodatabaseAsync(ret); task.SetResult(ret); break; case JobStatus.Failed: if (job.Error != null) { task.SetException(job.Error); } else { String message = string.Empty; var m = from msg in job.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); task.SetException(new Exception(message)); } task.SetResult(null); break; } }); syncGdbJob.ProgressChanged += ((object sender, EventArgs e) => { ProgressUpdate?.Invoke(syncGdbJob.Progress, 1.0); }); // Start the job var result = await syncGdbJob.GetResultAsync(); } else { var envelope = new Envelope(extent.MinX, extent.MinY, extent.MaxX, extent.MaxY, SpatialReference.Create(extent.WKID)); // Get the default parameters for the generate geodatabase task GenerateGeodatabaseParameters generateParams = await syncTask.CreateDefaultGenerateGeodatabaseParametersAsync(envelope); // Create a generate geodatabase job var generateGdbJob = syncTask.GenerateGeodatabase(generateParams, geodatabaseFilePath); // Handle the job changed event generateGdbJob.JobChanged += (async(object sender, EventArgs e) => { var job = sender as GenerateGeodatabaseJob; switch (job?.Status) { case JobStatus.Succeeded: ret = await job.GetResultAsync(); await syncTask.UnregisterGeodatabaseAsync(ret); task.SetResult(ret); break; case JobStatus.Failed: if (job.Error != null) { task.SetException(job.Error); } else { String message = string.Empty; var m = from msg in job.Messages select msg.Message; message += ": " + string.Join <string>("\n", m); task.SetException(new Exception(message)); } task.SetResult(null); break; } }); // Handle the progress changed event (to show progress bar) generateGdbJob.ProgressChanged += ((object sender, EventArgs e) => { ProgressUpdate?.Invoke(generateGdbJob.Progress, 1.0); }); // Start the job generateGdbJob.Start(); } return(await task.Task); }