Пример #1
0
        private void HandleSyncStatusChange(SyncGeodatabaseJob job)
        {
            JobStatus status = job.Status;

            // ユーザーにジョブの完了を伝える
            if (status == JobStatus.Succeeded)
            {
                ShowStatusMessage("ジオデータベースの同期が完了しました。");
            }

            // ジョブが失敗したかどうかを確認する
            if (status == JobStatus.Failed)
            {
                // ユーザーを表示するメッセージを作成する
                string message = "ジオデータベースの同期に失敗";

                // エラーメッセージを表示する(存在する場合)
                if (job.Error != null)
                {
                    message += ": " + job.Error.Message;
                }
                else
                {
                    // エラーがなければ、ジョブからのメッセージを表示する
                    foreach (JobMessage m in job.Messages)
                    {
                        // JobMessageからテキストを取得し、出力文字列に追加
                        message += "\n" + m.Message;
                    }
                }

                // メッセージを表示する
                ShowStatusMessage(message);
            }
        }
Пример #2
0
        private void Job_JobChanged(object sender, EventArgs e)
        {
            // ジョブオブジェクトを取得します。 HandleGenerationStatusChangeに渡されます。
            SyncGeodatabaseJob job = sender as SyncGeodatabaseJob;

            // スレッド化された実装の性質上、
            // UIと対話するためにディスパッチャを使用する必要がある
            Device.BeginInvokeOnMainThread(() =>
            {
                // 適切にプログレスバーを更新する
                if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed)
                {
                    // プログレスバーの値を更新する
                    UpdateProgressBar(0);

                    // プログレスバーを非表示にする
                    myProgressBar.IsVisible = false;
                }
                else
                {
                    // プログレスバーの値を更新する
                    UpdateProgressBar(job.Progress);

                    // プログレスバーを表示する
                    myProgressBar.IsVisible = true;
                }

                // /ジョブステータスの残りの部分を変更するか
                HandleSyncStatusChange(job);
            });
        }
        private async void Job_JobChanged(object sender, EventArgs e)
        {
            // Get the job object; will be passed to HandleGenerationStatusChange
            SyncGeodatabaseJob job = sender as SyncGeodatabaseJob;

            // Due to the nature of the threading implementation,
            //     the dispatcher needs to be used to interact with the UI
            // The dispatcher takes an Action, provided here as a lambda function
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                // Update the progress bar as appropriate
                if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed)
                {
                    // Update the progress bar's value
                    UpdateProgressBar(0);

                    // Hide the progress bar
                    MyProgressBar.Visibility = Visibility.Collapsed;
                }
                else
                {
                    // Show the progress bar
                    MyProgressBar.Visibility = Visibility.Visible;
                }

                // Do the remainder of the job status changed work
                HandleSyncStatusChange(job);
            });
        }
        private void HandleSyncCompleted(SyncGeodatabaseJob job)
        {
            // Tell the user about job completion.
            if (job.Status == JobStatus.Succeeded)
            {
                ((Page)Parent).DisplayAlert("Alert", "Geodatabase synchronization succeeded.", "OK");
            }
            // See if the job failed.
            else if (job.Status == JobStatus.Failed)
            {
                // Create a message to show the user.
                string message = "Sync geodatabase job failed";

                // Show an error message (if there is one).
                if (job.Error != null)
                {
                    message += ": " + job.Error.Message;
                }
                else
                {
                    // If no error, show messages from the job.
                    foreach (JobMessage m in job.Messages)
                    {
                        // Get the text from the JobMessage and add it to the output string.
                        message += "\n" + m.Message;
                    }
                }

                // Show the message.
                ((Page)Parent).DisplayAlert("Error", message, "OK");
            }
        }
Пример #5
0
        private void Job_JobChanged(object sender, EventArgs e)
        {
            // Get the job object; will be passed to HandleGenerationStatusChange
            SyncGeodatabaseJob job = sender as SyncGeodatabaseJob;

            // Due to the nature of the threading implementation,
            //     the dispatcher needs to be used to interact with the UI
            // The dispatcher takes an Action, provided here as a lambda function
            RunOnUiThread(() =>
            {
                // Update the progress bar as appropriate
                if (job.Status == JobStatus.Succeeded || job.Status == JobStatus.Failed)
                {
                    // Update the progress bar's value
                    UpdateProgressBar(0);

                    // Hide the progress bar
                    myProgressBar.Visibility = Android.Views.ViewStates.Gone;
                }
                else
                {
                    // Show the progress bar
                    myProgressBar.Visibility = Android.Views.ViewStates.Visible;
                }

                // Do the remainder of the job status changed work
                HandleSyncStatusChange(job);
            });
        }
Пример #6
0
        private void HandleSyncCompleted(SyncGeodatabaseJob job)
        {
            JobStatus status = job.Status;

            // Tell the user about job completion.
            if (status == JobStatus.Succeeded)
            {
                ShowStatusMessage("Sync task completed");
            }

            // See if the job failed.
            if (status == JobStatus.Failed)
            {
                // Create a message to show the user.
                string message = "Sync geodatabase job failed";

                // Show an error message (if there is one).
                if (job.Error != null)
                {
                    message += ": " + job.Error.Message;
                }
                else
                {
                    // If no error, show messages from the job.
                    foreach (JobMessage m in job.Messages)
                    {
                        // Get the text from the JobMessage and add it to the output string.
                        message += "\n" + m.Message;
                    }
                }

                // Show the message.
                ShowStatusMessage(message);
            }
        }
Пример #7
0
        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;
        }
Пример #8
0
        private void Job_ProgressChanged(object sender, EventArgs e)
        {
            // Get the job object
            SyncGeodatabaseJob job = sender as SyncGeodatabaseJob;

            // Update the progress bar
            UpdateProgressBar(job.Progress);
        }
Пример #9
0
        private void Job_ProgressChanged(object sender, EventArgs e)
        {
            // ジョブオブジェクトを取得する
            SyncGeodatabaseJob job = sender as SyncGeodatabaseJob;

            // プログレスバーを更新する
            UpdateProgressBar(job.Progress);
        }
Пример #10
0
        // 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;
            }
        }
Пример #11
0
        // 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;
            }
        }
Пример #12
0
        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, 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;
            }
        }
        // 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;
            }
        }
Пример #15
0
        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();
        }
Пример #16
0
        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);
            }
        }
Пример #17
0
        private void SyncGeodatabase()
        {
            // Return if not ready
            if (_readyForEdits != EditState.Ready)
            {
                return;
            }

            // 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 status updates
            job.JobChanged += Job_JobChanged;

            // Subscribe to progress updates
            job.ProgressChanged += Job_ProgressChanged;

            // Start the sync
            job.Start();
        }
Пример #18
0
        private void SyncGeodatabase()
        {
            // Return if not ready
            if (_readyForEdits != EditState.Ready)
            {
                return;
            }

            // 同期タスクのパラメータを作成する
            SyncGeodatabaseParameters parameters = new SyncGeodatabaseParameters()
            {
                GeodatabaseSyncDirection = SyncDirection.Bidirectional,
                RollbackOnFailure        = false
            };

            // ジオデータベース内の各フィーチャテーブルのレイヤー ID を取得してから、同期ジョブに追加する
            foreach (GeodatabaseFeatureTable table in _resultGdb.GeodatabaseFeatureTables)
            {
                // レイヤーのIDを取得する
                long id = table.ServiceLayerId;

                // CSyncLayerOption を作成する
                SyncLayerOption option = new SyncLayerOption(id);

                // オプションを追加する
                parameters.LayerOptions.Add(option);
            }

            // ジョブを作成する
            SyncGeodatabaseJob job = _gdbSyncTask.SyncGeodatabase(parameters, _resultGdb);

            // ステータス更新
            job.JobChanged += Job_JobChanged;

            // プログレスバーの更新
            job.ProgressChanged += Job_ProgressChanged;

            // 同期を開始する
            job.Start();
        }
        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);
                }
            }
        }
Пример #20
0
        private void HandleSyncCompleted(SyncGeodatabaseJob job)
        {
            // Hide the progress bar & enable the sync button.
            _progressBar.Hidden = true;
            _syncButton.Enabled = true;

            // Re-enable editing.
            _myMapView.GeoViewTapped += GeoViewTapped;

            switch (job.Status)
            {
            // Tell the user about job completion.
            case JobStatus.Succeeded:
                ShowStatusMessage("Sync task completed");
                break;

            // See if the job failed.
            case JobStatus.Failed:
                // Create a message to show the user.
                string message = "Sync geodatabase job failed";

                // Show an error message (if there is one).
                if (job.Error != null)
                {
                    message += ": " + job.Error.Message;
                }
                else
                {
                    // If no error, show messages from the job.
                    message = job.Messages.Aggregate(message, (current, m) => current + "\n" + m.Message);
                }

                // Show the message.
                ShowStatusMessage(message);
                break;
            }
        }
Пример #21
0
        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);
        }